libnih-1.0.3/0000755000175000017500000000000011504742362007765 500000000000000libnih-1.0.3/config.rpath0000755000175000017500000004364711461165267012240 00000000000000#! /bin/sh # Output a system dependent set of variables, describing how to set the # run time search path of shared libraries in an executable. # # Copyright 1996-2007 Free Software Foundation, Inc. # Taken from GNU libtool, 2001 # Originally by Gordon Matzigkeit , 1996 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # # The first argument passed to this file is the canonical host specification, # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM # or # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # The environment variables CC, GCC, LDFLAGS, LD, with_gnu_ld # should be set by the caller. # # The set of defined variables is at the end of this script. # Known limitations: # - On IRIX 6.5 with CC="cc", the run time search patch must not be longer # than 256 bytes, otherwise the compiler driver will dump core. The only # known workaround is to choose shorter directory names for the build # directory and/or the installation directory. # All known linkers require a `.a' archive for static linking (except MSVC, # which needs '.lib'). libext=a shrext=.so host="$1" host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` # Code taken from libtool.m4's _LT_CC_BASENAME. for cc_temp in $CC""; do case $cc_temp in compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; \-*) ;; *) break;; esac done cc_basename=`echo "$cc_temp" | sed -e 's%^.*/%%'` # Code taken from libtool.m4's AC_LIBTOOL_PROG_COMPILER_PIC. wl= if test "$GCC" = yes; then wl='-Wl,' else case "$host_os" in aix*) wl='-Wl,' ;; darwin*) case $cc_basename in xlc*) wl='-Wl,' ;; esac ;; mingw* | cygwin* | pw32* | os2*) ;; hpux9* | hpux10* | hpux11*) wl='-Wl,' ;; irix5* | irix6* | nonstopux*) wl='-Wl,' ;; newsos6) ;; linux* | k*bsd*-gnu) case $cc_basename in icc* | ecc*) wl='-Wl,' ;; pgcc | pgf77 | pgf90) wl='-Wl,' ;; ccc*) wl='-Wl,' ;; como) wl='-lopt=' ;; *) case `$CC -V 2>&1 | sed 5q` in *Sun\ C*) wl='-Wl,' ;; esac ;; esac ;; osf3* | osf4* | osf5*) wl='-Wl,' ;; rdos*) ;; solaris*) wl='-Wl,' ;; sunos4*) wl='-Qoption ld ' ;; sysv4 | sysv4.2uw2* | sysv4.3*) wl='-Wl,' ;; sysv4*MP*) ;; sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) wl='-Wl,' ;; unicos*) wl='-Wl,' ;; uts4*) ;; esac fi # Code taken from libtool.m4's AC_LIBTOOL_PROG_LD_SHLIBS. hardcode_libdir_flag_spec= hardcode_libdir_separator= hardcode_direct=no hardcode_minus_L=no case "$host_os" in cygwin* | mingw* | pw32*) # FIXME: the MSVC++ port hasn't been tested in a loooong time # When not using gcc, we currently assume that we are using # Microsoft Visual C++. if test "$GCC" != yes; then with_gnu_ld=no fi ;; interix*) # we just hope/assume this is gcc and not c89 (= MSVC++) with_gnu_ld=yes ;; openbsd*) with_gnu_ld=no ;; esac ld_shlibs=yes if test "$with_gnu_ld" = yes; then # Set some defaults for GNU ld with shared library support. These # are reset later if shared libraries are not supported. Putting them # here allows them to be overridden if necessary. # Unlike libtool, we use -rpath here, not --rpath, since the documented # option of GNU ld is called -rpath, not --rpath. hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' case "$host_os" in aix3* | aix4* | aix5*) # On AIX/PPC, the GNU linker is very broken if test "$host_cpu" != ia64; then ld_shlibs=no fi ;; amigaos*) hardcode_libdir_flag_spec='-L$libdir' hardcode_minus_L=yes # Samuel A. Falvo II reports # that the semantics of dynamic libraries on AmigaOS, at least up # to version 4, is to share data among multiple programs linked # with the same dynamic library. Since this doesn't match the # behavior of shared libraries on other platforms, we cannot use # them. ld_shlibs=no ;; beos*) if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then : else ld_shlibs=no fi ;; cygwin* | mingw* | pw32*) # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. hardcode_libdir_flag_spec='-L$libdir' if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then : else ld_shlibs=no fi ;; interix[3-9]*) hardcode_direct=no hardcode_libdir_flag_spec='${wl}-rpath,$libdir' ;; gnu* | linux* | k*bsd*-gnu) if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then : else ld_shlibs=no fi ;; netbsd*) ;; solaris*) if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then ld_shlibs=no elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then : else ld_shlibs=no fi ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) case `$LD -v 2>&1` in *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) ld_shlibs=no ;; *) if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`' else ld_shlibs=no fi ;; esac ;; sunos4*) hardcode_direct=yes ;; *) if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then : else ld_shlibs=no fi ;; esac if test "$ld_shlibs" = no; then hardcode_libdir_flag_spec= fi else case "$host_os" in aix3*) # Note: this linker hardcodes the directories in LIBPATH if there # are no directories specified by -L. hardcode_minus_L=yes if test "$GCC" = yes; then # Neither direct hardcoding nor static linking is supported with a # broken collect2. hardcode_direct=unsupported fi ;; aix4* | aix5*) if test "$host_cpu" = ia64; then # On IA64, the linker does run time linking by default, so we don't # have to do anything special. aix_use_runtimelinking=no else aix_use_runtimelinking=no # Test if we are trying to use run time linking or normal # AIX style linking. If -brtl is somewhere in LDFLAGS, we # need to do runtime linking. case $host_os in aix4.[23]|aix4.[23].*|aix5*) for ld_flag in $LDFLAGS; do if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then aix_use_runtimelinking=yes break fi done ;; esac fi hardcode_direct=yes hardcode_libdir_separator=':' if test "$GCC" = yes; then case $host_os in aix4.[012]|aix4.[012].*) collect2name=`${CC} -print-prog-name=collect2` if test -f "$collect2name" && \ strings "$collect2name" | grep resolve_lib_name >/dev/null then # We have reworked collect2 : else # We have old collect2 hardcode_direct=unsupported hardcode_minus_L=yes hardcode_libdir_flag_spec='-L$libdir' hardcode_libdir_separator= fi ;; esac fi # Begin _LT_AC_SYS_LIBPATH_AIX. echo 'int main () { return 0; }' > conftest.c ${CC} ${LDFLAGS} conftest.c -o conftest aix_libpath=`dump -H conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } }'` if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } }'` fi if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib" fi rm -f conftest.c conftest # End _LT_AC_SYS_LIBPATH_AIX. if test "$aix_use_runtimelinking" = yes; then hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" else if test "$host_cpu" = ia64; then hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib' else hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" fi fi ;; amigaos*) hardcode_libdir_flag_spec='-L$libdir' hardcode_minus_L=yes # see comment about different semantics on the GNU ld section ld_shlibs=no ;; bsdi[45]*) ;; cygwin* | mingw* | pw32*) # When not using gcc, we currently assume that we are using # Microsoft Visual C++. # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. hardcode_libdir_flag_spec=' ' libext=lib ;; darwin* | rhapsody*) hardcode_direct=no if test "$GCC" = yes ; then : else case $cc_basename in xlc*) ;; *) ld_shlibs=no ;; esac fi ;; dgux*) hardcode_libdir_flag_spec='-L$libdir' ;; freebsd1*) ld_shlibs=no ;; freebsd2.2*) hardcode_libdir_flag_spec='-R$libdir' hardcode_direct=yes ;; freebsd2*) hardcode_direct=yes hardcode_minus_L=yes ;; freebsd* | dragonfly*) hardcode_libdir_flag_spec='-R$libdir' hardcode_direct=yes ;; hpux9*) hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' hardcode_libdir_separator=: hardcode_direct=yes # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. hardcode_minus_L=yes ;; hpux10*) if test "$with_gnu_ld" = no; then hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' hardcode_libdir_separator=: hardcode_direct=yes # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. hardcode_minus_L=yes fi ;; hpux11*) if test "$with_gnu_ld" = no; then hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' hardcode_libdir_separator=: case $host_cpu in hppa*64*|ia64*) hardcode_direct=no ;; *) hardcode_direct=yes # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. hardcode_minus_L=yes ;; esac fi ;; irix5* | irix6* | nonstopux*) hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' hardcode_libdir_separator=: ;; netbsd*) hardcode_libdir_flag_spec='-R$libdir' hardcode_direct=yes ;; newsos6) hardcode_direct=yes hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' hardcode_libdir_separator=: ;; openbsd*) if test -f /usr/libexec/ld.so; then hardcode_direct=yes if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then hardcode_libdir_flag_spec='${wl}-rpath,$libdir' else case "$host_os" in openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*) hardcode_libdir_flag_spec='-R$libdir' ;; *) hardcode_libdir_flag_spec='${wl}-rpath,$libdir' ;; esac fi else ld_shlibs=no fi ;; os2*) hardcode_libdir_flag_spec='-L$libdir' hardcode_minus_L=yes ;; osf3*) hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' hardcode_libdir_separator=: ;; osf4* | osf5*) if test "$GCC" = yes; then hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' else # Both cc and cxx compiler support -rpath directly hardcode_libdir_flag_spec='-rpath $libdir' fi hardcode_libdir_separator=: ;; solaris*) hardcode_libdir_flag_spec='-R$libdir' ;; sunos4*) hardcode_libdir_flag_spec='-L$libdir' hardcode_direct=yes hardcode_minus_L=yes ;; sysv4) case $host_vendor in sni) hardcode_direct=yes # is this really true??? ;; siemens) hardcode_direct=no ;; motorola) hardcode_direct=no #Motorola manual says yes, but my tests say they lie ;; esac ;; sysv4.3*) ;; sysv4*MP*) if test -d /usr/nec; then ld_shlibs=yes fi ;; sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) ;; sysv5* | sco3.2v5* | sco5v6*) hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`' hardcode_libdir_separator=':' ;; uts4*) hardcode_libdir_flag_spec='-L$libdir' ;; *) ld_shlibs=no ;; esac fi # Check dynamic linker characteristics # Code taken from libtool.m4's AC_LIBTOOL_SYS_DYNAMIC_LINKER. # Unlike libtool.m4, here we don't care about _all_ names of the library, but # only about the one the linker finds when passed -lNAME. This is the last # element of library_names_spec in libtool.m4, or possibly two of them if the # linker has special search rules. library_names_spec= # the last element of library_names_spec in libtool.m4 libname_spec='lib$name' case "$host_os" in aix3*) library_names_spec='$libname.a' ;; aix4* | aix5*) library_names_spec='$libname$shrext' ;; amigaos*) library_names_spec='$libname.a' ;; beos*) library_names_spec='$libname$shrext' ;; bsdi[45]*) library_names_spec='$libname$shrext' ;; cygwin* | mingw* | pw32*) shrext=.dll library_names_spec='$libname.dll.a $libname.lib' ;; darwin* | rhapsody*) shrext=.dylib library_names_spec='$libname$shrext' ;; dgux*) library_names_spec='$libname$shrext' ;; freebsd1*) ;; freebsd* | dragonfly*) case "$host_os" in freebsd[123]*) library_names_spec='$libname$shrext$versuffix' ;; *) library_names_spec='$libname$shrext' ;; esac ;; gnu*) library_names_spec='$libname$shrext' ;; hpux9* | hpux10* | hpux11*) case $host_cpu in ia64*) shrext=.so ;; hppa*64*) shrext=.sl ;; *) shrext=.sl ;; esac library_names_spec='$libname$shrext' ;; interix[3-9]*) library_names_spec='$libname$shrext' ;; irix5* | irix6* | nonstopux*) library_names_spec='$libname$shrext' case "$host_os" in irix5* | nonstopux*) libsuff= shlibsuff= ;; *) case $LD in *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") libsuff= shlibsuff= ;; *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") libsuff=32 shlibsuff=N32 ;; *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") libsuff=64 shlibsuff=64 ;; *) libsuff= shlibsuff= ;; esac ;; esac ;; linux*oldld* | linux*aout* | linux*coff*) ;; linux* | k*bsd*-gnu) library_names_spec='$libname$shrext' ;; knetbsd*-gnu) library_names_spec='$libname$shrext' ;; netbsd*) library_names_spec='$libname$shrext' ;; newsos6) library_names_spec='$libname$shrext' ;; nto-qnx*) library_names_spec='$libname$shrext' ;; openbsd*) library_names_spec='$libname$shrext$versuffix' ;; os2*) libname_spec='$name' shrext=.dll library_names_spec='$libname.a' ;; osf3* | osf4* | osf5*) library_names_spec='$libname$shrext' ;; rdos*) ;; solaris*) library_names_spec='$libname$shrext' ;; sunos4*) library_names_spec='$libname$shrext$versuffix' ;; sysv4 | sysv4.3*) library_names_spec='$libname$shrext' ;; sysv4*MP*) library_names_spec='$libname$shrext' ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) library_names_spec='$libname$shrext' ;; uts4*) library_names_spec='$libname$shrext' ;; esac sed_quote_subst='s/\(["`$\\]\)/\\\1/g' escaped_wl=`echo "X$wl" | sed -e 's/^X//' -e "$sed_quote_subst"` shlibext=`echo "$shrext" | sed -e 's,^\.,,'` escaped_libname_spec=`echo "X$libname_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` escaped_library_names_spec=`echo "X$library_names_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` escaped_hardcode_libdir_flag_spec=`echo "X$hardcode_libdir_flag_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` LC_ALL=C sed -e 's/^\([a-zA-Z0-9_]*\)=/acl_cv_\1=/' <. # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # Originally written by Alexandre Oliva . case $1 in '') echo "$0: No command. Try \`$0 --help' for more information." 1>&2 exit 1; ;; -h | --h*) cat <<\EOF Usage: depcomp [--help] [--version] PROGRAM [ARGS] Run PROGRAMS ARGS to compile a file, generating dependencies as side-effects. Environment variables: depmode Dependency tracking mode. source Source file read by `PROGRAMS ARGS'. object Object file output by `PROGRAMS ARGS'. DEPDIR directory where to store dependencies. depfile Dependency file to output. tmpdepfile Temporary file to use when outputing dependencies. libtool Whether libtool is used (yes/no). Report bugs to . EOF exit $? ;; -v | --v*) echo "depcomp $scriptversion" exit $? ;; esac if test -z "$depmode" || test -z "$source" || test -z "$object"; then echo "depcomp: Variables source, object and depmode must be set" 1>&2 exit 1 fi # Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. depfile=${depfile-`echo "$object" | sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} rm -f "$tmpdepfile" # Some modes work just like other modes, but use different flags. We # parameterize here, but still list the modes in the big case below, # to make depend.m4 easier to write. Note that we *cannot* use a case # here, because this file can only contain one case statement. if test "$depmode" = hp; then # HP compiler uses -M and no extra arg. gccflag=-M depmode=gcc fi if test "$depmode" = dashXmstdout; then # This is just like dashmstdout with a different argument. dashmflag=-xM depmode=dashmstdout fi cygpath_u="cygpath -u -f -" if test "$depmode" = msvcmsys; then # This is just like msvisualcpp but w/o cygpath translation. # Just convert the backslash-escaped backslashes to single forward # slashes to satisfy depend.m4 cygpath_u="sed s,\\\\\\\\,/,g" depmode=msvisualcpp fi case "$depmode" in gcc3) ## gcc 3 implements dependency tracking that does exactly what ## we want. Yay! Note: for some reason libtool 1.4 doesn't like ## it if -MD -MP comes after the -MF stuff. Hmm. ## Unfortunately, FreeBSD c89 acceptance of flags depends upon ## the command line argument order; so add the flags where they ## appear in depend2.am. Note that the slowdown incurred here ## affects only configure: in makefiles, %FASTDEP% shortcuts this. for arg do case $arg in -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; *) set fnord "$@" "$arg" ;; esac shift # fnord shift # $arg done "$@" stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi mv "$tmpdepfile" "$depfile" ;; gcc) ## There are various ways to get dependency output from gcc. Here's ## why we pick this rather obscure method: ## - Don't want to use -MD because we'd like the dependencies to end ## up in a subdir. Having to rename by hand is ugly. ## (We might end up doing this anyway to support other compilers.) ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like ## -MM, not -M (despite what the docs say). ## - Using -M directly means running the compiler twice (even worse ## than renaming). if test -z "$gccflag"; then gccflag=-MD, fi "$@" -Wp,"$gccflag$tmpdepfile" stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" echo "$object : \\" > "$depfile" alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ## The second -e expression handles DOS-style file names with drive letters. sed -e 's/^[^:]*: / /' \ -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" ## This next piece of magic avoids the `deleted header file' problem. ## The problem is that when a header file which appears in a .P file ## is deleted, the dependency causes make to die (because there is ## typically no way to rebuild the header). We avoid this by adding ## dummy dependencies for each header file. Too bad gcc doesn't do ## this for us directly. tr ' ' ' ' < "$tmpdepfile" | ## Some versions of gcc put a space before the `:'. On the theory ## that the space means something, we add a space to the output as ## well. ## Some versions of the HPUX 10.20 sed can't process this invocation ## correctly. Breaking it into two sed invocations is a workaround. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; hp) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; sgi) if test "$libtool" = yes; then "$@" "-Wp,-MDupdate,$tmpdepfile" else "$@" -MDupdate "$tmpdepfile" fi stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files echo "$object : \\" > "$depfile" # Clip off the initial element (the dependent). Don't try to be # clever and replace this with sed code, as IRIX sed won't handle # lines with more than a fixed number of characters (4096 in # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; # the IRIX cc adds comments like `#:fec' to the end of the # dependency line. tr ' ' ' ' < "$tmpdepfile" \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ tr ' ' ' ' >> "$depfile" echo >> "$depfile" # The second pass generates a dummy entry for each header file. tr ' ' ' ' < "$tmpdepfile" \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ >> "$depfile" else # The sourcefile does not contain any dependencies, so just # store a dummy comment line, to avoid errors with the Makefile # "include basename.Plo" scheme. echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" ;; aix) # The C for AIX Compiler uses -M and outputs the dependencies # in a .u file. In older versions, this file always lives in the # current directory. Also, the AIX compiler puts `$object:' at the # start of each line; $object doesn't have directory information. # Version 6 uses the directory in both cases. dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` test "x$dir" = "x$object" && dir= base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` if test "$libtool" = yes; then tmpdepfile1=$dir$base.u tmpdepfile2=$base.u tmpdepfile3=$dir.libs/$base.u "$@" -Wc,-M else tmpdepfile1=$dir$base.u tmpdepfile2=$dir$base.u tmpdepfile3=$dir$base.u "$@" -M fi stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" exit $stat fi for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" do test -f "$tmpdepfile" && break done if test -f "$tmpdepfile"; then # Each line is of the form `foo.o: dependent.h'. # Do two passes, one to just change these to # `$object: dependent.h' and one to simply `dependent.h:'. sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" # That's a tab and a space in the []. sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" else # The sourcefile does not contain any dependencies, so just # store a dummy comment line, to avoid errors with the Makefile # "include basename.Plo" scheme. echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" ;; icc) # Intel's C compiler understands `-MD -MF file'. However on # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c # ICC 7.0 will fill foo.d with something like # foo.o: sub/foo.c # foo.o: sub/foo.h # which is wrong. We want: # sub/foo.o: sub/foo.c # sub/foo.o: sub/foo.h # sub/foo.c: # sub/foo.h: # ICC 7.1 will output # foo.o: sub/foo.c sub/foo.h # and will wrap long lines using \ : # foo.o: sub/foo.c ... \ # sub/foo.h ... \ # ... "$@" -MD -MF "$tmpdepfile" stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" # Each line is of the form `foo.o: dependent.h', # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. # Do two passes, one to just change these to # `$object: dependent.h' and one to simply `dependent.h:'. sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" # Some versions of the HPUX 10.20 sed can't process this invocation # correctly. Breaking it into two sed invocations is a workaround. sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; hp2) # The "hp" stanza above does not work with aCC (C++) and HP's ia64 # compilers, which have integrated preprocessors. The correct option # to use with these is +Maked; it writes dependencies to a file named # 'foo.d', which lands next to the object file, wherever that # happens to be. # Much of this is similar to the tru64 case; see comments there. dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` test "x$dir" = "x$object" && dir= base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` if test "$libtool" = yes; then tmpdepfile1=$dir$base.d tmpdepfile2=$dir.libs/$base.d "$@" -Wc,+Maked else tmpdepfile1=$dir$base.d tmpdepfile2=$dir$base.d "$@" +Maked fi stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile1" "$tmpdepfile2" exit $stat fi for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" do test -f "$tmpdepfile" && break done if test -f "$tmpdepfile"; then sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile" # Add `dependent.h:' lines. sed -ne '2,${ s/^ *// s/ \\*$// s/$/:/ p }' "$tmpdepfile" >> "$depfile" else echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" "$tmpdepfile2" ;; tru64) # The Tru64 compiler uses -MD to generate dependencies as a side # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put # dependencies in `foo.d' instead, so we check for that too. # Subdirectories are respected. dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` test "x$dir" = "x$object" && dir= base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` if test "$libtool" = yes; then # With Tru64 cc, shared objects can also be used to make a # static library. This mechanism is used in libtool 1.4 series to # handle both shared and static libraries in a single compilation. # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d. # # With libtool 1.5 this exception was removed, and libtool now # generates 2 separate objects for the 2 libraries. These two # compilations output dependencies in $dir.libs/$base.o.d and # in $dir$base.o.d. We have to check for both files, because # one of the two compilations can be disabled. We should prefer # $dir$base.o.d over $dir.libs/$base.o.d because the latter is # automatically cleaned when .libs/ is deleted, while ignoring # the former would cause a distcleancheck panic. tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4 tmpdepfile2=$dir$base.o.d # libtool 1.5 tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5 tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504 "$@" -Wc,-MD else tmpdepfile1=$dir$base.o.d tmpdepfile2=$dir$base.d tmpdepfile3=$dir$base.d tmpdepfile4=$dir$base.d "$@" -MD fi stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" exit $stat fi for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" do test -f "$tmpdepfile" && break done if test -f "$tmpdepfile"; then sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" # That's a tab and a space in the []. sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" else echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" ;; #nosideeffect) # This comment above is used by automake to tell side-effect # dependency tracking mechanisms from slower ones. dashmstdout) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout, regardless of -o. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi # Remove `-o $object'. IFS=" " for arg do case $arg in -o) shift ;; $object) shift ;; *) set fnord "$@" "$arg" shift # fnord shift # $arg ;; esac done test -z "$dashmflag" && dashmflag=-M # Require at least two characters before searching for `:' # in the target name. This is to cope with DOS-style filenames: # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise. "$@" $dashmflag | sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile" rm -f "$depfile" cat < "$tmpdepfile" > "$depfile" tr ' ' ' ' < "$tmpdepfile" | \ ## Some versions of the HPUX 10.20 sed can't process this invocation ## correctly. Breaking it into two sed invocations is a workaround. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; dashXmstdout) # This case only exists to satisfy depend.m4. It is never actually # run, as this mode is specially recognized in the preamble. exit 1 ;; makedepend) "$@" || exit $? # Remove any Libtool call if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi # X makedepend shift cleared=no eat=no for arg do case $cleared in no) set ""; shift cleared=yes ;; esac if test $eat = yes; then eat=no continue fi case "$arg" in -D*|-I*) set fnord "$@" "$arg"; shift ;; # Strip any option that makedepend may not understand. Remove # the object too, otherwise makedepend will parse it as a source file. -arch) eat=yes ;; -*|$object) ;; *) set fnord "$@" "$arg"; shift ;; esac done obj_suffix=`echo "$object" | sed 's/^.*\././'` touch "$tmpdepfile" ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" rm -f "$depfile" cat < "$tmpdepfile" > "$depfile" sed '1,2d' "$tmpdepfile" | tr ' ' ' ' | \ ## Some versions of the HPUX 10.20 sed can't process this invocation ## correctly. Breaking it into two sed invocations is a workaround. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" "$tmpdepfile".bak ;; cpp) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi # Remove `-o $object'. IFS=" " for arg do case $arg in -o) shift ;; $object) shift ;; *) set fnord "$@" "$arg" shift # fnord shift # $arg ;; esac done "$@" -E | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | sed '$ s: \\$::' > "$tmpdepfile" rm -f "$depfile" echo "$object : \\" > "$depfile" cat < "$tmpdepfile" >> "$depfile" sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; msvisualcpp) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi IFS=" " for arg do case "$arg" in -o) shift ;; $object) shift ;; "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") set fnord "$@" shift shift ;; *) set fnord "$@" "$arg" shift shift ;; esac done "$@" -E 2>/dev/null | sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" rm -f "$depfile" echo "$object : \\" > "$depfile" sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" echo " " >> "$depfile" sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" rm -f "$tmpdepfile" ;; msvcmsys) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; none) exec "$@" ;; *) echo "Unknown depmode $depmode" 1>&2 exit 1 ;; esac exit 0 # Local Variables: # mode: shell-script # sh-indentation: 2 # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: libnih-1.0.3/nih/0000755000175000017500000000000011504742362010543 500000000000000libnih-1.0.3/nih/test_alloc.h0000644000175000017500000002054311445765555013006 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_TEST_ALLOC_H #define NIH_TEST_ALLOC_H #ifndef NIH_IN_TEST_H # error "This header may only be included by " #endif /* NIH_IN_TEST_H */ #include #include #include #include /* When testing, we need to be able to override the malloc, realloc and free * functions called by nih_alloc(). We can't use libc malloc hooks because * valgrind doesn't implement them - and I like valgrind. */ extern void *(*__nih_malloc)(size_t size); extern void *(*__nih_realloc)(void *ptr, size_t size); extern void (*__nih_free)(void *ptr); /** * TEST_ALLOC_SIZE: * @_ptr: allocated pointer, * @_sz: expected size. * * Check that the pointer @_ptr was allocated with nih_alloc(), and has * enough space for at least @_sz bytes. **/ #define TEST_ALLOC_SIZE(_ptr, _sz) \ if ((_ptr) == NULL) { \ TEST_FAILED ("wrong value for block %s, got unexpected NULL", \ #_ptr); \ } else if (nih_alloc_size (_ptr) < (_sz)) \ TEST_FAILED ("wrong size of block %p (%s), expected %zu got %zu", \ (_ptr), #_ptr, (size_t)(_sz), \ nih_alloc_size (_ptr)) /** * TEST_ALLOC_PARENT: * @_ptr: allocated pointer, * @_parent: expected parent. * * Check that the pointer @_ptr was allocated with nih_alloc() and has * the other block @_parent as a parent. @_parent may be the special * NULL parent. **/ #define TEST_ALLOC_PARENT(_ptr, _parent) \ if ((_ptr) == NULL) { \ TEST_FAILED ("wrong value for block %s, got unexpected NULL", \ #_ptr); \ } else if (! nih_alloc_parent ((_ptr), (_parent))) \ TEST_FAILED ("wrong parent of block %p (%s), expected %p (%s)", \ (_ptr), #_ptr, (_parent), #_parent) /** * TEST_ALLOC_NOT_PARENT: * @_ptr: allocated pointer, * @_parent: expected non-parent. * * Check that the pointer @_ptr was allocated with nih_alloc() and does not * have the other block @_parent as a parent. @_parent may be the special * NULL parent. **/ #define TEST_ALLOC_NOT_PARENT(_ptr, _parent) \ if ((_ptr) == NULL) { \ TEST_FAILED ("wrong value for block %s, got unexpected NULL", \ #_ptr); \ } else if (nih_alloc_parent ((_ptr), (_parent))) \ TEST_FAILED ("wrong parent of block %p (%s), got unexpected %p (%s)", \ (_ptr), #_ptr, (_parent), #_parent) /** * test_alloc_failed: * * Variable used by TEST_ALLOC_FAIL as the loop counter. **/ static int test_alloc_failed = 0; /** * _test_alloc_count: * * Number of times malloc is called by the TEST_ALLOC_FAIL macro. **/ static int _test_alloc_count = 0; /** * _test_alloc_call: * * Number of times malloc has been called during each cycle. **/ static int _test_alloc_call = 0; /** * _test_realloc: * * realloc() wrapper used by TEST_ALLOC_FAIL. * * When test_alloc_failed is zero, it increments test_alloc_count and returns * whatever realloc does. Otherwise it internally counts the number of times * it is called, and if that matches test_alloc_failed, then it returns NULL. **/ static inline __attribute__ ((used)) void * _test_realloc (void *ptr, size_t size) { if (! test_alloc_failed) { _test_alloc_count++; return realloc (ptr, size); } _test_alloc_call++; if (test_alloc_failed == _test_alloc_call) { errno = ENOMEM; return NULL; } else { return realloc (ptr, size); } } /** * _test_malloc: * * malloc() wrapped used by TEST_ALLOC_FAIL. * * Calls _test_realloc with a NULL pointer. **/ static inline __attribute__ ((used)) void * _test_malloc (size_t size) { return _test_realloc (NULL, size); } /** * TEST_ALLOC_FAIL: * * This macro expands to code that runs the following block repeatedly; the * first time (when the special test_alloc_failed variable is zero) is * used to determine how many allocations are performed by the following block; * subsequent calls (when test_alloc_failed is a positive integer) mean that * the test_alloc_failedth call to realloc has failed. * * This cannot be nested as it relies on setting an alternate allocator * and sharing a global state. **/ #define TEST_ALLOC_FAIL \ for (test_alloc_failed = -1, _test_alloc_count = 0; \ test_alloc_failed <= (_test_alloc_count + 1); \ test_alloc_failed++, _test_alloc_call = 0) \ if (test_alloc_failed < 0) { \ __nih_malloc = _test_malloc; \ __nih_realloc = _test_realloc; \ } else if (test_alloc_failed \ && (test_alloc_failed == \ (_test_alloc_count + 1))) { \ __nih_malloc = malloc; \ __nih_realloc = realloc; \ } else /** * TEST_ALLOC_SAFE: * * This macro may be used within a TEST_ALLOC_FAIL block to guard the * following block of code from failing allocation. **/ #define TEST_ALLOC_SAFE \ for (int _test_alloc_safe = 0; _test_alloc_safe < 3; \ _test_alloc_safe++) \ if (_test_alloc_safe < 1) { \ __nih_malloc = malloc; \ __nih_realloc = realloc; \ } else if (_test_alloc_safe > 1) { \ __nih_malloc = _test_malloc; \ __nih_realloc = _test_realloc; \ } else /** * struct _test_free_tag: * @entry: list entry, * @ptr: tagged object. * * This structure is used to find out whether an nih_alloc() allocated object * has been freed or not. It works by being allocated as a child of the * tagged object, and added to a linked list of known tags. When freed, * it is removed from the linked list. **/ struct _test_free_tag { NihList entry; void *ptr; }; /** * _test_free_tags: * * Linked list of tagged blocks. **/ static NihList _test_free_tags = { NULL, NULL }; /** * _test_free_tag: * @ptr: tagged object. * * Returns: TRUE if @ptr is tagged (not freed), FALSE if not (freed). **/ static inline int _test_free_tag (void *ptr) { NIH_LIST_FOREACH (&_test_free_tags, iter) { struct _test_free_tag *tag = (struct _test_free_tag *)iter; if (tag->ptr == ptr) return TRUE; } return FALSE; } /** * TEST_FREE_TAG: * @_ptr: allocated object. * * This macro is used to tag an nih_alloc() allocated object to determine * whether or not it is freed. It works by allocating a child object of * @_ptr and storing it in a linked list. * * This can be tested with either the TEST_FREE or TEST_NOT_FREE macros as * many times as you like. **/ #define TEST_FREE_TAG(_ptr) \ do { \ void *(*_test__nih_malloc)(size_t size) = __nih_malloc; \ struct _test_free_tag *_test_tag; \ \ __nih_malloc = malloc; \ _test_tag = nih_new ((_ptr), struct _test_free_tag); \ assert ((_ptr) != NULL); \ __nih_malloc = _test__nih_malloc; \ \ nih_list_init (&_test_tag->entry); \ _test_tag->ptr = (_ptr); \ nih_alloc_set_destructor (_test_tag, nih_list_destroy); \ \ if (! _test_free_tags.next) \ nih_list_init (&_test_free_tags); \ nih_list_add (&_test_free_tags, &_test_tag->entry); \ } while (0) /** * TEST_FREE: * @_ptr: allocated object. * * Check that the nih_alloc() allocated object @_ptr was freed as expected; it * must have been first prepared by using TEST_FREE_TAG on it otherwise this * will always fail. **/ #define TEST_FREE(_ptr) \ if (_test_free_tag (_ptr)) \ TEST_FAILED ("block %p (%s) not freed as expected", \ (_ptr), #_ptr) /** * TEST_NOT_FREE: * @_ptr: allocated block. * * Check that the nih_alloc() allocated object @_ptr was not freed * unexpectedly; it must have been first prepared by using TEST_FREE_TAG * on it otherwise this will always succeed. **/ #define TEST_NOT_FREE(_ptr) \ if (! _test_free_tag (_ptr)) \ TEST_FAILED ("block %p (%s) freed unexpectedly", \ (_ptr), #_ptr) #endif /* NIH_TEST_ALLOC_H */ libnih-1.0.3/nih/io.h0000644000175000017500000002557011445765555011271 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_IO_H #define NIH_IO_H #include #include #include #include /** * NihIoType: * * Whether an NihIo structure is used for a buffered stream of data, or * a queue of discreet messages. **/ typedef enum { NIH_IO_STREAM, NIH_IO_MESSAGE } NihIoType; /** * NihIoEvents: * * Events that we can watch for, generally used as a bit mask of the events * that have occurred. **/ typedef enum { NIH_IO_NONE = 00, NIH_IO_READ = 01, NIH_IO_WRITE = 02, NIH_IO_EXCEPT = 04, } NihIoEvents; /* Predefine the typedefs as we use them in the callbacks */ typedef struct nih_io_watch NihIoWatch; typedef struct nih_io NihIo; /** * NihIoWatcher: * @data: data pointer given when registered, * @watch: #NihIoWatch for which an event occurred, * @events: events that occurred. * * An I/O watcher is a function that is called whenever an event occurs * on a file descriptor or socket being watched. It is safe for the * watcher to remove the watch during the call. **/ typedef void (*NihIoWatcher) (void *data, NihIoWatch *watch, NihIoEvents events); /** * NihIoReader: * @data: data pointer given when registered, * @io: NihIo with data to be read, * @buf: buffer data is available in, * @len: bytes in @buf. * * An I/O reader is a function that is called whenever new data or a new * message has been received on a file descriptor or socket and placed * into the receive buffer or queue. * * In stream mode, @buf and @len will point to the entire receive buffer * and this function need not clear the buffer, it is entirely permitted * for the data to be left there. When further data arrives, the buffer * will be extended and the reader called again. * * In message mode, @buf and @len will point to the contents of the oldest * message in the receive queue. You'll almost certainly want to remove * this message from the queue, otherwise when a new message arrives, the * function will still be called with the same oldest message. * * It is safe to call nih_io_close() from within the reader function, this * results in the structure being flagged to be closed when the watcher * that invokes it has finished. You must not nih_free() @io or cause it * to be freed from within this function, except by nih_io_close(). **/ typedef void (*NihIoReader) (void *data, NihIo *io, const char *buf, size_t len); /** * NihIoCloseHandler: * @data: data pointer given when registered. * @io: NihIo that closed. * * An I/O close handler is a function that is called when the remote end * of a file descriptor or socket is closed and data can no longer be * read from it. * * It should take appropriate action, which may include closing the * file descriptor with nih_io_close(). You must not nih_free() @io or * cause it to be freed from within this function, except by nih_io_close(). **/ typedef void (*NihIoCloseHandler) (void *data, NihIo *io); /** * NihIoErrorHandler: * @data: data pointer given when registered, * @io: NihIo that caused the error. * * An I/O error handler is a function that is called to handle an error * raise while reading from the file descriptor or socket. The error * itself can be obtained using nih_error_get(). * * It should take appropriate action, which may include closing the * file descriptor with nih_io_close(). You must not nih_free() @io or * cause it to be freed from within this function, except by nih_io_close(). **/ typedef void (*NihIoErrorHandler) (void *data, NihIo *io); /** * NihIoWatch: * @entry: list header, * @fd: file descriptor, * @events: events to watch for, * @watcher: function called when @events occur on @fd, * @data: pointer passed to @watcher. * * This structure represents the most basic kind of I/O handling, a watch * on a file descriptor or socket that causes a function to be called * when listed events occur. * * The watch can be cancelled by calling nih_list_remove() on the structure * as they are held in a list internally. **/ struct nih_io_watch { NihList entry; int fd; NihIoEvents events; NihIoWatcher watcher; void *data; }; /** * NihIoBuffer: * @buf: memory allocated for buffer, * @size: allocated size of @buf, * @len: number of bytes of @buf used. * * This structure is used to represent a buffer holding data that is * waiting to be sent or processed. **/ typedef struct nih_io_buffer { char *buf; size_t size; size_t len; } NihIoBuffer; /** * NihIoMessage: * @entry: list header, * @addr: address received from or to be sent to, * @addrlen: length of @addr, * @data: buffer for message data, * @control: NULL-terminated array of control messages, * @int_data: user-supplied integer data, * @ptr_data: user-supplied pointer data. * * This structure is used to represent an individual message waiting in * a queue to be sent or processed. * * When a message is in the queue, it is sometimes useful to be able to * associate it with the source or destination of the message, for example * when handling errors. You may use the @int_data or @ptr_member to store * an integer or pointer value that is useful to you. These are not usually * initialised. **/ typedef struct nih_io_message { NihList entry; struct sockaddr *addr; socklen_t addrlen; NihIoBuffer *data; struct cmsghdr **control; union { int int_data; void *ptr_data; }; } NihIoMessage; /** * NihIo: * @type: type of structure, * @watch: associated file descriptor watch, * @send_buf: buffer that pools data to be sent (NIH_IO_STREAM), * @send_q: queue of messages to be sent (NIH_IO_MESSAGE), * @recv_buf: buffer that pools data received (NIH_IO_STREAM), * @recv_q: queue of messages received (NIH_IO_MESSAGE), * @reader: function called when new data in @recv_buf or @recv_q, * @close_handler: function called when socket closes, * @error_handler: function called when an error occurs, * @data: pointer passed to functions, * @shutdown: TRUE if the structure should be freed once the buffers are empty, * @free: pointer to variable to set to TRUE if freed during the watcher. * * This structure implements more featureful I/O handling than provided by * an NihIoWatch alone. * * When used in the stream mode (@type is NIH_IO_STREAM), it combines an * NihIoWatch and two NihIoBuffer structures to implement a high-throughput * alternative to the traditional stdio functions. * * Those functions are optimised to reduce the number of read() or write() * calls made on a file descriptor, and cannot be used to pool large * amounts of data for processing. * * The NihIo functions are instead optimised for being able to queue and * receive much data as possible, and have the data sent in the background * or processed at your leisure. * * When used in the message mode (@type is NIH_IO_MESSAGE), it combines the * NihIoWatch with an NihList of NihIoMessage structures to implement * asynchronous handling of datagram sockets. **/ struct nih_io { NihIoType type; NihIoWatch *watch; union { NihIoBuffer *send_buf; NihList *send_q; }; union { NihIoBuffer *recv_buf; NihList *recv_q; }; NihIoReader reader; NihIoCloseHandler close_handler; NihIoErrorHandler error_handler; void *data; int shutdown; int *free; }; NIH_BEGIN_EXTERN extern NihList *nih_io_watches; void nih_io_init (void); NihIoWatch * nih_io_add_watch (const void *parent, int fd, NihIoEvents events, NihIoWatcher watcher, void *data) __attribute__ ((warn_unused_result, malloc)); void nih_io_select_fds (int *nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds); void nih_io_handle_fds (fd_set *readfds, fd_set *writewfds, fd_set *exceptfds); NihIoBuffer * nih_io_buffer_new (const void *parent) __attribute__ ((warn_unused_result, malloc)); int nih_io_buffer_resize (NihIoBuffer *buffer, size_t grow); char * nih_io_buffer_pop (const void *parent, NihIoBuffer *buffer, size_t *len) __attribute__ ((warn_unused_result, malloc)); void nih_io_buffer_shrink (NihIoBuffer *buffer, size_t len); int nih_io_buffer_push (NihIoBuffer *buffer, const char *str, size_t len) __attribute__ ((warn_unused_result)); NihIoMessage *nih_io_message_new (const void *parent) __attribute__ ((warn_unused_result, malloc)); int nih_io_message_add_control (NihIoMessage *message, int level, int type, socklen_t len, const void *data) __attribute__ ((warn_unused_result)); NihIoMessage *nih_io_message_recv (const void *parent, int fd, size_t *len) __attribute__ ((warn_unused_result, malloc)); ssize_t nih_io_message_send (NihIoMessage *message, int fd) __attribute__ ((warn_unused_result)); NihIo * nih_io_reopen (const void *parent, int fd, NihIoType type, NihIoReader reader, NihIoCloseHandler close_handler, NihIoErrorHandler error_handler, void *data) __attribute__ ((warn_unused_result, malloc)); void nih_io_shutdown (NihIo *io); int nih_io_destroy (NihIo *io); NihIoMessage *nih_io_read_message (const void *parent, NihIo *io); void nih_io_send_message (NihIo *io, NihIoMessage *message); char * nih_io_read (const void *parent, NihIo *io, size_t *len) __attribute__ ((warn_unused_result, malloc)); int nih_io_write (NihIo *io, const char *str, size_t len) __attribute__ ((warn_unused_result)); char * nih_io_get (const void *parent, NihIo *io, const char *delim) __attribute__ ((warn_unused_result, malloc)); int nih_io_printf (NihIo *io, const char *format, ...) __attribute__ ((warn_unused_result, format (printf, 2, 3))); int nih_io_set_nonblock (int fd); int nih_io_set_cloexec (int fd); ssize_t nih_io_get_family (int fd); NIH_END_EXTERN #endif /* NIH_IO_H */ libnih-1.0.3/nih/macros.h0000644000175000017500000001315111445765555012136 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_MACROS_H #define NIH_MACROS_H /** * This header tends to be included by every file that uses libnih, it makes * sure various sensible macros and types (including standard ones from the * C library) are defined. **/ /* Get standard definitions from C library */ #include #include #ifdef __cplusplus /** * NIH_BEGIN_EXTERN: * * Use before beginning external definitions in header files, so that they * may be safely included from C++ code. Must be paired with NIH_END_EXTERN. **/ # define NIH_BEGIN_EXTERN extern "C" { /** * NIH_END_EXTERN: * * Use after external definitions in header files, so that they may be safely * included from C++ code. Must be paired with NIH_BEGIN_EXTERN. **/ # define NIH_END_EXTERN } #else # define NIH_BEGIN_EXTERN # define NIH_END_EXTERN #endif /* __cplusplus */ /** * FALSE: * * Defined to be zero. **/ #ifndef FALSE # define FALSE 0 #endif /* FALSE */ /** * TRUE: * * Defined to be the opposite of zero, you don't need to know what that is ;) **/ #ifndef TRUE # define TRUE (!FALSE) #endif /* TRUE */ /** * nih_min: * @_a: first value, * @_b: second value. * * Compares the two values @_a and @_b, which must be compatible C types. * * Returns: the smaller of the two values. **/ #define nih_min(_a, _b) \ ({ typeof (_a) __a = (_a); typeof (_b) __b = (_b); \ __a < __b ? __a : __b; }) /** * nih_max: * @_a: first value, * @_b: second value. * * Compares the two values @_a and @_b, which must be compatible C types. * * Returns: the larger of the two values. **/ #define nih_max(_a, _b) \ ({ typeof (_a) __a = (_a); typeof (_b) __b = (_b); \ __a > __b ? __a : __b; }) /** * NIH_ALIGN_SIZE: * * In general, pointer alignment is something that the compiler takes care * of for us; but in some situations (e.g. nih_alloc) we need to return a * pointer that is generically aligned for any data type without actually * knowing the data type. * * This is a good guess as to the largest alignment of the platform, based * on recommendations in the C standard and comments in GNU libc. **/ #define NIH_ALIGN_SIZE nih_max(2 * sizeof (size_t), \ __alignof__ (long long)) /** * NIH_STRINGIFY: * @_s: macro. * * Turns the macro @_s into a string. **/ #define _STRINGIFY_AGAIN(_s) #_s #define NIH_STRINGIFY(_s) _STRINGIFY_AGAIN(_s) /** * NIH_LIKELY: * @_e: C expression. * * Indicates to the compiler that the expression @_e is likely to be true, * can aid optimisation when used properly. **/ #define NIH_LIKELY(_e) __builtin_expect ((_e) ? TRUE : FALSE, TRUE) /** * NIH_UNLIKELY: * @_e: C expression. * * Indicates to the compiler that the expression @_e is likely to be false, * can aid optimisation when used properly. **/ #define NIH_UNLIKELY(_e) __builtin_expect ((_e) ? TRUE : FALSE, FALSE) /** * NIH_MUST: * @_e: C expression. * * Repeats the expression @_e until it yields a true value, normally used * around functions that perform memory allocation and return a pointer to * spin in out-of-memory situations. * * For situations where the the expression can raise an NihError and returns * false, where an error can include out-of-memory, you may want to use * NIH_SHOULD() to spin on OOM but break on other conditions. * * Returns: value of expression @_e which will be evaluated as many times * as necessary to become true. **/ #define NIH_MUST(_e) \ ({ typeof (_e) __ret; while (! (__ret = (_e))); __ret; }) /** * NIH_ZERO: * @_e: C expression. * * Repeats the expression @_e until it yields a zero value, normally used * around functions that return zero to indicate success and non-zero to * indicate a temporary failure. * * Returns: value of expression @_e which will be evaluated as many times * as necessary to become zero. **/ #define NIH_ZERO(_e) \ ({ typeof (_e) __ret; while ((__ret = (_e))); __ret; }) /* Make gettext friendlier */ #if ENABLE_NLS # include # include /** * _: * @_str: * * Marks the string @str for translation, if gettext is available. * * Returns: @_str or translated string. **/ # define _(_str) gettext (_str) /** * _n: * @_str1: singular form, * @_str2: plural form, * @_num: number. * * Selects the appropriate plural form from @_str1 and @_str2 based on @_num, * translating if gettext is available. * * Returns: @_str1, @_str2 or translated string. **/ # define _n(_str1, _str2, _num) ngettext (_str1, _str2, _num) /** * N_: * @_str: * * Marks the static string @_str for translation by gettext, but does not * return the translation. You must call gettext() on the string before * presenting it to the user. * * Returns: @_str **/ # define N_(_str) (_str) #else /* ENABLE_NLS */ # define _(_str) (_str) # define _n(_str1, _str2, _num) ((_num) == 1 ? (_str1) : (_str2)) # define N_(_str) (_str) #endif /* ENABLE_NLS */ #endif /* NIH_MACROS_H */ libnih-1.0.3/nih/file.h0000644000175000017500000000654311445765555011600 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_FILE_H #define NIH_FILE_H #include #include #include #include /** * NihFileFilter: * @data: data pointer, * @path: path to file, * @is_dir: TRUE if @path is a directory. * * A file filter is a function that can be called to determine whether * a particular path should be ignored because of its filename. * * Returns: TRUE if the path should be ignored, FALSE otherwise. **/ typedef int (*NihFileFilter) (void *data, const char *path, int is_dir); /** * NihFileVisitor: * @data: data pointer given to nih_dir_walk(), * @dirname: top-level path being walked, * @path: path to file, * @statbuf: stat of @path. * * A file visitor is a function that can be called for a filesystem object * visited by nih_dir_walk() that does not match the filter given to that * function. * * Returns: zero on success, negative value on raised error. **/ typedef int (*NihFileVisitor) (void *data, const char *dirname, const char *path, struct stat *statbuf); /** * NihFileErrorHandler: * @data: data pointer given to nih_dir_walk(), * @dirname: top-level path being walked, * @path: path to file, * @statbuf: stat of @path. * * A file error handler is a function called whenever the visitor function * returns a raised error, or the attempt to walk @path fails. Note that * @statbuf might be invalid if it was stat() that failed. * * This function should handle the error and return zero; alternatively * it may raise the error again (or a different error) and return a negative * value to abort the tree walk. * * Returns: zero on success, negative value on raised error. **/ typedef int (*NihFileErrorHandler) (void *data, const char *dirname, const char *path, struct stat *statbuf); NIH_BEGIN_EXTERN char *nih_file_read (const void *parent, const char *path, size_t *length) __attribute__ ((warn_unused_result, malloc)); void *nih_file_map (const char *path, int flags, size_t *length) __attribute__ ((warn_unused_result)); int nih_file_unmap (void *map, size_t length); int nih_file_is_hidden (const char *path); int nih_file_is_backup (const char *path); int nih_file_is_swap (const char *path); int nih_file_is_rcs (const char *path); int nih_file_is_packaging (const char *path); int nih_file_ignore (void *data, const char *path); int nih_dir_walk (const char *path, NihFileFilter filter, NihFileVisitor visitor, NihFileErrorHandler error, void *data) __attribute__ ((warn_unused_result)); NIH_END_EXTERN #endif /* NIH_FILE_H */ libnih-1.0.3/nih/watch.c0000644000175000017500000003742511445765555011765 00000000000000/* libnih * * watch.c - watching of files and directories with inotify * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /** * INOTIFY_EVENTS: * * The standard set of inotify events we use for watching any path; if * people want a different set, they can use inotify_add_watch() directly. **/ #define INOTIFY_EVENTS (IN_CREATE | IN_DELETE | IN_CLOSE_WRITE \ | IN_MOVE | IN_MOVE_SELF) /* Prototypes for static functions */ static NihWatchHandle *nih_watch_handle_by_wd (NihWatch *watch, int wd); static NihWatchHandle *nih_watch_handle_by_path (NihWatch *watch, const char *path); static int nih_watch_add_visitor (NihWatch *watch, const char *dirname, const char *path, struct stat *statbuf) __attribute__ ((warn_unused_result)); static void nih_watch_reader (NihWatch *watch, NihIo *io, const char *buf, size_t len); static void nih_watch_handle (NihWatch *watch, NihWatchHandle *handle, uint32_t events, uint32_t cookie, const char *name, int *caught_free); /** * nih_watch_new: * @parent: parent object for new watch, * @path: full path to be watched, * @subdirs: include sub-directories of @path, * @create: call @create_handler for existing files, * @filter: function to filter paths watched, * @create_handler: function called when a path is created, * @modify_handler: function called when a path is modified, * @delete_handler: function called when a path is deleted, * @data: pointer to pass to functions. * * Watches @path for changes, which may be either a single file or a * directory. If @path is a directory, then sub-directories can be included * by setting @subdirs to TRUE; both existing and newly created * sub-directories will be automatically watched. * * Additionally, the set of files and directories within @path can be * limited by passing a @filter function which will recieve the paths and * may return TRUE to indicate that the path received should not be watched. * * When a file is created within @path, or moved from outside this location * into it, @create_handler will be called. If @path is removed, or a file * is removed within @path, or moved to a location outside it, * @delete_handler will be called. Finally if @path is modified, or a file * within it is modified, @modify_handler will be called. * * If @create is TRUE, @create_handler will also be called for all of the * files that exist under @path when the watch is first added. This only * occurs if the watch can be added. * * This is a very high level wrapped around the inotify API; lower levels * can be obtained using the inotify API itself and some of the helper * functions used by this one. * * The returned watch structure is allocated with nih_alloc(), and contains * open inotify descriptors and child structures including NihIo, which are * children of the returned structure; there is no non-allocated version * because of this. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned watch. When all parents * of the returned watch are freed, the returned watch will also be * freed. * * Returns: new NihWatch structure, or NULL on raised error. **/ NihWatch * nih_watch_new (const void *parent, const char *path, int subdirs, int create, NihFileFilter filter, NihCreateHandler create_handler, NihModifyHandler modify_handler, NihDeleteHandler delete_handler, void *data) { NihWatch *watch; nih_assert (path != NULL); /* Allocate the NihWatch structure */ watch = NIH_MUST (nih_new (parent, NihWatch)); watch->path = NIH_MUST (nih_strdup (watch, path)); watch->created = NIH_MUST (nih_hash_string_new (watch, 0)); watch->subdirs = subdirs; watch->create = create; watch->filter = filter; watch->create_handler = create_handler; watch->modify_handler = modify_handler; watch->delete_handler = delete_handler; watch->data = data; watch->free = NULL; /* Open an inotify instance file descriptor */ watch->fd = inotify_init (); if (watch->fd < 0) { nih_error_raise_system (); nih_free (watch); return NULL; } /* Add the path (and subdirs) to the list of watches */ nih_list_init (&watch->watches); if (nih_watch_add (watch, path, subdirs) < 0) { close (watch->fd); nih_free (watch); return NULL; } /* Create an NihIo to handle incoming events. */ watch->io = NIH_SHOULD (nih_io_reopen (watch, watch->fd, NIH_IO_STREAM, (NihIoReader)nih_watch_reader, NULL, NULL, watch)); if (! watch->io) { close (watch->fd); nih_free (watch); return NULL; } nih_alloc_set_destructor (watch, nih_watch_destroy); return watch; } /** * nih_watch_handle_by_wd: * @watch: watch to search, * @wd: inotify watch descriptor. * * Searches @watch for the path that @wd is handling. * * Returns: NihWatchHandle for @wd, or NULL if none known. **/ static NihWatchHandle * nih_watch_handle_by_wd (NihWatch *watch, int wd) { nih_assert (watch != NULL); nih_assert (wd >= 0); NIH_LIST_FOREACH (&watch->watches, iter) { NihWatchHandle *handle = (NihWatchHandle *)iter; if (handle->wd == wd) return handle; } return NULL; } /** * nih_watch_handle_by_path: * @watch: watch to search, * @path: path being watched. * * Searches @watch for the watch descriptor that is handling @path. * * Returns: NihWatchHandle for @path, or NULL if none known. **/ static NihWatchHandle * nih_watch_handle_by_path (NihWatch *watch, const char *path) { nih_assert (watch != NULL); nih_assert (path != NULL); NIH_LIST_FOREACH (&watch->watches, iter) { NihWatchHandle *handle = (NihWatchHandle *)iter; if (! strcmp (handle->path, path)) return handle; } return NULL; } /** * nih_watch_add: * @watch: NihWatch to change, * @path: path to be watched, * @subdirs: also watch sub-directories? * * Adds a new @path to be watched to the existing @watch structure, the * same handlers will be called. @path need not be related to the path * originally given to @watch. * * If @subdirs is TRUE, and @path is a directory, then sub-directories of * the path are also watched. * * An NihWatchHandle structure is allocated and stored in the watches * member of @watch, it is also a child of that structure; there is no * non-allocated version of this because of this. * * Returns: zero on success, negative value on raised error. **/ int nih_watch_add (NihWatch *watch, const char *path, int subdirs) { NihWatchHandle *handle; nih_assert (watch != NULL); nih_assert (path != NULL); /* Allocate the NihWatchHandle structure */ handle = NIH_MUST (nih_new (watch, NihWatchHandle)); handle->path = NIH_MUST (nih_strdup (handle, path)); nih_list_init (&handle->entry); nih_alloc_set_destructor (handle, nih_list_destroy); /* Get a watch descriptor for the path */ handle->wd = inotify_add_watch (watch->fd, path, INOTIFY_EVENTS); if (handle->wd < 0) { nih_error_raise_system (); nih_free (handle); return -1; } /* Check for duplicates in the list */ if (nih_watch_handle_by_wd (watch, handle->wd)) { nih_free (handle); return 0; } nih_list_add (&watch->watches, &handle->entry); /* Recurse into sub-directories, attempting to add a watch for each * one; errors within the walk are warned automatically, so if this * fails, it means we literally couldn't watch the top-level. */ if (subdirs && (nih_dir_walk (path, watch->filter, (NihFileVisitor)nih_watch_add_visitor, NULL, watch) < 0)) { NihError *err; err = nih_error_get (); if (err->number != ENOTDIR) { nih_free (handle); return -1; } else nih_free (err); } return 0; } /** * nih_watch_add_visitor: * @watch: watch to add to, * @dirname: top-level being watched, * @path: path to add, * @statbuf: stat of @path. * * Callback function for nih_dir_walk(), used by nih_watch_add() to add * sub-directories. Just calls nih_watch_add() with subdirs as FALSE for * each directory found. * * If the create member of @watch is TRUE, it also calls the create handle * for each path found. * * Returns: zero on success, negative value on raised error. **/ static int nih_watch_add_visitor (NihWatch *watch, const char *dirname, const char *path, struct stat *statbuf) { nih_assert (watch != NULL); nih_assert (dirname != NULL); nih_assert (path != NULL); nih_assert (statbuf != NULL); if (watch->create && watch->create_handler) watch->create_handler (watch->data, watch, path, statbuf); if (S_ISDIR (statbuf->st_mode)) { int ret; ret = nih_watch_add (watch, path, FALSE); if (ret < 0) return ret; } return 0; } /** * nih_watch_destroy: * @watch: NihWatch to be destroyed. * * Closes the inotify descriptor and frees the NihIo instance handling it. * * Normally used or called from an nih_alloc() destructor. * * Returns: zero. **/ int nih_watch_destroy (NihWatch *watch) { nih_assert (watch != NULL); if (watch->free) *watch->free = TRUE; return 0; } /** * nih_watch_reader: * @watch: NihWatch for descriptor, * @io: NihIo with data to be read, * @buf: buffer data is available in, * @len: bytes in @buf. * * This function is called whenever there is data to be read on the inotify * file descriptor associated with @watch. Each event in the buffer is read, * including the following name, and handled by calling one of the functions * in @watch. **/ static void nih_watch_reader (NihWatch *watch, NihIo *io, const char *buf, size_t len) { int caught_free; nih_assert (watch != NULL); nih_assert (io != NULL); nih_assert (buf != NULL); nih_assert (len > 0); caught_free = FALSE; if (! watch->free) watch->free = &caught_free; while (len > 0) { NihWatchHandle *handle; struct inotify_event *event; size_t sz; /* Wait until there's a complete event waiting * (should always be true, but better to be safe than sorry) */ sz = sizeof (struct inotify_event); if (len < sz) goto finish; /* Never read an event without its name (again should always * be true */ event = (struct inotify_event *) buf; sz += event->len; if (len < sz) goto finish; /* Find the handle for this watch */ handle = nih_watch_handle_by_wd (watch, event->wd); if (handle) nih_watch_handle (watch, handle, event->mask, event->cookie, event->name, &caught_free); /* Check whether the user freed the watch from inside the * handler. Just drop out now; everything we had has gone. */ if (caught_free) return; /* Remove the event from the front of the buffer, and * decrease our own length counter. */ nih_io_buffer_shrink (io->recv_buf, sz); len -= sz; } finish: if (watch->free == &caught_free) watch->free = NULL; } /** * nih_watch_handle: * @watch: NihWatch for descriptor, * @handle: NihWatchHandle for individual path, * @events: inotify events mask, * @cookie: unique cookie for renames, * @name: name of path under @handle, * @caught_free: set to TRUE if the watch is freed. * * This handler is called when an event occurs for an individual watch * handle, it deals with the event and ensures that the @watch handlers * are called. **/ static void nih_watch_handle (NihWatch *watch, NihWatchHandle *handle, uint32_t events, uint32_t cookie, const char *name, int *caught_free) { NihListEntry *entry; int delayed = FALSE; struct stat statbuf; nih_local char *path = NULL; nih_assert (watch != NULL); nih_assert (handle != NULL); /* First check whether this event is being caused by the actual * path being watched by the handle being deleted or moved. In * either case, we drop the watch because we've lost the path. */ if ((events & IN_IGNORED) || (events & IN_MOVE_SELF)) { if (watch->delete_handler) watch->delete_handler (watch->data, watch, handle->path); if (*caught_free) return; nih_debug ("Ceasing watch on %s", handle->path); nih_free (handle); return; } /* Every other event must come with a name. */ if ((! name) || strchr (name, '/')) return; path = NIH_MUST (nih_sprintf (NULL, "%s/%s", handle->path, name)); /* Check the filter */ if (watch->filter && watch->filter (watch->data, path, events & IN_ISDIR)) return; /* Look to see whether we have a delayed create handler for this * path - it's handled differently depending on the events and * file type. */ entry = (NihListEntry *)nih_hash_lookup (watch->created, path); if (entry) { delayed = TRUE; nih_free (entry); } /* Handle it differently depending on the events mask */ if ((events & IN_CREATE) || (events & IN_MOVED_TO)) { if (stat (path, &statbuf) < 0) return; /* Delay the create handler when files are first created. */ if ((events & IN_CREATE) && (! S_ISDIR (statbuf.st_mode))) { entry = NIH_MUST (nih_list_entry_new (watch)); nih_ref (path, entry); entry->str = path; nih_hash_add (watch->created, &entry->entry); return; } if (watch->create_handler) watch->create_handler (watch->data, watch, path, &statbuf); if (*caught_free) return; /* See if it's a sub-directory, and we're handling those * ourselves. Add a watch to the directory and any * sub-directories within it. */ if (watch->subdirs && S_ISDIR (statbuf.st_mode)) { if (nih_watch_add (watch, path, TRUE) < 0) { NihError *err; err = nih_error_get (); nih_warn ("%s: %s: %s", path, _("Unable to watch directory"), err->message); nih_free (err); } } } else if (events & IN_CLOSE_WRITE) { if (stat (path, &statbuf) < 0) return; /* Use the create handler when a newly created file is * closed. */ if (delayed && watch->create_handler) { watch->create_handler (watch->data, watch, path, &statbuf); } else if (watch->modify_handler) watch->modify_handler (watch->data, watch, path, &statbuf); if (*caught_free) return; } else if ((events & IN_DELETE) || (events & IN_MOVED_FROM)) { NihWatchHandle *path_handle; /* Suppress the handler if the file was newly created. */ if ((! delayed) && watch->delete_handler) watch->delete_handler (watch->data, watch, path); if (*caught_free) return; /* If there's a watch for that path, we act as if it got * IN_IGNORED or IN_MOVE_SELF; just in case it's a symlink * that's getting removed or something. */ path_handle = nih_watch_handle_by_path (watch, path); if (path_handle) { nih_debug ("Ceasing watch on %s", path_handle->path); nih_free (path_handle); } } } libnih-1.0.3/nih/test_hash.h0000644000175000017500000000340011445765555012630 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_TEST_HASH_H #define NIH_TEST_HASH_H #ifndef NIH_IN_TEST_H # error "This header may only be included by " #endif /* NIH_IN_TEST_H */ #include #include /** * TEST_HASH_EMPTY: * @_hash: hash table. * * Check that the hash table @_hash is empty. **/ #define TEST_HASH_EMPTY(_hash) \ for (size_t _hash_i = 0; _hash_i < (_hash)->size; _hash_i++) \ if (! NIH_LIST_EMPTY (&(_hash)->bins[_hash_i])) \ TEST_FAILED ("hash %p (%s) not empty as expected", \ (_hash), #_hash) /** * TEST_HASH_NOT_EMPTY: * @_list: entry in list. * * Check that the hash table @_hash is not empty. **/ #define TEST_HASH_NOT_EMPTY(_hash) \ do { \ int _hash_empty = 1; \ for (size_t _hash_i = 0; _hash_i < (_hash)->size; _hash_i++) \ if (! NIH_LIST_EMPTY (&(_hash)->bins[_hash_i])) \ _hash_empty = 0; \ if (_hash_empty) \ TEST_FAILED ("hash %p (%s) empty, expected multiple members", \ (_hash), #_hash); \ } while (0) #endif /* NIH_TEST_HASH_H */ libnih-1.0.3/nih/config.c0000644000175000017500000007755611445765555012135 00000000000000/* libnih * * config.c - configuration file parsing * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include #include /* Prototypes for static functions */ static int nih_config_block_end (const char *file, size_t len, size_t *lineno, size_t *pos, const char *type, size_t *endpos) __attribute__ ((warn_unused_result)); static NihConfigStanza *nih_config_get_stanza (const char *name, NihConfigStanza *stanzas); /** * nih_config_has_token: * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number. * * Checks the current position in @file to see whether it has a parseable * token at this position; ie. we're not at the end of file, and the * current character is neither a comment or newline character. * * If this returns FALSE, it's normal to call nih_config_skip_comment() * to move to the next parseable point and check again. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file as a * whole. * * @pos is used as the offset within @file to begin, otherwise the start * is assumed. * * Returns: TRUE if the current character is before the end of file and * is neither a comment or newline, FALSE otherwise. **/ int nih_config_has_token (const char *file, size_t len, size_t *pos, size_t *lineno) { size_t p; nih_assert (file != NULL); p = (pos ? *pos : 0); if ((p < len) && (! strchr (NIH_CONFIG_CNL, file[p]))) { return TRUE; } else { return FALSE; } } /** * nih_config_token: * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number, * @dest: destination to copy to, * @delim: characters to stop on, * @dequote: remove quotes and escapes. * @toklen: pointer to store token length in. * * Parses a single token from @file which is stopped when any character * in @delim is encountered outside of a quoted string and not escaped * using a backslash. The length of the parsed token is stored in @toklen * if given. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file as a * whole. Usually when @dest is given, @file is instead the pointer to * the start of the token and @len is the difference between the start * and end of the token (NOT the return value from this function). * * If @pos is given then it will be used as the offset within @file to * begin (otherwise the start is assumed), and will be updated to point * to @delim or past the end of the file. * * If @lineno is given it will be incremented each time a new line is * discovered in the file. * * To copy the token into another string, collapsing any newlines and * surrounding whitespace to a single space, pass @dest which should be * pre-allocated to the right size (obtained by calling this function * with NULL). * * If you also want quotes to be removed and escaped characters to be * replaced with the character itself, set @dequote to TRUE. * * Returns: zero on success, negative value on raised error. **/ int nih_config_token (const char *file, size_t len, size_t *pos, size_t *lineno, char *dest, const char *delim, int dequote, size_t *toklen) { size_t p, ws = 0, nlws = 0, qc = 0, i = 0; int slash = FALSE, quote = 0, nl = FALSE, ret = 0; nih_assert (file != NULL); nih_assert (delim != NULL); /* We keep track of the following: * slash whether a \ is in effect * quote whether " or ' is in effect (set to which) * ws number of consecutive whitespace chars so far * nlws number of whitespace/newline chars * nl TRUE if we need to copy ws into nlws at first non-WS * qc number of quote characters that need removing. */ for (p = (pos ? *pos : 0); p < len; p++) { int extra = 0, isq = FALSE; if (slash) { slash = FALSE; /* Escaped newline */ if (file[p] == '\n') { nlws++; nl = TRUE; if (lineno) (*lineno)++; continue; } else if ((file[p] == '\\') || strchr (NIH_CONFIG_WS, file[p])) { extra++; if (dequote) qc++; } else if (dest) { dest[i++] = '\\'; } } else if (file[p] == '\\') { slash = TRUE; continue; } else if (quote) { if (file[p] == quote) { quote = 0; isq = TRUE; } else if (file[p] == '\n') { nl = TRUE; if (lineno) (*lineno)++; continue; } else if (strchr (NIH_CONFIG_WS, file[p])) { ws++; continue; } } else if ((file[p] == '\"') || (file[p] == '\'')) { quote = file[p]; isq = TRUE; } else if (strchr (delim, file[p])) { break; } else if (strchr (NIH_CONFIG_WS, file[p])) { ws++; continue; } if (nl) { /* Newline is recorded as a single space; * any surrounding whitespace is lost. */ nlws += ws; if (dest) dest[i++] = ' '; } else if (ws && dest) { /* Whitespace that we've encountered to date is * copied as it is. */ memcpy (dest + i, file + p - ws - extra, ws); i += ws; } /* Extra characters (the slash) needs to be copied * unless we're dequoting the string */ if (extra && dest && (! dequote)) { memcpy (dest + i, file + p - extra, extra); i += extra; } if (dest && (! (isq && dequote))) dest[i++] = file[p]; if (isq && dequote) qc++; ws = 0; nl = FALSE; extra = 0; } /* Add the NULL byte */ if (dest) dest[i++] = '\0'; /* A trailing slash on the end of the file makes no sense. */ if (slash) { nih_error_raise (NIH_CONFIG_TRAILING_SLASH, _(NIH_CONFIG_TRAILING_SLASH_STR)); ret = -1; goto finish; } /* Leaving quotes open is also generally bad. */ if (quote) { nih_error_raise (NIH_CONFIG_UNTERMINATED_QUOTE, _(NIH_CONFIG_UNTERMINATED_QUOTE_STR)); ret = -1; goto finish; } /* The token length we return is the length of the token with any * newlines and surrounding whitespace converted to a single * character and any trailing whitespace removed. * * The actual end of the text read is returned in *pos. */ if (toklen) *toklen = p - (pos ? *pos : 0) - ws - nlws - qc; finish: if (pos) *pos = p; return ret; } /** * nih_config_next_token: * @parent: parent object for returned token, * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number, * @delim: characters to stop on, * @dequote: remove quotes and escapes. * * Extracts a single token from @file which is stopped when any character * in @delim is encountered outside of a quoted string and not escaped * using a backslash. If @delim contains any whitespace character, then * all whitespace after the token is also consumed, but not returned, * including that with escaped newlines within it. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file as a * whole. * * If @pos is given then it will be used as the offset within @file to * begin (otherwise the start is assumed), and will be updated to point * to @delim or past the end of the file. * * If @lineno is given it will be incremented each time a new line is * discovered in the file. * * If you also want quotes to be removed and escaped characters to be * replaced with the character itself, set @dequote to TRUE. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned token. When all parents * of the returned token are freed, the returned token will also be * freed. * * Returns: the token found or NULL on raised error. **/ char * nih_config_next_token (const void *parent, const char *file, size_t len, size_t *pos, size_t *lineno, const char *delim, int dequote) { size_t p, arg_start, arg_len, arg_end; char *arg = NULL; nih_assert (file != NULL); p = (pos ? *pos : 0); arg_start = p; if (nih_config_token (file, len, &p, lineno, NULL, delim, dequote, &arg_len) < 0) goto finish; arg_end = p; if (! arg_len) { nih_error_raise (NIH_CONFIG_EXPECTED_TOKEN, _(NIH_CONFIG_EXPECTED_TOKEN_STR)); goto finish; } nih_config_skip_whitespace (file, len, &p, lineno); /* Copy in the new token */ arg = nih_alloc (parent, arg_len + 1); if (! arg) nih_return_system_error (NULL); if (nih_config_token (file + arg_start, arg_end - arg_start, NULL, NULL, arg, delim, dequote, NULL) < 0) goto finish; finish: if (pos) *pos = p; return arg; } /** * nih_config_next_arg: * @parent: parent object for returned argument, * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number. * * Extracts a single argument from @file, a dequoted token that is stopped * on any comment, space or newline character that is not quoted or escaped * with a backslash. Any whitespace after the argument is also consumed, * but not returned, including that with escaped newlines within it. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file as a * whole. * * If @pos is given then it will be used as the offset within @file to * begin (otherwise the start is assumed), and will be updated to point * to @delim or past the end of the file. * * If @lineno is given it will be incremented each time a new line is * discovered in the file. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned argument. When all parents * of the returned argument are freed, the returned argument will also be * freed. * * Returns: the argument found or NULL on raised error. **/ char * nih_config_next_arg (const void *parent, const char *file, size_t len, size_t *pos, size_t *lineno) { nih_assert (file != NULL); return nih_config_next_token (parent, file, len, pos, lineno, NIH_CONFIG_CNLWS, TRUE); } /** * nih_config_next_line: * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number. * * Skips to the end of the current line in @file, ignoring any tokens, * comments, etc. along the way. If you want to ensure that no arguments * are missed, use nih_config_skip_comment() instead. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file as a * whole. * * @pos is used as the offset within @file to begin, and will be updated * to point to past the end of the line or file. * * If @lineno is given it will be incremented each time a new line is * discovered in the file. **/ void nih_config_next_line (const char *file, size_t len, size_t *pos, size_t *lineno) { nih_assert (file != NULL); nih_assert (pos != NULL); /* Spool forwards until the end of the line */ while ((*pos < len) && (file[*pos] != '\n')) (*pos)++; /* Step over it */ if (*pos < len) { if (lineno) (*lineno)++; (*pos)++; } } /** * nih_config_skip_whitespace: * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number. * * Skips an amount of whitespace and finds either the next token or the end * of the current line in @file. Escaped newlines within the whitespace * are treated as whitespace. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file as a * whole. * * @pos is used as the offset within @file to begin, and will be updated * to point to past the end of the line or file. * * If @lineno is given it will be incremented each time a new line is * discovered in the file. **/ void nih_config_skip_whitespace (const char *file, size_t len, size_t *pos, size_t *lineno) { nih_assert (file != NULL); nih_assert (pos != NULL); /* Skip any amount of whitespace between them, we also need to * detect an escaped newline here. */ while (*pos < len) { if (file[*pos] == '\\') { /* Escape character, only continue scanning if * the next character is newline */ if ((len - *pos > 1) && (file[*pos + 1] == '\n')) { (*pos)++; } else { break; } } else if (! strchr (NIH_CONFIG_WS, file[*pos])) { break; } if (file[*pos] == '\n') if (lineno) (*lineno)++; /* Whitespace characer */ (*pos)++; } } /** * nih_config_skip_comment: * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number. * * Skips a comment and finds the end of the current line in @file. If the * current position does not point to the end of a line, or a comment, * then an error is raised. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file as a * whole. * * @pos is used as the offset within @file to begin, and will be updated * to point to past the end of the line or file. * * If @lineno is given it will be incremented each time a new line is * discovered in the file. * * Returns: zero on success, negative value on raised error. **/ int nih_config_skip_comment (const char *file, size_t len, size_t *pos, size_t *lineno) { nih_assert (file != NULL); nih_assert (pos != NULL); if (nih_config_has_token (file, len, pos, lineno)) { nih_error_raise (NIH_CONFIG_UNEXPECTED_TOKEN, _(NIH_CONFIG_UNEXPECTED_TOKEN_STR)); return -1; } nih_config_next_line (file, len, pos, lineno); return 0; } /** * nih_config_parse_args: * @parent: parent object for returned array, * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number. * * Extracts a list of arguments from @file, each argument is separated * by whitespace and parsing is stopped when a newline is encountered * outside of a quoted string and not escaped using a backslash. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file as a * whole. * * If @pos is given then it will be used as the offset within @file to * begin (otherwise the start is assumed), and will be updated to point * past the end of the line or the end of the file. * * If @lineno is given it will be incremented each time a new line is * discovered in the file. * * The arguments are returned as a NULL-terminated array, with each argument * dequoted before being returned. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned array. When all parents * of the returned array are freed, the returned array will also be * freed. * * Returns: the list of arguments found or NULL on raised error. **/ char ** nih_config_parse_args (const void *parent, const char *file, size_t len, size_t *pos, size_t *lineno) { char **args; size_t p, nargs; nih_assert (file != NULL); /* Begin with an empty array */ nargs = 0; args = nih_str_array_new (parent); if (! args) nih_return_system_error (NULL); /* Loop through the arguments until we hit a comment or newline */ p = (pos ? *pos : 0); while (nih_config_has_token (file, len, &p, lineno)) { char *arg; arg = nih_config_next_arg (args, file, len, &p, lineno); if (! arg) { nih_free (args); args = NULL; goto finish; } if (! nih_str_array_addp (&args, parent, &nargs, arg)) { nih_error_raise_system (); nih_free (args); return NULL; } } /* nih_config_has_token has returned FALSE, we must be either past * the end of the file, or at a comment or newline. */ if (nih_config_skip_comment (file, len, &p, lineno) < 0) nih_assert_not_reached (); finish: if (pos) *pos = p; return args; } /** * nih_config_parse_command: * @parent: parent object for returned string, * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number, * * Extracts a command and its arguments from @file, stopping when a * newline is encountered outside of a quoted string and not escaped * using a blackslash. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file as a * whole. * * If @pos is given then it will be used as the offset within @file to * begin (otherwise the start is assumed), and will be updated to point * past the end of the line or the end of the file. * * If @lineno is given it will be incremented each time a new line is * discovered in the file. * * The command is returned as a string allocated with nih_alloc(). * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: the command found or NULL on raised error. **/ char * nih_config_parse_command (const void *parent, const char *file, size_t len, size_t *pos, size_t *lineno) { char *cmd = NULL; size_t p, cmd_start, cmd_len, cmd_end; nih_assert (file != NULL); /* Find the length of string up to the first unescaped comment * or newline. */ p = (pos ? *pos : 0); cmd_start = p; if (nih_config_token (file, len, &p, lineno, NULL, NIH_CONFIG_CNL, FALSE, &cmd_len) < 0) goto finish; cmd_end = p; /* nih_config_token will eat up to the end of the file, a comment * or a newline; so this must always succeed. */ if (nih_config_skip_comment (file, len, &p, lineno) < 0) nih_assert_not_reached (); /* Now copy the string into the destination. */ cmd = nih_alloc (parent, cmd_len + 1); if (! cmd) nih_return_system_error (NULL); if (nih_config_token (file + cmd_start, cmd_end - cmd_start, NULL, NULL, cmd, NIH_CONFIG_CNL, FALSE, NULL) < 0) goto finish; finish: if (pos) *pos = p; return cmd; } /** * nih_config_parse_block: * @parent: parent object for returned string, * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number, * @type: block identifier. * * Extracts a block of text from @line, stopping when the pharse "end @type" * is encountered without any quotes or blackslash escaping within it. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file as a * whole. * * If @pos is given then it will be used as the offset within @file to * begin (otherwise the start is assumed), and will be updated to point * past the end of the block or the end of the file. * * Either @file or @pos should point to the start of the block, after the * opening stanza, rather than the start of the stanza that opens it. * * If @lineno is given it will be incremented each time a new line is * discovered in the file. * * The block is returned as a string allocated with nih_alloc(). * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: the text contained within the block or NULL on raised error. **/ char * nih_config_parse_block (const void *parent, const char *file, size_t len, size_t *pos, size_t *lineno, const char *type) { char *block = NULL; size_t p, pp, sh_start, sh_len, sh_end, ws; int lines; nih_assert (file != NULL); nih_assert (type != NULL); /* We need to find the end of the block which is a line that looks * like: * * WS? end WS @type CNLWS? * * Just to make things more difficult for ourselves, we work out the * common whitespace on the start of the block lines and remember * not to copy those out later */ p = (pos ? *pos : 0); sh_start = p; sh_end = 0; ws = 0; lines = 0; while (! nih_config_block_end (file, len, &p, lineno, type, &sh_end)) { size_t line_start; lines++; line_start = p; if (lines == 1) { /* Count whitespace on the first line */ while ((p < len) && strchr (NIH_CONFIG_WS, file[p])) p++; ws = p - line_start; } else { /* Compare how much whitespace matches the * first line; and decrease the count if it's * not as much. */ while ((p < len) && (p - line_start < ws) && (file[sh_start + p - line_start] == file[p])) p++; if (p - line_start < ws) ws = p - line_start; } nih_config_next_line (file, len, &p, lineno); if (p >= len) { nih_error_raise (NIH_CONFIG_UNTERMINATED_BLOCK, _(NIH_CONFIG_UNTERMINATED_BLOCK_STR)); goto finish; } } /* Copy the fragment into a string, removing common whitespace from * the start. We can be less strict here because we already know * the contents, etc. */ sh_len = sh_end - sh_start - (ws * lines); block = nih_alloc (parent, sh_len + 1); if (! block) nih_return_system_error (NULL); block[0] = '\0'; pp = sh_start; while (pp < sh_end) { size_t line_start; pp += ws; line_start = pp; while (file[pp++] != '\n') ; strncat (block, file + line_start, pp - line_start); } finish: if (pos) *pos = p; return block; } /** * nih_config_skip_block: * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number, * @type: block identifier, * @endpos: pointer to end of block. * * Skips over a block of text from @file, stopping when the phrase * "end @type" is encountered without any quotes or blackslash escaping * within it. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file as a * whole. * * If @pos is given then it will be used as the offset within @file to * begin (otherwise the start is assumed), and will be updated to point * past the end of the block and block marker or the end of the file. * * Either @file or @pos should point to the start of the block, after the * opening stanza, rather than the start of the stanza that opens it. * * If @lineno is given it will be incremented each time a new line is * discovered in the file. * * @endpos will be set to the end of the block and the start of the block * marker, this is useful for determining the length of the block skipped, * to parse it for example. * * Returns: zero on success, negative value on raised error. **/ int nih_config_skip_block (const char *file, size_t len, size_t *pos, size_t *lineno, const char *type, size_t *endpos) { size_t p; int ret = 0; nih_assert (file != NULL); nih_assert (type != NULL); p = (pos ? *pos : 0); while (! nih_config_block_end (file, len, &p, lineno, type, endpos)) { nih_config_next_line (file, len, &p, lineno); if (p >= len) { nih_error_raise (NIH_CONFIG_UNTERMINATED_BLOCK, _(NIH_CONFIG_UNTERMINATED_BLOCK_STR)); ret = -1; goto finish; } } finish: if (pos) *pos = p; return ret; } /** * nih_config_block_end: * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number, * @type: block identifier, * @endpos: pointer to end of block. * * Determines whether the current line contains an end of block marker, * and if so, sets @endpos to the end of the block. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file. @pos * will be updated to point past the end of the block and the end block * marker or the end of the file. * * @lineno will be incremented each time a new line is discovered. * * Returns: TRUE if at the end of the block, FALSE otherwise. **/ static int nih_config_block_end (const char *file, size_t len, size_t *pos, size_t *lineno, const char *type, size_t *endpos) { size_t p; nih_assert (file != NULL); nih_assert (pos != NULL); nih_assert (type != NULL); p = *pos; /* Skip initial whitespace */ while ((p < len) && strchr (NIH_CONFIG_WS, file[p])) p++; /* Check the first word (check we have at least 4 chars because of * the need for whitespace immediately after) */ if ((len - p < 4) || strncmp (file + p, "end", 3)) return FALSE; /* Must be whitespace after */ if (! strchr (NIH_CONFIG_WS, file[p + 3])) return FALSE; /* Find the second word */ p += 3; while ((p < len) && strchr (NIH_CONFIG_WS, file[p])) p++; /* Check the second word */ if ((len - p < strlen (type)) || strncmp (file + p, type, strlen (type))) return FALSE; /* May be followed by whitespace */ p += strlen (type); while ((p < len) && strchr (NIH_CONFIG_WS, file[p])) p++; /* May be a comment, in which case eat up to the newline */ if ((p < len) && (file[p] == '#')) { while ((p < len) && (file[p] != '\n')) p++; } /* Should be end of string, or a newline */ if ((p < len) && (file[p] != '\n')) return FALSE; /* Point past the new line */ if (p < len) { if (lineno) (*lineno)++; p++; } /* Set endpos to the beginning of the line (which is the end of the * script) but update pos to point past this line. */ if (endpos) *endpos = *pos; *pos = p; return TRUE; } /** * nih_config_get_stanza: * @name: name of stanza, * @stanzas: table of stanza handlers. * * Locates the handler for the @name stanza in the @stanzas table. The * last entry in the table should have NULL for both the name and handler * function pointers. * * If any entry exists with the stanza name "", this is returned instead * of NULL if no specific entry is found. * * Returns: stanza found or NULL if no handler for @name. **/ static NihConfigStanza * nih_config_get_stanza (const char *name, NihConfigStanza *stanzas) { NihConfigStanza *stanza, *catch = NULL; for (stanza = stanzas; (stanza->name && stanza->handler); stanza++) { if (! strlen (stanza->name)) catch = stanza; if (! strcmp (stanza->name, name)) return stanza; } return catch; } /** * nih_config_parse_stanza: * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number, * @stanzas: table of stanza handlers, * @data: pointer to pass to stanza handler. * * Extracts a configuration stanza from @file and calls the handler * function for that stanza found in the @stanzas table to handle the * rest of the line from thereon in. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file as a * whole. * * If @pos is given then it will be used as the offset within @file to * begin (otherwise the start is assumed), and will be updated to point * to @delim or past the end of the file. * * If @lineno is given it will be incremented each time a new line is * discovered in the file. * * Returns: zero on success or negative value on raised error. **/ int nih_config_parse_stanza (const char *file, size_t len, size_t *pos, size_t *lineno, NihConfigStanza *stanzas, void *data) { NihConfigStanza *stanza; nih_local char *name = NULL; size_t p; int ret = -1; nih_assert (file != NULL); nih_assert (stanzas != NULL); p = (pos ? *pos : 0); /* Get the next dequoted argument from the file */ name = nih_config_next_token (NULL, file, len, &p, lineno, NIH_CONFIG_CNLWS, FALSE); if (! name) goto finish; /* Lookup the stanza for it */ stanza = nih_config_get_stanza (name, stanzas); if (! stanza) nih_return_error (-1, NIH_CONFIG_UNKNOWN_STANZA, _(NIH_CONFIG_UNKNOWN_STANZA_STR)); ret = stanza->handler (data, stanza, file, len, &p, lineno); finish: if (pos) *pos = p; return ret; } /** * nih_config_parse_file: * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file, * @lineno: line number, * @stanzas: table of stanza handlers, * @data: pointer to pass to stanza handler. * * Parses configuration file lines from @file, skipping initial whitespace, * blank lines and comments while calling nih_config_parse_stanza() for * anything else. * * @file may be a memory mapped file, in which case @pos should be given * as the offset within and @len should be the length of the file as a * whole. * * If @pos is given then it will be used as the offset within @file to * begin (otherwise the start is assumed), and will be updated to point * to @delim or past the end of the file. * * If @lineno is given it will be incremented each time a new line is * discovered in the file. * * Returns: zero on success, negative value on raised error. **/ int nih_config_parse_file (const char *file, size_t len, size_t *pos, size_t *lineno, NihConfigStanza *stanzas, void *data) { int ret = -1; size_t p; nih_assert (file != NULL); nih_assert (stanzas != NULL); p = (pos ? *pos : 0); while (p < len) { /* Skip initial whitespace */ while ((p < len) && strchr (NIH_CONFIG_WS, file[p])) p++; /* Skip lines with only comments in them; because has_token * returns FALSE we know we're either past the end of the * file, at a comment, or a newline. */ if (! nih_config_has_token (file, len, &p, lineno)) { if (nih_config_skip_comment (file, len, &p, lineno) < 0) nih_assert_not_reached (); continue; } /* Must have a stanza, parse it */ if (nih_config_parse_stanza (file, len, &p, lineno, stanzas, data) < 0) goto finish; } ret = 0; finish: if (pos) *pos = p; return ret; } /** * nih_config_parse: * @filename: name of file to parse, * @pos: offset within @file, * @lineno: line number, * @stanzas: table of stanza handlers, * @data: pointer to pass to stanza handler. * * Reads @filename into memory and them parses configuration lines from it * using nih_config_parse_file(). * * If @pos is given then it will be used as the offset within @file to * begin (otherwise the start is assumed), and will be updated to point * to @delim or past the end of the file. * * If @lineno is given it will be incremented each time a new line is * discovered in the file. * * Returns: zero on success, negative value on raised error. **/ int nih_config_parse (const char *filename, size_t *pos, size_t *lineno, NihConfigStanza *stanzas, void *data) { nih_local char *file = NULL; size_t len; int ret; nih_assert (filename != NULL); file = nih_file_read (NULL, filename, &len); if (! file) return -1; if (lineno) *lineno = 1; ret = nih_config_parse_file (file, len, pos, lineno, stanzas, data); return ret; } libnih-1.0.3/nih/alloc.c0000644000175000017500000005111011445765555011734 00000000000000/* libnih * * alloc.c - multi-reference hierarchial allocator * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include "alloc.h" /** * NihAllocCtx: * @parents: parents of this context, * @children: children of this context, * @destructor: function to be called when freed, * @size: allocation size. * * This structure is placed before all allocations in memory and is used * to build up an n-ary tree of them. Allocations may have multiple * parent references and multiple children. Allocations are automatically * freed if the last parent reference is freed. When an allocation is * freed, all children are unreferenced and any destructors called. * * Members of @parents and @children are both NihAllocRef objects. **/ typedef struct nih_alloc_ctx { NihList parents; NihList children; NihDestructor destructor; size_t size; } NihAllocCtx; /** * NihAllocRef: * @children_entry: list head in parent's children list, * @parents_entry: list head in child's parents list, * @parent: pointer to parent context, * @child: pointer to child context. * * This structure is shared by both @parent and @child denoting a reference * between the two of them. It is placed in @parent's children list through * @children_entry and @child's parents list through @parents_entry. **/ typedef struct nih_alloc_ref { NihList children_entry; NihList parents_entry; NihAllocCtx *parent; NihAllocCtx *child; } NihAllocRef; /** * NIH_ALLOC_SIZE: * * Expands to the size of the NihAllocCtx structure plus whetever padding * is needed to ensure the following pointer is generically aligned. **/ #define NIH_ALLOC_SIZE (NIH_ALIGN_SIZE * (((sizeof (NihAllocCtx) - 1) \ / NIH_ALIGN_SIZE) + 1)) /** * NIH_ALLOC_CTX: * @ptr: pointer to block of memory. * * Obtain the location of the NihAllocCtx structure given a pointer to the * block of memory beyond it. * * Returns: pointer to NihAllocCtx structure or NULL if @ptr is NULL. **/ #define NIH_ALLOC_CTX(ptr) (ptr ? (void *)(ptr) - NIH_ALLOC_SIZE : NULL) /** * NIH_ALLOC_PTR: * @ctx: pointer to NihAllocCtx structure. * * Obtain the location of the block of memory given a pointer to the * NihAllocCtx structure in front of it. * * Returns: pointer to block of memory. **/ #define NIH_ALLOC_PTR(ctx) ((void *)(ctx) + NIH_ALLOC_SIZE) /** * NIH_ALLOC_FINALISED: * * Flag placed in the destructor field of a context to indicate the * destructor has been called and the object is pending being freed. **/ #define NIH_ALLOC_FINALISED ((void *)-1) /* Prototypes for static functions */ static inline int nih_alloc_context_free (NihAllocCtx *ctx); static inline NihAllocRef *nih_alloc_ref_new (NihAllocCtx *parent, NihAllocCtx *child) __attribute__ ((malloc)); static inline void nih_alloc_ref_free (NihAllocRef *ref); static inline NihAllocRef *nih_alloc_ref_lookup (NihAllocCtx *parent, NihAllocCtx *child); /* Point to the functions we actually call for allocation. */ void *(*__nih_malloc) (size_t size) = malloc; void *(*__nih_realloc) (void *ptr, size_t size) = realloc; void (*__nih_free) (void *ptr) = free; /** * nih_alloc: * @parent: parent object for new object, * @size: size of requested object. * * Allocates an object in memory of at least @size bytes and returns a * pointer to it. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned object otherwise the special * NULL parent will be used instead. When all parents of the returned * object are freed, the returned object will also be freed. * * If you have clean-up that you would like to run, you can assign a * destructor using the nih_alloc_set_destructor() function. * * Returns: newly allocated object or NULL if insufficient memory. **/ void * nih_alloc (const void *parent, size_t size) { NihAllocCtx *ctx; ctx = __nih_malloc (NIH_ALLOC_SIZE + size); if (! ctx) return NULL; nih_list_init (&ctx->parents); nih_list_init (&ctx->children); ctx->destructor = NULL; ctx->size = size; nih_alloc_ref_new (NIH_ALLOC_CTX (parent), ctx); return NIH_ALLOC_PTR (ctx); } /** * nih_realloc: * @ptr: object to reallocate, * @parent: parent object of new object, * @size: size of new object. * * Adjusts the size of the object @ptr to be at least @size bytes, which * may be larger or smaller than the existing object, and returns the * new pointer. * * If @ptr is NULL, this simply calls nih_alloc() and passes both @parent * and @size to it, returning the returned object. * * If @ptr is not NULL, @parent is ignored; though it is usual to pass a * parent of @ptr for style reasons. * * Returns: reallocated object or NULL if insufficient memory. **/ void * nih_realloc (void * ptr, const void *parent, size_t size) { NihAllocCtx *ctx; NihList * first_parent = NULL; NihList * first_child = NULL; if (! ptr) return nih_alloc (parent, size); ctx = NIH_ALLOC_CTX (ptr); nih_assert (ctx->destructor != NIH_ALLOC_FINALISED); /* This is somewhat more difficult than alloc or free because we * have two lists of pointers to worry about. Fortunately the * properties of NihList help us a lot here. * * The problem is that references between us and our parents, * and references between us and our children, all contain list * pointers that are potentially invalid once relloc has been * called. * * We could strip it all down before calling realloc then rebuild * it afterwards, but that's expensive and could be error-prone in * the case where the allocator fails. * * The solution is to rely on a property of nih_list_add(). The * entry passed (to be added) is cut out of its containing list * without dereferencing the return pointers, this means we can * cut the bad pointers out simply by calling nih_list_add() * to put the new entry back in the same position. * * Of course, this only works in the non-empty list case as trying * to cut an entry out of an empty list would dereference those * invalid pointers. Happily all we need to do for the empty * list case is call nih_list_init() again. * * So we just remember the first parent and first child reference, * or NULL if the list is empty. */ if (! NIH_LIST_EMPTY (&ctx->parents)) first_parent = ctx->parents.next; if (! NIH_LIST_EMPTY (&ctx->children)) first_child = ctx->children.next; /* Now do the actual realloc(), if this fails then we can just * return NULL since we've not actually changed anything. */ ctx = __nih_realloc (ctx, NIH_ALLOC_SIZE + size); if (! ctx) return NULL; ctx->size = size; /* Now update our parents and children lists, or reinitialise, * as noted above this ensures that all the pointers are correct */ if (first_parent) { nih_list_add_after (first_parent, &ctx->parents); } else { nih_list_init (&ctx->parents); } if (first_child) { nih_list_add_after (first_child, &ctx->children); } else { nih_list_init (&ctx->children); } /* We still have to fix up the parent and child pointers, but * that's easy. */ NIH_LIST_FOREACH (&ctx->parents, iter) { NihAllocRef *ref = NIH_LIST_ITER (iter, NihAllocRef, parents_entry); ref->child = ctx; } NIH_LIST_FOREACH (&ctx->children, iter) { NihAllocRef *ref = NIH_LIST_ITER (iter, NihAllocRef, children_entry); ref->parent = ctx; } return NIH_ALLOC_PTR (ctx); } /** * nih_free: * @ptr: object to free. * * Returns the object @ptr to the allocator so the memory consumed may be * re-used by something else. * * All parent references are discarded and the destructor for @ptr is called. * Then all children are recursively unreferenced. Those that have no * remaining parent references will also have their destructors called and * their children unreferenced, etc. Once all destructors have been called, * the objects themselves are freed. * * If you call nih_free() on an object with parent references, you should * make sure that any pointers to the object are reset. * * If you are unsure whether or not there are references you should call * nih_discard() which will discard the special NULL reference only if it * exists, only freeing the object if no other references remain. * * Otherwise to remove a particular parent reference you should call * nih_unref(). * * Returns: return value from @ptr's destructor, or 0. **/ int nih_free (void *ptr) { NihAllocCtx *ctx; nih_assert (ptr != NULL); ctx = NIH_ALLOC_CTX (ptr); nih_assert (ctx->destructor != NIH_ALLOC_FINALISED); /* Cast off our parents first, without recursing. This ensures * we always have zero references before we call the destructor, * and has the somewhat neat property of breaking any reference * loops. */ NIH_LIST_FOREACH_SAFE (&ctx->parents, iter) { NihAllocRef *ref = NIH_LIST_ITER (iter, NihAllocRef, parents_entry); nih_alloc_ref_free (ref); } return nih_alloc_context_free (ctx); } /** * nih_discard: * @ptr: object to discard. * * Discards the special NULL parent reference from @ptr if present; if * no other references have been taken @ptr will be freed and the value * from the destructor returned otherwise this function takes no * further action. * * You would use nih_discard() when you allocated @ptr without any parent * but have passed it to functions that may have taken a reference to it * in the meantime. Compare with nih_free() which acts even if there are * parent references, and nih_unref() which only removes a single parent * reference that is known to exist. * * Returns: return value from @ptr's destructor, or 0. **/ int nih_discard (void *ptr) { NihAllocCtx *ctx; NihAllocRef *ref; nih_assert (ptr != NULL); ctx = NIH_ALLOC_CTX (ptr); nih_assert (ctx->destructor != NIH_ALLOC_FINALISED); ref = nih_alloc_ref_lookup (NULL, ctx); if (! ref) return 0; nih_alloc_ref_free (ref); if (NIH_LIST_EMPTY (&ctx->parents)) return nih_alloc_context_free (ctx); return 0; } /** * _nih_discard_local: * @ptr: address of local object to be discarded. * * This function should never be called directly, it is used as part of the * implementation of nih_local and simply calls nih_discard() with the * local variable itself if non-NULL. **/ void _nih_discard_local (void *ptraddr) { /* Can't just take void ** as a parameter, since that will upset * gcc typechecking, and we want to be able to be used on any * pointer type. */ void **ptr = (void **)ptraddr; if (*ptr) nih_discard (*ptr); } /** * nih_alloc_context_free: * @ctx: context to free. * * This is the internal function called by nih_free(), nih_discard() and * nih_unref() to actually free an allocated context and its attached * objects. * * All parent references must have been discarded prior to calling this * function. * * The destructor for @ctx is called, and then all children are recursively * unreferenced. Those that have no remaining parent references will also * have their destructors called and their children unreferenced, etc. * Once all destructors have been called, the objects themselves are freed. * * Returns: return value from @ptr's destructor, or 0. **/ static inline int nih_alloc_context_free (NihAllocCtx *ctx) { int ret = 0; nih_assert (ctx != NULL); nih_assert (ctx->destructor != NIH_ALLOC_FINALISED); nih_assert (NIH_LIST_EMPTY (&ctx->parents)); /* We have no parents, call our destructor before doing anything * to our children. Save the return value, since this is what * we return. */ if (ctx->destructor) ret = ctx->destructor (NIH_ALLOC_PTR (ctx)); ctx->destructor = NIH_ALLOC_FINALISED; /* Recursively finalise all of our children. */ NIH_LIST_FOREACH_SAFE (&ctx->children, iter) { NihAllocRef *ref = NIH_LIST_ITER (iter, NihAllocRef, children_entry); /* Disassociate the child from its parent. * If that was not the last parent, the child should not * be freed, so destroy the rest of the reference and move * on. */ nih_list_destroy (&ref->parents_entry); if (! NIH_LIST_EMPTY (&ref->child->parents)) { nih_list_destroy (&ref->children_entry); free (ref); continue; } /* Child is to be destroyed and has no links back to its * parents. We call the destructor now. */ if (ref->child->destructor) ref->child->destructor (NIH_ALLOC_PTR (ref->child)); ref->child->destructor = NIH_ALLOC_FINALISED; /* Reparent all of its own children to us so that they too * will be finalised if the last reference is removed. * * In order to do this depth-first while preserving order, * we insert the items before our cursor; and then put the * cursor back at the head of them. */ NIH_LIST_FOREACH_SAFE (&ref->child->children, citer) { NihAllocRef *cref = NIH_LIST_ITER (citer, NihAllocRef, children_entry); nih_list_add (&_iter, &cref->children_entry); } nih_list_add_after (iter, &_iter); } /* We now have a single list of children all of which have no * references back to us as their parent, and all of had their * destructors called. * * Now we free them. */ NIH_LIST_FOREACH_SAFE (&ctx->children, iter) { NihAllocRef *ref = NIH_LIST_ITER (iter, NihAllocRef, children_entry); __nih_free (ref->child); nih_list_destroy (&ref->children_entry); free (ref); } /* And now we can free ourselves. */ __nih_free (ctx); return ret; } /** * nih_alloc_real_set_destructor: * @ptr: pointer to object, * @destructor: destructor function to set. * * Sets the destructor of the allocated object @ptr to @destructor, which * may be NULL to unset an existing destructor. Normally you would use * the nih_alloc_set_destructor() macro which expands to this function * but casts @destructor to the correct type, since almost all destructors * will be defined with their argument to be the type of the object * rather than void *. * * The destructor will be called before the object is freed, either * explicitly by nih_free() or nih_discard(), or because the last parent * has unreferenced the object. * * When the destructor is called, the parent references to the object will * have already been discarded but all children references will be intact * and none of the children will have been freed. There is no need to use * a destructor to unreference or free children, that is automatic. * * The pointer @ptr passed to the destructor is that of the object being * freed, and the destructor may return a value which will be the return * value of nih_free() or nih_discard() if used directly on the object. * * Since objects may also be freed by unreferencing, and the value is not * returned in this case, it should only be used for informational or * debugging purposes. **/ void nih_alloc_real_set_destructor (const void * ptr, NihDestructor destructor) { NihAllocCtx *ctx; nih_assert (ptr != NULL); ctx = NIH_ALLOC_CTX (ptr); nih_assert (ctx->destructor != NIH_ALLOC_FINALISED); ctx->destructor = destructor; } /** * nih_ref: * @ptr: object to reference, * @parent: new parent object. * * Adds a reference to the object @ptr from @parent, adding to any other * objects referencing @ptr. @parent may be the special NULL parent. * * The reference can be broken using nih_unref(). * * @ptr will only be automatically freed when the last parent unreferences * it. It may still be manually freed with nih_free(), though this doesn't * sort out any pointers. * * This function is generally used when accepting an object that you wish * to hold a reference to, which is cheaper than making a copy. The caller * must be careful to only use nih_discard() or nih_unref() to drop its own * reference. **/ void nih_ref (const void *ptr, const void *parent) { nih_assert (ptr != NULL); nih_alloc_ref_new (NIH_ALLOC_CTX (parent), NIH_ALLOC_CTX (ptr)); } /** * nih_alloc_ref_new: * @parent: parent context, * @child: child context. * * This is the internal function used by nih_ref() and nih_alloc() to * create a new reference between the @parent and @child contexts. * * Returns: new reference, already linked to both objects. **/ static inline NihAllocRef * nih_alloc_ref_new (NihAllocCtx *parent, NihAllocCtx *child) { NihAllocRef *ref; nih_assert ((parent == NULL) || (parent->destructor != NIH_ALLOC_FINALISED)); nih_assert (child != NULL); nih_assert (child->destructor != NIH_ALLOC_FINALISED); ref = NIH_MUST (malloc (sizeof (NihAllocRef))); nih_list_init (&ref->children_entry); nih_list_init (&ref->parents_entry); ref->parent = parent; ref->child = child; if (parent) nih_list_add_after (&parent->children, &ref->children_entry); nih_list_add_after (&child->parents, &ref->parents_entry); return ref; } /** * nih_unref: * @ptr: object to unreference, * @parent: parent object to remove. * * Removes the reference to the object @ptr from @parent, if this is the * last reference to @ptr then @ptr will be automatically freed. @parent * may be the special NULL parent. * * You never need to call this in your own destructors since children * are unreferenced automatically, however this function is useful if you * only hold a reference to an object for a short period and wish to * discard it. **/ void nih_unref (void * ptr, const void *parent) { NihAllocCtx *ctx; NihAllocRef *ref; nih_assert (ptr != NULL); ctx = NIH_ALLOC_CTX (ptr); nih_assert (ctx->destructor != NIH_ALLOC_FINALISED); ref = nih_alloc_ref_lookup (NIH_ALLOC_CTX (parent), ctx); nih_assert (ref != NULL); nih_alloc_ref_free (ref); if (NIH_LIST_EMPTY (&ctx->parents)) nih_alloc_context_free (ctx); } /** * nih_alloc_ref_free: * @ref: reference to free. * * This is the internal function used by nih_free() and nih_unref() to * remove the reference @ref from its parent and child contexts. It does * not free the child context, even if this is the last reference. * * This function is notably not called by nih_alloc_context_unref() since * that manipulates the references to perform finalisation. **/ static inline void nih_alloc_ref_free (NihAllocRef *ref) { nih_assert (ref != NULL); nih_list_destroy (&ref->children_entry); nih_list_destroy (&ref->parents_entry); free (ref); } /** * nih_alloc_parent: * @ptr: object to query, * @parent: parent object to look for. * * @parent may be the special NULL parent. * * Returns: TRUE if @parent has a reference to @ptr, FALSE otherwise. **/ int nih_alloc_parent (const void *ptr, const void *parent) { NihAllocCtx *ctx; NihAllocRef *ref; nih_assert (ptr != NULL); ctx = NIH_ALLOC_CTX (ptr); nih_assert (ctx->destructor != NIH_ALLOC_FINALISED); ref = nih_alloc_ref_lookup (NIH_ALLOC_CTX (parent), ctx); return ref ? TRUE : FALSE; } /** * nih_alloc_ref_lookup: * @parent: parent context, * @child: child context. * * This is the internal function used by nih_unref() and nih_alloc_parent() * to lookup a reference between the @parent and @child contexts. @parent * may be the special NULL parent. * * Returns: NihAllocRef structure or NULL if no reference exists. **/ static inline NihAllocRef * nih_alloc_ref_lookup (NihAllocCtx *parent, NihAllocCtx *child) { nih_assert ((parent == NULL) || (parent->destructor != NIH_ALLOC_FINALISED)); nih_assert (child != NULL); nih_assert (child->destructor != NIH_ALLOC_FINALISED); NIH_LIST_FOREACH (&child->parents, iter) { NihAllocRef *ref = NIH_LIST_ITER (iter, NihAllocRef, parents_entry); if (ref->parent == parent) return ref; } return NULL; } /** * nih_alloc_size: * @ptr: pointer to object. * * Returns: the size of the allocated object, which may be larger than * originally requested. **/ size_t nih_alloc_size (const void *ptr) { NihAllocCtx *ctx; nih_assert (ptr != NULL); ctx = NIH_ALLOC_CTX (ptr); nih_assert (ctx->destructor != NIH_ALLOC_FINALISED); return ctx->size; } libnih-1.0.3/nih/libnih.ver0000644000175000017500000000032611445765555012464 00000000000000LIBNIH_1_0 { global: nih_*; _nih_*; program_name; package_name; package_version; package_copyright; package_bugreport; package_string; local: *; }; LIBNIH_1.0.1 { __nih_*; } LIBNIH_1_0; libnih-1.0.3/nih/main.c0000644000175000017500000004041711445765555011576 00000000000000/* libnih * * main.c - main loop handling and functions often called from main() * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "main.h" /** * VAR_RUN: * * Directory to write pid files into. **/ #define VAR_RUN "/var/run" /** * DEV_NULL: * * Device bound to stdin/out/err when daemonising. **/ #define DEV_NULL "/dev/null" /** * program_name: * * The name of the program, taken from the argument array with the directory * name portion stripped. **/ const char *program_name = NULL; /** * package_name: * * The name of the overall package, usually set to the autoconf PACKAGE_NAME * macro. This should be used in preference. **/ const char *package_name = NULL; /** * package_version: * * The version of the overall package, thus also the version of the program. * Usually set to the autoconf PACKAGE_VERSION macro. This should be used * in preference. **/ const char *package_version = NULL; /** * package_copyright: * * The copyright message for the package, taken from the autoconf * AC_COPYRIGHT macro. **/ const char *package_copyright = NULL; /** * package_bugreport: * * The e-mail address to report bugs on the package to, taken from the * autoconf PACKAGE_BUGREPORT macro. **/ const char *package_bugreport = NULL; /** * package_string: * * The human string for the program, either "program (version)" or if the * program and package names differ, "program (package version)". * Generated by nih_main_init_full(). **/ const char *package_string = NULL; /** * pid_file: * * Location of the pid file, or NULL if a reasonable default is to be * assumed. Can be set using nih_main_set_pidfile(), and is then used by * nih_main_read_pidfile(), nih_main_write_pidfile() and * nih_main_unlink_pidfile(). **/ static char *pid_file = NULL; /** * interrupt_pipe: * * Pipe used for interrupting an active select() call in case a signal * comes in between the last time we handled the signal and the time we * ran the call. **/ static int interrupt_pipe[2] = { -1, -1 }; /** * exit_loop: * * Whether to exit the running main loop, set to TRUE by a call to * nih_main_loop_exit(). **/ static __thread int exit_loop = 0; /** * exit_status: * * Status to exit the running main loop with, set by nih_main_loop_exit(). **/ static __thread int exit_status = 0; /** * nih_main_loop_functions: * * List of functions to be called in each main loop iteration. Each item * is an NihMainLoopFunc structure. **/ NihList *nih_main_loop_functions = NULL; /** * nih_main_init_full: * @argv0: program name from arguments, * @package: package name from configure, * @version: package version from configure, * @bugreport: bug report address from configure, * @copyright: package copyright message from configure. * * Should be called at the beginning of main() to initialise the various * global variables exported from this module. For autoconf-using packages * call the nih_main_init() macro instead. **/ void nih_main_init_full (const char *argv0, const char *package, const char *version, const char *bugreport, const char *copyright) { nih_assert (argv0 != NULL); nih_assert (package != NULL); nih_assert (version != NULL); /* Only take the basename of argv0, and allow it to be a login * shell. */ program_name = strrchr (argv0, '/'); if (program_name) { program_name++; } else if (argv0[0] == '-') { program_name = argv0 + 1; } else { program_name = argv0; } package_name = package; package_version = version; /* bugreport and copyright may be NULL/empty */ if (bugreport && *bugreport) package_bugreport = bugreport; if (copyright && *copyright) package_copyright = copyright; if (package_string) nih_discard ((char *)package_string); if (strcmp (program_name, package_name)) { package_string = NIH_MUST (nih_sprintf (NULL, "%s (%s %s)", program_name, package_name, package_version)); } else { package_string = NIH_MUST (nih_sprintf (NULL, "%s %s", package_name, package_version)); } } /** * nih_main_suggest_help: * * Print a message suggesting --help to stderr. **/ void nih_main_suggest_help (void) { nih_assert (program_name != NULL); fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); } /** * nih_main_version: * * Print the program version to stdout. **/ void nih_main_version (void) { nih_local char *str; nih_assert (program_name != NULL); printf ("%s\n", package_string); if (package_copyright) printf ("%s\n", package_copyright); printf ("\n"); str = NIH_MUST (nih_str_screen_wrap ( NULL, _("This is free software; see the source for " "copying conditions. There is NO warranty; " "not even for MERCHANTABILITY or FITNESS " "FOR A PARTICULAR PURPOSE."), 0, 0)); printf ("%s\n", str); } /** * nih_main_daemonise: * * Perform the necessary steps to become a daemon process, this will only * return in the child process if successful. A file will be written to * /var/run/.pid containing the pid of the child process. * * This is preferable to the libc daemon() function because it ensures * that the new process is not a session leader, so can open ttys without * worrying about them becoming its controlling terminal. * * Returns: zero on success, negative value on raised error. **/ int nih_main_daemonise (void) { pid_t pid; int i, fd; nih_assert (program_name != NULL); /* Fork off child process. This begans the detachment from our * parent process; this will terminate the intermediate process. */ pid = fork (); if (pid < 0) { nih_return_system_error (-1); } else if (pid > 0) { exit (0); } /* Become session leader of a new process group, without any * controlling tty. */ setsid (); /* When the session leader dies, SIGHUP is sent to all processes * in that process group, including the child we're about to * spawn. So make damned sure it's ignored. */ nih_signal_set_ignore (SIGHUP); /* We now spawn off a second child (or at least attempt to), * we do this so that it is guaranteed not to be a session leader, * even by accident. Therefore any open() call on a tty won't * make that it's controlling terminal. */ pid = fork (); if (pid < 0) { nih_return_system_error (-1); } else if (pid > 0) { if (nih_main_write_pidfile (pid) < 0) { NihError *err; err = nih_error_get (); nih_warn ("%s: %s", _("Unable to write pid file"), err->message); nih_free (err); } exit (0); } /* We're now in a daemon child process. Change our working directory * and file creation mask to be more appropriate. */ if (chdir ("/")) ; umask (0); /* Close the stdin/stdout/stderr that we inherited */ for (i = 0; i < 3; i++) close (i); /* And instead bind /dev/null to them */ fd = open (DEV_NULL, O_RDWR); if (fd >= 0) { while (dup (fd) < 0) ; while (dup (fd) < 0) ; } return 0; } /** * nih_main_set_pidfile: * @filename: filename to be set. * * Set the location of the process's pid file or NULL to return it to the * default location under /var/run. @filename must be an absolute path. **/ void nih_main_set_pidfile (const char *filename) { if (pid_file) nih_discard (pid_file); pid_file = NULL; if (filename) { nih_assert (filename[0] == '/'); pid_file = NIH_MUST (nih_strdup (NULL, filename)); } } /** * nih_main_get_pidfile: * * Returns the location of the process's pid file, which may be overridden * by nih_main_set_pidfile(). This is guaranteed to be an absolute path. * * Returns: internal copy of the string. **/ const char * nih_main_get_pidfile (void) { nih_assert (program_name != NULL); if (! pid_file) pid_file = NIH_MUST (nih_sprintf (NULL, "%s/%s.pid", VAR_RUN, program_name)); return pid_file; } /** * nih_main_read_pidfile: * * Reads the pid from the process'd pid file location, which can be set * with nih_main_get_pidfile(). * * Returns: pid read or negative value on no available pid. **/ pid_t nih_main_read_pidfile (void) { FILE *pidfile; const char *filename; pid_t pid; filename = nih_main_get_pidfile (); pidfile = fopen (filename, "r"); if (pidfile) { if (fscanf (pidfile, "%d", &pid) != 1) pid = -1; fclose (pidfile); } else { pid = -1; } return pid; } /** * nih_main_write_pidfile: * @pid: pid to be written. * * Writes the given @pid to the process's pid file location, which can be * set with nih_main_set_pidfile(). * * The write is performed in such a way that at the point the file exists, * the pid can be read from it. * * Returns: zero on success, negative value on raised error. **/ int nih_main_write_pidfile (pid_t pid) { FILE *pidfile; const char *filename, *ptr; nih_local char *tmpname; mode_t oldmask; int ret = -1; nih_assert (pid > 0); /* Write to a hidden temporary file alongside the pid file. * The return value is guaranteed to be an absolute path. */ filename = nih_main_get_pidfile (); ptr = strrchr (filename, '/'); tmpname = NIH_MUST (nih_sprintf (NULL, "%.*s/.%s.tmp", (int)(ptr - filename), filename, ptr + 1)); oldmask = umask (022); /* Write the pid file as atomically as we can */ pidfile = fopen (tmpname, "w"); if (! pidfile) { nih_error_raise_system (); goto error; } if ((fprintf (pidfile, "%d\n", pid) <= 0) || (fflush (pidfile) < 0) || (fsync (fileno (pidfile)) < 0) || (fclose (pidfile) < 0)) { nih_error_raise_system (); fclose (pidfile); unlink (tmpname); goto error; } if (rename (tmpname, filename) < 0) { nih_error_raise_system (); unlink (tmpname); goto error; } ret = 0; error: umask (oldmask); return ret; } /** * nih_main_unlink_pidfile: * * Removes the process's pid file, which can be set with * nih_main_set_pidfile(). * * Errors are ignored, since there's not much you can do about it. **/ void nih_main_unlink_pidfile (void) { const char *filename; filename = nih_main_get_pidfile (); unlink (filename); } /** * nih_main_loop_init: * * Initialise the loop functions list. **/ void nih_main_loop_init (void) { if (! nih_main_loop_functions) nih_main_loop_functions = NIH_MUST (nih_list_new (NULL)); /* Set up the interrupt pipe, we need it to be non blocking so that * we don't accidentally block if there's too many signals been * triggered or something */ if (interrupt_pipe[0] == -1) { NIH_ZERO (pipe (interrupt_pipe)); nih_io_set_nonblock (interrupt_pipe[0]); nih_io_set_nonblock (interrupt_pipe[1]); nih_io_set_cloexec (interrupt_pipe[0]); nih_io_set_cloexec (interrupt_pipe[1]); } } /** * nih_main_loop: * * Implements a fully functional main loop for a typical process, handling * I/O events, signals, termination of child processes, timers, etc. * * Returns: value given to nih_main_loop_exit(). **/ int nih_main_loop (void) { nih_main_loop_init (); /* Set a handler for SIGCHLD so that it can interrupt syscalls */ nih_signal_set_handler (SIGCHLD, nih_signal_handler); while (! exit_loop) { NihTimer *next_timer; struct timespec now; struct timeval timeout; fd_set readfds, writefds, exceptfds; char buf[1]; int nfds, ret; /* Use the due time of the next timer to calculate how long * to spend in select(). That way we don't sleep for any * less or more time than we need to. */ next_timer = nih_timer_next_due (); if (next_timer) { nih_assert (clock_gettime (CLOCK_MONOTONIC, &now) == 0); timeout.tv_sec = next_timer->due - now.tv_sec; timeout.tv_usec = 0; } /* Start off with empty watch lists */ FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); /* Always look for changes in the interrupt pipe */ FD_SET (interrupt_pipe[0], &readfds); nfds = interrupt_pipe[0] + 1; /* And look for changes in anything we're watching */ nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); /* Now we hang around until either a signal comes in (and * calls nih_main_loop_interrupt), a file descriptor we're * watching changes in some way or it's time to run a timer. */ ret = select (nfds, &readfds, &writefds, &exceptfds, (next_timer ? &timeout : NULL)); /* Deal with events */ if (ret > 0) nih_io_handle_fds (&readfds, &writefds, &exceptfds); /* Deal with signals. * * Clear the list first so that if a signal occurs while * handling signals it'll ensure that the functions get * a chance to decide whether to do anything next time round * without having to wait. */ while (read (interrupt_pipe[0], buf, sizeof (buf)) > 0) ; nih_signal_poll (); /* Deal with terminated children */ nih_child_poll (); /* Deal with timers */ nih_timer_poll (); /* Run the loop functions */ NIH_LIST_FOREACH_SAFE (nih_main_loop_functions, iter) { NihMainLoopFunc *func = (NihMainLoopFunc *)iter; func->callback (func->data, func); } } exit_loop = 0; return exit_status; } /** * nih_main_loop_interrupt: * * Interrupts the current (or next) main loop iteration because of an * event that potentially needs immediate processing, or because some * condition of the main loop has been changed. **/ void nih_main_loop_interrupt (void) { nih_main_loop_init (); if (interrupt_pipe[1] != -1) while (write (interrupt_pipe[1], "", 1) < 0) ; } /** * nih_main_loop_exit: * @status: exit status. * * Instructs the current (or next) main loop to exit with the given exit * status; if the loop is in the middle of processing, it will exit once * all that processing is complete. * * This may be safely called by functions called by the main loop. **/ void nih_main_loop_exit (int status) { exit_status = status; exit_loop = TRUE; nih_main_loop_interrupt (); } /** * nih_main_loop_add_func: * @parent: parent object for new callback, * @callback: function to call, * @data: pointer to pass to @callback. * * Adds @callback to the list of functions that should be called once * in each main loop iteration. * * The callback structure is allocated using nih_alloc() and stored in a * linked list. Removal of the callback can be performed by freeing it. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned callback. When all parents * of the returned callback are freed, the returned callback will also be * freed. * * Returns: the function information, or NULL if insufficient memory. **/ NihMainLoopFunc * nih_main_loop_add_func (const void *parent, NihMainLoopCb callback, void *data) { NihMainLoopFunc *func; nih_assert (callback != NULL); nih_main_loop_init (); func = nih_new (parent, NihMainLoopFunc); if (! func) return NULL; nih_list_init (&func->entry); nih_alloc_set_destructor (func, nih_list_destroy); func->callback = callback; func->data = data; nih_list_add (nih_main_loop_functions, &func->entry); return func; } /** * nih_main_term_signal: * @data: ignored, * @signal: ignored. * * Signal callback that instructs the main loop to exit with a normal * exit status, usually registered for SIGTERM and SIGINT for non-daemons. **/ void nih_main_term_signal (void *data, NihSignal *signal) { nih_main_loop_exit (0); } libnih-1.0.3/nih/child.c0000644000175000017500000001270611445765555011735 00000000000000/* libnih * * child.c - child process termination handling * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include "child.h" /** * WAITOPTS: * * Options to pass to waitid(). **/ #define WAITOPTS (WEXITED | WSTOPPED | WCONTINUED) /** * nih_child_watches: * * This is the list of current child watches, not sorted into any * particular order. Each item is an NihChildWatch structure. **/ NihList *nih_child_watches = NULL; /** * nih_child_init: * * Initialise the list of child watches. **/ void nih_child_init (void) { if (! nih_child_watches) nih_child_watches = NIH_MUST (nih_list_new (NULL)); } /** * nih_child_add_watch: * @parent: parent object for new watch, * @pid: process id to watch or -1, * @events: events to watch for, * @handler: function to call on @events, * @data: pointer to pass to @handler. * * Adds @handler to the list of functions that should be called by * nih_child_poll() if any of the events listed in @events occurs to the * process with id @pid. If @pid is -1 then @handler is called for all * children. * * The watch structure is allocated using nih_alloc() and stored in a linked * list; there is no non-allocated version because of this and because it * will be automatically freed once called if @pid is not -1 and the event * indicates that the process has terminated. * * Removal of the watch can be performed by freeing it. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned watch. When all parents * of the returned watch are freed, the returned watch will also be * freed. * * Returns: the watch information, or NULL if insufficient memory. **/ NihChildWatch * nih_child_add_watch (const void *parent, pid_t pid, NihChildEvents events, NihChildHandler handler, void *data) { NihChildWatch *watch; nih_assert (pid != 0); nih_assert (handler != NULL); nih_child_init (); watch = nih_new (parent, NihChildWatch); if (! watch) return NULL; nih_list_init (&watch->entry); nih_alloc_set_destructor (watch, nih_list_destroy); watch->pid = pid; watch->events = events; watch->handler = handler; watch->data = data; nih_list_add (nih_child_watches, &watch->entry); return watch; } /** * nih_child_poll: * * Repeatedly call waitid() until there are no children waiting to be * reaped. For each child that an event occurs for, the list of child * watches is iterated and the handler function for appropriate entries * is called. * * It is safe for the handler to remove itself. **/ void nih_child_poll (void) { siginfo_t info; nih_child_init (); /* NOTE: there's a strange kernel inconsistency, when the waitid() * syscall is native, it takes special care to zero this struct * before returning ... but when it's a compat syscall, it * specifically *doesn't* zero the struct. * * So we have to take care to do it ourselves before every call. */ memset (&info, 0, sizeof (info)); while (waitid (P_ALL, 0, &info, WAITOPTS | WNOHANG) == 0) { pid_t pid; NihChildEvents event; int status, free_watch = TRUE; pid = info.si_pid; if (! pid) break; /* Convert siginfo information to handler function arguments; * in practice this is mostly just copying, with a few bits * of lore. */ switch (info.si_code) { case CLD_EXITED: event = NIH_CHILD_EXITED; status = info.si_status; break; case CLD_KILLED: event = NIH_CHILD_KILLED; status = info.si_status; break; case CLD_DUMPED: event = NIH_CHILD_DUMPED; status = info.si_status; break; case CLD_TRAPPED: if (((info.si_status & 0x7f) == SIGTRAP) && (info.si_status & ~0x7f)) { event = NIH_CHILD_PTRACE; status = info.si_status >> 8; } else { event = NIH_CHILD_TRAPPED; status = info.si_status; } free_watch = FALSE; break; case CLD_STOPPED: event = NIH_CHILD_STOPPED; status = info.si_status; free_watch = FALSE; break; case CLD_CONTINUED: event = NIH_CHILD_CONTINUED; status = info.si_status; free_watch = FALSE; break; default: nih_assert_not_reached (); } NIH_LIST_FOREACH_SAFE (nih_child_watches, iter) { NihChildWatch *watch = (NihChildWatch *)iter; if ((watch->pid != pid) && (watch->pid != -1)) continue; if (! (watch->events & event)) continue; watch->handler (watch->data, pid, event, status); if (free_watch && (watch->pid != -1)) nih_free (watch); } /* For next waitid call */ memset (&info, 0, sizeof (info)); } } libnih-1.0.3/nih/test_list.h0000644000175000017500000000313511445765555012665 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_TEST_LIST_H #define NIH_TEST_LIST_H #ifndef NIH_IN_TEST_H # error "This header may only be included by " #endif /* NIH_IN_TEST_H */ #include /** * TEST_LIST_EMPTY: * @_list: entry in list. * * Check that the list of which @_list is a member is empty, ie. that * @_list is the sole member. **/ #define TEST_LIST_EMPTY(_list) \ if (! NIH_LIST_EMPTY (_list)) \ TEST_FAILED ("list %p (%s) not empty as expected", \ (_list), #_list) /** * TEST_LIST_NOT_EMPTY: * @_list: entry in list. * * Check that the list of which @_list is a member is not empty, ie. that * there are more members than just @_list. **/ #define TEST_LIST_NOT_EMPTY(_list) \ if (NIH_LIST_EMPTY (_list)) \ TEST_FAILED ("list %p (%s) empty, expected multiple members", \ (_list), #_list) #endif /* NIH_TEST_LIST_H */ libnih-1.0.3/nih/test_values.h0000644000175000017500000001727211445765555013220 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_TEST_VALUES_H #define NIH_TEST_VALUES_H #ifndef NIH_IN_TEST_H # error "This header may only be included by " #endif /* NIH_IN_TEST_H */ #include #include #include /** * assert0: * @_expr: expression to check. * * Wrapper around the usual assert() function that handles the common case * of asserting that @_expr returns zero, rather than a TRUE value. **/ #define assert0(_expr) \ assert ((_expr) == 0) /** * TEST_TRUE: * @_expr: value or expression to test. * * Check that the expression @_expr evaluates to TRUE. **/ #define TEST_TRUE(_expr) \ if (! (_expr)) \ TEST_FAILED ("wrong value for %s, expected TRUE got FALSE", \ #_expr) /** * TEST_FALSE: * @_expr: value or expression to test. * * Check that the expression @_expr evaluates to FALSE. **/ #define TEST_FALSE(_expr) \ if (_expr) \ TEST_FAILED ("wrong value for %s, expected FALSE got TRUE", \ #_expr) /** * TEST_EQ: * @_a: first integer, * @_b: second integer. * * Check that the two numeric values @_a and @_b are equal, they are cast * to ssize_t for display purposes. **/ #define TEST_EQ(_a, _b) \ if ((_a) != (_b)) \ TEST_FAILED ("wrong value for %s, expected %zi got %zi", \ #_a, (ssize_t)(_b), (ssize_t)(_a)) /** * TEST_EQ_U: * @_a: first unsigned integer, * @_b: second unsigned integer. * * Check that the two numeric values @_a and @_b are equal, they are cast * to size_t for display purposes. **/ #define TEST_EQ_U(_a, _b) \ if ((_a) != (_b)) \ TEST_FAILED ("wrong value for %s, expected %zu got %zu", \ #_a, (size_t)(_b), (size_t)(_a)) /** * TEST_EQ_P: * @_a: first pointer, * @_b: second pointer. * * Check that the two pointers @_a and @_b are equal. **/ #define TEST_EQ_P(_a, _b) \ if ((_a) != (_b)) \ TEST_FAILED ("wrong value for %s, expected %p got %p", \ #_a, (_b), (_a)) /** * TEST_EQ_STR: * @_a: first string, * @_b: second string. * * Check that the two strings @_a and @_b are equal. **/ #define TEST_EQ_STR(_a, _b) \ if ((_a) == NULL) { \ TEST_FAILED ("wrong value for %s, expected '%s' got NULL", \ #_a, (_b)); \ } else if (strcmp ((_a), (_b))) \ TEST_FAILED ("wrong value for %s, expected '%s' got '%s'", \ #_a, (_b), (_a)) /** * TEST_EQ_STRN: * @_a: first string, * @_b: second string. * * Check that the two strings @_a and @_b are equal, up to the length of * the second string. **/ #define TEST_EQ_STRN(_a, _b) \ if ((_a) == NULL) { \ TEST_FAILED ("wrong value for %s, expected '%.*s' got NULL", \ #_a, (int)strlen (_b), (_b)); \ } else if (strncmp ((_a), (_b), strlen (_b))) \ TEST_FAILED ("wrong value for %s, expected '%.*s' got '%.*s'", \ #_a, (int)strlen (_b), (_b), \ (int)strlen (_b), (_a)) /** * TEST_EQ_MEM: * @_a: first memory area, * @_b: second memory area, * @_l: length of @_a and @_b. * * Check that the two @_l byte long areas of memory at @_a and @_b are * identical. **/ #define TEST_EQ_MEM(_a, _b, _l) \ if ((_a) == NULL) { \ TEST_FAILED ("wrong value for %s, got unexpected NULL", \ #_a); \ } else if (memcmp ((_a), (_b), (_l))) \ TEST_FAILED ("wrong %zu bytes at %p (%s), expected %p (%s)", \ (size_t)(_l), (_a), #_a, (_b), #_b) /** * TEST_NE: * @_a: first integer, * @_b: second integer. * * Check that the two numeric values @_a and @_b are not equal, they are * cast to ssize_t for display purposes. **/ #define TEST_NE(_a, _b) \ if ((_a) == (_b)) \ TEST_FAILED ("wrong value for %s, got unexpected %zi", \ #_a, (ssize_t)(_b)) /** * TEST_NE_U: * @_a: first unsigned integer, * @_b: second unsigned integer. * * Check that the two numeric values @_a and @_b are not equal, they are * cast to size_t for display purposes. **/ #define TEST_NE_U(_a, _b) \ if ((_a) == (_b)) \ TEST_FAILED ("wrong value for %s, got unexpected %zu", \ #_a, (size_t)(_b)) /** * TEST_NE_P: * @_a: first pointer, * @_b: second pointer. * * Check that the two pointers @_a and @_b are not equal. **/ #define TEST_NE_P(_a, _b) \ if ((_a) == (_b)) \ TEST_FAILED ("wrong value for %s, got unexpected %p", \ #_a, (_b)) /** * TEST_NE_STR: * @_a: first string, * @_b: second string. * * Check that the two strings @_a and @_b are not equal. **/ #define TEST_NE_STR(_a, _b) \ if ((_a) == NULL) { \ TEST_FAILED ("wrong value for %s, expected string got NULL", \ #_a); \ } else if (! strcmp ((_a), (_b))) \ TEST_FAILED ("wrong value for %s, got unexpected '%s'", \ #_a, (_b)) /** * TEST_NE_STRN: * @_a: first string, * @_b: second string. * * Check that the two strings @_a and @_b are not equal, up to the length * of the second string. **/ #define TEST_NE_STRN(_a, _b) \ if ((_a) == NULL) { \ TEST_FAILED ("wrong value for %s, got unexpected NULL", \ #_a); \ } else if (! strncmp ((_a), (_b), strlen (_b))) \ TEST_FAILED ("wrong value for %s, got unexpected '%.*s'", \ #_a, (int)strlen (_b), (_b)) /** * TEST_NE_MEM: * @_a: first memory area, * @_b: second memory area, * @_l: length of @_a and @_b. * * Check that the two @_l byte long areas of memory at @_a and @_b are * different. **/ #define TEST_NE_MEM(_a, _b, _l) \ if ((_a) == NULL) { \ TEST_FAILED ("wrong value for %s, got unexpected NULL", \ #_a); \ } else if (! memcmp ((_a), (_b), (_l))) \ TEST_FAILED ("wrong %zu bytes at %p (%s), got unexpected %p (%s)", \ (size_t)(_l), (_a), #_a, (_b), #_b) /** * TEST_LT: * @_a: first integer, * @_b: second integer. * * Check that the numeric value @_a is less than the numeric value @_b, * they are cast to ssize_t for display purposes. **/ #define TEST_LT(_a, _b) \ if ((_a) >= (_b)) \ TEST_FAILED ("wrong value for %s, expected less than %zi got %zi", \ #_a, (ssize_t)(_b), (ssize_t)(_a)) /** * TEST_LE: * @_a: first integer, * @_b: second integer. * * Check that the numeric value @_a is less than or equal to the numeric * value @_b, they are cast to ssize_t for display purposes. **/ #define TEST_LE(_a, _b) \ if ((_a) > (_b)) \ TEST_FAILED ("wrong value for %s, expected %zi or lower got %zi", \ #_a, (ssize_t)(_b), (ssize_t)(_a)) /** * TEST_GT: * @_a: first integer, * @_b: second integer. * * Check that the numeric value @_a is greater than the numeric value @_b, * they are cast to ssize_t for display purposes. **/ #define TEST_GT(_a, _b) \ if ((_a) <= (_b)) \ TEST_FAILED ("wrong value for %s, expected greater than %zi got %zi", \ #_a, (ssize_t)(_b), (ssize_t)(_a)) /** * TEST_GE: * @_a: first integer, * @_b: second integer. * * Check that the numeric value @_a is greater than or equal to the numeric * value @_b, they are cast to ssize_t for display purposes. **/ #define TEST_GE(_a, _b) \ if ((_a) < (_b)) \ TEST_FAILED ("wrong value for %s, expected %zi or greater got %zi", \ #_a, (ssize_t)(_b), (ssize_t)(_a)) #endif /* NIH_TEST_VALUES_H */ libnih-1.0.3/nih/test.h0000644000175000017500000000226111445765555011631 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_TEST_H #define NIH_TEST_H /* For _GNU_SOURCE */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #define NIH_IN_TEST_H #include #include #include #include #include #include #include #include #undef NIH_IN_TEST_H #endif /* NIH_TEST_H */ libnih-1.0.3/nih/tree.c0000644000175000017500000003355011445765555011611 00000000000000/* libnih * * tree.c - generic binary tree implementation * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include "tree.h" /** * nih_tree_init: * @tree: tree node to be initialised. * * Initialise an already allocated tree node, once done it can be used * as the start of a new binary tree or added to an existing tree. **/ void nih_tree_init (NihTree *tree) { nih_assert (tree != NULL); tree->parent = tree->left = tree->right = NULL; } /** * nih_tree_new: * @parent: parent object for new node. * * Allocates a new tree structure, usually used as the root of a new * binary tree. You may prefer to allocate the NihTree structure statically * and use nih_tree_init() to initialise it instead. * * The structure is allocated using nih_alloc() so can be used as a context * to other allocations. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned tree node. When all parents * of the returned tree node are freed, the returned tree node will also be * freed. * * Returns: the new tree node or NULL if the allocation failed. **/ NihTree * nih_tree_new (const void *parent) { NihTree *tree; tree = nih_new (parent, NihTree); if (! tree) return NULL; nih_tree_init (tree); nih_alloc_set_destructor (tree, nih_tree_destroy); return tree; } /** * nih_tree_entry_new: * @parent: parent object for new entry. * * Allocates a new tree entry structure, leaving the caller to set the * data of the entry. * * The structure is allocated using nih_alloc() so can be used as a context * to other allocations. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned tree entry. When all parents * of the returned tree entry are freed, the returned tree entry will also be * freed. * * Returns: the new tree entry or NULL if the allocation failed. **/ NihTreeEntry * nih_tree_entry_new (const void *parent) { NihTreeEntry *tree; tree = nih_new (parent, NihTreeEntry); if (! tree) return NULL; nih_tree_init (&tree->node); nih_alloc_set_destructor (tree, nih_tree_destroy); tree->data = NULL; return tree; } /** * nih_tree_add: * @tree: node in the destination tree, * @node: node to be added to the tree, * @where: where @node should be added. * * Adds @node to a new binary tree, either as a child of or, or replacing, * the existing node @tree. The exact position is determined by @where, * which may be NIH_TREE_LEFT or NIH_TREE_RIGHT to indicate that @node * should be a child of @tree or NIH_TREE_HERE to indicate that @node * should replace @tree. * * If @node is already in another tree it is removed so there is no need * to call nih_tree_remove() before this function. There is also no * requirement that the trees be different, so this can be used to reorder * a tree. * * Returns: node replaced by @node, normally NULL. **/ NihTree * nih_tree_add (NihTree *tree, NihTree *node, NihTreeWhere where) { NihTree *replaced = NULL; nih_assert (tree != NULL); if (node) nih_tree_remove (node); if (where == NIH_TREE_LEFT) { replaced = tree->left; if (replaced) replaced->parent = NULL; tree->left = node; if (node) node->parent = tree; } else if (where == NIH_TREE_RIGHT) { replaced = tree->right; if (replaced) replaced->parent = NULL; tree->right = node; if (node) node->parent = tree; } return replaced; } /** * nih_tree_remove: * @node: node to be removed. * * Removes @node and its children from the containing tree. Neither the * node nor children are freed, and the children are not unlinked from the * node. Instead the node is returned so that it can be added to another * tree (through there's no need to call nih_tree_remove() first if you * wanted to do that) or used as the root of a new tree. * * Returns: @node as a root node. **/ NihTree * nih_tree_remove (NihTree *node) { nih_assert (node != NULL); if (node->parent) { if (node->parent->left == node) { node->parent->left = NULL; } else if (node->parent->right == node) { node->parent->right = NULL; } node->parent = NULL; } return node; } /** * nih_tree_unlink: * @node: node to be removed. * * Removes @node from its containing tree, as nih_tree_remove() does, but * also unlinks the node's children from itself so that they don't have * a dangling pointer. * * Returns: @node. **/ NihTree * nih_tree_unlink (NihTree *node) { nih_assert (node != NULL); nih_tree_remove (node); if (node->left) node->left->parent = NULL; if (node->right) node->right->parent = NULL; node->left = node->right = NULL; return node; } /** * nih_tree_destroy: * @node: node to be removed. * * Removes @node from its containing tree. * * Normally used or called from an nih_alloc() destructor so that the list * item is automatically removed from its containing list when freed. * * Returns: zero. **/ int nih_tree_destroy (NihTree *node) { nih_assert (node != NULL); nih_tree_unlink (node); return 0; } /** * VISIT: * @_node: node to check. * * Macro to expand to check whether a node is set, and whether the filter is * either unset or says not to filter this node. **/ #define VISIT(_node) ((_node) && ((! filter) || (! filter (data, (_node))))) /** * nih_tree_next_full: * @tree: tree to iterate, * @node: node just visited, * @filter: filter function to test each node, * @data: data pointer to pass to @filter. * * Iterates the @tree in-order non-recursively; to obtain the first node, * @tree should be set to the root of the tree and @node should be NULL. * Then for subsequent nodes, @node should be the previous return value * from this function. * * If @filter is given, it will be called for each node visited and must * return FALSE otherwise the node and its children will be ignored. * * Returns: next in-order node within @tree or NULL if no further nodes. **/ NihTree * nih_tree_next_full (NihTree *tree, NihTree *node, NihTreeFilter filter, void *data) { NihTree *prev; nih_assert (tree != NULL); if (node) { prev = node; if (VISIT (node->right)) { node = node->right; } else { if (node == tree) return NULL; node = node->parent; } } else { prev = tree->parent; node = tree; } for (;;) { NihTree *tmp = node; if ((prev == node->parent) && VISIT (node->left)) { node = node->left; } else if (VISIT (node->right) && (prev == node->right)) { if (node == tree) return NULL; node = node->parent; } else if (VISIT (node)) { return node; } else { return NULL; } prev = tmp; } } /** * nih_tree_prev_full: * @tree: tree to iterate, * @node: node just visited, * @filter: filter function to test each node, * @data: data pointer to pass to @filter. * * Reverse-iterates the @tree in-order non-recursively; to obtain the last * node, @tree should be set to the root of the tree and @node should be NULL. * Then for subsequent nodes, @node should be the previous return value * from this function. * * If @filter is given, it will be called for each node visited and must * return FALSE otherwise the node and its children will be ignored. * * Returns: previous in-order node within @tree or NULL if no further nodes. **/ NihTree * nih_tree_prev_full (NihTree *tree, NihTree *node, NihTreeFilter filter, void *data) { NihTree *prev; nih_assert (tree != NULL); if (node) { prev = node; if (VISIT (node->left)) { node = node->left; } else { if (node == tree) return NULL; node = node->parent; } } else { prev = tree->parent; node = tree; } for (;;) { NihTree *tmp = node; if ((prev == node->parent) && VISIT (node->right)) { node = node->right; } else if (VISIT (node->left) && (prev == node->left)) { if (node == tree) return NULL; node = node->parent; } else if (VISIT (node)) { return node; } else { return NULL; } prev = tmp; } return NULL; } /** * nih_tree_next_pre_full: * @tree: tree to iterate, * @node: node just visited, * @filter: filter function to test each node, * @data: data pointer to pass to @filter. * * Iterates the @tree in-order non-recursively; to obtain the first node, * @tree should be set to the root of the tree and @node should be NULL. * Then for subsequent nodes, @node should be the previous return value * from this function. * * If @filter is given, it will be called for each node visited and must * return FALSE otherwise the node and its children will be ignored. * * Returns: next in-order node within @tree or NULL if no further nodes. **/ NihTree * nih_tree_next_pre_full (NihTree *tree, NihTree *node, NihTreeFilter filter, void *data) { NihTree *prev; nih_assert (tree != NULL); if (node) { prev = node; if (VISIT (node->left)) { return node->left; } else if (VISIT (node->right)) { return node->right; } else { if (node == tree) return NULL; node = node->parent; } } else if (VISIT (tree)) { return tree; } else { return NULL; } for (;;) { NihTree *tmp = node; if ((prev != node->right) && VISIT (node->right)) { return node->right; } else { if (node == tree) return NULL; node = node->parent; } prev = tmp; } } /** * nih_tree_prev_pre_full: * @tree: tree to iterate, * @node: node just visited, * @filter: filter function to test each node, * @data: data pointer to pass to @filter. * * Reverse-iterates the @tree in-order non-recursively; to obtain the last * node, @tree should be set to the root of the tree and @node should be NULL. * Then for subsequent nodes, @node should be the previous return value * from this function. * * If @filter is given, it will be called for each node visited and must * return FALSE otherwise the node and its children will be ignored. * * Returns: previous in-order node within @tree or NULL if no further nodes. **/ NihTree * nih_tree_prev_pre_full (NihTree *tree, NihTree *node, NihTreeFilter filter, void *data) { NihTree *prev; nih_assert (tree != NULL); if (node) { prev = node; if (node == tree) return NULL; node = node->parent; } else { prev = tree->parent; node = tree; } for (;;) { NihTree *tmp = node; if ((prev == node->parent) && VISIT (node->right)) { node = node->right; } else if ((prev != node->left) && VISIT (node->left)) { node = node->left; } else if (VISIT (node)) { return node; } else { return NULL; } prev = tmp; } } /** * nih_tree_next_post_full: * @tree: tree to iterate, * @node: node just visited, * @filter: filter function to test each node, * @data: data pointer to pass to @filter. * * Iterates the @tree in-order non-recursively; to obtain the first node, * @tree should be set to the root of the tree and @node should be NULL. * Then for subsequent nodes, @node should be the previous return value * from this function. * * If @filter is given, it will be called for each node visited and must * return FALSE otherwise the node and its children will be ignored. * * Returns: next in-order node within @tree or NULL if no further nodes. **/ NihTree * nih_tree_next_post_full (NihTree *tree, NihTree *node, NihTreeFilter filter, void *data) { NihTree *prev; nih_assert (tree != NULL); if (node) { prev = node; if (node == tree) return NULL; node = node->parent; } else { prev = tree->parent; node = tree; } for (;;) { NihTree *tmp = node; if ((prev == node->parent) && VISIT (node->left)) { node = node->left; } else if ((prev != node->right) && VISIT (node->right)) { node = node->right; } else if (VISIT (node)) { return node; } else { return NULL; } prev = tmp; } } /** * nih_tree_prev_post_full: * @tree: tree to iterate, * @node: node just visited, * @filter: filter function to test each node, * @data: data pointer to pass to @filter. * * Reverse-iterates the @tree in-order non-recursively; to obtain the last * node, @tree should be set to the root of the tree and @node should be NULL. * Then for subsequent nodes, @node should be the previous return value * from this function. * * If @filter is given, it will be called for each node visited and must * return FALSE otherwise the node and its children will be ignored. * * Returns: previous in-order node within @tree or NULL if no further nodes. **/ NihTree * nih_tree_prev_post_full (NihTree *tree, NihTree *node, NihTreeFilter filter, void *data) { NihTree *prev; nih_assert (tree != NULL); if (node) { prev = node; if (VISIT (node->right)) { return node->right; } else if (VISIT (node->left)) { return node->left; } else { if (node == tree) return NULL; node = node->parent; } } else if (VISIT (tree)) { return tree; } else { return NULL; } for (;;) { NihTree *tmp = node; if ((prev != node->left) && VISIT (node->left)) { return node->left; } else { if (node == tree) return NULL; node = node->parent; } prev = tmp; } } libnih-1.0.3/nih/error.c0000644000175000017500000002432411445765555012002 00000000000000/* libnih * * error.c - error handling * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include "error.h" /* Prototypes for static functions */ static void nih_error_clear (void); static int nih_error_destroy (NihError *error); /** * NihErrorCtx: * @entry: list header, * @error: current error. * * This structure is used to provide barriers that errors cannot cross, * for example when performing an operation after an error has occurred. **/ typedef struct nih_error_ctx { NihList entry; NihError *error; } NihErrorCtx; /** * context_stack: * * Stack of error contexts. **/ static __thread NihList *context_stack = NULL; /** * CURRENT_CONTEXT: * * Macro to obtain the current context. **/ #define CURRENT_CONTEXT ((NihErrorCtx *)context_stack->prev) /** * DEFAULT_CONTEXT: * * Macro to obtain the default context. **/ #define DEFAULT_CONTEXT ((NihErrorCtx *)context_stack->next) /** * nih_error_init: * * Initialise the context stack. **/ void nih_error_init (void) { if (! context_stack) { context_stack = NIH_MUST (nih_list_new (NULL)); nih_error_push_context (); nih_assert (atexit (nih_error_clear) == 0); } } /** * _nih_error_raise: * @filename: filename where the error was raised, * @line: line number of @filename where the error was raised, * @function: function name the error was raised within, * @number: numeric identifier, * @message: human-readable message. * * Raises an error with the given details in the current error context, * if an unhandled error already exists then an error message is emmitted * through the logging system; you should try to avoid this. * * @message should be a static string, as it will not be freed when the * error object is. * * This function should never be called directly, instead use the * nih_error_raise() macro to pass the correct arguments for @filename, * @line and @function. **/ void _nih_error_raise (const char *filename, int line, const char *function, int number, const char *message) { NihError *error; nih_assert (filename != NULL); nih_assert (line > 0); nih_assert (function != NULL); nih_assert (number > 0); nih_assert (message != NULL); nih_error_init (); error = NIH_MUST (nih_new (NULL, NihError)); error->number = number; error->message = message; _nih_error_raise_error (filename, line, function, error); } /** * _nih_error_raise_printf: * @filename: filename where the error was raised, * @line: line number of @filename where the error was raised, * @function: function name the error was raised within, * @number: numeric identifier, * @format: format string for human-readable message. * * Raises an error with the given details in the current error context, * if an unhandled error already exists then an error message is emmitted * through the logging system; you should try to avoid this. * * The human-readable message for the error is parsed according to @format, * and allocated as a child of the error object so that it is freed. * * This function should never be called directly, instead use the * nih_error_raise_printf() macro to pass the correct arguments for @filename, * @line and @function. **/ void _nih_error_raise_printf (const char *filename, int line, const char *function, int number, const char *format, ...) { NihError *error; va_list args; nih_assert (filename != NULL); nih_assert (line > 0); nih_assert (function != NULL); nih_assert (number > 0); nih_assert (format != NULL); nih_error_init (); error = NIH_MUST (nih_new (NULL, NihError)); error->number = number; va_start (args, format); error->message = NIH_MUST (nih_vsprintf (error, format, args)); va_end (args); _nih_error_raise_error (filename, line, function, error); } /** * _nih_error_raise_system: * @filename: filename where the error was raised, * @line: line number of @filename where the error was raised, * @function: function name the error was raised within. * * Raises an error with details taken from the current value of errno, * if an unhandled error already exists then an error message is emmitted * through the logging system; you should try to avoid this. * * This function should never be called directly, instead use the * nih_error_raise_system() macro to pass the correct arguments for @filename, * @line and @function. **/ void _nih_error_raise_system (const char *filename, int line, const char *function) { NihError *error; int saved_errno; nih_assert (filename != NULL); nih_assert (line > 0); nih_assert (function != NULL); nih_assert (errno > 0); saved_errno = errno; nih_error_init (); error = NIH_MUST (nih_new (NULL, NihError)); error->number = saved_errno; error->message = NIH_MUST (nih_strdup (error, strerror (saved_errno))); _nih_error_raise_error (filename, line, function, error); errno = saved_errno; } /** * _nih_error_raise_error: * @filename: filename where the error was raised, * @line: line number of @filename where the error was raised, * @function: function name the error was raised within, * @error: existing object to raise. * * Raises the existing error object in the current error context, * if an unhandled error already exists then an error message is emmitted * through the logging system; you should try to avoid this. * * This is normally used to raise a taken error that has not been handled, * or to raise a custom error object. * * The destructor of @error will be overwritten so that the context can * be cleared when the error is freed. * * This function should never be called directly, instead use the * nih_error_raise_error() macro to pass the correct arguments for @filename, * @line and @function. **/ void _nih_error_raise_error (const char *filename, int line, const char *function, NihError * error) { nih_assert (filename != NULL); nih_assert (line > 0); nih_assert (function != NULL); nih_assert (error != NULL); nih_assert (error->number > 0); nih_assert (error->message != NULL); nih_error_init (); nih_error_clear (); error->filename = filename; error->line = line; error->function = function; CURRENT_CONTEXT->error = error; nih_alloc_set_destructor (error, nih_error_destroy); } /** * nih_error_clear: * * Ensure that the current context has no raised error, if it does then * there's a programming error so we abort after logging where the error * was originally raised. **/ static void nih_error_clear (void) { nih_assert (context_stack != NULL); if (! NIH_UNLIKELY (CURRENT_CONTEXT->error)) return; nih_fatal ("%s:%d: Unhandled error from %s: %s", CURRENT_CONTEXT->error->filename, CURRENT_CONTEXT->error->line, CURRENT_CONTEXT->error->function, CURRENT_CONTEXT->error->message); abort (); } /** * nih_error_get: * * Returns the last unhandled error from the current context. * * The object must be freed with nih_free() once you are finished with it, * otherwise the error will still considered to be raised. * * Returns: error object from current context. **/ NihError * nih_error_get (void) { NihError *error; nih_assert (context_stack != NULL); nih_assert (CURRENT_CONTEXT->error != NULL); error = CURRENT_CONTEXT->error; return error; } /** * nih_error_steal: * * Returns the last unhandled error from the current context, and removes * it from the error context. To re-raise, it must be given to * nih_error_raise_error(). * * Returns: error object from current context. **/ NihError * nih_error_steal (void) { NihError *error; nih_assert (context_stack != NULL); nih_assert (CURRENT_CONTEXT->error != NULL); error = CURRENT_CONTEXT->error; CURRENT_CONTEXT->error = NULL; nih_alloc_set_destructor (error, NULL); return error; } /** * nih_error_destroy: * @error: error being freed. * * This is the destructor function for errors, attached when the error * is connected to the context. It ensures that the error is removed from * the context when it is freed. * * Returns: always zero. **/ static int nih_error_destroy (NihError *error) { nih_assert (error != NULL); nih_assert (context_stack != NULL); nih_assert (CURRENT_CONTEXT->error != NULL); nih_assert (CURRENT_CONTEXT->error == error); CURRENT_CONTEXT->error = NULL; return 0; } /** * nih_error_push_context: * * Creates a new context in which errors can occur without disturbing any * previous unhandled error, useful for touring a particular piece of * processing that handles its own errors and may be triggered as a result * of another error. **/ void nih_error_push_context (void) { NihErrorCtx *new_context; nih_error_init (); new_context = NIH_MUST (nih_new (context_stack, NihErrorCtx)); nih_list_init (&new_context->entry); new_context->error = NULL; nih_list_add (context_stack, &new_context->entry); } /** * nih_error_pop_context: * * Ends the last context created with nih_error_push_context(), deliberate * care should be taken so that these are always properly nested (through * the correct use of scope, for example) and contexts are not left unpopped. **/ void nih_error_pop_context (void) { NihErrorCtx *context; nih_assert (context_stack != NULL); nih_assert (CURRENT_CONTEXT != DEFAULT_CONTEXT); context = CURRENT_CONTEXT; nih_error_clear (); nih_list_remove (&context->entry); nih_free (context); } libnih-1.0.3/nih/logging.c0000644000175000017500000001312311445765555012272 00000000000000/* libnih * * logging.c - message logging * * Copyright © 2010 Scott James Remnant . * Copyright © 2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include "logging.h" /** * __abort_msg: * * A glibc variable that keeps the assertion message in the core dump. **/ extern char *__abort_msg __attribute__ ((weak)); /** * logger: * * Function used to output log messages. **/ static NihLogger logger = NULL; /** * nih_log_priority: * * Lowest priority of log messages that will be given to the logger by * default. **/ NihLogLevel nih_log_priority = NIH_LOG_UNKNOWN; /** * nih_log_init: * * Initialise the default logger and priority. **/ void nih_log_init (void) { if (! logger) logger = nih_logger_printf; if (! nih_log_priority) nih_log_priority = NIH_LOG_MESSAGE; } /** * nih_log_set_logger: * @new_logger: new logger function. * * Sets the function that will be used to output log messages above the * priority set with nih_log_set_priority(). **/ void nih_log_set_logger (NihLogger new_logger) { nih_assert (new_logger != NULL); nih_log_init (); logger = new_logger; } /** * nih_log_set_priority: * @new_priority: new minimum priority. * * Sets the minimum priority of log messages to be given to the logger * function, any messages below this will be discarded. **/ void nih_log_set_priority (NihLogLevel new_priority) { nih_assert (new_priority > NIH_LOG_UNKNOWN); nih_log_init (); nih_log_priority = new_priority; } /** * nih_log_abort_message: * @message: message to be logged. * * Save @message in the glibc __abort_msg variable so it can be retrieved * by debuggers if we should crash at this point. **/ static void nih_log_abort_message (const char *message) { if (! &__abort_msg) return; if (__abort_msg) nih_discard (__abort_msg); __abort_msg = NIH_MUST (nih_strdup (NULL, message)); } /** * nih_log_message: * @priority: priority of message, * @format: printf-style format string. * * Outputs a message constructed from @format and the rest of the arguments * by passing it to the logger function if @priority is not lower than * the minimum priority. * * The message should not be newline-terminated. * * Returns: zero if successful, positive value if message was discarded due * to being below the minimum priority and negative value if the logger failed. **/ int nih_log_message (NihLogLevel priority, const char *format, ...) { nih_local char *message = NULL; va_list args; int ret; nih_assert (format != NULL); nih_log_init (); if (priority < nih_log_priority) return 1; va_start (args, format); message = NIH_MUST (nih_vsprintf (NULL, format, args)); va_end (args); if (priority >= NIH_LOG_FATAL) nih_log_abort_message (message); /* Output the message */ ret = logger (priority, message); return ret; } /** * nih_logger_printf: * @priority: priority of message being logged, * @message: message to log. * * Outputs the @message to standard output, or standard error depending * on @priority, prefixed with the program name and terminated with a new * line. * * Returns: zero on completion, negative value on error. **/ int nih_logger_printf (NihLogLevel priority, const char *message) { nih_assert (message != NULL); /* Warnings and errors belong on stderr, and must be prefixed * with the program name. Information and debug go on stdout and * are not prefixed. */ if (priority >= NIH_LOG_WARN) { const char *format; size_t idx; /* Follow GNU conventions and don't put a space between the * program name and message if the message is of the form * "something: message" */ idx = strcspn (message, " :"); if (message[idx] == ':') { format = "%s:%s\n"; } else { format = "%s: %s\n"; } if (fprintf (stderr, format, program_name, message) < 0) return -1; } else { if (printf ("%s\n", message) < 0) return -1; } return 0; } /** * nih_logger_syslog: * @priority: priority of message being logged, * @message: message to log. * * Outputs the @message to the system logging daemon, it is up to the * program to call openlog and set up the parameters for the connection. * * Returns: zero on completion, negative value on error. **/ int nih_logger_syslog (NihLogLevel priority, const char *message) { int level; nih_assert (message != NULL); switch (priority) { case NIH_LOG_DEBUG: level = LOG_DEBUG; break; case NIH_LOG_INFO: level = LOG_INFO; break; case NIH_LOG_MESSAGE: level = LOG_NOTICE; break; case NIH_LOG_WARN: level = LOG_WARNING; break; case NIH_LOG_ERROR: level = LOG_ERR; break; case NIH_LOG_FATAL: level = LOG_CRIT; break; default: level = LOG_NOTICE; } syslog (level, "%s", message); return 0; } libnih-1.0.3/nih/test_process.h0000644000175000017500000000667211445765555013401 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_TEST_PROCESS_H #define NIH_TEST_PROCESS_H #ifndef NIH_IN_TEST_H # error "This header may only be included by " #endif /* NIH_IN_TEST_H */ #include #include /** * TEST_CHILD: * @_pid: variable to store pid in. * * Spawn a child in which a test can be performed without affecting the * main flow of the process. The pid of the child is stored in @_pid. * * This macro ensures that the child has begun exectution before the * parent is allowed to continue through the usual use of a pipe. * * A block of code should follow this macro, which is the code that will * be run in the child process; if the block ends, the child will abort. **/ #define TEST_CHILD(_pid) \ do { \ int _test_fds[2]; \ fflush (stdout); \ fflush (stderr); \ assert0 (pipe (_test_fds)); \ _pid = fork (); \ if (_pid > 0) { \ char _test_buf[1]; \ close (_test_fds[1]); \ assert (read (_test_fds[0], _test_buf, 1) == 1); \ close (_test_fds[0]); \ } else if (_pid == 0) { \ close (_test_fds[0]); \ assert (write (_test_fds[1], "\n", 1) == 1); \ close (_test_fds[1]); \ } \ } while (0); \ if (_pid == 0) \ for (int _test_child = 0; _test_child < 2; _test_child++) \ if (_test_child) { \ abort (); \ } else /** * TEST_CHILD_WAIT: * @_pid: variable to store pid in, * @_fd: variable to store lock fd in. * * Spawn a child in which a test can be performed while the parent waits * in this macro for the child to reach the TEST_CHILD_RELEASE macro * or die. * * The pid of the child is stored in @_pid, a file descriptor is stored * in the @_fd variable which is used by the TEST_CHILD_RELEASE macro. * * A block of code should follow this macro, which is the code that will * be run in the child process; if the block ends, the child will abort. **/ #define TEST_CHILD_WAIT(_pid, _fd) \ do { \ int _test_fds[2]; \ fflush (stdout); \ fflush (stderr); \ assert0 (pipe (_test_fds)); \ _pid = fork (); \ if (_pid > 0) { \ char _test_buf[1]; \ close (_test_fds[1]); \ assert (read (_test_fds[0], _test_buf, 1) == 1); \ close (_test_fds[0]); \ } else if (_pid == 0) { \ close (_test_fds[0]); \ _fd = _test_fds[1]; \ } \ } while (0); \ if (_pid == 0) \ for (int _test_child = 0; _test_child < 2; _test_child++) \ if (_test_child) { \ abort (); \ } else /** * TEST_CHILD_RELEASE: * @_fd: variable lock fd stored in. * * Release the parent of a child spawned by TEST_CHILD_WAIT now that the * child has reached the critical point. **/ #define TEST_CHILD_RELEASE(_fd) \ do { \ assert (write ((_fd), "\n", 1) == 1); \ close (_fd); \ } while (0) #endif /* NIH_TEST_PROCESS_H */ libnih-1.0.3/nih/Makefile.am0000644000175000017500000000623311445765555012540 00000000000000## Process this file with automake to produce Makefile.in AM_CPPFLAGS = \ -DLOCALEDIR="\"$(localedir)\"" \ -I$(top_builddir) -I$(top_srcdir) \ -I$(top_srcdir)/intl lib_LTLIBRARIES = libnih.la libnih_la_SOURCES = \ alloc.c \ string.c \ list.c \ hash.c \ tree.c \ timer.c \ signal.c \ child.c \ io.c \ file.c \ watch.c \ main.c \ option.c \ command.c \ config.c \ logging.c \ error.c libnih_la_LDFLAGS = \ -version-info 1:0:0 if HAVE_VERSION_SCRIPT_ARG libnih_la_LDFLAGS += @VERSION_SCRIPT_ARG@=$(srcdir)/libnih.ver endif libnih_la_LIBADD = -lrt include_HEADERS = \ libnih.h nihincludedir = $(includedir)/nih nihinclude_HEADERS = \ macros.h \ alloc.h \ string.h \ list.h \ hash.h \ tree.h \ timer.h \ signal.h \ child.h \ io.h \ file.h \ watch.h \ main.h \ option.h \ command.h \ config.h \ logging.h \ error.h \ errors.h \ test.h \ test_output.h \ test_values.h \ test_process.h \ test_divert.h \ test_files.h \ test_alloc.h \ test_list.h \ test_hash.h pkgconfigdir = $(prefix)/lib/pkgconfig pkgconfig_DATA = libnih.pc EXTRA_DIST = libnih.ver libnih.supp libnih.pc.in TESTS = \ test_alloc \ test_string \ test_list \ test_hash \ test_tree \ test_timer \ test_signal \ test_child \ test_io \ test_file \ test_watch \ test_main \ test_option \ test_command \ test_config \ test_logging \ test_error check_PROGRAMS = $(TESTS) test_alloc_SOURCES = tests/test_alloc.c test_alloc_LDFLAGS = -static test_alloc_LDADD = libnih.la test_string_SOURCES = tests/test_string.c test_string_LDFLAGS = -static test_string_LDADD = libnih.la -lutil test_list_SOURCES = tests/test_list.c test_list_LDFLAGS = -static test_list_LDADD = libnih.la test_hash_SOURCES = tests/test_hash.c test_hash_LDFLAGS = -static test_hash_LDADD = libnih.la test_tree_SOURCES = tests/test_tree.c test_tree_LDFLAGS = -static test_tree_LDADD = libnih.la test_timer_SOURCES = tests/test_timer.c test_timer_LDFLAGS = -static test_timer_LDADD = libnih.la test_signal_SOURCES = tests/test_signal.c test_signal_LDFLAGS = -static test_signal_LDADD = libnih.la test_child_SOURCES = tests/test_child.c test_child_LDFLAGS = -static test_child_LDADD = libnih.la test_io_SOURCES = tests/test_io.c test_io_LDFLAGS = -static test_io_LDADD = libnih.la test_file_SOURCES = tests/test_file.c test_file_LDFLAGS = -static test_file_LDADD = libnih.la test_watch_SOURCES = tests/test_watch.c test_watch_LDFLAGS = -static test_watch_LDADD = libnih.la test_main_SOURCES = tests/test_main.c test_main_LDFLAGS = -static test_main_LDADD = libnih.la test_option_SOURCES = tests/test_option.c test_option_LDFLAGS = -static test_option_LDADD = libnih.la test_command_SOURCES = tests/test_command.c test_command_LDFLAGS = -static test_command_LDADD = libnih.la test_config_SOURCES = tests/test_config.c test_config_LDFLAGS = -static test_config_LDADD = libnih.la test_logging_SOURCES = tests/test_logging.c test_logging_LDFLAGS = -static test_logging_LDADD = libnih.la test_error_SOURCES = tests/test_error.c test_error_LDFLAGS = -static test_error_LDADD = libnih.la .PHONY: tests tests: $(BUILT_SOURCES) $(check_PROGRAMS) clean-local: rm -f *.gcno *.gcda maintainer-clean-local: rm -f *.gcov libnih-1.0.3/nih/tree.h0000644000175000017500000003230411445765555011612 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_TREE_H #define NIH_TREE_H #include /** * Provides a generic binary tree implementation. No assumption is * made about the structure of the tree, or its rules. Instead when * you add a node to a tree, you must specify the parent node and whether * to add the new node to its left or right. * * Tree nodes may be created in one of two ways. The most common is to * embed the NihTree structure as the first member of your own structure, * and initialise it with nih_tree_init() after allocating the structure. * Alternatively you may create NihTreeEntry structures with * nih_tree_entry_new() and point at your own data from them. * * If you need no data for the tree root, you may use NihTree itself and * allocate it with nih_tree_new(). * * Nodes may be added to the tree with nih_tree_add(), passing the parent * node, the new node and whether to add to the left or right. * * To remove a node from the tree, and its children, use nih_tree_remove(); * the node removed becomes the root of a new tree. * * Nodes may be moved between trees, or relocated within a tree, by simply * calling nih_tree_add() - there's no need to call nih_tree_remove() first. * * A node may also be removed from a tree and from its children using * nih_tree_unlink(); the node removed, and each of its children, become * the roots of new trees. * * Tree-iteration may be performed non-recursively in a pre-order, in-order * or post-order fashion; forwards or backwards. The functions * nih_tree_next_full(), nih_tree_prev_full(), nih_tree_next_pre_full(), * nih_tree_prev_pre_full(), nih_tree_next_post_full() and * nih_tree_prev_post_full() all return the next or previous node, allowing * for filtering. If you do not need to filter macros are provided that * pass NULL, named without the _full extension. * * These are almost always used in a for loop, so macros are provided that * expand to a for loop for each of the different orders; * NIH_TREE_FOREACH_FULL(), NIH_TREE_FOREACH_PRE_FULL() and * NIH_TREE_FOREACH_POST_FULL(). Versions which pass NULL for the filter * are provided without the _FULL extension. **/ /** * NihTreeWhere: * * These constants define a position for one node, relative to another; * usually for when adding a node to an existing tree. **/ typedef enum { NIH_TREE_LEFT = -1, NIH_TREE_RIGHT = 1, } NihTreeWhere; /** * NihTree: * @parent: parent node in the tree, * @left: left child node, * @right: right child node. * * This structure can be used both to refer to a binary tree and can be * placed in your own structures to use them as tree nodes. * * A node without any parent (root node) has @parent set to NULL, nodes * without any children (leaf nodes) have @left and @right set to NULL. * * NihTree is most useful for implementing pure binary trees, where the * properties of that structure (such as simple location or traversal) are * desired. * * General trees (where each node may have zero or more nodes, beyond two) * can be implemented using binary trees as described by Knuth (fundamentally, * head right for siblings, left for children) or as lists of children in * each node (such as used by nih_alloc); pick whichever suits your data * best. **/ typedef struct nih_tree { struct nih_tree *parent, *left, *right; } NihTree; /** * NihTreeEntry: * @node: tree node, * @data: data pointer, * @str: string pointer, * @int_data: integer value. * * This structure can be used as a generic NihTree node that contains * a pointer to generic data, a string or contains an integer value. * * You should take care of setting the data yourself. **/ typedef struct nih_tree_entry { NihTree node; union { void *data; char *str; int int_data; }; } NihTreeEntry; /** * NihTreeFilter: * @data: data pointer, * @node: node to be visited. * * A tree filter is a function that is called when iterating a tree to * determine whether a particular node and its children should be ignored. * * Returns: TRUE if the node should be ignored, FALSE otherwise. **/ typedef int (*NihTreeFilter) (void *data, NihTree *node); /** * NIH_TREE_FOREACH_FULL: * @tree: root of the tree to iterate, * @iter: name of iterator variable, * @filter: filter function to test each node, * @data: data pointer to pass to @filter. * * Expands to a for statement that in-order iterates over each node in @tree, * setting @iter to each node for the block within the loop. * * If @filter is given, it will be called for each node visited and must * return FALSE otherwise the node and its children will be ignored. * * You should not make changes to the structure of the tree while iterating, * since the order will be relatively unpredictable. **/ #define NIH_TREE_FOREACH_FULL(tree, iter, filter, data) \ for (NihTree *iter = nih_tree_next_full ((tree), NULL, (filter), (data)); \ iter != NULL; \ iter = nih_tree_next_full ((tree), iter, (filter), (data))) /** * NIH_TREE_FOREACH_PRE_FULL: * @tree: root of the tree to iterate, * @iter: name of iterator variable, * @filter: filter function to test each node, * @data: data pointer to pass to @filter. * * Expands to a for statement that pre-order iterates over each node in @tree, * setting @iter to each node for the block within the loop. * * If @filter is given, it will be called for each node visited and must * return FALSE otherwise the node and its children will be ignored. * * You should not make changes to the structure of the tree while iterating, * since the order will be relatively unpredictable. **/ #define NIH_TREE_FOREACH_PRE_FULL(tree, iter, filter, data) \ for (NihTree *iter = nih_tree_next_pre_full ((tree), NULL, (filter), (data)); \ iter != NULL; \ iter = nih_tree_next_pre_full ((tree), iter, (filter), (data))) /** * NIH_TREE_FOREACH_POST_FULL: * @tree: root of the tree to iterate, * @iter: name of iterator variable, * @filter: filter function to test each node, * @data: data pointer to pass to @filter. * * Expands to a for statement that post-order iterates over each node in @tree, * setting @iter to each node for the block within the loop. * * If @filter is given, it will be called for each node visited and must * return FALSE otherwise the node and its children will be ignored. * * You should not make changes to the structure of the tree while iterating, * since the order will be relatively unpredictable. **/ #define NIH_TREE_FOREACH_POST_FULL(tree, iter, filter, data) \ for (NihTree *iter = nih_tree_next_post_full ((tree), NULL, (filter), (data)); \ iter != NULL; \ iter = nih_tree_next_post_full ((tree), iter, (filter), (data))) /** * nih_tree_next: * @tree: tree to iterate, * @node: node just visited. * * Iterates the @tree in-order non-recursively; to obtain the first node, * @tree should be set to the root of the tree and @node should be NULL. * Then for subsequent nodes, @node should be the previous return value * from this function. * * Returns: next in-order node within @tree or NULL if no further nodes. **/ #define nih_tree_next(tree, node) \ nih_tree_next_full ((tree), (node), NULL, NULL) /** * nih_tree_prev: * @tree: tree to iterate, * @node: node just visited. * * Reverse-iterates the @tree in-order non-recursively; to obtain the last * node, @tree should be set to the root of the tree and @node should be NULL. * Then for subsequent nodes, @node should be the previous return value * from this function. * * Returns: previous in-order node within @tree or NULL if no further nodes. **/ #define nih_tree_prev(tree, node) \ nih_tree_prev_full ((tree), (node), NULL, NULL) /** * nih_tree_next_pre: * @tree: tree to iterate, * @node: node just visited. * * Iterates the @tree in-order non-recursively; to obtain the first node, * @tree should be set to the root of the tree and @node should be NULL. * Then for subsequent nodes, @node should be the previous return value * from this function. * * Returns: next in-order node within @tree or NULL if no further nodes. **/ #define nih_tree_next_pre(tree, node) \ nih_tree_next_pre_full ((tree), (node), NULL, NULL) /** * nih_tree_prev_pre: * @tree: tree to iterate, * @node: node just visited. * * Reverse-iterates the @tree in-order non-recursively; to obtain the last * node, @tree should be set to the root of the tree and @node should be NULL. * Then for subsequent nodes, @node should be the previous return value * from this function. * * Returns: previous in-order node within @tree or NULL if no further nodes. **/ #define nih_tree_prev_pre(tree, node) \ nih_tree_prev_pre_full ((tree), (node), NULL, NULL) /** * nih_tree_next_post: * @tree: tree to iterate, * @node: node just visited. * * Iterates the @tree in-order non-recursively; to obtain the first node, * @tree should be set to the root of the tree and @node should be NULL. * Then for subsequent nodes, @node should be the previous return value * from this function. * * Returns: next in-order node within @tree or NULL if no further nodes. **/ #define nih_tree_next_post(tree, node) \ nih_tree_next_post_full ((tree), (node), NULL, NULL) /** * nih_tree_prev_post: * @tree: tree to iterate, * @node: node just visited. * * Reverse-iterates the @tree in-order non-recursively; to obtain the last * node, @tree should be set to the root of the tree and @node should be NULL. * Then for subsequent nodes, @node should be the previous return value * from this function. * * Returns: previous in-order node within @tree or NULL if no further nodes. **/ #define nih_tree_prev_post(tree, node) \ nih_tree_prev_post_full ((tree), (node), NULL, NULL) /** * NIH_TREE_FOREACH: * @tree: root of the tree to iterate, * @iter: name of iterator variable. * * Expands to a for statement that in-order iterates over each node in @tree, * setting @iter to each node for the block within the loop. * * You should not make changes to the structure of the tree while iterating, * since the order will be relatively unpredictable. **/ #define NIH_TREE_FOREACH(tree, iter) \ for (NihTree *iter = nih_tree_next ((tree), NULL); iter != NULL; \ iter = nih_tree_next ((tree), iter)) /** * NIH_TREE_FOREACH_PRE: * @tree: root of the tree to iterate, * @iter: name of iterator variable. * * Expands to a for statement that pre-order iterates over each node in @tree, * setting @iter to each node for the block within the loop. * * You should not make changes to the structure of the tree while iterating, * since the order will be relatively unpredictable. **/ #define NIH_TREE_FOREACH_PRE(tree, iter) \ for (NihTree *iter = nih_tree_next_pre ((tree), NULL); iter != NULL; \ iter = nih_tree_next_pre ((tree), iter)) /** * NIH_TREE_FOREACH_POST: * @tree: root of the tree to iterate, * @iter: name of iterator variable. * * Expands to a for statement that post-order iterates over each node in @tree, * setting @iter to each node for the block within the loop. * * You should not make changes to the structure of the tree while iterating, * since the order will be relatively unpredictable. **/ #define NIH_TREE_FOREACH_POST(tree, iter) \ for (NihTree *iter = nih_tree_next_post ((tree), NULL); iter != NULL; \ iter = nih_tree_next_post ((tree), iter)) NIH_BEGIN_EXTERN void nih_tree_init (NihTree *tree); NihTree * nih_tree_new (const void *parent) __attribute__ ((warn_unused_result, malloc)); NihTreeEntry *nih_tree_entry_new (const void *parent) __attribute__ ((warn_unused_result, malloc)); NihTree * nih_tree_add (NihTree *tree, NihTree *node, NihTreeWhere where); NihTree * nih_tree_remove (NihTree *node); NihTree * nih_tree_unlink (NihTree *node); int nih_tree_destroy (NihTree *node); NihTree * nih_tree_next_full (NihTree *tree, NihTree *node, NihTreeFilter filter, void *data); NihTree * nih_tree_prev_full (NihTree *tree, NihTree *node, NihTreeFilter filter, void *data); NihTree * nih_tree_next_pre_full (NihTree *tree, NihTree *node, NihTreeFilter filter, void *data); NihTree * nih_tree_prev_pre_full (NihTree *tree, NihTree *node, NihTreeFilter filter, void *data); NihTree * nih_tree_next_post_full (NihTree *tree, NihTree *node, NihTreeFilter filter, void *data); NihTree * nih_tree_prev_post_full (NihTree *tree, NihTree *node, NihTreeFilter filter, void *data); NIH_END_EXTERN #endif /* NIH_TREE_H */ libnih-1.0.3/nih/signal.h0000644000175000017500000000511411445765555012127 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_SIGNAL_H #define NIH_SIGNAL_H #include #include #include /** * NihSignalHandler: * @data: pointer given with handler, * @signal: signal watch structure. * * A signal handler is called whenever the signal has been raised, it * is passed the NihSignal structure rather than the actual signal so that * it can be removed if desired. **/ typedef struct nih_signal NihSignal; typedef void (*NihSignalHandler) (void *data, NihSignal *signal); /** * NihSignal: * @entry: list header, * @signum: signal to catch, * @handler: function called when caught, * @data: pointer passed to @handler. * * This structure contains information about a function that should be * called whenever a particular signal is raised. The calling is done * inside the main loop rather than inside the signal handler, so the * function is free to do whatever it wishes. * * The callback can be removed by using nih_list_remove() as they are * held in a list internally. **/ struct nih_signal { NihList entry; int signum; NihSignalHandler handler; void *data; }; NIH_BEGIN_EXTERN extern NihList *nih_signals; void nih_signal_init (void); int nih_signal_set_handler (int signum, void (*handler)(int)); int nih_signal_set_default (int signum); int nih_signal_set_ignore (int signum); void nih_signal_reset (void); NihSignal * nih_signal_add_handler (const void *parent, int signum, NihSignalHandler handler, void *data) __attribute__ ((warn_unused_result, malloc)); void nih_signal_handler (int signum); void nih_signal_poll (void); const char *nih_signal_to_name (int signum); int nih_signal_from_name (const char *signame); NIH_END_EXTERN #endif /* NIH_SIGNAL_H */ libnih-1.0.3/nih/libnih.pc.in0000644000175000017500000000030411445765555012673 00000000000000prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: libnih Description: NIH Utility Library Version: @VERSION@ Libs: -L${libdir} -lnih Cflags: -I${includedir} libnih-1.0.3/nih/timer.h0000644000175000017500000000744111445765555011777 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_TIMER_H #define NIH_TIMER_H #include #include #include /** * NihTimerCb: * @data: pointer given with callback, * @timer: timer that triggered the call. * * The timer callback is called whenever the timer has been triggered. * For periodic and scheduled timers, the timer may be removed by calling * nih_list_remove() or similar; this happens automatically for timeouts. **/ typedef struct nih_timer NihTimer; typedef void (*NihTimerCb) (void *data, NihTimer *timer); /** * NihTimerType: * * Used to identify the different types of timers that can be registered; * note that scheduled timers are not yet implemented. **/ typedef enum { NIH_TIMER_TIMEOUT, NIH_TIMER_PERIODIC, NIH_TIMER_SCHEDULED } NihTimerType; /** * NihTimerSchedule: * @minutes: minutes past the hour (0-59), * @hours: hours (0-23), * @mdays: days of month (1-31), * @months: months (1-12), * @wdays: days of week (0-7). * * Indidcates when scheduled timers should be run, each member is a bit * field where the bit is 1 if the timer should be run for that value and * 0 if not. **/ typedef struct nih_timer_schedule { uint64_t minutes; uint32_t hours; uint32_t mdays; uint16_t months; uint8_t wdays; } NihTimerSchedule; /** * NihTimer: * @entry: list header, * @due: time next due, * @type: type of timer, * @timeout: seconds after registration timer should be triggered (timeout), * @period: seconds between triggerings of timer (periodic), * @schedule: detail of when to call the timer (scheduled), * @callback: function called when timer triggered, * @data: pointer passed to callback. * * Timers may be used whenever a function needs to be called later in * the process. They are divided into three types, identified by @type. * * Timeouts are called once, @timeout seconds after they were registered. * Periodic timers are called every @period seconds after they were registered. * Scheduled timers are called based on the information in @schedule. * * In all cases, a timer may be cancelled by calling nih_list_remove() on * it as they are held in a list internally. **/ struct nih_timer { NihList entry; time_t due; NihTimerType type; union { time_t timeout; time_t period; NihTimerSchedule schedule; }; NihTimerCb callback; void *data; }; NIH_BEGIN_EXTERN extern NihList *nih_timers; void nih_timer_init (void); NihTimer *nih_timer_add_timeout (const void *parent, time_t timeout, NihTimerCb callback, void *data) __attribute__ ((warn_unused_result, malloc)); NihTimer *nih_timer_add_periodic (const void *parent, time_t period, NihTimerCb callback, void *data) __attribute__ ((warn_unused_result, malloc)); NihTimer *nih_timer_add_scheduled (const void *parent, NihTimerSchedule *schedule, NihTimerCb callback, void *data) __attribute__ ((warn_unused_result, malloc)); NihTimer *nih_timer_next_due (void); void nih_timer_poll (void); NIH_END_EXTERN #endif /* NIH_TIMER_H */ libnih-1.0.3/nih/hash.c0000644000175000017500000002477311445765555011604 00000000000000/* libnih * * hash.c - Fuller/Noll/Vo hash table implementation * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include "hash.h" /** * FNV_PRIME: * * This constant is defined in the FNV description based on the size of * the hash, in our case 32-bits. **/ #define FNV_PRIME 16777619UL /** * FNV_OFFSET_BASIS: * * This constant is also defined in the FNV description and is the result * of hashing a known string wth the FNV-0 algorithm and the above prime. **/ #define FNV_OFFSET_BASIS 2166136261UL /** * primes: * * Prime numbers always give the best hash table sizes, this is a selected * list of primes giving a reasonable spread. We pick the largest one that * is smaller than the estimated number of entries for the hash. **/ static const uint32_t primes[] = { 17, 37, 79, 163, 331, 673, 1259, 2521, 5051, 10103, 20219, 40459, 80929, 160231, 320449, 640973, 1281563, 2566637, 5136083, 10250323 }; /** * num_primes: * * Number of prime numbers defined above. **/ static const size_t num_primes = sizeof (primes) / sizeof (uint32_t); /** * nih_hash_new: * @parent: parent of new hash, * @entries: rough number of entries expected, * @key_function: function used to obtain keys for entries, * @hash_function: function used to obtain hash for keys, * @cmp_function: function used to compare keys. * * Allocates a new hash table, the number of buckets selected is a prime * number that is no larger than @entries; this should be set to a rough * number of expected entries to ensure optimum distribution. * * Individual members of the hash table are NihList members, so to * associate them with a constant key @key_function must be provided, to * convert that key into a hash @hash_function must be provided and to * compare keys @cmp_function must be provided. The nih_hash_string_new() * macro wraps this function for the most common case of a string key as * the first structure member. * * The structure is allocated using nih_alloc() so it can be used as a * context to other allocations; there is no non-allocated version of this * function because the hash must be usable as a parent context to its bins. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned hash table. When all parents * of the returned hash table are freed, the returned hash table will also be * freed. * * Returns: the new hash table or NULL if the allocation failed. **/ NihHash * nih_hash_new (const void *parent, size_t entries, NihKeyFunction key_function, NihHashFunction hash_function, NihCmpFunction cmp_function) { NihHash *hash; size_t i; nih_assert (key_function != NULL); nih_assert (hash_function != NULL); nih_assert (cmp_function != NULL); hash = nih_new (parent, NihHash); if (! hash) return NULL; /* Pick the largest prime number smaller than the number of entries */ hash->size = primes[0]; for (i = 0; (i < num_primes) && (primes[i] < entries); i++) hash->size = primes[i]; /* Allocate bins */ hash->bins = nih_alloc (hash, sizeof (NihList) * hash->size); if (! hash->bins) { nih_free (hash); return NULL; } /* Initialise bins */ for (i = 0; i < hash->size; i++) nih_list_init (&hash->bins[i]); hash->key_function = key_function; hash->hash_function = hash_function; hash->cmp_function = cmp_function; return hash; } /** * nih_hash_add: * @hash: destination hash table, * @entry: entry to be added. * * Adds @entry to @hash using the value returned by the hash functions * to indicate which bin the entry should be placed into. * * For speed reasons, this function does not check whether an entry already * exists with the key. If you need that constraint use either * nih_hash_add_unique() or nih_hash_replace(). * * If @entry is already in another list it is removed so there is no need * to call nih_list_remove() before this function. * * Returns: @entry which is now a member of one of @hash's bins. **/ NihList * nih_hash_add (NihHash *hash, NihList *entry) { const void *key; uint32_t hashval; NihList *bin; nih_assert (hash != NULL); nih_assert (entry != NULL); key = hash->key_function (entry); hashval = hash->hash_function (key) % hash->size; bin = &hash->bins[hashval]; return nih_list_add (bin, entry); } /** * nih_hash_add_unique: * @hash: destination hash table, * @entry: entry to be added. * * Adds @entry to @hash using the value returned by the hash functions * to indicate which bin the entry should be placed into, provided the key * is unique. * * Because the hash table does not store the key of each entry, this requires * that the key function be called for each entry in the destination bin, so * should only be used where the uniqueness constraint is required and not * already enforced by other code. * * If @entry is already in another list it is removed so there is no need * to call nih_list_remove() before this function. * * Returns: @entry which is now a member of one of @hash's bins or NULL if * an entry already existed with the same key. **/ NihList * nih_hash_add_unique (NihHash *hash, NihList *entry) { const void *key; uint32_t hashval; NihList *bin; nih_assert (hash != NULL); nih_assert (entry != NULL); key = hash->key_function (entry); hashval = hash->hash_function (key) % hash->size; bin = &hash->bins[hashval]; NIH_LIST_FOREACH (bin, iter) { if (! hash->cmp_function (key, hash->key_function (iter))) return NULL; } return nih_list_add (bin, entry); } /** * nih_hash_replace: * @hash: destination hash table, * @entry: entry to be added. * * Adds @entry to @hash using the value returned by the hash functions * to indicate which bin the entry should be placed into, replacing any * existing entry with the same key. * * Because the hash table does not store the key of each entry, this requires * that the key function be called for each entry in the destination bin, so * should only be used where the uniqueness constraint is required and not * already enforced by other code. * * The replaced entry is returned, it is up to the caller to free it and * ensure this does not come as a surprise to other code. * * If @entry is already in another list it is removed so there is no need * to call nih_list_remove() before this function. * * Returns: existing entry with the same key replaced in the table, or NULL * if no such entry existed. **/ NihList * nih_hash_replace (NihHash *hash, NihList *entry) { const void *key; uint32_t hashval; NihList *bin, *ret = NULL; nih_assert (hash != NULL); nih_assert (entry != NULL); key = hash->key_function (entry); hashval = hash->hash_function (key) % hash->size; bin = &hash->bins[hashval]; NIH_LIST_FOREACH (bin, iter) { if (! hash->cmp_function (key, hash->key_function (iter))) { ret = nih_list_remove (iter); break; } } nih_list_add (bin, entry); return ret; } /** * nih_hash_search: * @hash: hash table to search, * @key: key to look for, * @entry: previous entry found. * * Finds all entries in @hash with a key of @key by calling the hash's * key function on each entry in the appropriate bin, starting with @entry, * until one is found. * * The initial @entry can be found by passing NULL or using nih_hash_lookup(). * * Returns: next entry in the hash or NULL if there are no more entries. **/ NihList * nih_hash_search (NihHash *hash, const void *key, NihList *entry) { uint32_t hashval; NihList *bin; nih_assert (hash != NULL); nih_assert (key != NULL); hashval = hash->hash_function (key) % hash->size; bin = &hash->bins[hashval]; NIH_LIST_FOREACH (bin, iter) { if (iter == entry) { entry = NULL; continue; } else if (entry) { continue; } else if (! hash->cmp_function (key, hash->key_function (iter))) { return iter; } } return NULL; } /** * nih_hash_lookup: * @hash: hash table to search. * @key: key to look for. * * Finds the first entry in @hash with a key of @key by calling the hash's * NihKeyFunction on each entry in the appropriate bin until one is found. * * If multiple entries are expected, use nih_hash_search() instead. * * Returns: entry found or NULL if no entry existed. **/ NihList * nih_hash_lookup (NihHash *hash, const void *key) { return nih_hash_search (hash, key, NULL); } /** * nih_hash_string_key: * @entry: entry to create key for. * * Key function that can be used for any list entry where the first member * immediately after the list header is a pointer to the string containing * the name. * * Returns: pointer to that string. **/ const char * nih_hash_string_key (NihList *entry) { nih_assert (entry != NULL); return *((const char **)((char *)entry + sizeof (NihList))); } /** * nih_hash_string_hash: * @key: string key to hash. * * Generates and returns a 32-bit hash for the given string key using the * FNV-1 algorithm as documented at http://www.isthe.com/chongo/tech/comp/fnv/ * * The returned key will need to be bounded within the number of bins * used in the hash table. * * Returns: 32-bit hash. **/ uint32_t nih_hash_string_hash (const char *key) { register uint32_t hash = FNV_OFFSET_BASIS; nih_assert (key != NULL); while (*key) { hash *= FNV_PRIME; hash ^= *(key++); } return hash; } /** * nih_hash_string_cmp: * @key1: key to compare, * @key2: key to compare against. * * Compares @key1 to @key2 case-sensitively. * * Returns: integer less than, equal to or greater than zero if @key1 is * respectively less then, equal to or greater than @key2. **/ int nih_hash_string_cmp (const char *key1, const char *key2) { nih_assert (key1 != NULL); nih_assert (key2 != NULL); return strcmp (key1, key2); } libnih-1.0.3/nih/errors.h0000644000175000017500000000405511445765555012171 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_ERRORS_H #define NIH_ERRORS_H #include #include /* Allocated error numbers */ enum { /* 0x0000 thru 0xFFFF reserved for errno */ NIH_ERROR_ERRNO_START = 0x0000L, /* 0x10000 thru 0x1FFFF reserved for libnih */ NIH_ERROR_LIBNIH_START = 0x10000L, NIH_CONFIG_EXPECTED_TOKEN, NIH_CONFIG_UNEXPECTED_TOKEN, NIH_CONFIG_TRAILING_SLASH, NIH_CONFIG_UNTERMINATED_QUOTE, NIH_CONFIG_UNTERMINATED_BLOCK, NIH_CONFIG_UNKNOWN_STANZA, NIH_DIR_LOOP_DETECTED, /* 0x20000 thru 0x2FFFF reserved for applications */ NIH_ERROR_APPLICATION_START = 0x20000L, /* 0x30000 thru 0x3FFFF reserved for libnih-dbus */ NIH_ERROR_LIBNIH_DBUS_START = 0x30000L, /* 0x80000 upwards for other libraries */ NIH_ERROR_LIBRARY_START = 0x80000L }; /* Error strings for defined messages */ #define NIH_CONFIG_EXPECTED_TOKEN_STR N_("Expected token") #define NIH_CONFIG_UNEXPECTED_TOKEN_STR N_("Unexpected token") #define NIH_CONFIG_TRAILING_SLASH_STR N_("Trailing slash in file") #define NIH_CONFIG_UNTERMINATED_QUOTE_STR N_("Unterminated quoted string") #define NIH_CONFIG_UNTERMINATED_BLOCK_STR N_("Unterminated block") #define NIH_CONFIG_UNKNOWN_STANZA_STR N_("Unknown stanza") #define NIH_DIR_LOOP_DETECTED_STR N_("Directory loop detected") #endif /* NIH_ERRORS_H */ libnih-1.0.3/nih/command.h0000644000175000017500000000767111445765555012302 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_COMMAND_H #define NIH_COMMAND_H /** * Builds on the command-line option and arguments parser to provide an * application interface where the first non-option argument is the name * of a command. Both global and command-specific options are permitted, * and global options may appear both before and after the command. * * Description your commands using an array of NihCommand members, * with each describing its options using an array of NihOption members. * Pass this all to nih_command_parser(). * * Commands are implemented with a handler function that is called, * when nih_command_parser returns it has completed its work. **/ #include #include /** * NihCommandAction; * @command: NihCommand invoked, * @args: command-line arguments. * * A command action is a function called when a command is found in the * command-line arguments. It is passed the list of arguments that * follow as an array allocated with nih_alloc(). * * The return value of the function is returned from nih_command_parser(). **/ typedef struct nih_command NihCommand; typedef int (*NihCommandAction) (NihCommand *command, char * const *args); /** * NihCommandGroup: * @title: descriptive help message. * * This structure is used to define a group of commands that are collated * together when help is given. **/ typedef struct nih_command_group { char *title; } NihCommandGroup; /** * NihCommand: * @command: command name, * @usage: usage string, * @synopsis: synopsis string, * @help: help string, * @group: group option is member of, * @options: command-specific options, * @action: function to call when found. * * This structure defines a command that may be found in the command-line * arguments after any application-specific options, and before any * command-specific options. @command must be specified which is the * string looked for. * * After @command is found in the arguments, following options are * considered specific to the command. These are specified in @options, * which should be an array of NihOption structures terminated by * NIH_OPTION_LAST. This may be NULL, in which case it is treated the same * as an empty list. * * Any remaining command-line arguments are placed in an array and given * as an argument to the @action function. * * Help for the command is built from @usage, @synopsis and @help as if * they were passed to nih_option_set_usage(), etc. for this command. **/ struct nih_command { char *command; char *usage; char *synopsis; char *help; NihCommandGroup *group; NihOption *options; NihCommandAction action; }; /** * NIH_COMMAND_LAST: * * This macro may be used as the last command in the list to avoid typing * all those NULLs yourself. **/ #define NIH_COMMAND_LAST { NULL, NULL, NULL, NULL, NULL, NULL, NULL } NIH_BEGIN_EXTERN int nih_command_parser (const void *parent, int argc, char *argv[], NihOption *options, NihCommand *commands); NihCommand *nih_command_join (const void *parent, const NihCommand *a, const NihCommand *b) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_COMMAND_H */ libnih-1.0.3/nih/child.h0000644000175000017500000000617411445765555011744 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_CHILD_H #define NIH_CHILD_H #include #include #include #include /** * NihChildEvents: * * Events that can occur for child processes, and used to determine the * content of the translated status field. For NIH_CHILD_EXITED this will * contain the exit status of the program; for NIH_CHILD_PTRACE this will * contain one of the PTRACE_EVENT_* constants; otherwise this will * contain the signal that killed, dumped, stopped or continued the process * or was trapped through ptrace. **/ typedef enum { NIH_CHILD_NONE = 0000, NIH_CHILD_EXITED = 0001, NIH_CHILD_KILLED = 0002, NIH_CHILD_DUMPED = 0004, NIH_CHILD_STOPPED = 0010, NIH_CHILD_CONTINUED = 0020, NIH_CHILD_TRAPPED = 0040, NIH_CHILD_PTRACE = 0100, NIH_CHILD_ALL = 0177 } NihChildEvents; /** * NihChildHandler: * @data: data pointer given with callback, * @pid: process that changed, * @event: event that occurred on the child, * @status: exit status of process, signal that killed it or ptrace event. * * A child handler is a function called for events on the child process * obtained through waitid(). **/ typedef void (*NihChildHandler) (void *data, pid_t pid, NihChildEvents event, int status); /** * NihChildWatch: * @entry: list header, * @pid: process id to watch or -1, * @events: events to watch for, * @handler: function called when events occur to child, * @data: pointer passed to @reaper. * * This structure represents a watch on a particular child, the @reaper * function is called when an event in @events occurs to a child with * process id @pid. If @pid is -1 then this function is called when @events * occur for all processes. * * The watch can be cancelled by calling nih_list_remove() on the structure * as they are held in a list internally. **/ typedef struct nih_child_watch { NihList entry; pid_t pid; NihChildEvents events; NihChildHandler handler; void *data; } NihChildWatch; NIH_BEGIN_EXTERN extern NihList *nih_child_watches; void nih_child_init (void); NihChildWatch *nih_child_add_watch (const void *parent, pid_t pid, NihChildEvents events, NihChildHandler handler, void *data) __attribute__ ((warn_unused_result, malloc)); void nih_child_poll (void); NIH_END_EXTERN #endif /* NIH_CHILD_H */ libnih-1.0.3/nih/config.h0000644000175000017500000001430711445765555012123 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_CONFIG_H #define NIH_CONFIG_H /** * Implements a flexible configuration parser based on keyword stanzas and zero * or more arguments, handling such matters as quotation, whitespace and * commands for you. * * You describe the stanzas with an array of NihConfigStanza members, * each is handled by a function that receives a number of arguments * referencing the current position within the file being parsed. * * The function may then call any of the parsing functions to parse its * arguments, consuming as much of the following file as it wishes. Most * will call nih_config_parse_args() to do the hard work. * * Configuration can be parsed as a file with nih_config_parse_file() or * as a string with nih_config_parse(). **/ #include #include /** * NihConfigHandler: * @data: data passed to parser, * @stanza: stanza found, * @filename: name of file being parsed, * @lineno: line number, * @file: file or string to parse, * @len: length of @file, * @pos: offset within @file. * * A config handler is a function that is called when @stanza is found * in a configuration file. * * @file may be a memory mapped file, in which case @pos is given * as the offset within that the stanza's arguments begin, and @len will * be the length of the file as a whole. * * @pos must be updated to point to the next stanza in the configuration * file, past whatever terminator is used for the one being parsed. * * If @lineno is not NULL, it contains the current line number and must be * incremented each time a new line is discovered in the file. * * (These things are taken care of for you if you use the nih_config_* * functions). * * If you encounter errors, you should use the usual logging functions to * output warnings using both @filename and @lineno, but only if @filename * is not NULL. * * Returns: zero on success, negative value on raised error. **/ typedef struct nih_config_stanza NihConfigStanza; typedef int (*NihConfigHandler) (void *data, NihConfigStanza *stanza, const char *file, size_t len, size_t *pos, size_t *lineno); /** * NihConfigStanza: * @name: stanza name, * @handler: function to call. * * This structure defines a configuration file stanza, when a stanza * called @name is found within a configuration file, @handler will be * called from a position after the stanza and any following whitespace. **/ struct nih_config_stanza { char *name; NihConfigHandler handler; }; /** * NIH_CONFIG_LAST: * * This macro may be used as the last stanza in the list to avoid typing * all those NULLs yourself. **/ #define NIH_CONFIG_LAST { NULL, NULL } /** * NIH_CONFIG_WS: * * Definition of what characters we consider whitespace. **/ #define NIH_CONFIG_WS " \t\r" /** * NIH_CONFIG_CNL: * * Definition of what characters nominally end a line; a comment start * character or a newline. **/ #define NIH_CONFIG_CNL "#\n" /** * NIH_CONFIG_CNLWS: * * Defintion of what characters nominally separate tokens. **/ #define NIH_CONFIG_CNLWS " \t\r#\n" NIH_BEGIN_EXTERN int nih_config_has_token (const char *file, size_t len, size_t *pos, size_t *lineno); int nih_config_token (const char *file, size_t len, size_t *pos, size_t *lineno, char *dest, const char *delim, int dequote, size_t *toklen) __attribute__ ((warn_unused_result)); char * nih_config_next_token (const void *parent, const char *file, size_t len, size_t *pos, size_t *lineno, const char *delim, int dequote) __attribute__ ((warn_unused_result, malloc)); char * nih_config_next_arg (const void *parent, const char *file, size_t len, size_t *pos, size_t *lineno) __attribute__ ((warn_unused_result, malloc)); void nih_config_next_line (const char *file, size_t len, size_t *pos, size_t *lineno); void nih_config_skip_whitespace (const char *file, size_t len, size_t *pos, size_t *lineno); int nih_config_skip_comment (const char *file, size_t len, size_t *pos, size_t *lineno) __attribute__ ((warn_unused_result)); char ** nih_config_parse_args (const void *parent, const char *file, size_t len, size_t *pos, size_t *lineno) __attribute__ ((warn_unused_result, malloc)); char * nih_config_parse_command (const void *parent, const char *file, size_t len, size_t *pos, size_t *lineno) __attribute__ ((warn_unused_result, malloc)); char * nih_config_parse_block (const void *parent, const char *file, size_t len, size_t *pos, size_t *lineno, const char *type) __attribute__ ((warn_unused_result, malloc)); int nih_config_skip_block (const char *file, size_t len, size_t *lineno, size_t *pos, const char *type, size_t *endpos) __attribute__ ((warn_unused_result)); int nih_config_parse_stanza (const char *file, size_t len, size_t *pos, size_t *lineno, NihConfigStanza *stanzas, void *data) __attribute__ ((warn_unused_result)); int nih_config_parse_file (const char *file, size_t len, size_t *pos, size_t *lineno, NihConfigStanza *stanzas, void *data) __attribute__ ((warn_unused_result)); int nih_config_parse (const char *filename, size_t *pos, size_t *lineno, NihConfigStanza *stanzas, void *data) __attribute__ ((warn_unused_result)); NIH_END_EXTERN #endif /* NIH_CONFIG_H */ libnih-1.0.3/nih/io.c0000644000175000017500000012422511445765555011261 00000000000000/* libnih * * io.c - file and socket input/output handling * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "io.h" /* Prototypes for static functions */ static void nih_io_watcher (NihIo *io, NihIoWatch *watch, NihIoEvents events); static inline ssize_t nih_io_watcher_read (NihIo *io, NihIoWatch *watch) __attribute__ ((warn_unused_result)); static inline ssize_t nih_io_watcher_write (NihIo *io, NihIoWatch *watch) __attribute__ ((warn_unused_result)); static void nih_io_closed (NihIo *io); static void nih_io_error (NihIo *io); static void nih_io_shutdown_check (NihIo *io); static NihIoMessage * nih_io_first_message (NihIo *io); /** * nih_io_watches; * * This is the list of current watches on file descriptors and sockets, * not sorted into any particular order. Each item is an NihIoWatch * structure. **/ NihList *nih_io_watches = NULL; /** * nih_io_init: * * Initialise the list of I/O watches. **/ void nih_io_init (void) { if (! nih_io_watches) nih_io_watches = NIH_MUST (nih_list_new (NULL)); } /** * nih_io_add_watch: * @parent: parent object for new watch, * @fd: file descriptor or socket to watch, * @events: events to watch for, * @watcher: function to call when @events occur on @fd, * @data: pointer to pass to @watcher. * * Adds @fd to the list of file descriptors and sockets to watch, when any * of @events occur @watcher will be called. @events is a bit mask * of the different events we care about. * * This is the simplest form of watch and satisfies most basic purposes. * * The watch structure is allocated using nih_alloc() and stored in a linked * list; there is no non-allocated version because of this. * * Removal of the watch can be performed by freeing it. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned watch. When all parents * of the returned watch are freed, the returned watch will also be * freed. * * Returns: the watch structure, or NULL if insufficient memory. **/ NihIoWatch * nih_io_add_watch (const void *parent, int fd, NihIoEvents events, NihIoWatcher watcher, void *data) { NihIoWatch *watch; nih_assert (fd >= 0); nih_assert (watcher != NULL); nih_io_init (); watch = nih_new (parent, NihIoWatch); if (! watch) return NULL; nih_list_init (&watch->entry); nih_alloc_set_destructor (watch, nih_list_destroy); watch->fd = fd; watch->events = events; watch->watcher = watcher; watch->data = data; nih_list_add (nih_io_watches, &watch->entry); return watch; } /** * nih_io_select_fds: * @nfds: pointer to store highest number in, * @readfds: pointer to set of descriptors to check for read, * @writefds: pointer to set of descriptors to check for write, * @exceptfds: pointer to set of descriptors to check for exceptions. * * Fills the given fd_set arrays based on the list of I/O watches. **/ void nih_io_select_fds (int *nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds) { nih_assert (nfds != NULL); nih_assert (readfds != NULL); nih_assert (writefds != NULL); nih_assert (exceptfds != NULL); nih_io_init (); NIH_LIST_FOREACH (nih_io_watches, iter) { NihIoWatch *watch = (NihIoWatch *)iter; if (watch->events & NIH_IO_READ) { FD_SET (watch->fd, readfds); *nfds = nih_max (*nfds, watch->fd + 1); } if (watch->events & NIH_IO_WRITE) { FD_SET (watch->fd, writefds); *nfds = nih_max (*nfds, watch->fd + 1); } if (watch->events & NIH_IO_EXCEPT) { FD_SET (watch->fd, exceptfds); *nfds = nih_max (*nfds, watch->fd + 1); } } } /** * nih_io_handle_fds: * @readfds: pointer to set of descriptors ready for read, * @writefds: pointer to set of descriptors ready for write, * @exceptfds: pointer to set of descriptors with exceptions. * * Receives arrays of fd_set structures which have been cleared of any * descriptors which haven't changed and iterates the watch list calling * the appropriate functions. * * It is safe for watches to remove the watch during their call. **/ void nih_io_handle_fds (fd_set *readfds, fd_set *writefds, fd_set *exceptfds) { nih_assert (readfds != NULL); nih_assert (writefds != NULL); nih_assert (exceptfds != NULL); nih_io_init (); NIH_LIST_FOREACH_SAFE (nih_io_watches, iter) { NihIoWatch *watch = (NihIoWatch *)iter; NihIoEvents events; events = NIH_IO_NONE; if ((watch->events & NIH_IO_READ) && FD_ISSET (watch->fd, readfds)) events |= NIH_IO_READ; if ((watch->events & NIH_IO_WRITE) && FD_ISSET (watch->fd, writefds)) events |= NIH_IO_WRITE; if ((watch->events & NIH_IO_EXCEPT) && FD_ISSET (watch->fd, exceptfds)) events |= NIH_IO_EXCEPT; if (events) watch->watcher (watch->data, watch, events); } } /** * nih_io_buffer_new: * @parent: parent object for new buffer. * * Allocates a new NihIoBuffer structure containing an empty buffer. * * The buffer is allocated using nih_alloc() and all functions that use the * buffer ensure that the internal data is an nih_alloc() child of the buffer * itself, so this can be freed using nih_free(); there is no non-allocated * version because of this, * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned buffer. When all parents * of the returned buffer are freed, the returned buffer will also be * freed. * * Returns: new buffer, or NULL if insufficient memory. **/ NihIoBuffer * nih_io_buffer_new (const void *parent) { NihIoBuffer *buffer; buffer = nih_new (parent, NihIoBuffer); if (! buffer) return NULL; buffer->buf = NULL; buffer->size = 0; buffer->len = 0; return buffer; } /** * nih_io_buffer_resize: * @buffer: buffer to be resized, * @grow: number of bytes to grow by. * * This function resizes the given @buffer so there is enough space for * both the current data and @grow additional bytes (which may be zero). * If there is more room than there needs to be, the buffer may actually * be decreased in size. * * Returns: zero on success, negative value if insufficient memory. **/ int nih_io_buffer_resize (NihIoBuffer *buffer, size_t grow) { char *new_buf; size_t new_len, new_size; nih_assert (buffer != NULL); new_len = buffer->len + grow; if (! new_len) { /* No bytes to store, so clean up the buffer */ if (buffer->buf) nih_unref (buffer->buf, buffer); buffer->buf = NULL; buffer->size = 0; return 0; } /* Round buffer to next largest multiple of BUFSIZ */ new_size = ((new_len - 1) / BUFSIZ) * BUFSIZ + BUFSIZ; if (new_size == buffer->size) return 0; /* Adjust buffer memory */ new_buf = nih_realloc (buffer->buf, buffer, new_size); if (! new_buf) return -1; /* Clear the area between the old and new size; this is because we * tend to pass these buffers to syscalls, and passing around * unintialised data upsets people. */ if (new_size > buffer->size) memset (new_buf + buffer->size, '\0', new_size - buffer->size); /* Note: don't adjust the length */ buffer->buf = new_buf; buffer->size = new_size; return 0; } /** * nih_io_buffer_pop: * @parent: parent object for new object, * @buffer: buffer to shrink, * @len: bytes to take. * * Takes @len bytes from the start of @buffer, reducing the size if * necessary, and returns them in a new string allocated with nih_alloc(). * @len is updated to contain the actual number of bytes returned. * * The returned string is always NULL terminated, even if there was * not a NULL in the buffer. * * If there are not @len bytes in the buffer, the maximum amount there is * will be returned, if there is nothing you'll get a zero-length string. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned object. When all parents * of the returned watch are freed, the returned object will also be * object. * * Returns: newly allocated data pointer, or NULL if insufficient memory. **/ char * nih_io_buffer_pop (const void *parent, NihIoBuffer *buffer, size_t *len) { char *str; nih_assert (buffer != NULL); nih_assert (len != NULL); *len = nih_min (*len, buffer->len); str = nih_alloc (parent, *len + 1); if (! str) return NULL; /* Copy the data into the new string and add NULL */ memcpy (str, buffer->buf, *len); str[*len] = '\0'; /* Move the buffer up */ nih_io_buffer_shrink (buffer, *len); return str; } /** * nih_io_buffer_shrink: * @buffer: buffer to shrink, * @len: bytes to remove from the front. * * Removes @len bytes from the beginning of @buffer and moves the rest * of the data up to begin there. **/ void nih_io_buffer_shrink (NihIoBuffer *buffer, size_t len) { nih_assert (buffer != NULL); len = nih_min (len, buffer->len); memmove (buffer->buf, buffer->buf + len, buffer->len - len); buffer->len -= len; /* Don't worry if this fails, it just means the buffer is larger * than it needs to be. */ nih_io_buffer_resize (buffer, 0); } /** * nih_io_buffer_push: * @buffer: buffer to extend, * @str: data to push, * @len: length of @str. * * Pushes @len bytes from @str onto the end of @buffer, increasing the size * if necessary. * * Returns: zero on success, negative value if insufficient memory. **/ int nih_io_buffer_push (NihIoBuffer *buffer, const char *str, size_t len) { nih_assert (buffer != NULL); nih_assert (str != NULL); if (nih_io_buffer_resize (buffer, len) < 0) return -1; /* Copy the data into the buffer */ memcpy (buffer->buf + buffer->len, str, len); buffer->len += len; return 0; } /** * nih_io_message_new: * @parent: parent object for new message. * * Allocates a new NihIoMessage structure with empty buffers. * * All functions that use the message structure ensure that the internal * data is an nih_alloc() child of the message or its buffers, so the entire * message freed using nih_free(); there is no non-allocated version because * of this. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned message. When all parents * of the returned message are freed, the returned message will also be * freed. * * @parent should not be the NihIo object this is to be sent with, that * will take a reference when you send the message. * * Returns: new message, or NULL if insufficient memory. **/ NihIoMessage * nih_io_message_new (const void *parent) { NihIoMessage *message; message = nih_new (parent, NihIoMessage); if (! message) return NULL; nih_list_init (&message->entry); nih_alloc_set_destructor (message, nih_list_destroy); message->addr = NULL; message->addrlen = 0; message->data = nih_io_buffer_new (message); if (! message->data) goto error; message->control = nih_new (message, struct cmsghdr *); if (! message->control) goto error; message->control[0] = NULL; return message; error: nih_free (message); return NULL; } /** * nih_io_message_add_control: * @message: message to add control message to, * @level: level of control message, * @type: protocol-specific type, * @len: length of control data, * @data: control data. * * Adds a new control message with the @level and @type given to @message. * The control data is copied from @data into the message and should be @len * bytes long. * * Returns: zero on success, negative value if insufficient memory. **/ int nih_io_message_add_control (NihIoMessage *message, int level, int type, socklen_t len, const void *data) { struct cmsghdr *cmsg, **ptr; size_t cmsglen = 0; nih_assert (message != NULL); nih_assert (data != NULL); /* Allocate the control message first */ cmsg = nih_alloc (message->control, CMSG_SPACE (len)); if (! cmsg) return -1; /* Then increase the size of the array, if this fails then we can * still leave things in a consistent state. */ for (ptr = message->control; *ptr; ptr++) cmsglen++; ptr = nih_realloc (message->control, message, sizeof (struct cmsghdr *) * (cmsglen + 2)); if (! ptr) { nih_free (cmsg); return -1; } message->control = ptr; message->control[cmsglen++] = cmsg; message->control[cmsglen] = NULL; cmsg->cmsg_level = level; cmsg->cmsg_type = type; cmsg->cmsg_len = CMSG_LEN (len); memcpy (CMSG_DATA (cmsg), data, len); return 0; } /** * nih_io_message_recv: * @parent: parent object for new message, * @fd: file descriptor to read from, * @len: number of bytes read. * * Allocates a new NihIoMessage structure and fills it with a message * received on @fd with recvmsg(). The buffer is increased in size until * all of the message can fit within it. @len is set to contain the actual * number of bytes read. * * The message structure is allocated using nih_alloc() and normally * stored in a linked list. Removal of the message can be performed by * freeing it. * * All functions that use the message structure ensure that the internal * data is an nih_alloc() child of the message or its buffers, so the entire * message freed using nih_free(). * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned message. When all parents * of the returned message are freed, the returned message will also be * freed. * * Returns: new message, or NULL on raised error. */ NihIoMessage * nih_io_message_recv (const void *parent, int fd, size_t *len) { NihIoMessage *message; nih_local NihIoBuffer *ctrl_buf = NULL; struct msghdr msghdr; struct iovec iov[1]; struct cmsghdr *cmsg; ssize_t recv_len; nih_assert (fd >= 0); nih_assert (len != NULL); message = nih_io_message_new (parent); if (! message) goto error; /* Allocate a buffer to store received control messages in */ ctrl_buf = nih_io_buffer_new (NULL); if (! ctrl_buf) goto error; /* Reserve enough space to hold the name based on the socket type */ switch (nih_io_get_family (fd)) { case PF_UNIX: message->addrlen = sizeof (struct sockaddr_un); break; case PF_INET: message->addrlen = sizeof (struct sockaddr_in); break; case PF_INET6: message->addrlen = sizeof (struct sockaddr_in6); break; default: message->addrlen = 0; } if (message->addrlen) { message->addr = nih_alloc (message, message->addrlen); if (! message->addr) goto error; msghdr.msg_name = message->addr; msghdr.msg_namelen = message->addrlen; } else { msghdr.msg_name = NULL; msghdr.msg_namelen = 0; } /* Set the flags to indicate a truncated message so that we allocate * some initial buffer space. */ msghdr.msg_flags = MSG_TRUNC | MSG_CTRUNC; do { /* Increase the size of the message buffer */ if ((msghdr.msg_flags & MSG_TRUNC) && (nih_io_buffer_resize (message->data, (message->data->size + BUFSIZ)) < 0)) goto error; msghdr.msg_iov = iov; msghdr.msg_iovlen = 1; iov[0].iov_base = message->data->buf; iov[0].iov_len = message->data->size; /* Increase the size of the control buffer */ if ((msghdr.msg_flags & MSG_CTRUNC) && (nih_io_buffer_resize (ctrl_buf, (ctrl_buf->size + BUFSIZ)) < 0)) goto error; msghdr.msg_control = ctrl_buf->buf; msghdr.msg_controllen = ctrl_buf->size; msghdr.msg_flags = 0; /* Peek at the message to determine whether or not it has * been truncated. */ recv_len = recvmsg (fd, &msghdr, MSG_PEEK); if (recv_len < 0) goto error; } while ((msghdr.msg_flags & MSG_TRUNC) || (msghdr.msg_flags & MSG_CTRUNC)); /* Receive properly this time */ recv_len = recvmsg (fd, &msghdr, 0); if (recv_len < 0) goto error; /* Update the lengths, both to the caller and of the message structure * buffers based on what was actually received. */ *len = recv_len; message->data->len = recv_len; message->addrlen = msghdr.msg_namelen; /* Copy control messages out of the buffer and add them to the * message. */ for (cmsg = CMSG_FIRSTHDR (&msghdr); cmsg; cmsg = CMSG_NXTHDR (&msghdr, cmsg)) { size_t len; len = cmsg->cmsg_len - CMSG_ALIGN (sizeof (struct cmsghdr)); NIH_ZERO (nih_io_message_add_control (message, cmsg->cmsg_level, cmsg->cmsg_type, len, CMSG_DATA (cmsg))); } return message; error: nih_error_raise_system (); if (message) nih_free (message); return NULL; } /** * nih_io_message_send: * @message: message to be sent, * @fd: file descriptor to send to. * * Send @message, an already allocated and filled NihIoMessage structure * to the file descriptor or socket @fd using sendmsg(). * * If @fd is not connected, the destination for the message can be specified * in the addr and addrlen members of the structure. The message data itself * should be pushed into the data member, and any control data added to the * control member (usually using nih_io_message_add_control()). * * Returns: length of message sent, negative value on raised error. **/ ssize_t nih_io_message_send (NihIoMessage *message, int fd) { nih_local NihIoBuffer *ctrl_buf = NULL; struct msghdr msghdr; struct iovec iov[1]; struct cmsghdr **ptr; ssize_t len; nih_assert (message != NULL); nih_assert (fd >= 0); msghdr.msg_name = message->addr; msghdr.msg_namelen = message->addrlen; msghdr.msg_iov = iov; msghdr.msg_iovlen = 1; iov[0].iov_base = message->data->buf; iov[0].iov_len = message->data->len; /* Allocate a buffer in which we store the control messages that we * need to send. */ ctrl_buf = nih_io_buffer_new (NULL); if (! ctrl_buf) nih_return_system_error (-1); for (ptr = message->control; *ptr; ptr++) { size_t len; len = CMSG_SPACE ((*ptr)->cmsg_len - CMSG_ALIGN (sizeof (struct cmsghdr))); if (nih_io_buffer_resize (ctrl_buf, len) < 0) nih_return_system_error (-1); memcpy (ctrl_buf->buf + ctrl_buf->len, *ptr, (*ptr)->cmsg_len); ctrl_buf->len += len; } msghdr.msg_control = ctrl_buf->buf; msghdr.msg_controllen = ctrl_buf->len; msghdr.msg_flags = 0; len = sendmsg (fd, &msghdr, 0); if (len < 0) nih_return_system_error (-1); return len; } /** * nih_io_reopen: * @parent: parent object for new structure, * @fd: file descriptor to manage, * @type: handling mode, * @reader: function to call when new data available, * @close_handler: function to call on close, * @error_handler: function to call on error, * @data: data to pass to functions. * * This allocates a new NihIo structure using nih_alloc(), used to manage an * already opened file descriptor. The descriptor is set to be non-blocking * if it hasn't already been and the SIGPIPE signal is set to be ignored. * The file descriptor will be closed when the structure is freed. * * If @type is NIH_IO_STREAM, the descriptor is managed in stream mode; data * to be sent and data received are held in a single buffer that is expanded * and shrunk as required. If @type is NIH_IO_MESSAGE, the descriptor is * managed in message mode; individual messages are queued to be sent and * are received into a queue as discreet messages. * * Data is automatically read from the file descriptor whenever it is * available, and stored in the receive buffer or queue. If @reader is * given, this function is called whenever new data has been received. * In stream mode, this function is under no obligation to remove any data, * it's perfectly valid to leave it in the buffer until more data is added. * In message mode, the message must be processed as even if more messages * are read, the reader will only be called with the first one in the queue. * * If @close_handler is given then it is called whenever the remote end of the * file descriptor is closed, otherwise the local end is closed and the * entire structure freed (which may be surprising to you). * * If @error_handler is given then it is called whenever any errors are * raised, otherwise the @close_handler is called or the same action taken * if that is not given either. * * The returned structure is allocated with nih_alloc() and children buffers * and watches are allocated as children so will be automatically freed; * there is no non-allocated version because of this. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned structure. When all parents * of the returned structure are freed, the returned structure will also be * freed. * * Returns: newly allocated structure, or NULL on raised error. **/ NihIo * nih_io_reopen (const void *parent, int fd, NihIoType type, NihIoReader reader, NihIoCloseHandler close_handler, NihIoErrorHandler error_handler, void *data) { NihIo *io; nih_assert (fd >= 0); io = nih_new (parent, NihIo); if (! io) nih_return_system_error (NULL); io->type = type; io->reader = reader; io->close_handler = close_handler; io->error_handler = error_handler; io->data = data; io->shutdown = FALSE; io->free = NULL; switch (io->type) { case NIH_IO_STREAM: io->send_buf = nih_io_buffer_new (io); if (! io->send_buf) goto error; io->recv_buf = nih_io_buffer_new (io); if (! io->recv_buf) goto error; break; case NIH_IO_MESSAGE: io->send_q = nih_list_new (io); if (! io->send_q) goto error; io->recv_q = nih_list_new (io); if (! io->recv_q) goto error; break; default: nih_assert_not_reached (); } /* Watcher function is called at first only if we have data to read */ io->watch = nih_io_add_watch (io, fd, NIH_IO_READ, (NihIoWatcher)nih_io_watcher, io); if (! io->watch) goto error; /* Irritating signal, means we terminate if the remote end * disconnects between a read() and a write() ... far better to * just get an errno! */ nih_signal_set_ignore (SIGPIPE); /* We want to be able to repeatedly call read and write on the * file descriptor so we always get maximum throughput, and we * don't want to end up blocking; so set the socket so that * doesn't happen. */ if (nih_io_set_nonblock (fd) < 0) goto error; nih_alloc_set_destructor (io, nih_io_destroy); return io; error: nih_error_raise_system (); nih_free (io); return NULL; } /** * nih_io_watcher: * @io: NihIo structure, * @watch: NihIoWatch for which an event occurred, * @events: events that occurred. * * This is the watcher function associated with all file descriptors being * managed by NihIo. It ensures that any data or messages available are * read and placed into the receive buffer or queue, and the reader function * is called if set. * * Any data or messaages in the send buffer or queue are written out if the * @events includes NIH_IO_WRITE. * * Errors are handled when data is read, and result in the error handled * function being called if set, otherwise the close handler is called if * set and the socket closed. **/ static void nih_io_watcher (NihIo *io, NihIoWatch *watch, NihIoEvents events) { int caught_free; nih_assert (io != NULL); nih_assert (watch != NULL); caught_free = FALSE; if (! io->free) io->free = &caught_free; /* There's data to be read */ if (events & NIH_IO_READ) { ssize_t len; len = nih_io_watcher_read (io, watch); /* We want to call the reader if we have any data in the * buffer or messages in the receive queue, even if the * remote end is closed or there was an error. In the * latter case, it means we give it once last chance to * process the messages. */ if (io->reader) { nih_error_push_context(); switch (io->type) { case NIH_IO_STREAM: if (io->recv_buf->len) io->reader (io->data, io, io->recv_buf->buf, io->recv_buf->len); break; case NIH_IO_MESSAGE: { NihIoMessage *last = NULL, *message; /* Call reader until the first message on the * queue does not change. */ last = NULL; while (((message = nih_io_first_message (io)) != last) && message) { io->reader (io->data, io, message->data->buf, message->data->len); if (caught_free) break; last = message; } break; } default: nih_assert_not_reached(); } nih_error_pop_context(); } /* Deal with errors */ if (len < 0) { NihError *err; err = nih_error_get (); switch (err->number) { case EAGAIN: case EINTR: case ENOMEM: nih_free (err); break; default: if (caught_free) return; nih_io_error (io); if (caught_free) return; goto finish; } } /* We might have been freed */ if (caught_free) return; /* Deal with socket being closed */ if ((io->type == NIH_IO_STREAM) && (! len)) { nih_io_closed (io); if (caught_free) return; goto finish; } } /* There's room to write data, send as much as we can */ if (events & NIH_IO_WRITE) { ssize_t len; len = nih_io_watcher_write (io, watch); /* Deal with errors */ if (len < 0) { NihError *err; err = nih_error_get (); switch (err->number) { case EAGAIN: case EINTR: case ENOMEM: nih_free (err); break; default: nih_io_error (io); if (caught_free) return; goto finish; } } } finish: if (io->free == &caught_free) io->free = NULL; /* Shut down the socket if it is empty */ nih_io_shutdown_check (io); } /** * nih_io_watcher_read: * @io: NihIo structure, * @watch: NihIoWatch for which an event occurred. * * Read data from the socket directly into the buffer or receive queue to * save hauling temporary blocks around. This function will call read() * or recvmsg() as many times as possible to keep the kernel-side buffers * small. * * It returns once a call errors or returns zero to indicate that the * remote end closed. * * Returns: size of last read, zero if remote end closed and negative * value on raised error. **/ static inline ssize_t nih_io_watcher_read (NihIo *io, NihIoWatch *watch) { ssize_t len = 0; nih_assert (io != NULL); nih_assert (watch != NULL); for (;;) { NihIoMessage *message; switch (io->type) { case NIH_IO_STREAM: /* Make sure there's room for at least 80 bytes * (random minimum read). */ if (nih_io_buffer_resize (io->recv_buf, 80) < 0) nih_return_system_error (-1); len = read (watch->fd, io->recv_buf->buf + io->recv_buf->len, io->recv_buf->size - io->recv_buf->len); if (len < 0) { nih_return_system_error (-1); } else if (len > 0) { io->recv_buf->len += len; } else { return 0; } break; case NIH_IO_MESSAGE: /* Use BUFSIZ as the maximum message size. */ len = BUFSIZ; message = nih_io_message_recv (io, watch->fd, (size_t *)&len); if (! message) { return -1; } else { nih_list_add (io->recv_q, &message->entry); } break; default: nih_assert_not_reached (); } } return len; } /** * nih_io_watcher_write: * @io: NihIo structure, * @watch: NihIoWatch for which an event occurred. * * Write data directly from the buffer or receive queue into the socket to * save hauling temporary blocks around. This function will call write() * or sendmsg() as many times as possible to keep the buffer or queue * small. * * It returns once a call errors or returns zero to indicate that the * remote end closed. * * Returns: size of last write, zero if remote end closed and negative * value on raised error. **/ static inline ssize_t nih_io_watcher_write (NihIo *io, NihIoWatch *watch) { ssize_t len = 0; nih_assert (io != NULL); nih_assert (watch != NULL); switch (io->type) { case NIH_IO_STREAM: while (io->send_buf->len) { len = write (watch->fd, io->send_buf->buf, io->send_buf->len); if (len < 0) nih_return_system_error (-1); nih_io_buffer_shrink (io->send_buf, len); } /* Don't check for writability if we have nothing to write */ if (! io->send_buf->len) watch->events &= ~NIH_IO_WRITE; break; case NIH_IO_MESSAGE: while (! NIH_LIST_EMPTY (io->send_q)) { NihIoMessage *message; message = (NihIoMessage *)io->send_q->next; len = nih_io_message_send (message, watch->fd); if (len < 0) return -1; nih_unref (message, io); } /* Don't check for writability if we have nothing to write */ if (NIH_LIST_EMPTY (io->send_q)) watch->events &= ~NIH_IO_WRITE; break; default: nih_assert_not_reached (); } return len; } /** * nih_io_error: * @io: structure error occurred for. * * This function is called to deal with errors that have occurred on a * file descriptor being managed by NihIo. * * Normally this just calls the error handler, or if not available, it * behaves as if the remote end was closed. **/ static void nih_io_error (NihIo *io) { nih_assert (io != NULL); if (io->error_handler) { io->error_handler (io->data, io); } else { NihError *err; err = nih_error_get (); nih_error ("%s: %s", _("Error while reading from descriptor"), err->message); nih_free (err); nih_io_closed (io); } } /** * nih_io_closed: * @io: structure to be closed. * * This function is called when the local end of a file descriptor being * managed by NihIo should be closed. Usually this is because the remote * end has been closed (without error) but it can also be because no * error handler was given * * Normally this just calls the close handler, or if not available, it * closes the file descriptor and frees the structure (which may be * surprising if you were hanging on to a pointer of it). * * Note that this can result in the error handler getting called if * there's an error caught by closing the socket. **/ static void nih_io_closed (NihIo *io) { nih_assert (io != NULL); if (io->close_handler) { io->close_handler (io->data, io); } else { nih_free (io); } } /** * nih_io_shutdown: * @io: structure to be closed. * * Marks the NihIo structure to be closed once the buffers or queue have * been emptied, rather than immediately. Closure is performed by calling * the close handler if given or nih_io_close(). * * This is most useful to send a burst of data and discard the structure * once the data has been sent, without worrying about keeping track of * the structure in the mean time. **/ void nih_io_shutdown (NihIo *io) { nih_assert (io != NULL); io->shutdown = TRUE; nih_io_shutdown_check (io); } /** * nih_io_shutdown_check: * @io: structure to be closed. * * Checks whether the NihIo structure is set to be shutdown, and has now * reached the point to be closed. Call whenever you remove data from a * buffer. **/ static void nih_io_shutdown_check (NihIo *io) { nih_assert (io != NULL); if (! io->shutdown) return; switch (io->type) { case NIH_IO_STREAM: if ((! io->send_buf->len) && (! io->recv_buf->len)) nih_io_closed (io); break; case NIH_IO_MESSAGE: if (NIH_LIST_EMPTY (io->send_q) && NIH_LIST_EMPTY (io->recv_q)) nih_io_closed (io); break; default: nih_assert_not_reached (); } } /** * nih_io_destroy: * @io: structure to be destroyed. * * Closes the file descriptor associated with an NihIo structure so that * the structure can be freed. IF an error is caught by closing the * descriptor, the error handler is called instead of the error being raised; * this allows you to group your error handling in one place rather than * special-case close. * * Normally used or called from an nih_alloc() destructor. * * Returns: zero. **/ int nih_io_destroy (NihIo *io) { nih_assert (io != NULL); if (io->free) *(io->free) = TRUE; if ((close (io->watch->fd) < 0) && io->error_handler) { nih_error_raise_system (); io->error_handler (io->data, io); } return 0; } /** * nih_io_first_message: * @io: structure to read from. * * Used to obtain the oldest message in the receive queue of @io, the * returned message is not removed from the queue, so this can be used * to "peek" at the message or manipulate it. * * The message can be removed from the queue with nih_list_remove() or * nih_free(). * * This may only be used when @io is in message mode. * * Returns: message in queue, or NULL if the queue is empty. **/ static NihIoMessage * nih_io_first_message (NihIo *io) { nih_assert (io != NULL); nih_assert (io->type == NIH_IO_MESSAGE); if (NIH_LIST_EMPTY (io->recv_q)) return NULL; return (NihIoMessage *)io->recv_q->next; } /** * nih_io_read_message: * @parent: parent object for new message, * @io: structure to read from. * * Obtains the oldest message in the receive queue of @io, removes it * from the queue and returns it reparented. * * This may only be used when @io is in message mode. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned message. When all parents * of the returned message are freed, the returned message will also be * freed. * * Returns: message from queue, or NULL if the queue is empty. **/ NihIoMessage * nih_io_read_message (const void *parent, NihIo *io) { NihIoMessage *message; nih_assert (io != NULL); nih_assert (io->type == NIH_IO_MESSAGE); message = nih_io_first_message (io); if (message) { nih_list_remove (&message->entry); nih_ref (message, parent); nih_unref (message, io); } nih_io_shutdown_check (io); return message; } /** * nih_io_send_message: * @io: structure to write to, * @message: message to write. * * Appends message to the send queue of @io so that it will be sent in * turn when possible. * * @message itself is added to the queue, and freed once written. * * When called on a message already in the send queue, this moves it to * the end of the queue. It's entirely permitted to call this on messages * taken from the receive queue (usually of another NihIo). * * This may only be used when @io is in message mode. **/ void nih_io_send_message (NihIo *io, NihIoMessage *message) { nih_assert (io != NULL); nih_assert (io->type == NIH_IO_MESSAGE); nih_assert (message != NULL); nih_list_add (io->send_q, &message->entry); nih_ref (message, io); io->watch->events |= NIH_IO_WRITE; } /** * nih_io_read: * @parent: parent object for new string, * @io: structure to read from, * @len: number of bytes to read. * * Reads @len bytes from the receive buffer of @io or the oldest message * in the receive queue and returns the data in a new string allocated with * nih_alloc() that is always NULL terminated even if there was not a NULL * in the buffer. * * @len is updated to contain the actual number of bytes returned. * * If there are not @len bytes in the buffer or message, the maximum amount * there is will be returned, if there is nothing you'll get a zero-length * string. * * If the message has no more data in the buffer, it is removed from the * receive queue, and the next call to this function will operate on the * next oldest message in the queue. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string, or NULL if insufficient memory. **/ char * nih_io_read (const void *parent, NihIo *io, size_t *len) { NihIoMessage *message; NihIoBuffer *buf; char *str; nih_assert (io != NULL); nih_assert (len != NULL); switch (io->type) { case NIH_IO_STREAM: message = NULL; buf = io->recv_buf; break; case NIH_IO_MESSAGE: /* Need to return a zero-length string if there's no message * in the queue. */ message = nih_io_first_message (io); if (! message) { *len = 0; str = nih_strdup (parent, ""); goto finish; } buf = message->data; break; default: nih_assert_not_reached (); } str = nih_io_buffer_pop (parent, buf, len); if (message && (! message->data->len)) nih_unref (message, io); finish: nih_io_shutdown_check (io); return str; } /** * nih_io_write: * @io: structure to write to, * @str: data to write, * @len: length of @str. * * Writes @len bytes from @str into the send buffer of @io, or into a new * message placed in the send queue. The data will not be sent immediately * but whenever possible. * * Care should be taken to ensure @len does not include the NULL * terminator unless you really want that sent. * * Returns: zero on success, negative value if insufficient memory. **/ int nih_io_write (NihIo *io, const char *str, size_t len) { nih_local NihIoMessage *message = NULL; NihIoBuffer * buf; nih_assert (io != NULL); nih_assert (str != NULL); switch (io->type) { case NIH_IO_STREAM: message = NULL; buf = io->send_buf; break; case NIH_IO_MESSAGE: message = nih_io_message_new (NULL); if (! message) return -1; buf = message->data; break; default: nih_assert_not_reached (); } if (nih_io_buffer_push (buf, str, len) < 0) return -1; if (message) { nih_io_send_message (io, message); } else if (buf->len) { io->watch->events |= NIH_IO_WRITE; } return 0; } /** * nih_io_get: * @parent: parent object for new string, * @io: structure to read from, * @delim: character to read until. * * Reads from the receive buffer of @io or the oldest message in the * receive queue until a character in @delim or the NULL terminator is * found, and returns a new string allocated with nih_alloc() that contains * a copy of the string up to, but not including, the delimiter. * * @delim may be the empty string if only the NULL terminator is considered * a delimiter. * * The string and the delimiter are removed from the buffer or message. * * If the message has no more data in the buffer, it is removed from the * receive queue, and the next call to this function will operate on the * next oldest message in the queue. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if delimiter not found or * insufficient memory. **/ char * nih_io_get (const void *parent, NihIo *io, const char *delim) { NihIoMessage *message; NihIoBuffer *buf; char *str; size_t i; nih_assert (io != NULL); nih_assert (delim != NULL); str = NULL; switch (io->type) { case NIH_IO_STREAM: message = NULL; buf = io->recv_buf; break; case NIH_IO_MESSAGE: message = nih_io_first_message (io); if (! message) goto finish; buf = message->data; break; default: nih_assert_not_reached (); } /* Find the end of the string */ for (i = 0; i < buf->len; i++) { if (strchr (delim, buf->buf[i]) || (buf->buf[i] == '\0')) { /* Remove the string, and then the delimiter */ str = nih_io_buffer_pop (parent, buf, &i); if (! str) return NULL; nih_io_buffer_shrink (buf, 1); break; } } if (message && (! message->data->len)) nih_unref (message, io); finish: nih_io_shutdown_check (io); return str; } /** * nih_io_printf: * @io: structure to write to, * @format: printf format string. * * Writes data formatted according to the printf-style @format string to * the send buffer of @io, or into a new message placed in the send queue. * The data will not be sent immediately but whenever possible. * * Returns: zero on success, negative value if insufficient memory. **/ int nih_io_printf (NihIo *io, const char *format, ...) { nih_local char *str = NULL; va_list args; int ret; nih_assert (io != NULL); nih_assert (format != NULL); va_start (args, format); str = nih_vsprintf (NULL, format, args); va_end (args); if (! str) return -1; ret = nih_io_write (io, str, strlen (str)); return ret; } /** * nih_io_set_nonblock: * @fd: file descriptor to change. * * Change the flags of @fd so that all operations become non-blocking. * * Returns: zero on success, negative value on invalid file descriptor. **/ int nih_io_set_nonblock (int fd) { int flags; nih_assert (fd >= 0); flags = fcntl (fd, F_GETFL); if (flags < 0) return -1; flags |= O_NONBLOCK; if (fcntl (fd, F_SETFL, flags) < 0) return -1; return 0; } /** * nih_io_set_cloexec: * @fd: file descriptor to change. * * Change the flags of @fd so that the file descriptor is closed on exec(). * * Returns: zero on success, negative value on invalid file descriptor. **/ int nih_io_set_cloexec (int fd) { int flags; nih_assert (fd >= 0); flags = fcntl (fd, F_GETFD); if (flags < 0) return -1; flags |= FD_CLOEXEC; if (fcntl (fd, F_SETFD, flags) < 0) return -1; return 0; } /** * nih_io_get_family: * @fd: file descriptor to check. * * Queries the socket so that the family it belongs to (PF_UNIX, PF_INET, * PF_INET6) can be found. * * Returns: the family of the socket, or -1 on error. **/ ssize_t nih_io_get_family (int fd) { socklen_t socklen; union { sa_family_t family; struct sockaddr_un un; struct sockaddr_in in; struct sockaddr_in6 in6; } addr; nih_assert (fd >= 0); socklen = sizeof (addr); if (getsockname (fd, (struct sockaddr *)&addr, &socklen) < 0) return -1; return addr.family; } libnih-1.0.3/nih/test_output.h0000644000175000017500000000456711445765555013264 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_TEST_OUTPUT_H #define NIH_TEST_OUTPUT_H #ifndef NIH_IN_TEST_H # error "This header may only be included by " #endif /* NIH_IN_TEST_H */ #include #include /** * TEST_GROUP: * @_name: name of group being tested. * * Output a message indicating that a group of tests testing @_name are * being performed. **/ #define TEST_GROUP(_name) \ printf ("Testing %s\n", _name) /** * TEST_FUNCTION: * @_func: name of function being tested. * * Output a message indicating that tests of the function named @_func are * being performed. **/ #define TEST_FUNCTION(_func) \ printf ("Testing %s()\n", _func) /** * TEST_FUNCTION_FEATURE: * @_func: name of function being tested, * @_feat: feature being tested. * * Output a message indicating that tests of the function named @_func are * being performed, specifically of the @_feat feature. **/ #define TEST_FUNCTION_FEATURE(_func, _feat) \ printf ("Testing %s() %s\n", _func, _feat) /** * TEST_FEATURE: * @_feat: name of function feature being tested. * * Output a message indicating that a sub-test of a function is being * performed, specifically the feature named _feat. **/ #define TEST_FEATURE(_feat) \ printf ("...%s\n", _feat); /** * TEST_FAILED: * @_fmt: format string. * * Output a formatted message indicating that a test has failed, including * the file, line number and function where the failure happened. **/ #define TEST_FAILED(_fmt, ...) \ do { \ printf ("BAD: " _fmt "\n\tat %s:%d (%s).\n", \ ##__VA_ARGS__, __FILE__, __LINE__, __FUNCTION__); \ abort (); \ } while (0) #endif /* NIH_TEST_OUTPUT_H */ libnih-1.0.3/nih/watch.h0000644000175000017500000001226211445765555011762 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_WATCH_H #define NIH_WATCH_H #include #include #include #include #include #include #include #include /* Predefine the typedefs as we use them in the callbacks */ typedef struct nih_watch NihWatch; /** * NihCreateHandler: * @data: data pointer given when registered, * @watch: NihWatch for directory tree, * @path: full path to file, * @statbuf: stat of @path. * * A create handler is a function that is called whenever a file or other * object is created under or moved into a directory tree being watched. * @path contains the path to the file, including the directory prefix * which can be found in @watch. * * It is safe to remove the watch with nih_free() from this function. **/ typedef void (*NihCreateHandler) (void *data, NihWatch *watch, const char *path, struct stat *statbuf); /** * NihModifyHandler: * @data: data pointer given when registered, * @watch: NihWatch for directory tree, * @path: full path to file, * @statbuf: stat of @path. * * A modify handler is a function that is called whenever a file or other * object is changed within a directory tree being watched. @path contains * the path to the file, including the directory prefix which can be * found in @watch. * * It is safe to remove the watch with nih_free() from this function. **/ typedef void (*NihModifyHandler) (void *data, NihWatch *watch, const char *path, struct stat *statbuf); /** * NihDeleteHandler: * @data: data pointer given when registered, * @watch: NihWatch for directory tree, * @path: full path to file. * * A delete handler is a function that is called whenever a file or other * object is deleted from or moved out of a directory tree being watched. * @path contains the path to the file, including the directory prefix * which can be found in @watch. * * If the directory being watched itself is deleted, or an error occurs * with the inotify socket (including closure), this function is called * with the top-level path as an argument (check watch->path). It is * normal and safe to free the watch at this point. * * It is safe to remove the watch with nih_free() from this function. **/ typedef void (*NihDeleteHandler) (void *data, NihWatch *watch, const char *path); /** * NihWatch: * @fd: inotify instance, * @io: NihIo structure to watch @fd, * @path: full path to be watched, * @watches: list of watch descriptors, * @subdirs: include sub-directories of @path, * @create: call @create_handler for existing files, * @filter: function to filter paths watched, * @create_handler: function called when a path is created, * @modify_handler: function called when a path is modified, * @delete_handler: function called when a path is deleted, * @created: hash table of created files, * @data: pointer to pass to functions, * @free: allows free to be called within a handler. * * This structure represents an inotify instance that is watching @path, * and optionally sub-directories underneath it. It can also be used to * just watch multiple different files calling the same functions for each. **/ struct nih_watch { int fd; NihIo *io; char *path; NihList watches; int subdirs; int create; NihFileFilter filter; NihCreateHandler create_handler; NihModifyHandler modify_handler; NihDeleteHandler delete_handler; NihHash *created; void *data; int *free; }; /** * NihWatchHandle: * @entry: entry in list, * @wd: inotify watch handle, * @path: path being watched. * * This structure represents an inotify watch on an individual @path with * a unique watch descriptor @wd. They are stored in the watches list of * an NihWatch structure. **/ typedef struct nih_watch_handle { NihList entry; int wd; char *path; } NihWatchHandle; NIH_BEGIN_EXTERN NihWatch *nih_watch_new (const void *parent, const char *path, int subdirs, int create, NihFileFilter filter, NihCreateHandler create_handler, NihModifyHandler modify_handler, NihDeleteHandler delete_handler, void *data) __attribute__ ((warn_unused_result, malloc)); int nih_watch_add (NihWatch *watch, const char *path, int subdirs) __attribute__ ((warn_unused_result)); int nih_watch_destroy (NihWatch *watch); NIH_END_EXTERN #endif /* NIH_WATCH_H */ libnih-1.0.3/nih/test_files.h0000644000175000017500000002120411445765555013011 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_TEST_FILES_H #define NIH_TEST_FILES_H #ifndef NIH_IN_TEST_H # error "This header may only be included by " #endif /* NIH_IN_TEST_H */ #include #include #include #include #include #include #include #include /** * TEST_FILENAME: * @_var: variable to store filename in. * * Generate a filename that may be used for testing, it's unlinked it if * exists and it's up to you to unlink it when done. @_var should be at * least PATH_MAX long. **/ #define TEST_FILENAME(_var) \ do { \ snprintf ((_var), sizeof (_var), "/tmp/%s-%s-%d-%d", \ strrchr (__FILE__, '/') ? strrchr (__FILE__, '/') + 1 : __FILE__, \ __FUNCTION__, __LINE__, getpid ()); \ unlink (_var); \ } while (0) /** * TEST_FILE_EQ: * @_file: FILE to read from, * @_line: line to expect. * * Check that the next line in the file @_file is @_line, which should * include the terminating newline if one is expected. **/ #define TEST_FILE_EQ(_file, _line) \ do { \ char _test_file[512]; \ if (! fgets (_test_file, sizeof (_test_file), (_file))) \ TEST_FAILED ("eof on file %p (%s), expected '%s'", \ (_file), #_file, (_line)); \ if (strcmp (_test_file, (_line))) \ TEST_FAILED ("wrong content in file %p (%s), expected '%s' got '%s'", \ (_file), #_file, (_line), _test_file); \ } while (0) /** * TEST_FILE_MATCH: * @_file: FILE to read from, * @_pattern: pattern to expect. * * Check that the next line in the file @_file matches the glob pattern * @_pattern, which should include the terminating newline if one is expected. **/ #define TEST_FILE_MATCH(_file, _pattern) \ do { \ char _test_file[512]; \ if (! fgets (_test_file, sizeof (_test_file), (_file))) \ TEST_FAILED ("eof on file %p (%s), expected '%s'", \ (_file), #_file, (_pattern)); \ if (fnmatch ((_pattern), _test_file, 0)) \ TEST_FAILED ("wrong content in file %p (%s), expected '%s' got '%s'", \ (_file), #_file, (_pattern), _test_file); \ } while (0) /** * TEST_FILE_EQ_N: * @_file: FILE to read from, * @_line: line to expect. * * Check that the start of the next line in the file @_file is @_line, up to * the length of that argument. **/ #define TEST_FILE_EQ_N(_file, _line) \ do { \ char _test_file[512]; \ if (! fgets (_test_file, sizeof (_test_file), (_file))) \ TEST_FAILED ("eof on file %p (%s), expected '%s'", \ (_file), #_file, (_line)); \ if (strncmp (_test_file, (_line), strlen (_line))) \ TEST_FAILED ("wrong content in file %p (%s), expected '%.*s' got '%.*s'", \ (_file), #_file, (int)strlen (_line), (_line), \ (int)strlen (_line), _test_file); \ } while (0) /** * TEST_FILE_NE: * @_file: FILE to read from, * @_line: line to expect. * * Check that the next line in the file @_file is not @_line, but also not * end of file. **/ #define TEST_FILE_NE(_file, _line) \ do { \ char _test_file[512]; \ if (! fgets (_test_file, sizeof (_test_file), (_file))) \ TEST_FAILED ("eof on file %p (%s), expected line other than '%s'", \ (_file), #_file, (_line)); \ if (! strcmp (_test_file, (_line))) \ TEST_FAILED ("wrong content in file %p (%s), got unexpected '%s'", \ (_file), #_file, (_line)); \ } while (0) /** * TEST_FILE_NE_N: * @_file: FILE to read from, * @_line: line to expect. * * Check that the next line in the file @_file does not start with @_line, * up to the length of that argument; but also not end of file. **/ #define TEST_FILE_NE_N(_file, _line) \ do { \ char _test_file[512]; \ if (! fgets (_test_file, sizeof (_test_file), (_file))) \ TEST_FAILED ("eof on file %p (%s), expected line other than '%s'", \ (_file), #_file, (_line)); \ if (! strncmp (_test_file, (_line), strlen (_line))) \ TEST_FAILED ("wrong content in file %p (%s), got unexpected '%.*s'", \ (_file), #_file, (int)strlen (_line), (_line)); \ } while (0) /** * TEST_FILE_END: * @_file: FILE to check. * * Check that the end of the file @_file has been reached, and that there * are no more lines to read. **/ #define TEST_FILE_END(_file) \ do { \ char _test_file[512];\ if (fgets (_test_file, sizeof (_test_file), (_file))) \ TEST_FAILED ("wrong content in file %p (%s), expected eof got '%s'", \ (_file), #_file, _test_file); \ } while (0) /** * TEST_FILE_RESET: * @_file: FILE to reset. * * This macro may be used to reset a temporary file such that it can be * treated as a new one. **/ #define TEST_FILE_RESET(_file) \ do { \ fflush (_file); \ rewind (_file); \ assert0 (ftruncate (fileno (_file), 0)); \ } while (0) /** * TEST_EXPECTED_STR: * @_str: string to check, * @_filename: filename to compare against. * * Check that the string @_str exactly matches the contents of the * file @_filename, which is local to the expected directory. **/ #define TEST_EXPECTED_STR(_str, _filename) \ do { \ char _test_file[512]; \ char * _test_basename; \ int _test_fd; \ struct stat _test_stat; \ char * _test_buf; \ \ strcpy (_test_file, __FILE__); \ _test_basename = strrchr (_test_file, '/'); \ strcpy (_test_basename ? _test_basename + 1 : _test_file, "expected/"); \ strcat (_test_file, (_filename)); \ \ _test_fd = open (_test_file, O_RDONLY); \ assert (_test_fd >= 0); \ \ assert (fstat (_test_fd, &_test_stat) == 0); \ \ _test_buf = mmap (NULL, _test_stat.st_size, PROT_READ, \ MAP_SHARED, _test_fd, 0); \ assert (_test_buf != MAP_FAILED); \ \ if ((_str) == NULL) { \ TEST_FAILED ("wrong value for %s, expected '%.*s' got NULL", \ #_str, (int)_test_stat.st_size, _test_buf); \ } else if ((strlen (_str) != (size_t)_test_stat.st_size) \ || strncmp ((_str), _test_buf, _test_stat.st_size)) \ TEST_FAILED ("wrong value for %s, expected '%.*s' got '%s'", \ #_str, (int)_test_stat.st_size, _test_buf, \ (_str)); \ \ assert (munmap (_test_buf, _test_stat.st_size) == 0); \ assert (close (_test_fd) == 0); \ } while (0) /** * TEST_EXPECTED_FILE: * @_file: open file to check, * @_filename: filename to compare against. * * Check that the contents of file @_file exactly matches the contents of * the file @_filename, which is local to the expected directory. **/ #define TEST_EXPECTED_FILE(_file, _filename) \ do { \ char _test_file[512]; \ char * _test_basename; \ int _test_fd; \ struct stat _test_stat_a; \ struct stat _test_stat_b; \ char * _test_buf_a; \ char * _test_buf_b; \ \ strcpy (_test_file, __FILE__); \ _test_basename = strrchr (_test_file, '/'); \ strcpy (_test_basename ? _test_basename + 1 : _test_file, "expected/"); \ strcat (_test_file, (_filename)); \ \ _test_fd = open (_test_file, O_RDONLY); \ assert (_test_fd >= 0); \ \ assert (fstat (_test_fd, &_test_stat_a) == 0); \ assert (fstat (fileno (_file), &_test_stat_b) == 0); \ \ _test_buf_a = mmap (NULL, _test_stat_a.st_size, PROT_READ, \ MAP_SHARED, _test_fd, 0); \ assert (_test_buf_a != MAP_FAILED); \ \ _test_buf_b = mmap (NULL, _test_stat_b.st_size, PROT_READ, \ MAP_SHARED, fileno (_file), 0); \ assert (_test_buf_b != MAP_FAILED); \ \ if ((_test_stat_a.st_size != _test_stat_b.st_size) \ || strncmp (_test_buf_a, _test_buf_b, \ _test_stat_a.st_size)) \ TEST_FAILED ("wrong value for %s, expected '%.*s' got '%.*s'", \ #_file, (int)_test_stat_a.st_size, _test_buf_a, \ (int)_test_stat_b.st_size, _test_buf_b); \ \ assert (munmap (_test_buf_a, _test_stat_a.st_size) == 0); \ assert (munmap (_test_buf_b, _test_stat_b.st_size) == 0); \ assert (close (_test_fd) == 0); \ } while (0) #endif /* NIH_TEST_FILES_H */ libnih-1.0.3/nih/signal.c0000644000175000017500000002125511445765555012126 00000000000000/* libnih * * signal.c - easier and main-loop signal handling * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include "signal.h" /** * NUM_SIGNALS: * * Highest number that is not used for a signal that we care about, on * Linux this is always 32. **/ #define NUM_SIGNALS 32 /** * SignalName: * @num: number of signal, * @name: name of signal. * * Structure used to associate signal names and numbers to each other. **/ typedef struct { int num; const char *name; } SignalName; /** * signal_names: * * List of signal name to number mappings, the last entry in the list has * a NULL name and negative number. **/ static const SignalName signal_names[] = { { SIGHUP, "HUP" }, { SIGINT, "INT" }, { SIGQUIT, "QUIT" }, { SIGILL, "ILL" }, { SIGTRAP, "TRAP" }, { SIGABRT, "ABRT" }, { SIGIOT, "IOT" }, #ifdef SIGEMT { SIGEMT, "EMT" }, #endif { SIGBUS, "BUS" }, { SIGFPE, "FPE" }, { SIGKILL, "KILL" }, { SIGUSR1, "USR1" }, { SIGSEGV, "SEGV" }, { SIGUSR2, "USR2" }, { SIGPIPE, "PIPE" }, { SIGALRM, "ALRM" }, { SIGTERM, "TERM" }, #ifdef SIGSTKFLT { SIGSTKFLT, "STKFLT" }, #endif { SIGCHLD, "CHLD" }, { SIGCLD, "CLD" }, { SIGCONT, "CONT" }, { SIGSTOP, "STOP" }, { SIGTSTP, "TSTP" }, { SIGTTIN, "TTIN" }, { SIGTTOU, "TTOU" }, { SIGURG, "URG" }, { SIGXCPU, "XCPU" }, { SIGXFSZ, "XFSZ" }, { SIGVTALRM, "VTALRM" }, { SIGPROF, "PROF" }, { SIGWINCH, "WINCH" }, { SIGIO, "IO" }, { SIGPOLL, "POLL" }, #ifdef SIGLOST { SIGLOST, "LOST" }, #endif { SIGPWR, "PWR" }, { SIGSYS, "SYS" }, #ifdef SIGUNUSED { SIGUNUSED, "UNUSED" }, #endif { -1, NULL } }; /** * signals_caught: * * This array is used to indicate whether a signal has been caught or not, * the signal handler increments the appropriate array entry for the signal * and nih_signal_poll() clears it again once functions have been dispatched. **/ static volatile sig_atomic_t signals_caught[NUM_SIGNALS]; /** * nih_signals: * * This is the list of registered signals, not sorted into any particular * order. Each item is an NihSignal structure. **/ NihList *nih_signals = NULL; /** * nih_signal_init: * * Initialise the list of signals. **/ void nih_signal_init (void) { if (! nih_signals) nih_signals = NIH_MUST (nih_list_new (NULL)); } /** * nih_signal_set_handler: * @signum: signal number, * @handler: new handler function. * * Sets signal @signum to call the @handler function when raised, with * sensible defaults for the flags and signal mask. * * Returns: zero on success, negative value on invalid signal. **/ int nih_signal_set_handler (int signum, void (*handler)(int)) { struct sigaction act; nih_assert (signum > 0); nih_assert (signum < NUM_SIGNALS); nih_assert (handler != NULL); act.sa_handler = handler; act.sa_flags = 0; if (signum != SIGALRM) act.sa_flags |= SA_RESTART; sigemptyset (&act.sa_mask); if (sigaction (signum, &act, NULL) < 0) return -1; return 0; } /** * nih_signal_set_default: * @signum: signal number. * * Sets signal @signum to perform the operating system default action when * raised, with sensible defaults for the flags and signal mask. * * Returns: zero on success, negative value on invalid signal. **/ int nih_signal_set_default (int signum) { struct sigaction act; nih_assert (signum > 0); nih_assert (signum < NUM_SIGNALS); act.sa_handler = SIG_DFL; act.sa_flags = 0; sigemptyset (&act.sa_mask); if (sigaction (signum, &act, NULL) < 0) return -1; return 0; } /** * nih_signal_set_ignore: * @signum: signal number. * * Sets signal @signum to be ignored, with sensible defaults for the flags * and signal mask. * * Returns: zero on success, negative value on invalid signal. **/ int nih_signal_set_ignore (int signum) { struct sigaction act; nih_assert (signum > 0); nih_assert (signum < NUM_SIGNALS); act.sa_handler = SIG_IGN; act.sa_flags = 0; sigemptyset (&act.sa_mask); if (sigaction (signum, &act, NULL) < 0) return -1; return 0; } /** * nih_signal_reset: * * Resets all signals to their default handling. **/ void nih_signal_reset (void) { int i; for (i = 1; i < NUM_SIGNALS; i++) nih_signal_set_default (i); } /** * nih_signal_add_handler: * @parent: parent object for new signal, * @signum: signal number to catch, * @handler: function to call, * @data: pointer to pass to @handler. * * Adds @handler to the list of functions that should be called by * nih_signal_poll() if the @signum signal was raised. The signal must first * have been set to nih_signal_handler() using nih_signal_set_handler(), * * The callback structure is allocated using nih_alloc() and stored in a * linked list; there is no non-allocated version because of this. * * Removal of the handler can be performed by freeing it. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned signal. When all parents * of the returned signal are freed, the returned signal will also be * freed. * * Returns: the signal information, or NULL if insufficient memory. **/ NihSignal * nih_signal_add_handler (const void *parent, int signum, NihSignalHandler handler, void *data) { NihSignal *signal; nih_assert (signum > 0); nih_assert (signum < NUM_SIGNALS); nih_assert (handler != NULL); nih_signal_init (); signal = nih_new (parent, NihSignal); if (! signal) return NULL; nih_list_init (&signal->entry); nih_alloc_set_destructor (signal, nih_list_destroy); signal->signum = signum; signal->handler = handler; signal->data = data; nih_list_add (nih_signals, &signal->entry); return signal; } /** * nih_signal_handler: * @signum: signal raised. * * This signal handler should be used for any signals that you wish to use * nih_signal_add_handler() and nih_signal_poll() for. It simply sets a * volatile sig_atomic_t variable so that the signal can be detected in * the main loop. **/ void nih_signal_handler (int signum) { nih_assert (signum > 0); nih_assert (signum < NUM_SIGNALS); signals_caught[signum]++; nih_main_loop_interrupt (); } /** * nih_signal_poll: * * Iterate the list of registered signal handlers and call the function * if that signal has been raised since the last time nih_signal_poll() was * called. * * It is safe for the handler to remove itself. **/ void nih_signal_poll (void) { int s; nih_signal_init (); NIH_LIST_FOREACH_SAFE (nih_signals, iter) { NihSignal *signal = (NihSignal *)iter; if (! signals_caught[signal->signum]) continue; signal->handler (signal->data, signal); } for (s = 0; s < NUM_SIGNALS; s++) signals_caught[s] = 0; } /** * nih_signal_to_name: * @signum: signal number to look up. * * Looks up @signum in the table of signal names and returns the common * name for the signal, in the form TERM/CHLD. * * Returns: static name string or NULL if signal is unknown. **/ const char * nih_signal_to_name (int signum) { const SignalName *sig; nih_assert (signum > 0); for (sig = signal_names; (sig->num > 0) && sig->name; sig++) if (sig->num == signum) return sig->name; return NULL; } /** * nih_signal_from_name: * @signame: signal name to look up. * * Looks up @signame in the table of signal names and returns the * number for the signal; @signame may be in the form SIGTERM or TERM. * * Returns: signal number or negative value if signal is unknown. **/ int nih_signal_from_name (const char *signame) { const SignalName *sig; nih_assert (signame != NULL); if (! strncmp (signame, "SIG", 3)) signame += 3; for (sig = signal_names; (sig->num > 0) && sig->name; sig++) if (! strcmp (sig->name, signame)) return sig->num; return -1; } libnih-1.0.3/nih/timer.c0000644000175000017500000001744511445765555011777 00000000000000/* libnih * * timer.c - timeouts, periodic and scheduled timers * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include "timer.h" /** * nih_timers: * * This is the list of all registered timers, it is not sorted into any * particular order. The due time of timers should be set when the timer * is added to this list, or rescheduled; it is not calculated on the fly. * * Each item is an NihTimer structure. **/ NihList *nih_timers = NULL; /** * nih_timer_init: * * Initialise the timer list. **/ void nih_timer_init (void) { if (! nih_timers) nih_timers = NIH_MUST (nih_list_new (NULL)); } /** * nih_timer_add_timeout: * @parent: parent object for new timer, * @timeout: seconds to wait before triggering, * @callback: function to be called, * @data: pointer to pass to function as first argument. * * Arranges for the @callback function to be called in @timeout seconds * time, or the soonest period thereafter. A timer may be called * immediately by passing zero or a non-negative number as @timeout. * * The timer structure is allocated using nih_alloc() and stored in * a linked list; there is no non-allocated version of this function * because of this and because it will be automatically freed once called. * * Cancellation of the timer can be performed by freeing it. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned timer. When all parents * of the returned timer are freed, the returned timer will also be * freed. * * Returns: the new timer information, or NULL if insufficient memory. **/ NihTimer * nih_timer_add_timeout (const void *parent, time_t timeout, NihTimerCb callback, void *data) { NihTimer * timer; struct timespec now; nih_assert (callback != NULL); nih_timer_init (); timer = nih_new (parent, NihTimer); if (! timer) return NULL; nih_list_init (&timer->entry); nih_alloc_set_destructor (timer, nih_list_destroy); timer->type = NIH_TIMER_TIMEOUT; timer->timeout = timeout; timer->callback = callback; timer->data = data; nih_assert (clock_gettime (CLOCK_MONOTONIC, &now) == 0); timer->due = now.tv_sec + timeout; nih_list_add (nih_timers, &timer->entry); return timer; } /** * nih_timer_add_periodic: * @parent: parent object for new timer, * @period: number of seconds between calls, * @callback: function to be called, * @data: pointer to pass to function as first argument. * * Arranges for the @callback function to be called every @period seconds, * or the soonest time thereafter. * * The timer structure is allocated using nih_alloc() and stored in * a linked list; there is no non-allocated version of this function * because of this. * * Cancellation of the timer can be performed by freeing it. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned timer. When all parents * of the returned timer are freed, the returned timer will also be * freed. * * Returns: the new timer information, or NULL if insufficient memory. **/ NihTimer * nih_timer_add_periodic (const void *parent, time_t period, NihTimerCb callback, void *data) { NihTimer * timer; struct timespec now; nih_assert (callback != NULL); nih_assert (period > 0); nih_timer_init (); timer = nih_new (parent, NihTimer); if (! timer) return NULL; nih_list_init (&timer->entry); nih_alloc_set_destructor (timer, nih_list_destroy); timer->type = NIH_TIMER_PERIODIC; timer->period = period; timer->callback = callback; timer->data = data; nih_assert (clock_gettime (CLOCK_MONOTONIC, &now) == 0); timer->due = now.tv_sec + period; nih_list_add (nih_timers, &timer->entry); return timer; } /** * nih_timer_add_scheduled: * @parent: parent object for new timer, * @schedule: trigger schedule, * @callback: function to be called, * @data: pointer to pass to function as first argument. * * Arranges for the @callback function to be called based on the @schedule * given. * * The timer structure is allocated using nih_alloc() and stored in * a linked list; there is no non-allocated version of this function * because of this. * * Cancellation of the timer can be performed by freeing it. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned timer. When all parents * of the returned timer are freed, the returned timer will also be * freed. * * Returns: the new timer information, or NULL if insufficient memory. **/ NihTimer * nih_timer_add_scheduled (const void *parent, NihTimerSchedule *schedule, NihTimerCb callback, void *data) { NihTimer *timer; nih_assert (callback != NULL); nih_assert (schedule != NULL); nih_timer_init (); timer = nih_new (parent, NihTimer); if (! timer) return NULL; nih_list_init (&timer->entry); nih_alloc_set_destructor (timer, nih_list_destroy); timer->type = NIH_TIMER_SCHEDULED; memcpy (&timer->schedule, schedule, sizeof (NihTimerSchedule)); timer->callback = callback; timer->data = data; /* FIXME Not implemented */ timer->due = 0; nih_list_add (nih_timers, &timer->entry); return timer; } /** * nih_timer_next_due: * * Iterates the complete list of timers looking for the one with the * lowest due time, so that the timer returned is either due to be triggered * now or in some period's time. * * Normally used to determine how long we can sleep for by subtracting the * current time from the due time of the next timer. * * Returns: next timer due, or NULL if there are no timers. **/ NihTimer * nih_timer_next_due (void) { NihTimer *next; nih_timer_init (); next = NULL; NIH_LIST_FOREACH (nih_timers, iter) { NihTimer *timer = (NihTimer *)iter; if ((next == NULL) || (timer->due < next->due)) next = timer; } return next; } /** * nih_timer_poll: * * Iterates the complete list of timers and triggers any for which the * due time is less than or equal to the current time by calling their * callback functions. * * Arranges for the timer to be rescheuled, unless it is a timeout in which * case it is removed from the timer list. **/ void nih_timer_poll (void) { struct timespec now; nih_timer_init (); nih_assert (clock_gettime (CLOCK_MONOTONIC, &now) == 0); NIH_LIST_FOREACH_SAFE (nih_timers, iter) { NihTimer *timer = (NihTimer *)iter; int free_when_done = FALSE; if (timer->due > now.tv_sec) continue; switch (timer->type) { case NIH_TIMER_TIMEOUT: nih_ref (timer, nih_timers); free_when_done = TRUE; break; case NIH_TIMER_PERIODIC: timer->due = now.tv_sec + timer->period; break; case NIH_TIMER_SCHEDULED: /* FIXME Not implemented */ timer->due = 0; break; } nih_error_push_context (); timer->callback (timer->data, timer); nih_error_pop_context (); if (free_when_done) nih_free (timer); } } libnih-1.0.3/nih/Makefile.in0000644000175000017500000021617411503251220012526 00000000000000# Makefile.in generated by automake 1.11.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, # 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, # Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ @HAVE_VERSION_SCRIPT_ARG_TRUE@am__append_1 = @VERSION_SCRIPT_ARG@=$(srcdir)/libnih.ver TESTS = test_alloc$(EXEEXT) test_string$(EXEEXT) test_list$(EXEEXT) \ test_hash$(EXEEXT) test_tree$(EXEEXT) test_timer$(EXEEXT) \ test_signal$(EXEEXT) test_child$(EXEEXT) test_io$(EXEEXT) \ test_file$(EXEEXT) test_watch$(EXEEXT) test_main$(EXEEXT) \ test_option$(EXEEXT) test_command$(EXEEXT) \ test_config$(EXEEXT) test_logging$(EXEEXT) test_error$(EXEEXT) check_PROGRAMS = $(am__EXEEXT_1) subdir = nih DIST_COMMON = $(include_HEADERS) $(nihinclude_HEADERS) \ $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ $(srcdir)/libnih.pc.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/codeset.m4 \ $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/glibc2.m4 \ $(top_srcdir)/m4/glibc21.m4 $(top_srcdir)/m4/iconv.m4 \ $(top_srcdir)/m4/intdiv0.m4 $(top_srcdir)/m4/intl.m4 \ $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/intmax.m4 \ $(top_srcdir)/m4/inttypes-pri.m4 \ $(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/lcmessage.m4 \ $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libnih.m4 \ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/lock.m4 \ $(top_srcdir)/m4/longlong.m4 $(top_srcdir)/m4/ltoptions.m4 \ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \ $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/m4/po.m4 \ $(top_srcdir)/m4/printf-posix.m4 $(top_srcdir)/m4/progtest.m4 \ $(top_srcdir)/m4/size_max.m4 $(top_srcdir)/m4/stdint_h.m4 \ $(top_srcdir)/m4/uintmax_t.m4 $(top_srcdir)/m4/visibility.m4 \ $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/m4/wint_t.m4 \ $(top_srcdir)/m4/xsize.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = libnih.pc CONFIG_CLEAN_VPATH_FILES = am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" \ "$(DESTDIR)$(includedir)" "$(DESTDIR)$(nihincludedir)" LTLIBRARIES = $(lib_LTLIBRARIES) libnih_la_DEPENDENCIES = am_libnih_la_OBJECTS = alloc.lo string.lo list.lo hash.lo tree.lo \ timer.lo signal.lo child.lo io.lo file.lo watch.lo main.lo \ option.lo command.lo config.lo logging.lo error.lo libnih_la_OBJECTS = $(am_libnih_la_OBJECTS) AM_V_lt = $(am__v_lt_$(V)) am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) am__v_lt_0 = --silent libnih_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(libnih_la_LDFLAGS) $(LDFLAGS) -o $@ am__EXEEXT_1 = test_alloc$(EXEEXT) test_string$(EXEEXT) \ test_list$(EXEEXT) test_hash$(EXEEXT) test_tree$(EXEEXT) \ test_timer$(EXEEXT) test_signal$(EXEEXT) test_child$(EXEEXT) \ test_io$(EXEEXT) test_file$(EXEEXT) test_watch$(EXEEXT) \ test_main$(EXEEXT) test_option$(EXEEXT) test_command$(EXEEXT) \ test_config$(EXEEXT) test_logging$(EXEEXT) test_error$(EXEEXT) am_test_alloc_OBJECTS = test_alloc.$(OBJEXT) test_alloc_OBJECTS = $(am_test_alloc_OBJECTS) test_alloc_DEPENDENCIES = libnih.la test_alloc_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_alloc_LDFLAGS) $(LDFLAGS) -o $@ am_test_child_OBJECTS = test_child.$(OBJEXT) test_child_OBJECTS = $(am_test_child_OBJECTS) test_child_DEPENDENCIES = libnih.la test_child_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_child_LDFLAGS) $(LDFLAGS) -o $@ am_test_command_OBJECTS = test_command.$(OBJEXT) test_command_OBJECTS = $(am_test_command_OBJECTS) test_command_DEPENDENCIES = libnih.la test_command_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_command_LDFLAGS) $(LDFLAGS) -o $@ am_test_config_OBJECTS = test_config.$(OBJEXT) test_config_OBJECTS = $(am_test_config_OBJECTS) test_config_DEPENDENCIES = libnih.la test_config_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_config_LDFLAGS) $(LDFLAGS) -o $@ am_test_error_OBJECTS = test_error.$(OBJEXT) test_error_OBJECTS = $(am_test_error_OBJECTS) test_error_DEPENDENCIES = libnih.la test_error_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_error_LDFLAGS) $(LDFLAGS) -o $@ am_test_file_OBJECTS = test_file.$(OBJEXT) test_file_OBJECTS = $(am_test_file_OBJECTS) test_file_DEPENDENCIES = libnih.la test_file_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_file_LDFLAGS) $(LDFLAGS) -o $@ am_test_hash_OBJECTS = test_hash.$(OBJEXT) test_hash_OBJECTS = $(am_test_hash_OBJECTS) test_hash_DEPENDENCIES = libnih.la test_hash_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_hash_LDFLAGS) $(LDFLAGS) -o $@ am_test_io_OBJECTS = test_io.$(OBJEXT) test_io_OBJECTS = $(am_test_io_OBJECTS) test_io_DEPENDENCIES = libnih.la test_io_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_io_LDFLAGS) $(LDFLAGS) -o $@ am_test_list_OBJECTS = test_list.$(OBJEXT) test_list_OBJECTS = $(am_test_list_OBJECTS) test_list_DEPENDENCIES = libnih.la test_list_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_list_LDFLAGS) $(LDFLAGS) -o $@ am_test_logging_OBJECTS = test_logging.$(OBJEXT) test_logging_OBJECTS = $(am_test_logging_OBJECTS) test_logging_DEPENDENCIES = libnih.la test_logging_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_logging_LDFLAGS) $(LDFLAGS) -o $@ am_test_main_OBJECTS = test_main.$(OBJEXT) test_main_OBJECTS = $(am_test_main_OBJECTS) test_main_DEPENDENCIES = libnih.la test_main_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_main_LDFLAGS) $(LDFLAGS) -o $@ am_test_option_OBJECTS = test_option.$(OBJEXT) test_option_OBJECTS = $(am_test_option_OBJECTS) test_option_DEPENDENCIES = libnih.la test_option_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_option_LDFLAGS) $(LDFLAGS) -o $@ am_test_signal_OBJECTS = test_signal.$(OBJEXT) test_signal_OBJECTS = $(am_test_signal_OBJECTS) test_signal_DEPENDENCIES = libnih.la test_signal_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_signal_LDFLAGS) $(LDFLAGS) -o $@ am_test_string_OBJECTS = test_string.$(OBJEXT) test_string_OBJECTS = $(am_test_string_OBJECTS) test_string_DEPENDENCIES = libnih.la test_string_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_string_LDFLAGS) $(LDFLAGS) -o $@ am_test_timer_OBJECTS = test_timer.$(OBJEXT) test_timer_OBJECTS = $(am_test_timer_OBJECTS) test_timer_DEPENDENCIES = libnih.la test_timer_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_timer_LDFLAGS) $(LDFLAGS) -o $@ am_test_tree_OBJECTS = test_tree.$(OBJEXT) test_tree_OBJECTS = $(am_test_tree_OBJECTS) test_tree_DEPENDENCIES = libnih.la test_tree_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_tree_LDFLAGS) $(LDFLAGS) -o $@ am_test_watch_OBJECTS = test_watch.$(OBJEXT) test_watch_OBJECTS = $(am_test_watch_OBJECTS) test_watch_DEPENDENCIES = libnih.la test_watch_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_watch_LDFLAGS) $(LDFLAGS) -o $@ DEFAULT_INCLUDES = depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ $(AM_CFLAGS) $(CFLAGS) AM_V_CC = $(am__v_CC_$(V)) am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) am__v_CC_0 = @echo " CC " $@; AM_V_at = $(am__v_at_$(V)) am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) am__v_at_0 = @ CCLD = $(CC) LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_CCLD = $(am__v_CCLD_$(V)) am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) am__v_CCLD_0 = @echo " CCLD " $@; AM_V_GEN = $(am__v_GEN_$(V)) am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) am__v_GEN_0 = @echo " GEN " $@; SOURCES = $(libnih_la_SOURCES) $(test_alloc_SOURCES) \ $(test_child_SOURCES) $(test_command_SOURCES) \ $(test_config_SOURCES) $(test_error_SOURCES) \ $(test_file_SOURCES) $(test_hash_SOURCES) $(test_io_SOURCES) \ $(test_list_SOURCES) $(test_logging_SOURCES) \ $(test_main_SOURCES) $(test_option_SOURCES) \ $(test_signal_SOURCES) $(test_string_SOURCES) \ $(test_timer_SOURCES) $(test_tree_SOURCES) \ $(test_watch_SOURCES) DIST_SOURCES = $(libnih_la_SOURCES) $(test_alloc_SOURCES) \ $(test_child_SOURCES) $(test_command_SOURCES) \ $(test_config_SOURCES) $(test_error_SOURCES) \ $(test_file_SOURCES) $(test_hash_SOURCES) $(test_io_SOURCES) \ $(test_list_SOURCES) $(test_logging_SOURCES) \ $(test_main_SOURCES) $(test_option_SOURCES) \ $(test_signal_SOURCES) $(test_string_SOURCES) \ $(test_timer_SOURCES) $(test_tree_SOURCES) \ $(test_watch_SOURCES) DATA = $(pkgconfig_DATA) HEADERS = $(include_HEADERS) $(nihinclude_HEADERS) ETAGS = etags CTAGS = ctags # If stdout is a non-dumb tty, use colors. If test -t is not supported, # then this fails; a conservative approach. Of course do not redirect # stdout here, just stderr. am__tty_colors = \ red=; grn=; lgn=; blu=; std=; \ test "X$(AM_COLOR_TESTS)" != Xno \ && test "X$$TERM" != Xdumb \ && { test "X$(AM_COLOR_TESTS)" = Xalways || test -t 1 2>/dev/null; } \ && { \ red=''; \ grn=''; \ lgn=''; \ blu=''; \ std=''; \ } DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ ALLOCA = @ALLOCA@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@ CATOBJEXT = @CATOBJEXT@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CFLAG_VISIBILITY = @CFLAG_VISIBILITY@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DATADIRNAME = @DATADIRNAME@ DBUS_CFLAGS = @DBUS_CFLAGS@ DBUS_LIBS = @DBUS_LIBS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ EXPAT_LIBS = @EXPAT_LIBS@ FGREP = @FGREP@ GENCAT = @GENCAT@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ GLIBC2 = @GLIBC2@ GLIBC21 = @GLIBC21@ GMSGFMT = @GMSGFMT@ GMSGFMT_015 = @GMSGFMT_015@ GREP = @GREP@ HAVE_ASPRINTF = @HAVE_ASPRINTF@ HAVE_POSIX_PRINTF = @HAVE_POSIX_PRINTF@ HAVE_SNPRINTF = @HAVE_SNPRINTF@ HAVE_VISIBILITY = @HAVE_VISIBILITY@ HAVE_WPRINTF = @HAVE_WPRINTF@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INSTOBJEXT = @INSTOBJEXT@ INTLBISON = @INTLBISON@ INTLLIBS = @INTLLIBS@ INTLOBJS = @INTLOBJS@ INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@ INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBMULTITHREAD = @LIBMULTITHREAD@ LIBOBJS = @LIBOBJS@ LIBPTH = @LIBPTH@ LIBPTH_PREFIX = @LIBPTH_PREFIX@ LIBS = @LIBS@ LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBC = @LTLIBC@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ LTLIBMULTITHREAD = @LTLIBMULTITHREAD@ LTLIBOBJS = @LTLIBOBJS@ LTLIBPTH = @LTLIBPTH@ LTLIBTHREAD = @LTLIBTHREAD@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ NIH_DBUS_TOOL = @NIH_DBUS_TOOL@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_COPYRIGHT = @PACKAGE_COPYRIGHT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ POSUB = @POSUB@ PRI_MACROS_BROKEN = @PRI_MACROS_BROKEN@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@ USE_NLS = @USE_NLS@ VERSION = @VERSION@ VERSION_SCRIPT_ARG = @VERSION_SCRIPT_ARG@ WINDRES = @WINDRES@ WOE32 = @WOE32@ WOE32DLL = @WOE32DLL@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AM_CPPFLAGS = \ -DLOCALEDIR="\"$(localedir)\"" \ -I$(top_builddir) -I$(top_srcdir) \ -I$(top_srcdir)/intl lib_LTLIBRARIES = libnih.la libnih_la_SOURCES = \ alloc.c \ string.c \ list.c \ hash.c \ tree.c \ timer.c \ signal.c \ child.c \ io.c \ file.c \ watch.c \ main.c \ option.c \ command.c \ config.c \ logging.c \ error.c libnih_la_LDFLAGS = -version-info 1:0:0 $(am__append_1) libnih_la_LIBADD = -lrt include_HEADERS = \ libnih.h nihincludedir = $(includedir)/nih nihinclude_HEADERS = \ macros.h \ alloc.h \ string.h \ list.h \ hash.h \ tree.h \ timer.h \ signal.h \ child.h \ io.h \ file.h \ watch.h \ main.h \ option.h \ command.h \ config.h \ logging.h \ error.h \ errors.h \ test.h \ test_output.h \ test_values.h \ test_process.h \ test_divert.h \ test_files.h \ test_alloc.h \ test_list.h \ test_hash.h pkgconfigdir = $(prefix)/lib/pkgconfig pkgconfig_DATA = libnih.pc EXTRA_DIST = libnih.ver libnih.supp libnih.pc.in test_alloc_SOURCES = tests/test_alloc.c test_alloc_LDFLAGS = -static test_alloc_LDADD = libnih.la test_string_SOURCES = tests/test_string.c test_string_LDFLAGS = -static test_string_LDADD = libnih.la -lutil test_list_SOURCES = tests/test_list.c test_list_LDFLAGS = -static test_list_LDADD = libnih.la test_hash_SOURCES = tests/test_hash.c test_hash_LDFLAGS = -static test_hash_LDADD = libnih.la test_tree_SOURCES = tests/test_tree.c test_tree_LDFLAGS = -static test_tree_LDADD = libnih.la test_timer_SOURCES = tests/test_timer.c test_timer_LDFLAGS = -static test_timer_LDADD = libnih.la test_signal_SOURCES = tests/test_signal.c test_signal_LDFLAGS = -static test_signal_LDADD = libnih.la test_child_SOURCES = tests/test_child.c test_child_LDFLAGS = -static test_child_LDADD = libnih.la test_io_SOURCES = tests/test_io.c test_io_LDFLAGS = -static test_io_LDADD = libnih.la test_file_SOURCES = tests/test_file.c test_file_LDFLAGS = -static test_file_LDADD = libnih.la test_watch_SOURCES = tests/test_watch.c test_watch_LDFLAGS = -static test_watch_LDADD = libnih.la test_main_SOURCES = tests/test_main.c test_main_LDFLAGS = -static test_main_LDADD = libnih.la test_option_SOURCES = tests/test_option.c test_option_LDFLAGS = -static test_option_LDADD = libnih.la test_command_SOURCES = tests/test_command.c test_command_LDFLAGS = -static test_command_LDADD = libnih.la test_config_SOURCES = tests/test_config.c test_config_LDFLAGS = -static test_config_LDADD = libnih.la test_logging_SOURCES = tests/test_logging.c test_logging_LDFLAGS = -static test_logging_LDADD = libnih.la test_error_SOURCES = tests/test_error.c test_error_LDFLAGS = -static test_error_LDADD = libnih.la all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu nih/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu nih/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): libnih.pc: $(top_builddir)/config.status $(srcdir)/libnih.pc.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ install-libLTLIBRARIES: $(lib_LTLIBRARIES) @$(NORMAL_INSTALL) test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ list2=; for p in $$list; do \ if test -f $$p; then \ list2="$$list2 $$p"; \ else :; fi; \ done; \ test -z "$$list2" || { \ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ } uninstall-libLTLIBRARIES: @$(NORMAL_UNINSTALL) @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ for p in $$list; do \ $(am__strip_dir) \ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ done clean-libLTLIBRARIES: -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ test "$$dir" != "$$p" || dir=.; \ echo "rm -f \"$${dir}/so_locations\""; \ rm -f "$${dir}/so_locations"; \ done libnih.la: $(libnih_la_OBJECTS) $(libnih_la_DEPENDENCIES) $(AM_V_CCLD)$(libnih_la_LINK) -rpath $(libdir) $(libnih_la_OBJECTS) $(libnih_la_LIBADD) $(LIBS) clean-checkPROGRAMS: @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \ echo " rm -f" $$list; \ rm -f $$list || exit $$?; \ test -n "$(EXEEXT)" || exit 0; \ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list test_alloc$(EXEEXT): $(test_alloc_OBJECTS) $(test_alloc_DEPENDENCIES) @rm -f test_alloc$(EXEEXT) $(AM_V_CCLD)$(test_alloc_LINK) $(test_alloc_OBJECTS) $(test_alloc_LDADD) $(LIBS) test_child$(EXEEXT): $(test_child_OBJECTS) $(test_child_DEPENDENCIES) @rm -f test_child$(EXEEXT) $(AM_V_CCLD)$(test_child_LINK) $(test_child_OBJECTS) $(test_child_LDADD) $(LIBS) test_command$(EXEEXT): $(test_command_OBJECTS) $(test_command_DEPENDENCIES) @rm -f test_command$(EXEEXT) $(AM_V_CCLD)$(test_command_LINK) $(test_command_OBJECTS) $(test_command_LDADD) $(LIBS) test_config$(EXEEXT): $(test_config_OBJECTS) $(test_config_DEPENDENCIES) @rm -f test_config$(EXEEXT) $(AM_V_CCLD)$(test_config_LINK) $(test_config_OBJECTS) $(test_config_LDADD) $(LIBS) test_error$(EXEEXT): $(test_error_OBJECTS) $(test_error_DEPENDENCIES) @rm -f test_error$(EXEEXT) $(AM_V_CCLD)$(test_error_LINK) $(test_error_OBJECTS) $(test_error_LDADD) $(LIBS) test_file$(EXEEXT): $(test_file_OBJECTS) $(test_file_DEPENDENCIES) @rm -f test_file$(EXEEXT) $(AM_V_CCLD)$(test_file_LINK) $(test_file_OBJECTS) $(test_file_LDADD) $(LIBS) test_hash$(EXEEXT): $(test_hash_OBJECTS) $(test_hash_DEPENDENCIES) @rm -f test_hash$(EXEEXT) $(AM_V_CCLD)$(test_hash_LINK) $(test_hash_OBJECTS) $(test_hash_LDADD) $(LIBS) test_io$(EXEEXT): $(test_io_OBJECTS) $(test_io_DEPENDENCIES) @rm -f test_io$(EXEEXT) $(AM_V_CCLD)$(test_io_LINK) $(test_io_OBJECTS) $(test_io_LDADD) $(LIBS) test_list$(EXEEXT): $(test_list_OBJECTS) $(test_list_DEPENDENCIES) @rm -f test_list$(EXEEXT) $(AM_V_CCLD)$(test_list_LINK) $(test_list_OBJECTS) $(test_list_LDADD) $(LIBS) test_logging$(EXEEXT): $(test_logging_OBJECTS) $(test_logging_DEPENDENCIES) @rm -f test_logging$(EXEEXT) $(AM_V_CCLD)$(test_logging_LINK) $(test_logging_OBJECTS) $(test_logging_LDADD) $(LIBS) test_main$(EXEEXT): $(test_main_OBJECTS) $(test_main_DEPENDENCIES) @rm -f test_main$(EXEEXT) $(AM_V_CCLD)$(test_main_LINK) $(test_main_OBJECTS) $(test_main_LDADD) $(LIBS) test_option$(EXEEXT): $(test_option_OBJECTS) $(test_option_DEPENDENCIES) @rm -f test_option$(EXEEXT) $(AM_V_CCLD)$(test_option_LINK) $(test_option_OBJECTS) $(test_option_LDADD) $(LIBS) test_signal$(EXEEXT): $(test_signal_OBJECTS) $(test_signal_DEPENDENCIES) @rm -f test_signal$(EXEEXT) $(AM_V_CCLD)$(test_signal_LINK) $(test_signal_OBJECTS) $(test_signal_LDADD) $(LIBS) test_string$(EXEEXT): $(test_string_OBJECTS) $(test_string_DEPENDENCIES) @rm -f test_string$(EXEEXT) $(AM_V_CCLD)$(test_string_LINK) $(test_string_OBJECTS) $(test_string_LDADD) $(LIBS) test_timer$(EXEEXT): $(test_timer_OBJECTS) $(test_timer_DEPENDENCIES) @rm -f test_timer$(EXEEXT) $(AM_V_CCLD)$(test_timer_LINK) $(test_timer_OBJECTS) $(test_timer_LDADD) $(LIBS) test_tree$(EXEEXT): $(test_tree_OBJECTS) $(test_tree_DEPENDENCIES) @rm -f test_tree$(EXEEXT) $(AM_V_CCLD)$(test_tree_LINK) $(test_tree_OBJECTS) $(test_tree_LDADD) $(LIBS) test_watch$(EXEEXT): $(test_watch_OBJECTS) $(test_watch_DEPENDENCIES) @rm -f test_watch$(EXEEXT) $(AM_V_CCLD)$(test_watch_LINK) $(test_watch_OBJECTS) $(test_watch_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alloc.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/child.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/command.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/config.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/error.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/file.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hash.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/logging.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/option.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signal.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_alloc.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_child.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_command.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_config.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_error.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_file.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_hash.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_io.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_list.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_logging.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_option.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_signal.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_string.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_timer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_tree.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_watch.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timer.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tree.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/watch.Plo@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< test_alloc.o: tests/test_alloc.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_alloc.o -MD -MP -MF $(DEPDIR)/test_alloc.Tpo -c -o test_alloc.o `test -f 'tests/test_alloc.c' || echo '$(srcdir)/'`tests/test_alloc.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_alloc.Tpo $(DEPDIR)/test_alloc.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_alloc.c' object='test_alloc.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_alloc.o `test -f 'tests/test_alloc.c' || echo '$(srcdir)/'`tests/test_alloc.c test_alloc.obj: tests/test_alloc.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_alloc.obj -MD -MP -MF $(DEPDIR)/test_alloc.Tpo -c -o test_alloc.obj `if test -f 'tests/test_alloc.c'; then $(CYGPATH_W) 'tests/test_alloc.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_alloc.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_alloc.Tpo $(DEPDIR)/test_alloc.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_alloc.c' object='test_alloc.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_alloc.obj `if test -f 'tests/test_alloc.c'; then $(CYGPATH_W) 'tests/test_alloc.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_alloc.c'; fi` test_child.o: tests/test_child.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_child.o -MD -MP -MF $(DEPDIR)/test_child.Tpo -c -o test_child.o `test -f 'tests/test_child.c' || echo '$(srcdir)/'`tests/test_child.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_child.Tpo $(DEPDIR)/test_child.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_child.c' object='test_child.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_child.o `test -f 'tests/test_child.c' || echo '$(srcdir)/'`tests/test_child.c test_child.obj: tests/test_child.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_child.obj -MD -MP -MF $(DEPDIR)/test_child.Tpo -c -o test_child.obj `if test -f 'tests/test_child.c'; then $(CYGPATH_W) 'tests/test_child.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_child.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_child.Tpo $(DEPDIR)/test_child.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_child.c' object='test_child.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_child.obj `if test -f 'tests/test_child.c'; then $(CYGPATH_W) 'tests/test_child.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_child.c'; fi` test_command.o: tests/test_command.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_command.o -MD -MP -MF $(DEPDIR)/test_command.Tpo -c -o test_command.o `test -f 'tests/test_command.c' || echo '$(srcdir)/'`tests/test_command.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_command.Tpo $(DEPDIR)/test_command.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_command.c' object='test_command.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_command.o `test -f 'tests/test_command.c' || echo '$(srcdir)/'`tests/test_command.c test_command.obj: tests/test_command.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_command.obj -MD -MP -MF $(DEPDIR)/test_command.Tpo -c -o test_command.obj `if test -f 'tests/test_command.c'; then $(CYGPATH_W) 'tests/test_command.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_command.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_command.Tpo $(DEPDIR)/test_command.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_command.c' object='test_command.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_command.obj `if test -f 'tests/test_command.c'; then $(CYGPATH_W) 'tests/test_command.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_command.c'; fi` test_config.o: tests/test_config.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_config.o -MD -MP -MF $(DEPDIR)/test_config.Tpo -c -o test_config.o `test -f 'tests/test_config.c' || echo '$(srcdir)/'`tests/test_config.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_config.Tpo $(DEPDIR)/test_config.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_config.c' object='test_config.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_config.o `test -f 'tests/test_config.c' || echo '$(srcdir)/'`tests/test_config.c test_config.obj: tests/test_config.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_config.obj -MD -MP -MF $(DEPDIR)/test_config.Tpo -c -o test_config.obj `if test -f 'tests/test_config.c'; then $(CYGPATH_W) 'tests/test_config.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_config.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_config.Tpo $(DEPDIR)/test_config.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_config.c' object='test_config.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_config.obj `if test -f 'tests/test_config.c'; then $(CYGPATH_W) 'tests/test_config.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_config.c'; fi` test_error.o: tests/test_error.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_error.o -MD -MP -MF $(DEPDIR)/test_error.Tpo -c -o test_error.o `test -f 'tests/test_error.c' || echo '$(srcdir)/'`tests/test_error.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_error.Tpo $(DEPDIR)/test_error.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_error.c' object='test_error.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_error.o `test -f 'tests/test_error.c' || echo '$(srcdir)/'`tests/test_error.c test_error.obj: tests/test_error.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_error.obj -MD -MP -MF $(DEPDIR)/test_error.Tpo -c -o test_error.obj `if test -f 'tests/test_error.c'; then $(CYGPATH_W) 'tests/test_error.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_error.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_error.Tpo $(DEPDIR)/test_error.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_error.c' object='test_error.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_error.obj `if test -f 'tests/test_error.c'; then $(CYGPATH_W) 'tests/test_error.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_error.c'; fi` test_file.o: tests/test_file.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_file.o -MD -MP -MF $(DEPDIR)/test_file.Tpo -c -o test_file.o `test -f 'tests/test_file.c' || echo '$(srcdir)/'`tests/test_file.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_file.Tpo $(DEPDIR)/test_file.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_file.c' object='test_file.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_file.o `test -f 'tests/test_file.c' || echo '$(srcdir)/'`tests/test_file.c test_file.obj: tests/test_file.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_file.obj -MD -MP -MF $(DEPDIR)/test_file.Tpo -c -o test_file.obj `if test -f 'tests/test_file.c'; then $(CYGPATH_W) 'tests/test_file.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_file.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_file.Tpo $(DEPDIR)/test_file.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_file.c' object='test_file.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_file.obj `if test -f 'tests/test_file.c'; then $(CYGPATH_W) 'tests/test_file.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_file.c'; fi` test_hash.o: tests/test_hash.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_hash.o -MD -MP -MF $(DEPDIR)/test_hash.Tpo -c -o test_hash.o `test -f 'tests/test_hash.c' || echo '$(srcdir)/'`tests/test_hash.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_hash.Tpo $(DEPDIR)/test_hash.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_hash.c' object='test_hash.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_hash.o `test -f 'tests/test_hash.c' || echo '$(srcdir)/'`tests/test_hash.c test_hash.obj: tests/test_hash.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_hash.obj -MD -MP -MF $(DEPDIR)/test_hash.Tpo -c -o test_hash.obj `if test -f 'tests/test_hash.c'; then $(CYGPATH_W) 'tests/test_hash.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_hash.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_hash.Tpo $(DEPDIR)/test_hash.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_hash.c' object='test_hash.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_hash.obj `if test -f 'tests/test_hash.c'; then $(CYGPATH_W) 'tests/test_hash.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_hash.c'; fi` test_io.o: tests/test_io.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_io.o -MD -MP -MF $(DEPDIR)/test_io.Tpo -c -o test_io.o `test -f 'tests/test_io.c' || echo '$(srcdir)/'`tests/test_io.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_io.Tpo $(DEPDIR)/test_io.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_io.c' object='test_io.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_io.o `test -f 'tests/test_io.c' || echo '$(srcdir)/'`tests/test_io.c test_io.obj: tests/test_io.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_io.obj -MD -MP -MF $(DEPDIR)/test_io.Tpo -c -o test_io.obj `if test -f 'tests/test_io.c'; then $(CYGPATH_W) 'tests/test_io.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_io.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_io.Tpo $(DEPDIR)/test_io.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_io.c' object='test_io.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_io.obj `if test -f 'tests/test_io.c'; then $(CYGPATH_W) 'tests/test_io.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_io.c'; fi` test_list.o: tests/test_list.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_list.o -MD -MP -MF $(DEPDIR)/test_list.Tpo -c -o test_list.o `test -f 'tests/test_list.c' || echo '$(srcdir)/'`tests/test_list.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_list.Tpo $(DEPDIR)/test_list.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_list.c' object='test_list.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_list.o `test -f 'tests/test_list.c' || echo '$(srcdir)/'`tests/test_list.c test_list.obj: tests/test_list.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_list.obj -MD -MP -MF $(DEPDIR)/test_list.Tpo -c -o test_list.obj `if test -f 'tests/test_list.c'; then $(CYGPATH_W) 'tests/test_list.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_list.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_list.Tpo $(DEPDIR)/test_list.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_list.c' object='test_list.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_list.obj `if test -f 'tests/test_list.c'; then $(CYGPATH_W) 'tests/test_list.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_list.c'; fi` test_logging.o: tests/test_logging.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_logging.o -MD -MP -MF $(DEPDIR)/test_logging.Tpo -c -o test_logging.o `test -f 'tests/test_logging.c' || echo '$(srcdir)/'`tests/test_logging.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_logging.Tpo $(DEPDIR)/test_logging.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_logging.c' object='test_logging.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_logging.o `test -f 'tests/test_logging.c' || echo '$(srcdir)/'`tests/test_logging.c test_logging.obj: tests/test_logging.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_logging.obj -MD -MP -MF $(DEPDIR)/test_logging.Tpo -c -o test_logging.obj `if test -f 'tests/test_logging.c'; then $(CYGPATH_W) 'tests/test_logging.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_logging.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_logging.Tpo $(DEPDIR)/test_logging.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_logging.c' object='test_logging.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_logging.obj `if test -f 'tests/test_logging.c'; then $(CYGPATH_W) 'tests/test_logging.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_logging.c'; fi` test_main.o: tests/test_main.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_main.o -MD -MP -MF $(DEPDIR)/test_main.Tpo -c -o test_main.o `test -f 'tests/test_main.c' || echo '$(srcdir)/'`tests/test_main.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_main.Tpo $(DEPDIR)/test_main.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_main.c' object='test_main.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_main.o `test -f 'tests/test_main.c' || echo '$(srcdir)/'`tests/test_main.c test_main.obj: tests/test_main.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_main.obj -MD -MP -MF $(DEPDIR)/test_main.Tpo -c -o test_main.obj `if test -f 'tests/test_main.c'; then $(CYGPATH_W) 'tests/test_main.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_main.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_main.Tpo $(DEPDIR)/test_main.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_main.c' object='test_main.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_main.obj `if test -f 'tests/test_main.c'; then $(CYGPATH_W) 'tests/test_main.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_main.c'; fi` test_option.o: tests/test_option.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_option.o -MD -MP -MF $(DEPDIR)/test_option.Tpo -c -o test_option.o `test -f 'tests/test_option.c' || echo '$(srcdir)/'`tests/test_option.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_option.Tpo $(DEPDIR)/test_option.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_option.c' object='test_option.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_option.o `test -f 'tests/test_option.c' || echo '$(srcdir)/'`tests/test_option.c test_option.obj: tests/test_option.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_option.obj -MD -MP -MF $(DEPDIR)/test_option.Tpo -c -o test_option.obj `if test -f 'tests/test_option.c'; then $(CYGPATH_W) 'tests/test_option.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_option.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_option.Tpo $(DEPDIR)/test_option.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_option.c' object='test_option.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_option.obj `if test -f 'tests/test_option.c'; then $(CYGPATH_W) 'tests/test_option.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_option.c'; fi` test_signal.o: tests/test_signal.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_signal.o -MD -MP -MF $(DEPDIR)/test_signal.Tpo -c -o test_signal.o `test -f 'tests/test_signal.c' || echo '$(srcdir)/'`tests/test_signal.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_signal.Tpo $(DEPDIR)/test_signal.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_signal.c' object='test_signal.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_signal.o `test -f 'tests/test_signal.c' || echo '$(srcdir)/'`tests/test_signal.c test_signal.obj: tests/test_signal.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_signal.obj -MD -MP -MF $(DEPDIR)/test_signal.Tpo -c -o test_signal.obj `if test -f 'tests/test_signal.c'; then $(CYGPATH_W) 'tests/test_signal.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_signal.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_signal.Tpo $(DEPDIR)/test_signal.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_signal.c' object='test_signal.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_signal.obj `if test -f 'tests/test_signal.c'; then $(CYGPATH_W) 'tests/test_signal.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_signal.c'; fi` test_string.o: tests/test_string.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_string.o -MD -MP -MF $(DEPDIR)/test_string.Tpo -c -o test_string.o `test -f 'tests/test_string.c' || echo '$(srcdir)/'`tests/test_string.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_string.Tpo $(DEPDIR)/test_string.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_string.c' object='test_string.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_string.o `test -f 'tests/test_string.c' || echo '$(srcdir)/'`tests/test_string.c test_string.obj: tests/test_string.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_string.obj -MD -MP -MF $(DEPDIR)/test_string.Tpo -c -o test_string.obj `if test -f 'tests/test_string.c'; then $(CYGPATH_W) 'tests/test_string.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_string.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_string.Tpo $(DEPDIR)/test_string.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_string.c' object='test_string.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_string.obj `if test -f 'tests/test_string.c'; then $(CYGPATH_W) 'tests/test_string.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_string.c'; fi` test_timer.o: tests/test_timer.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_timer.o -MD -MP -MF $(DEPDIR)/test_timer.Tpo -c -o test_timer.o `test -f 'tests/test_timer.c' || echo '$(srcdir)/'`tests/test_timer.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_timer.Tpo $(DEPDIR)/test_timer.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_timer.c' object='test_timer.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_timer.o `test -f 'tests/test_timer.c' || echo '$(srcdir)/'`tests/test_timer.c test_timer.obj: tests/test_timer.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_timer.obj -MD -MP -MF $(DEPDIR)/test_timer.Tpo -c -o test_timer.obj `if test -f 'tests/test_timer.c'; then $(CYGPATH_W) 'tests/test_timer.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_timer.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_timer.Tpo $(DEPDIR)/test_timer.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_timer.c' object='test_timer.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_timer.obj `if test -f 'tests/test_timer.c'; then $(CYGPATH_W) 'tests/test_timer.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_timer.c'; fi` test_tree.o: tests/test_tree.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_tree.o -MD -MP -MF $(DEPDIR)/test_tree.Tpo -c -o test_tree.o `test -f 'tests/test_tree.c' || echo '$(srcdir)/'`tests/test_tree.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_tree.Tpo $(DEPDIR)/test_tree.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_tree.c' object='test_tree.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_tree.o `test -f 'tests/test_tree.c' || echo '$(srcdir)/'`tests/test_tree.c test_tree.obj: tests/test_tree.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_tree.obj -MD -MP -MF $(DEPDIR)/test_tree.Tpo -c -o test_tree.obj `if test -f 'tests/test_tree.c'; then $(CYGPATH_W) 'tests/test_tree.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_tree.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_tree.Tpo $(DEPDIR)/test_tree.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_tree.c' object='test_tree.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_tree.obj `if test -f 'tests/test_tree.c'; then $(CYGPATH_W) 'tests/test_tree.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_tree.c'; fi` test_watch.o: tests/test_watch.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_watch.o -MD -MP -MF $(DEPDIR)/test_watch.Tpo -c -o test_watch.o `test -f 'tests/test_watch.c' || echo '$(srcdir)/'`tests/test_watch.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_watch.Tpo $(DEPDIR)/test_watch.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_watch.c' object='test_watch.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_watch.o `test -f 'tests/test_watch.c' || echo '$(srcdir)/'`tests/test_watch.c test_watch.obj: tests/test_watch.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_watch.obj -MD -MP -MF $(DEPDIR)/test_watch.Tpo -c -o test_watch.obj `if test -f 'tests/test_watch.c'; then $(CYGPATH_W) 'tests/test_watch.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_watch.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_watch.Tpo $(DEPDIR)/test_watch.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_watch.c' object='test_watch.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_watch.obj `if test -f 'tests/test_watch.c'; then $(CYGPATH_W) 'tests/test_watch.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_watch.c'; fi` mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-pkgconfigDATA: $(pkgconfig_DATA) @$(NORMAL_INSTALL) test -z "$(pkgconfigdir)" || $(MKDIR_P) "$(DESTDIR)$(pkgconfigdir)" @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgconfigdir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgconfigdir)" || exit $$?; \ done uninstall-pkgconfigDATA: @$(NORMAL_UNINSTALL) @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ test -n "$$files" || exit 0; \ echo " ( cd '$(DESTDIR)$(pkgconfigdir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(pkgconfigdir)" && rm -f $$files install-includeHEADERS: $(include_HEADERS) @$(NORMAL_INSTALL) test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)" @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \ $(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \ done uninstall-includeHEADERS: @$(NORMAL_UNINSTALL) @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ test -n "$$files" || exit 0; \ echo " ( cd '$(DESTDIR)$(includedir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(includedir)" && rm -f $$files install-nihincludeHEADERS: $(nihinclude_HEADERS) @$(NORMAL_INSTALL) test -z "$(nihincludedir)" || $(MKDIR_P) "$(DESTDIR)$(nihincludedir)" @list='$(nihinclude_HEADERS)'; test -n "$(nihincludedir)" || list=; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(nihincludedir)'"; \ $(INSTALL_HEADER) $$files "$(DESTDIR)$(nihincludedir)" || exit $$?; \ done uninstall-nihincludeHEADERS: @$(NORMAL_UNINSTALL) @list='$(nihinclude_HEADERS)'; test -n "$(nihincludedir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ test -n "$$files" || exit 0; \ echo " ( cd '$(DESTDIR)$(nihincludedir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(nihincludedir)" && rm -f $$files ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) set x; \ here=`pwd`; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags check-TESTS: $(TESTS) @failed=0; all=0; xfail=0; xpass=0; skip=0; \ srcdir=$(srcdir); export srcdir; \ list=' $(TESTS) '; \ $(am__tty_colors); \ if test -n "$$list"; then \ for tst in $$list; do \ if test -f ./$$tst; then dir=./; \ elif test -f $$tst; then dir=; \ else dir="$(srcdir)/"; fi; \ if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ all=`expr $$all + 1`; \ case " $(XFAIL_TESTS) " in \ *[\ \ ]$$tst[\ \ ]*) \ xpass=`expr $$xpass + 1`; \ failed=`expr $$failed + 1`; \ col=$$red; res=XPASS; \ ;; \ *) \ col=$$grn; res=PASS; \ ;; \ esac; \ elif test $$? -ne 77; then \ all=`expr $$all + 1`; \ case " $(XFAIL_TESTS) " in \ *[\ \ ]$$tst[\ \ ]*) \ xfail=`expr $$xfail + 1`; \ col=$$lgn; res=XFAIL; \ ;; \ *) \ failed=`expr $$failed + 1`; \ col=$$red; res=FAIL; \ ;; \ esac; \ else \ skip=`expr $$skip + 1`; \ col=$$blu; res=SKIP; \ fi; \ echo "$${col}$$res$${std}: $$tst"; \ done; \ if test "$$all" -eq 1; then \ tests="test"; \ All=""; \ else \ tests="tests"; \ All="All "; \ fi; \ if test "$$failed" -eq 0; then \ if test "$$xfail" -eq 0; then \ banner="$$All$$all $$tests passed"; \ else \ if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ fi; \ else \ if test "$$xpass" -eq 0; then \ banner="$$failed of $$all $$tests failed"; \ else \ if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ fi; \ fi; \ dashes="$$banner"; \ skipped=""; \ if test "$$skip" -ne 0; then \ if test "$$skip" -eq 1; then \ skipped="($$skip test was not run)"; \ else \ skipped="($$skip tests were not run)"; \ fi; \ test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ dashes="$$skipped"; \ fi; \ report=""; \ if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ report="Please report to $(PACKAGE_BUGREPORT)"; \ test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ dashes="$$report"; \ fi; \ dashes=`echo "$$dashes" | sed s/./=/g`; \ if test "$$failed" -eq 0; then \ echo "$$grn$$dashes"; \ else \ echo "$$red$$dashes"; \ fi; \ echo "$$banner"; \ test -z "$$skipped" || echo "$$skipped"; \ test -z "$$report" || echo "$$report"; \ echo "$$dashes$$std"; \ test "$$failed" -eq 0; \ else :; fi distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: check-am all-am: Makefile $(LTLIBRARIES) $(DATA) $(HEADERS) installdirs: for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(includedir)" "$(DESTDIR)$(nihincludedir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ `test -z '$(STRIP)' || \ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install mostlyclean-generic: clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-am clean-am: clean-checkPROGRAMS clean-generic clean-libLTLIBRARIES \ clean-libtool clean-local mostlyclean-am distclean: distclean-am -rm -rf ./$(DEPDIR) -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-includeHEADERS install-nihincludeHEADERS \ install-pkgconfigDATA install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-libLTLIBRARIES install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -rf ./$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic \ maintainer-clean-local mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES \ uninstall-nihincludeHEADERS uninstall-pkgconfigDATA .MAKE: check-am install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \ clean-checkPROGRAMS clean-generic clean-libLTLIBRARIES \ clean-libtool clean-local ctags distclean distclean-compile \ distclean-generic distclean-libtool distclean-tags distdir dvi \ dvi-am html html-am info info-am install install-am \ install-data install-data-am install-dvi install-dvi-am \ install-exec install-exec-am install-html install-html-am \ install-includeHEADERS install-info install-info-am \ install-libLTLIBRARIES install-man install-nihincludeHEADERS \ install-pdf install-pdf-am install-pkgconfigDATA install-ps \ install-ps-am install-strip installcheck installcheck-am \ installdirs maintainer-clean maintainer-clean-generic \ maintainer-clean-local mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags uninstall uninstall-am uninstall-includeHEADERS \ uninstall-libLTLIBRARIES uninstall-nihincludeHEADERS \ uninstall-pkgconfigDATA .PHONY: tests tests: $(BUILT_SOURCES) $(check_PROGRAMS) clean-local: rm -f *.gcno *.gcda maintainer-clean-local: rm -f *.gcov # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: libnih-1.0.3/nih/command.c0000644000175000017500000003126011445765555012264 00000000000000/* libnih * * command.c - command parser based on nih_option_parser * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include /* Prototypes for static functions */ static NihCommand *nih_command_get (NihCommand *commands, const char *command); static int nih_command_handle (const void *parent, int argc, char *argv[], NihOption *options, NihCommand *commands, NihCommand *command); static void nih_command_help (NihCommand *commands); static void nih_command_group_help (NihCommandGroup *group, NihCommand *commands, NihCommandGroup **groups); /** * default_commands: * * These default commands are appended to those defined by the user * so they can be overriden. **/ static const NihCommand default_commands[] = { { "help", NULL, N_("display list of commands"), NULL, NULL, NULL, NULL }, NIH_COMMAND_LAST }; /** * no_options: * * This is used whenever the options member of NihCommand is NULL. **/ static const NihOption no_options[] = { NIH_OPTION_LAST }; /** * nih_command_parser: * @parent: parent for arguments arrays, * @argc: number of arguments, * @argv: command-line arguments, * @options: global options, * @commands: commands to look for. * * Parses the command-line arguments given in @argv until the first * non-option argument is found. Options preceeding that are handled * according to @options by nih_option_parser(). * * The argument is looked up in @commands, and if found, that is used to * process the remaining options and arguments. * * Alternatively if the program name can be found in @commands, then the * entire @argv list is treated as the command instead of locating the * first non-option. * * Reminaing arguments are passed to the action function of the @commands * member found. * * The usage stem and string are constructed automatically, calling * nih_option_set_usage() or nih_option_set_usage_stem() before this * function will have no effect. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for arguments arrays. When all parents * of the array are freed, the array will also be freed. * * Errors are handled by printing a message to standard error. * * Returns: return value from action function or negative value on error. **/ int nih_command_parser (const void *parent, int argc, char *argv[], NihOption *options, NihCommand *commands) { nih_local NihCommand *cmds = NULL; NihCommand *cmd; nih_local char *footer = NULL, *stem = NULL; nih_local char **args = NULL; char **arg; int ret; nih_assert (argc > 0); nih_assert (argv != NULL); nih_assert (options != NULL); nih_assert (commands != NULL); nih_assert (program_name != NULL); cmds = nih_command_join (NULL, commands, default_commands); /* First check the program name for a valid command */ cmd = nih_command_get (cmds, program_name); if (cmd) return nih_command_handle (parent, argc, argv, options, cmds, cmd); /* Set help strings to make ordinary --help look right */ footer = NIH_MUST (nih_sprintf (NULL, _("For a list of commands, " "try `%s help'."), program_name)); nih_option_set_footer (footer); nih_option_set_usage (_("COMMAND [OPTION]... [ARG]...")); /* Parse options up until the first non-opt argument */ args = nih_option_parser (NULL, argc, argv, options, TRUE); /* Clean up help strings */ nih_option_set_footer (NULL); nih_option_set_usage (NULL); /* Check for option parsing errors */ if (! args) return -1; /* Check we actually got a command */ if (! args[0]) { fprintf (stderr, _("%s: missing command\n"), program_name); nih_main_suggest_help (); return -1; } /* Find that command */ cmd = nih_command_get (cmds, args[0]); if (! cmd) { fprintf (stderr, _("%s: invalid command: %s\n"), program_name, args[0]); nih_main_suggest_help (); return -1; } /* Count the number of arguments in the args array */ for (arg = args; *arg; arg++) ; /* Set the usage stem to include the command name */ stem = NIH_MUST (nih_sprintf (NULL, _("%s [OPTION]..."), cmd->command)); nih_option_set_usage_stem (stem); /* Handle the command */ ret = nih_command_handle (parent, arg - args, args, options, cmds, cmd); /* Clean up usage stem */ nih_option_set_usage_stem (NULL); return ret; } /** * nih_command_join: * @parent: parent object for new array, * @a: first command array, * @b: second command array. * * Joins the two command arrays together to produce a combined array * containing the commands from @a followed by the commands from @b. * * The new list is allocated with nih_alloc(), but the members are just * copied in from @a and @b including any pointers therein. Freeing the * new array with nih_free() is entirely safe. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned array. When all parents * of the returned array are freed, the returned array will also be * freed. * * Returns: combined command array. **/ NihCommand * nih_command_join (const void *parent, const NihCommand *a, const NihCommand *b) { const NihCommand *cmd; NihCommand *cmds; size_t alen = 0, blen = 0; nih_assert (a != NULL); nih_assert (b != NULL); /* Count commands in first list */ for (cmd = a; cmd->command; cmd++) alen++; /* Count commands in second list */ for (cmd = b; cmd->command; cmd++) blen++; /* Allocate combined list */ cmds = NIH_MUST (nih_alloc (parent, sizeof (NihCommand) * (alen + blen + 1))); /* Copy options, making sure to copy the last option from b */ memcpy (cmds, a, sizeof (NihCommand) * alen); memcpy (cmds + alen, b, sizeof (NihCommand) * (blen + 1)); return cmds; } /** * nih_command_get: * @commands: command list, * @command: command to find. * * Find the command structure with the given @command in the @commands list. * * Returns; pointer to command or NULL if not found. **/ static NihCommand * nih_command_get (NihCommand *commands, const char *command) { NihCommand *cmd; for (cmd = commands; cmd->command; cmd++) if (! strcmp (command, cmd->command)) return cmd; return NULL; } /** * nih_command_handle: * @parent: parent for arguments arrays, * @argc: number of arguments, * @argv: command-line arguments, * @options: global options, * @commands: commands looked for, * @command: NihCommand invoked. * * This function is called to handle a @command that was either invoked * directly by program name, or found as an argument on the command line. * The list of commands looked for should be in @commands so that the * "help" command can be handled. * * @argv should be the list of arguments starting from the name of the * command, which is skipped. @options is added to any options specified * in @command so that global options are always available. * * After parsing the options, remaining arguments are passed to the action * function of @command. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the arguments arrays. When all parents * of the array are freed, the array will also be freed. * * Errors are handled by printing a message to standard error. * * Returns: return value from action or negative value on error. **/ static int nih_command_handle (const void *parent, int argc, char *argv[], NihOption *options, NihCommand *commands, NihCommand *command) { char **args; const NihOption *cmd_opts; nih_local NihOption *opts = NULL; int ret; nih_assert (argc > 0); nih_assert (argv != NULL); nih_assert (options != NULL); nih_assert (commands != NULL); nih_assert (command != NULL); /* Join the command and global options together, allow command to * take precedence */ cmd_opts = command->options ? command->options : no_options; opts = nih_option_join (NULL, cmd_opts, options); /* Set up the option parser from the command information */ nih_option_set_usage (_(command->usage)); nih_option_set_synopsis (_(command->synopsis)); nih_option_set_help (_(command->help)); /* Parse the remaining arguments against all of the options */ args = nih_option_parser (parent, argc, argv, opts, FALSE); /* Clean up help strings again */ nih_option_set_usage (NULL); nih_option_set_synopsis (NULL); nih_option_set_help (NULL); /* Check for option parsing failure */ if (! args) return -1; /* Handle the special cased commands first */ if (! strcmp (command->command, "help")) { nih_command_help (commands); exit (0); } /* Delegate to the command handler */ ret = command->action (command, args); nih_free (args); return ret; } /** * nih_command_help: * @commands: list of commands. * * Output a list of the known commands to standard output grouped by the * group member of the command. **/ static void nih_command_help (NihCommand *commands) { NihCommand *cmd; nih_local NihCommandGroup **groups = NULL; size_t group, ngroups; int other = FALSE; nih_assert (program_name != NULL); groups = NULL; ngroups = 0; /* Count the number of command groups */ for (cmd = commands; cmd->command; cmd++) { if (! cmd->group) { other = TRUE; continue; } for (group = 0; group < ngroups; group++) { if (groups[group] == cmd->group) break; } if (group < ngroups) continue; groups = NIH_MUST (nih_realloc (groups, NULL, (sizeof (NihCommandGroup *) * (ngroups + 1)))); groups[ngroups++] = cmd->group; } /* Iterate the command groups we found in order, and display * only their commands */ for (group = 0; group < ngroups; group++) nih_command_group_help (groups[group], commands, groups); /* Display the other group */ if (other) nih_command_group_help (NULL, commands, groups); /* Say how to find out about a command */ printf (_("For more information on a command, " "try `%s COMMAND --help'.\n"), program_name); } /** * nih_command_group_help: * @group: group to display, * @commands: list of commands, * @groups: all groups. * * Output a list of commands in the given @group to standard output. **/ static void nih_command_group_help (NihCommandGroup *group, NihCommand *commands, NihCommandGroup **groups) { NihCommand *cmd; size_t width; nih_assert (commands != NULL); if (group) { printf (_("%s commands:\n"), _(group->title)); } else if (groups) { printf (_("Other commands:\n")); } else { printf (_("Commands:\n")); } width = nih_max (nih_str_screen_width (), 50U) - 30; for (cmd = commands; cmd->command; cmd++) { nih_local char *str = NULL; char *ptr; size_t len = 0; if (cmd->group != group) continue; if (! cmd->synopsis) continue; /* Indent by two spaces */ printf (" "); len += 2; /* Output the command */ printf ("%s", cmd->command); len += strlen (cmd->command); /* Format the synopsis string to fit in the latter * half of the screen */ str = NIH_MUST (nih_str_wrap (NULL, cmd->synopsis, width, 0, 2)); /* Write the description to the screen */ ptr = str; while (ptr && *ptr) { size_t linelen; /* Not enough room on this line */ if (len > 28) { printf ("\n"); len = 0; } /* Pad line up to the right column */ while (len < 30) { printf (" "); len++; } /* Output the line up until the next line */ linelen = strcspn (ptr, "\n"); printf ("%.*s\n", (int)linelen, ptr); len = 0; /* Skip to the next line */ ptr += linelen; if (*ptr == '\n') ptr++; } } printf ("\n"); } libnih-1.0.3/nih/option.h0000644000175000017500000001157111445765555012166 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_OPTION_H #define NIH_OPTION_H /** * Provides a flexible command-line option and arguments parser that * automatically provides built-in options for adjusting output verbosity * and provides --help output. * * Describe your commands options using an array of NihOption members * and pass this along with the argc and argv variables to * nih_option_parser(). * * Options can be set from arguments with helper functions, nih_option_count() * and nih_option_int() are provided for you. * * Help and usage output can be customised with the nih_option_set_usage(), * nih_option_set_usage_stem(), nih_option_set_synopsis(), * nih_option_set_help() and nih_option_set_footer() functions. Be sure * to call these before the option parser. **/ #include /** * NihOptionSetter; * @option: NihOption invoked, * @arg: argument to parse. * * An option setter is a function that is called whenever an option is * found in the command-line arguments. If the option expects a value * then the argument is passed to the function, otherwise NULL is * passed. * * The function may use the value member of @option to store the parsed * value, or may take its own action. * * If there is an error with the argument the function may return zero * to abort parsing. **/ typedef struct nih_option NihOption; typedef int (*NihOptionSetter) (NihOption *option, const char *arg); /** * NihOptionGroup: * @title: descriptive help message. * * This structure is used to define a group of options that are collated * together when --help is given. **/ typedef struct nih_option_group { char *title; } NihOptionGroup; /** * NihOption: * @option: short option character, * @long_option: long option name, * @help: descriptive help message, * @group: group option is member of, * @arg_name: description of value or NULL if option takes no argument, * @value: pointer of variable to store argument in, * @setter: function to store the value. * * This structure defines an option that may be found in the command-line * arguments. One or both of @option and @long_option myst be specified, * if no short option is wanted it may be zero and if no @long_option is * wanted it may be NULL. * * If @arg_name is not NULL then the option takes the next non-option * argument from the command-line; if @setter is not NULL it is passed * this argument, otherwise @value should contain the address of a char * * in which a newly allocated copy of the argument will be stored. * * If @arg_name is NULL then NULL if passed to @setter. If both * @arg_name and @setter are NULL then @value should contain the address * of an int in which a TRUE value is stored. **/ struct nih_option { int option; char *long_option; char *help; NihOptionGroup *group; char *arg_name; void *value; NihOptionSetter setter; }; /** * NIH_OPTION_LAST: * * This macro may be used as the last option in the list to avoid typing * all those NULLs and 0s yourself. **/ #define NIH_OPTION_LAST { 0, NULL, NULL, NULL, NULL, NULL, NULL } NIH_BEGIN_EXTERN char ** nih_option_parser (const void *parent, int argc, char *argv[], NihOption *options, int break_nonopt) __attribute__ ((warn_unused_result, malloc)); NihOption *nih_option_join (const void *parent, const NihOption *a, const NihOption *b) __attribute__ ((warn_unused_result, malloc)); int nih_option_count (NihOption *option, const char *arg); int nih_option_int (NihOption *option, const char *arg); int nih_option_quiet (NihOption *option, const char *arg); int nih_option_verbose (NihOption *option, const char *arg); int nih_option_debug (NihOption *option, const char *arg); void nih_option_set_usage (const char *usage); void nih_option_set_usage_stem (const char *usage); void nih_option_set_synopsis (const char *synopsis); void nih_option_set_help (const char *help); void nih_option_set_footer (const char *footer); NIH_END_EXTERN #endif /* NIH_OPTION_H */ libnih-1.0.3/nih/list.h0000644000175000017500000001736711445765555011642 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_LIST_H #define NIH_LIST_H /** * Provides a generic circular doubly-linked list implementation. Like * all doubly-linked lists, each entry carries both a pointer to the * previous entry in the list and a pointer to the next entry in the list. * However this is also circular, so instead of the first entry's previous * pointer and last entry's next pointers containing NULL, they instead * point to the last entry and first entry respectively. * * A single NihList structure is generally used as the list head, so * for an empty list, that structure's previous and next pointers point * to itself. * * This has the advantage over other implementations of a constant time * operation to append or prepend an entry to the list, insert before or * after a known entry, and remove an entry from the list. * * List entries may be created in one of two ways. The most common is to * embed the NihList structure as the frist member of your own structure, * and initialise it with nih_list_init() after allocating the structure. * Alternatively you may create NihListEntry structures with * nih_list_entry_new() and point at your own data from them. * * The list head itself may be created with nih_list_new(). * * Entries are added to the list with nih_list_add(), passing an existing * entry which is most commonly the list head. This adds the entry "before" * the given entry, in the list head case this appends the entry to the list. * To add "after" the given entry (prepending in the list head case) use * nih_list_add_before(). * * To remove an entry from the list use nih_list_remove(). The entry * effectively becomes the list head of an empty list. * * Entries may be moved between lists, or rearranged within a list, by * simply calling nih_list_add() - there's no need to call nih_list_remove() * first. * * List iteration may be performed by following the prev or next pointers * in a for loop. Since this is an extremely common operation, the * NIH_LIST_FOREACH() macro is provided that expands to this for loop. * * Since this macro only holds a pointer to the entry being iterated, most * operations that change a list are not safe. To change a list safely * while iterating, including being able to free the visited node, use * the NIH_LIST_FOREACH_SAFE() macro. However note that since this macro * changes the list as it iterates it itself, it is not safe to traverse * or iterate the list and make assumptions about the type of node being * seen. **/ #include /** * NihList: * @prev: previous entry in the list, * @next: next entry in the list. * * This structure can be used both to refer to a linked list and can be * placed in your own structures to use them as list entries. * * The list is circular so the @next pointer of the last entry points to * the first, and the @prev pointer of the first entry points to the last. * An empty list simply has the @prev and @next pointers pointing to itself. **/ typedef struct nih_list { struct nih_list *prev, *next; } NihList; /** * NihListEntry: * @entry: list header, * @data: data pointer, * @str: string pointer, * @int_data: integer value. * * This structure can be used as a generic NihList node that contains * a pointer to generic data, a string or contains an integer value. * * You should take care of setting the data yourself. **/ typedef struct nih_list_entry { NihList entry; union { void *data; char *str; int int_data; }; } NihListEntry; /** * NIH_LIST_EMPTY: * @list: entry in the list to check. * * Checks whether the given list is empty by comparing the next and * previous pointers for equality. * * Returns: TRUE if empty, FALSE otherwise. **/ #define NIH_LIST_EMPTY(list) (((list)->prev == (list)) \ && ((list)->next) == (list)) /** * NIH_LIST_FOREACH: * @list: entry in the list to iterate, * @iter: name of iterator variable. * * Expands to a for statement that iterates over each entry in @list * except @list itself, setting @iter to each entry for the block within * the loop. * * This is the cheapest form of iteration, however it is not safe to perform * various modifications to the list; most importantly, you must not change * the member being iterated in any way, including removing it from the list * or freeing it. If you need to do that, use NIH_LIST_FOREACH_SAFE() instead. * * However since it doesn't modify the list being iterated in any way, it * is safe to traverse or iterate the list again while iterating. **/ #define NIH_LIST_FOREACH(list, iter) \ for (NihList *iter = (list)->next; iter != (list); iter = iter->next) /** * NIH_LIST_FOREACH_SAFE: * @list: entry in the list to iterate, * @iter: name of iterator variable. * * Expands to a for statement that iterates over each entry in @list * except @list itself, setting @iter to each entry for the block within * the loop. * * The iteration is performed safely by placing a cursor node after @iter; * this means that any node including @iter can be removed from the list, * added to a different list, or entries added before or after it. * * Note that if you add an entry directly after @iter and wish it to be * visited, you would need to use NIH_LIST_FOREACH() instead, as this * would be placed before the cursor and thus skipped. * * Also since the list has an extra node during iteration of a different * type, it is expressly not safe to traverse or iterate the list while * iterating. If you need to perform multiple iterations, or reference * the next or previous pointers of a node, you must use NIH_LIST_FOREACH(). **/ #define NIH_LIST_FOREACH_SAFE(list, iter) \ for (NihList _##iter __attribute__((cleanup(nih_list_destroy))) = \ { &_##iter, &_##iter }, \ *iter = nih_list_add_after ((list)->next, &_##iter)->prev; \ iter != (list) && iter != &_##iter; \ iter = nih_list_add_after (_##iter.next, &_##iter)->prev) /** * NIH_LIST_ITER: * @iter: iterator variable, * @type: type of list member, * @head: name of list head structure member. * * Normally the list head is the first member of the structure, so you can * simply cast an NihList * iterator to the structure you're expecting to * find. * * However when that is not true, you can use this macro to perform the * cast based on the offset of @head within @type. * * Returns: pointer to top of structure being iterated. **/ #define NIH_LIST_ITER(iter, type, head) \ (type *)((void *)(iter) - offsetof (type, head)) NIH_BEGIN_EXTERN void nih_list_init (NihList *entry); NihList * nih_list_new (const void *parent) __attribute__ ((warn_unused_result, malloc)); NihListEntry *nih_list_entry_new (const void *parent) __attribute__ ((warn_unused_result, malloc)); NihList * nih_list_add (NihList *list, NihList *entry); NihList * nih_list_add_after (NihList *list, NihList *entry); NihList * nih_list_remove (NihList *entry); int nih_list_destroy (NihList *entry); NIH_END_EXTERN #endif /* NIH_LIST_H */ libnih-1.0.3/nih/libnih.supp0000644000175000017500000002337111445765555012664 00000000000000# This is a valgrind suppressions file. # Common patterns are for every allocation to be followed by one with # nih_alloc_ref_new() inserted between the call to nih_alloc() and malloc() # this is the reference object for that object. # # Also if the call is ever made within a TEST_ALLOC_FAIL loop, you'll also # need a test with: # fun:realloc # fun:_test_realloc # fun:_test_malloc # in between the nih_alloc() and malloc() calls. # There is a slight overhead to using some parts of libnih in the form # of a heap-allocated list head used to link all allocated structures # by that component. # # They are allocated the first time that part of libnih is used by the # static nih_*_init function; valgrind complains because they are not # freed before exit, as there's little point to doing so. { nih-timer-init Memcheck:Leak fun:malloc fun:nih_alloc fun:nih_list_new fun:nih_timer_init } { nih-timer-init Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_list_new fun:nih_timer_init } { nih-signal-init Memcheck:Leak fun:malloc fun:nih_alloc fun:nih_list_new fun:nih_signal_init } { nih-signal-init Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_list_new fun:nih_signal_init } { nih-child-init Memcheck:Leak fun:malloc fun:nih_alloc fun:nih_list_new fun:nih_child_init } { nih-child-init Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_list_new fun:nih_child_init } { nih-io-init Memcheck:Leak fun:malloc fun:nih_alloc fun:nih_list_new fun:nih_io_init } { nih-io-init Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_list_new fun:nih_io_init } { nih-file-init Memcheck:Leak fun:malloc fun:nih_alloc fun:nih_list_new fun:nih_file_init } { nih-file-init Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_list_new fun:nih_file_init } { nih-main-loop-init Memcheck:Leak fun:malloc fun:nih_alloc fun:nih_list_new fun:nih_main_loop_init } { nih-main-loop-init Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_list_new fun:nih_main_loop_init } # NihError has both a list and a default context in that list { nih-error-init Memcheck:Leak fun:malloc fun:nih_alloc fun:nih_list_new fun:nih_error_init } { nih-error-init Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_list_new fun:nih_error_init } { nih-error-init Memcheck:Leak fun:malloc fun:nih_alloc fun:nih_error_push_context fun:nih_error_init } { nih-error-init Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_error_push_context fun:nih_error_init } # nih_main_init_full stores the pacakge_string string in a # heap-allocated pointer. It survives the life of the process and # is only not freed because there's little point in doing so. { nih-package-string Memcheck:Leak fun:malloc fun:nih_alloc fun:nih_vsprintf fun:nih_sprintf fun:nih_main_init_full } { nih-package-string Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_vsprintf fun:nih_sprintf fun:nih_main_init_full } # A copy of any log message of fatal or above is stored in case a crash # follows; valgrind picks this up as a leak, even though we hang on to # the pointer and only ever allocate one of them. # # nih_fatal() may be called both in and out of TEST_ALLOC_FAIL { nih-log-abort-message Memcheck:Leak fun:malloc fun:nih_alloc fun:nih_strndup fun:nih_strdup fun:nih_log_abort_message } { nih-log-abort-message Memcheck:Leak fun:malloc fun:realloc fun:_test_realloc fun:_test_malloc fun:nih_alloc fun:nih_strndup fun:nih_strdup fun:nih_log_abort_message } { nih-log-abort-message Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_strndup fun:nih_strdup fun:nih_log_abort_message } # tmpfile is used by some test cases ... valgrind doesn't have a built-in # suppression for it. { glibc-tmpfile Memcheck:Leak fun:malloc fun:fdopen fun:tmpfile } { glibc-tmpfile Memcheck:Leak fun:malloc fun:fdopen@@GLIBC_2.1 fun:tmpfile@@GLIBC_2.1 } { glibc-tmpfile Memcheck:Leak fun:malloc fun:fdopen@@GLIBC_2.2.5 fun:tmpfile@@GLIBC_2.2.5 } # test_main.c:test_damonise() allocates a pid file string which makes # valgrind think that it's leaked when we exit { test-main-daemonise Memcheck:Leak fun:malloc fun:nih_alloc fun:nih_vsprintf fun:nih_sprintf fun:nih_main_get_pidfile fun:nih_main_write_pidfile fun:nih_main_daemonise fun:test_daemonise } { test-main-daemonise Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_vsprintf fun:nih_sprintf fun:nih_main_get_pidfile fun:nih_main_write_pidfile fun:nih_main_daemonise fun:test_daemonise } # test_command.c:test_help() exits inside --help which makes valgrind # think that the command parser state has been leaked { test-command-help Memcheck:Leak fun:malloc fun:realloc fun:_test_realloc fun:_test_malloc fun:nih_alloc fun:nih_command_join fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_command_join fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:realloc fun:_test_realloc fun:_test_malloc fun:nih_alloc fun:nih_vsprintf fun:nih_sprintf fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_vsprintf fun:nih_sprintf fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:realloc fun:_test_realloc fun:_test_malloc fun:nih_alloc fun:nih_str_array_new fun:nih_option_parser fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_str_array_new fun:nih_option_parser fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:realloc fun:_test_realloc fun:_test_malloc fun:nih_alloc fun:nih_strndup fun:nih_strdup fun:nih_str_array_add fun:nih_option_parser fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_strndup fun:nih_strdup fun:nih_str_array_add fun:nih_option_parser fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:realloc fun:_test_realloc fun:nih_realloc fun:nih_str_array_addp fun:nih_str_array_add fun:nih_option_parser fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_ref fun:nih_str_array_addp fun:nih_str_array_add fun:nih_option_parser fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:realloc fun:_test_realloc fun:_test_malloc fun:nih_alloc fun:nih_option_join fun:nih_command_handle fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_option_join fun:nih_command_handle fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:realloc fun:_test_realloc fun:_test_malloc fun:nih_alloc fun:nih_str_array_new fun:nih_option_parser fun:nih_command_handle fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_str_array_new fun:nih_option_parser fun:nih_command_handle fun:nih_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:realloc fun:_test_realloc fun:_test_malloc fun:nih_alloc fun:nih_option_join fun:nih_command_handle fun:nih_commmand_parser fun:test_command_parser fun:test_help } { test-command-help Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_option_join fun:nih_command_handle fun:nih_commmand_parser fun:test_command_parser fun:test_help } # test_error.c:test_raise_error() is expected to leak an error context # and the error inside it, because it's testing whether a double-raise # is caught inside a child process which it expects to abort { test-error-raise-error Memcheck:Leak fun:malloc fun:nih_alloc fun:nih_error_push_context fun:test_raise_error } { test-error-raise-error Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_error_push_context fun:test_raise_error } { test-error-raise-error Memcheck:Leak fun:malloc fun:nih_alloc fun:test_raise_error } { test-error-raise-error Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:test_raise_error } # test_error.c:test_pop_context() is expected to leak an error context # and the error inside it, because it's testing whether this is caught # on child exit { test-error-pop-context Memcheck:Leak fun:malloc fun:nih_alloc fun:nih_error_push_context fun:test_pop_context } { test-error-pop-context Memcheck:Leak fun:malloc fun:realloc fun:_test_realloc fun:_test_malloc fun:nih_alloc fun:nih_error_push_context fun:test_pop_context } { test-error-pop-context Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:nih_error_push_context fun:test_pop_context } { test-error-pop-context Memcheck:Leak fun:malloc fun:realloc fun:_test_realloc fun:_test_malloc fun:nih_alloc fun:_nih_error_raise fun:test_pop_context } { test-error-pop-context Memcheck:Leak fun:malloc fun:nih_alloc_ref_new fun:nih_alloc fun:_nih_error_raise fun:test_pop_context } libnih-1.0.3/nih/alloc.h0000644000175000017500000002773311445765555011757 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_ALLOC_H #define NIH_ALLOC_H /** * All functions in libnih use these functions to allocate and destroy * objects in memory, they wrap the usual malloc(), realloc() and free() * calls to provide a multi-reference hierarchial allocator. * * When you allocate an object using nih_alloc() or nih_new(), you pass * an optional parent. This may be any other object allocated with these * functions. A reference from the parent to the newly allocated object * is created. If no parent is passed the object is referenced from the * special NULL parent. * * You may add additional references to the object using nih_ref(), again * passing any other object allocated with these functions as the parent * or the special NULL parent. * * Thus any object may have one or more parents. Indeed, an object * (including the NULL parent) may hold multiple references to another * object. * * When an object is freed, the references to its children are discarded * and if it held the last reference to one of those children, the child * is freed as well. * * This takes away a lof the effort of object management; allocating the * members of a structure with the structure as a parent means that if you * free the structure, all of its members will be freed as well. * * You may still need to do additional clean-up, for example closing file * descriptors or other non-allocated resources. You can set a destructor * function for the object with nih_alloc_set_destructor(), this is called * during the free process. * * To remove a reference to a child, potentially freeing it but without * freeing the parent object, use nih_unref(). * * To free a top-level object, use nih_free(). nih_free() always frees the * object, even if it has parent references which it will discard. This * obviously does not clean up any pointers in the parent object which * point at the freed child. * * In many situations, you will allocate an object using nih_alloc() with * no parent and pass that to functions which may take a reference to it. * When finished, you need to discard the object safely; if no references * were taken, it should be freed - otherwise it's safe to leave. Use * nih_discard() instead of nih_free() to do this. * * Such constructs are often better handled using nih_local variables. * * * = Common patterns = * * At first, it seems like there's a bewildering array of different ways * you can shoot yourself in the foot with this library, however if you * stick to the usual patterns it's a very safe and versatile library. * * == Structures == * * When allocating structures, you tend to write your function so that * the prospective parent is passed in as the first argument and always * allocate with that. * * obj = nih_new (parent, Object); * * That way, the caller decides how they want your object linked to * other things. If there's an error while populating the structure, * the standard style is just to call nih_free() rather than * unreferencing * * error: * nih_free (obj); * return NULL; * * Since you're putting it together, this use of nih_free() is perfectly * acceptable. * * == Structure members == * * Structure members are just about always allocated with the structure * as their parent context. * * obj->child = nih_new (obj, Child); * * This pretty much saves you from ever worrying about them, as they * will be automatically freed whenever you free the parent object; * including error handling cases. * * Should you ever replace the child, you shouldn't call nih_free() but * nih_unref(), to be safe against other code having taken a reference. * * nih_unref (obj->child, obj); * obj->child = nih_new (obj, Child); * * This will clean up the child, unless someone else is using it. * * == Floating objects == * * Often in a function you'll want to allocate an object but won't yet * have anything to attach it to. This also often applies to global * variables as well. * * You simply pass NULL in as the parent; the returned object has only * this special reference. * * obj = nih_new (NULL, Object); * * To discard the floating object you should use nih_discard() instead * of nih_free(), which will not free the object if another function * you've called in the meantime took a reference to it. * * Better yet, use nih_local to have the object automatically discarded * when it goes out of scope: * * { * nih_local Object *obj = NULL; * obj = nih_new (NULL, Object); * * // work with obj, including passing it to functions that may * // reference it * } * * == Taking a reference == * * Provided the above patterns are followed, taking a reference to an * object you are passed is perfectly safe. Simply call nih_ref(), * for example to store it in your own structure: * * adopt->obj = obj; * nih_ref (adopt->obj, adopt); * * When you want to drop your reference, you should only ever use * nih_unref(). * * nih_unref (adopt->obj, adopt); * adopt->obj = NULL; * * == Returning a member == * * This is a relatively rare case, but examples exist. * * Sometimes you want to provide a function that returns one of your * structure members, disowning it in the process. Your function will * most likely take a parent object to which you want to reparent the * member. * * This is as easy as referencing the new parent and dropping your own * reference. * * nih_ref (child, parent); * * child = obj->child; * obj->child = NULL; * * nih_unref (obj->child, obj); * * // child may now be returned * * == Worker objects == * * Finally another pattern exits in the nih_alloc() world that doesn't * quite obey the above rules, and instead takes advantage of the design * to provide something that wouldn't be possible otherwise. * * A worker is an object that performs some function out-of-band on * behalf of another object. They may be stored elsewhere, such as a * linked list, and will be set up such that if they are freed, the * work they are doing is cancelled. * * A good example would be a timer object; you'd have a list of timers * which you iterate in the main loop. The destructor of the timer * object removes it from this list. When the timer expires, some * work occurs, and the timer object frees itself. * * Thus to attach a timer to our object, all we need do is create the * timer with our object as a parent. There is absolutely no need * to store the timer as a structure member, unless we would need to * cancel it for other reasons. * * If our object is freed, the timer is freed to so there's no danger * of the callback firing and acting on a freed object. If the timer * fires, the callback can do its work, and the timer will be freed * afterwards. * * Much of the main loop related objects in libnih behave in this way. **/ #include /** * NihDestructor: * @ptr: pointer to be destroyed. * * A destructor is a function that can be associated with an allocated * object in memory and is called before the object is freed. The pointer * @ptr passed to the destructor is that of the object being freed. * * A typical use of a destructor would be to close a file descriptor held * by an object. * * When the destructor is called, the parent references to the object will * have already been discarded but all children references will be intact * and none of the children will have been freed. There is no need to use * a destructor to unreference or free children, that is automatic. * * Returns: value returned by nih_free() or nih_discard() if used directly * on the object. **/ typedef int (*NihDestructor) (void *ptr); /** * nih_new: * @parent: parent object for new object, * @type: type of data to store. * * Allocates an object in memory large enough to store a @type object * and returns a pointer to it. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned object otherwise the special * NULL parent will be used instead. When all parents of the returned * object are freed, the returned object will also be freed. * * If you have clean-up that you would like to run, you can assign a * destructor using the nih_alloc_set_destructor() function. * * Returns: newly allocated object or NULL if insufficient memory. **/ #define nih_new(parent, type) (type *)nih_alloc(parent, sizeof (type)) /** * nih_alloc_set_destructor: * @ptr: pointer to object, * @destructor: destructor function to set. * * Sets the destructor of the allocated object @ptr to @destructor, which * may be NULL to unset an existing destructor. This is a macro that casts * @destructor to the NihDestructor type, since almost all destructors * will be defined with their argument to be the type of the object * rather than void *. * * The destructor will be called before the object is freed, either * explicitly by nih_free() or nih_discard(), or because the last parent * has unreferenced the object. * * When the destructor is called, the parent references to the object will * have already been discarded but all children references will be intact * and none of the children will have been freed. There is no need to use * a destructor to unreference or free children, that is automatic. * * The pointer @ptr passed to the destructor is that of the object being * freed, and the destructor may return a value which will be the return * value of nih_free() or nih_discard() if used directly on the object. * * Since objects may also be freed by unreferencing, and the value is not * returned in this case, it should only be used for informational or * debugging purposes. **/ #define nih_alloc_set_destructor(ptr, destructor) \ nih_alloc_real_set_destructor (ptr, (NihDestructor)destructor) /** * nih_local: * * This macro may be used in a variable definition when the variable * should be automatically cleaned up when it goes out of scope. You * should ensure that the pointer is either allocated with nih_alloc() * or set to NULL; * * { * nih_local char *foo = NULL; * * foo = nih_strdup (NULL, "some data"); * } // foo is automatically discarded * * It is permissible to take references to foo within its scope, or by * functions called, in which case it will not be freed. Also it is * generally nonsensical to allocate with a parent, since this too will * prevent it from beign freed. **/ #define nih_local __attribute__ ((cleanup(_nih_discard_local))) NIH_BEGIN_EXTERN void * nih_alloc (const void *parent, size_t size) __attribute__ ((warn_unused_result, malloc)); void * nih_realloc (void *ptr, const void *parent, size_t size) __attribute__ ((warn_unused_result, malloc)); int nih_free (void *ptr); int nih_discard (void *ptr); void _nih_discard_local (void *ptraddr); void nih_alloc_real_set_destructor (const void *ptr, NihDestructor destructor); void nih_ref (const void *ptr, const void *parent); void nih_unref (void *ptr, const void *parent); int nih_alloc_parent (const void *ptr, const void *parent); size_t nih_alloc_size (const void *ptr); NIH_END_EXTERN #endif /* NIH_ALLOC_H */ libnih-1.0.3/nih/error.h0000644000175000017500000002347211445765555012012 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_ERROR_H #define NIH_ERROR_H /** * Many functions in libnih use these functions to report information about * errors, those that don't use the ordinary errno mechnism which can * also be reported within this framework. * * Errors are raised as NihError structures, kept globally. Only one error * may be active at any one time, raising an error when another is already * raised will result in an assertion. * * Errors are raised with the nih_error_raise() or nih_error_raise_printf() * functions, passing the error number and a human-readable messages. * * System errors can be raised with nih_error_raise_system(), and both * caught errors and self-allocated errors can be raised with * nih_error_raise_error(). * * You then report the error condition through your return value, or some * other stack-based method. * * A higher function that wishes to handle the error calls nih_error_get() * to retrieve it, it's an error to do so if you do not know that an error * is pending. This returns the currently raised error structure. * * To clear the error, it should be freed with nih_free(). To return the * error from your own function, simply don't free it. * * Errors may be partitioned using contexts, a new context is pushed with * nih_error_push_context(); any errors raised are now stored in this * context and any previous raised errors are hidden from view. The context * can be popped again with nih_error_pop_context() provided that any raised * error has been dealt with. The previously hidden raised errors are now * visible again. * * To raise an error from one context, into another, you can't simply call * nih_error_get() before nih_error_pop_context() since the latter will * assert because of the unfreed error. Instead nih_error_steal() may be * used which returns the error as nih_error_get() does but also removes * it from the context. * * nih_error_steal() may also be used to stash errors before trying an * alternate code path. **/ #include #include #include /** * NihError: * @filename: filename where the error was raised, * @line: line number of @filename where the error was raised, * @function: function name the error was raised within, * @number: numeric identifier, * @message: human-readable message. * * This structure represents an error, defining the error @number for * programmers to capture and handle them and a human-readable @message * that should be pre-translated. * * The structure is allocated when an error occurs, and only one structure * may exist in one context at a time; when another error is raised, the * existing error, if any, is freed. * * You may also use this structure as the header for more complicated error * objects, in which case do not worry about setting @filename, @line or * @function since these are set when you call nih_error_raise_error(); the * correct way to do this is to place the macro NIH_ERROR_MEMBERS at the * front of your structure, rather than an NihError named member - this * makes code that uses your custom error a little easier. **/ typedef struct nih_error { #define NIH_ERROR_MEMBERS \ const char *filename; \ int line; \ const char *function; \ \ int number; \ const char *message; NIH_ERROR_MEMBERS } NihError; /** * nih_error_raise: * @number: numeric identifier, * @message: human-readable message. * * Raises an error with the given details in the current error context, * if an unhandled error already exists then an error message is emmitted * through the logging system; you should try to avoid this. * * @message should be a static string, as it will not be freed when the * error object is. **/ #define nih_error_raise(number, message) \ _nih_error_raise (__FILE__, __LINE__, __FUNCTION__, number, message) /** * nih_error_raise_printf: * @number: numeric identifier, * @format: format string for human-readable message. * * Raises an error with the given details in the current error context, * if an unhandled error already exists then an error message is emmitted * through the logging system; you should try to avoid this. * * The human-readable message for the error is parsed according to @format, * and allocated as a child of the error object so that it is freed. **/ #define nih_error_raise_printf(number, format, ...) \ _nih_error_raise_printf (__FILE__, __LINE__, __FUNCTION__, \ number, format, __VA_ARGS__) /** * nih_error_raise_system: * * Raises an error with details taken from the current value of errno, * if an unhandled error already exists then an error message is emmitted * through the logging system; you should try to avoid this. **/ #define nih_error_raise_system() \ _nih_error_raise_system (__FILE__, __LINE__, __FUNCTION__) /** * nih_error_raise_no_memory: * * Raises an ENOMEM system error, if an unhandled error already exists then * an error message is emitted through the logging system; you should try * to avoid this. **/ #define nih_error_raise_no_memory() \ _nih_error_raise (__FILE__, __LINE__, __FUNCTION__, \ ENOMEM, strerror (ENOMEM)) /** * nih_error_raise_error: * @error: existing object to raise. * * Raises the existing error object in the current error context, * if an unhandled error already exists then an error message is emmitted * through the logging system; you should try to avoid this. * * This is normally used to raise a taken error that has not been handled, * or to raise a custom error object. * * The destructor of @error will be overwritten so that the context can * be cleared when the error is freed. **/ #define nih_error_raise_error(error) \ _nih_error_raise_error (__FILE__, __LINE__, __FUNCTION__, error) /** * nih_return_error: * @retval: return value for function, * @number: numeric identifier, * @message: human-readable message. * * Raises an error with the given details in the current error context, * if an unhandled error already exists then an error message is emmitted * through the logging system; you should try to avoid this. * * Will return from the current function with @retval, which may be left * empty to return from a void function. **/ #define nih_return_error(retval, number, message) \ do { \ nih_error_raise (number, message); \ return retval; \ } while (0) /** * nih_return_system_error: * @retval: return value for function. * * Raises an error with details taken from the current value of errno, * if an unhandled error already exists then an error message is emmitted * through the logging system; you should try to avoid this. * * Will return from the current function with @retval, which may be left * empty to return from a void function. **/ #define nih_return_system_error(retval) \ do { \ nih_error_raise_system (); \ return retval; \ } while (0) /** * nih_return_no_memory_error: * @retval: return value for function. * * Raises an ENOMEM system error, if an unhandled error already exists then * an error message is emitted through the logging system; you should try * to avoid this. * * Will return from the current function with @retval, which may be left * empty to return from a void function. **/ #define nih_return_no_memory_error(retval) \ do { \ nih_error_raise_no_memory (); \ return retval; \ } while (0) /** * NIH_SHOULD: * @_e: C expression. * * Repeats the expression @_e until it either yields a true value, or * raises an error other than ENOMEM. * * This can only be used when the expression always raises an error if * it does not yield a true value. * * The raised error remains raised and should be dealt with following * this function, thus you should store the value of the expression so you * know whether or not an error occurred. * * Returns: value of expression @_e which will be evaluated as many times * as necessary to become true. **/ #define NIH_SHOULD(_e) \ ({ \ typeof (_e) __ret; \ while (! (__ret = (_e))) { \ NihError *_nih_should_err; \ \ _nih_should_err = nih_error_get (); \ if (_nih_should_err->number == ENOMEM) { \ nih_free (_nih_should_err); \ } else { \ break; \ } \ } \ __ret; \ }) NIH_BEGIN_EXTERN void nih_error_init (void); void _nih_error_raise (const char *filename, int line, const char *function, int number, const char *message); void _nih_error_raise_printf (const char *filename, int line, const char *function, int number, const char *format, ...) __attribute__ ((format (printf, 5, 6))); void _nih_error_raise_system (const char *filename, int line, const char *function); void _nih_error_raise_error (const char *filename, int line, const char *function, NihError *error); NihError *nih_error_get (void) __attribute__ ((warn_unused_result)); NihError *nih_error_steal (void) __attribute__ ((warn_unused_result)); void nih_error_push_context (void); void nih_error_pop_context (void); NIH_END_EXTERN #endif /* NIH_ERROR_H */ libnih-1.0.3/nih/main.h0000644000175000017500000001034611445765555011601 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_MAIN_H #define NIH_MAIN_H #include #include #include /** * NihMainLoopCb: * @data: pointer given with callback, * @loop: loop callback structure. * * Main loop callbacks are called each time through the main loop to * perform any additional processing before the process is put back * to sleep. For anything time critical, timers should be used instead. * * The @loop pointer can be used to remove the callback. **/ typedef struct nih_main_loop_func NihMainLoopFunc; typedef void (*NihMainLoopCb) (void *data, NihMainLoopFunc *loop); /** * NihMainLoopFunc: * @entry: list header, * @callback: function called, * @data: pointer passed to @callback. * * This structure contains information about a function that should be * called once in each main loop iteration. * * The callback can be removed by using nih_list_remove() as they are * held in a list internally. **/ struct nih_main_loop_func { NihList entry; NihMainLoopCb callback; void *data; }; /** * nih_main_init_gettext: * * Initialises gettext using the PACKAGE_NAME and LOCALEDIR macros that should * be set by Autoconf/Automake. **/ #if ENABLE_NLS # ifndef LOCALEDIR # define LOCALEDIR NULL # endif /* LOCALEDIR */ # define nih_main_init_gettext() \ do { \ setlocale (LC_ALL, ""); \ bindtextdomain (PACKAGE_NAME, LOCALEDIR); \ textdomain (PACKAGE_NAME); \ } while (0) #else /* ENABLE_NLS */ # define nih_main_init_gettext() #endif /* ENABLE_NLS */ /** * nih_main_init: * @argv0: program name from arguments. * * Should be called at the beginning of main() to initialise the various * global variables exported from this module. Expands both * nih_main_init_gettext() and nih_main_init_full() * passing values set by Autoconf AC_INIT and AC_COPYRIGHT macros. **/ #ifndef PACKAGE_COPYRIGHT # define PACKAGE_COPYRIGHT NULL #endif /* PACKAGE_COPYRIGHT */ #define nih_main_init(argv0) \ do { \ nih_main_init_gettext (); \ nih_main_init_full (argv0, PACKAGE_NAME, PACKAGE_VERSION, \ PACKAGE_BUGREPORT, PACKAGE_COPYRIGHT); \ } while (0); NIH_BEGIN_EXTERN extern const char *program_name; extern const char *package_name; extern const char *package_version; extern const char *package_copyright; extern const char *package_bugreport; extern const char *package_string; extern NihList *nih_main_loop_functions; void nih_main_init_full (const char *argv0, const char *package, const char *version, const char *bugreport, const char *copyright); void nih_main_suggest_help (void); void nih_main_version (void); int nih_main_daemonise (void) __attribute__ ((warn_unused_result)); void nih_main_set_pidfile (const char *filename); const char * nih_main_get_pidfile (void); pid_t nih_main_read_pidfile (void); int nih_main_write_pidfile (pid_t pid) __attribute__ ((warn_unused_result)); void nih_main_unlink_pidfile (void); void nih_main_loop_init (void); int nih_main_loop (void); void nih_main_loop_interrupt (void); void nih_main_loop_exit (int status); NihMainLoopFunc *nih_main_loop_add_func (const void *parent, NihMainLoopCb callback, void *data) __attribute__ ((warn_unused_result, malloc)); void nih_main_term_signal (void *data, NihSignal *signal); NIH_END_EXTERN #endif /* NIH_MAIN_H */ libnih-1.0.3/nih/test_divert.h0000644000175000017500000000534711445765555013216 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_TEST_DIVERT_H #define NIH_TEST_DIVERT_H #ifndef NIH_IN_TEST_H # error "This header may only be included by " #endif /* NIH_IN_TEST_H */ #include #include #include /** * TEST_DIVERT_STDOUT_FD: * @_fd: fd to send standard output to. * * This macro diverts standard output to a different file descriptor * for the duration of a block of code that should follow it. **/ #define TEST_DIVERT_STDOUT_FD(_fd) \ for (int _test_stdout = 0, _test_oldstdout = dup (STDOUT_FILENO); \ _test_stdout < 3; _test_stdout++) \ if (_test_stdout < 1) { \ fflush (stdout); \ assert (dup2 ((_fd), STDOUT_FILENO) >= 0); \ } else if (_test_stdout > 1) { \ fflush (stdout); \ assert (dup2 (_test_oldstdout, STDOUT_FILENO) >= 0); \ close (_test_oldstdout); \ } else /** * TEST_DIVERT_STDOUT: * @_file: FILE to send standard output to. * * This macro diverts standard output to a different file for the duration * of a block of code that should follow it. */ #define TEST_DIVERT_STDOUT(_file) \ TEST_DIVERT_STDOUT_FD (fileno (_file)) /** * TEST_DIVERT_STDERR_FD: * @_fd: fd to send standard error to. * * This macro diverts standard error to a different file descriptor for the * duration of a block of code that should follow it. */ #define TEST_DIVERT_STDERR_FD(_fd) \ for (int _test_stderr = 0, _test_oldstderr = dup (STDERR_FILENO); \ _test_stderr < 3; _test_stderr++) \ if (_test_stderr < 1) { \ fflush (stderr); \ assert (dup2 ((_fd), STDERR_FILENO) >= 0); \ } else if (_test_stderr > 1) { \ fflush (stderr); \ assert (dup2 (_test_oldstderr, STDERR_FILENO) >= 0); \ close (_test_oldstderr); \ } else /** * TEST_DIVERT_STDERR: * @_file: FILE to send standard error to. * * This macro diverts standard error to a different file for the duration * of a block of code that should follow it. */ #define TEST_DIVERT_STDERR(_file) \ TEST_DIVERT_STDERR_FD (fileno (_file)) #endif /* NIH_TEST_DIVERT_H */ libnih-1.0.3/nih/string.h0000644000175000017500000000717311445765555012167 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_STRING_H #define NIH_STRING_H /** * These functions provide string utilities that use the nih_alloc() * functions for memory management. This allows you to create and modify * strings, and arrays of strings, which may be referenced by other objects * and cleaned up automatically. **/ #include #include NIH_BEGIN_EXTERN char * nih_sprintf (const void *parent, const char *format, ...) __attribute__ ((format (printf, 2, 3), warn_unused_result, malloc)); char * nih_vsprintf (const void *parent, const char *format, va_list args) __attribute__ ((format (printf, 2, 0), warn_unused_result, malloc)); char * nih_strdup (const void *parent, const char *str) __attribute__ ((warn_unused_result, malloc)); char * nih_strndup (const void *parent, const char *str, size_t len) __attribute__ ((warn_unused_result, malloc)); char * nih_strcat (char **str, const void *parent, const char *src) __attribute__ ((warn_unused_result, malloc)); char * nih_strncat (char **str, const void *parent, const char *src, size_t len) __attribute__ ((warn_unused_result, malloc)); char * nih_strcat_sprintf (char **str, const void *parent, const char *format, ...) __attribute__ ((format (printf, 3, 4), warn_unused_result, malloc)); char * nih_strcat_vsprintf (char **str, const void *parent, const char *format, va_list args) __attribute__ ((format (printf, 3, 0), warn_unused_result, malloc)); char **nih_str_split (const void *parent, const char *str, const char *delim, int repeat) __attribute__ ((warn_unused_result, malloc)); char **nih_str_array_new (const void *parent) __attribute__ ((warn_unused_result, malloc)); char **nih_str_array_add (char ***array, const void *parent, size_t *len, const char *str) __attribute__ ((warn_unused_result, malloc)); char **nih_str_array_addn (char ***array, const void *parent, size_t *len, const char *str, size_t strlen) __attribute__ ((warn_unused_result, malloc)); char **nih_str_array_addp (char ***array, const void *parent, size_t *len, void *ptr) __attribute__ ((warn_unused_result, malloc)); char **nih_str_array_copy (const void *parent, size_t *len, char * const *array) __attribute__ ((warn_unused_result, malloc)); char **nih_str_array_append (char ***array, const void *parent, size_t *len, char * const *args) __attribute__ ((warn_unused_result, malloc)); char * nih_str_wrap (const void *parent, const char *str, size_t len, size_t first_indent, size_t indent) __attribute__ ((warn_unused_result, malloc)); size_t nih_str_screen_width (void); char * nih_str_screen_wrap (const void *parent, const char *str, size_t first_indent, size_t indent) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_STRING_H */ libnih-1.0.3/nih/file.c0000644000175000017500000004304011445765555011564 00000000000000/* libnih * * file.c - file and directory utility functions * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /** * NihDirEntry: * @entry: list header, * @dev: device number, * @ino: inode number. * * This structure is used to detect directory loops, and is stored in a stack * as we recurse down the directory tree. **/ typedef struct nih_dir_entry { NihList entry; dev_t dev; ino_t ino; } NihDirEntry; /* Prototypes for static functions */ static char **nih_dir_walk_scan (const char *path, NihFileFilter filter, void *data) __attribute__ ((warn_unused_result, malloc)); static int nih_dir_walk_visit (const char *dirname, NihList *dirs, const char *path, NihFileFilter filter, NihFileVisitor visitor, NihFileErrorHandler error, void *data) __attribute__ ((warn_unused_result)); /** * nih_file_read: * @parent: parent object for new string, * @path: path to read, * @length: pointer to store file length in. * * Opens the file at @path and reads the contents into memory, returning * a newly allocated string. If the file is particularly large, it may * not be possible to read into memory at all, and you'll need to use * nih_file_map() instead. * * The returned data will NOT be NULL terminated. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * nih_file_read (const void *parent, const char *path, size_t *length) { struct stat statbuf; FILE *fp; char *file = NULL; nih_assert (path != NULL); nih_assert (length != NULL); fp = fopen (path, "r"); if (! fp) nih_return_system_error (NULL); if (fstat (fileno (fp), &statbuf) < 0) goto error; if ((size_t)statbuf.st_size > SIZE_MAX) { errno = EFBIG; goto error; } *length = statbuf.st_size; file = nih_alloc (parent, statbuf.st_size); if (! file) goto error; if (fread (file, 1, statbuf.st_size, fp) != (size_t)statbuf.st_size) { errno = EILSEQ; goto error; } fclose (fp); return file; error: nih_error_raise_system (); if (file) nih_free (file); fclose (fp); return NULL; } /** * nih_file_map: * @path: path to open, * @flags: open mode, * @length: pointer to store file length. * * Opens the file at @path and maps it into memory, returning the mapped * pointer and the length of the file (required to unmap it later). The * file is opened with the @flags given. * * Returns: memory mapped file or NULL on raised error. **/ void * nih_file_map (const char *path, int flags, size_t *length) { struct stat statbuf; char *map; int fd, prot; nih_assert (path != NULL); nih_assert (length != NULL); nih_assert (((flags & O_ACCMODE) == O_RDONLY) || ((flags & O_ACCMODE) == O_RDWR)); fd = open (path, flags); if (fd < 0) nih_return_system_error (NULL); prot = PROT_READ; if ((flags & O_ACCMODE) == O_RDWR) prot |= PROT_WRITE; if (fstat (fd, &statbuf) < 0) goto error; if ((size_t)statbuf.st_size > SIZE_MAX) { errno = EFBIG; goto error; } *length = statbuf.st_size; map = mmap (NULL, *length, prot, MAP_SHARED, fd, 0); if (map == MAP_FAILED) goto error; close (fd); return map; error: nih_error_raise_system (); close (fd); return NULL; } /** * nih_file_unmap: * @map: memory mapped file, * @length: length of file. * * Unmap a file previously mapped with nih_file_map(). * * Returns: zero on success, NULL on raised error. **/ int nih_file_unmap (void *map, size_t length) { nih_assert (map != NULL); if (munmap (map, length) < 0) nih_return_system_error (-1); return 0; } /** * nih_file_is_hidden: * @path: path to check. * * Determines whether @path represents a hidden file, matching it against * common patterns for that type of file. * * Returns: TRUE if it matches, FALSE otherwise. **/ int nih_file_is_hidden (const char *path) { const char *ptr; size_t len; nih_assert (path != NULL); ptr = strrchr (path, '/'); if (ptr) path = ptr + 1; len = strlen (path); /* Matches .*; standard hidden pattern */ if ((len >= 1) && (path[0] == '.')) return TRUE; return FALSE; } /** * nih_file_is_backup: * @path: path to check. * * Determines whether @path represents a backup file, matching it against * common patterns for that type of file. * * Returns: TRUE if it matches, FALSE otherwise. **/ int nih_file_is_backup (const char *path) { const char *ptr; size_t len; nih_assert (path != NULL); ptr = strrchr (path, '/'); if (ptr) path = ptr + 1; len = strlen (path); ptr = path + len; /* Matches *~; standard backup style */ if ((len >= 1) && (ptr[-1] == '~')) return TRUE; /* Matches *.bak; common backup extension */ if ((len >= 4) && (! strcmp (&ptr[-4], ".bak"))) return TRUE; /* Matches *.BAK; as above, but on case-insensitive filesystems */ if ((len >= 4) && (! strcmp (&ptr[-4], ".BAK"))) return TRUE; /* Matches #*#; used by emacs for unsaved files */ if ((len >= 2) && (path[0] == '#') && (ptr[-1] == '#')) return TRUE; return FALSE; } /** * nih_file_is_swap: * @path: path to check. * * Determines whether @path represents an editor swap file, matching it * against common patterns for that type of file. * * Returns: TRUE if it matches, FALSE otherwise. **/ int nih_file_is_swap (const char *path) { const char *ptr; size_t len; nih_assert (path != NULL); ptr = strrchr (path, '/'); if (ptr) path = ptr + 1; len = strlen (path); ptr = path + len; /* Matches *.swp; used by vi */ if ((len >= 4) && (! strcmp (&ptr[-4], ".swp"))) return TRUE; /* Matches *.swo; used by vi */ if ((len >= 4) && (! strcmp (&ptr[-4], ".swo"))) return TRUE; /* Matches *.swn; used by vi */ if ((len >= 4) && (! strcmp (&ptr[-4], ".swn"))) return TRUE; /* Matches .#*; used by emacs */ if ((len >= 2) && (! strncmp (path, ".#", 2))) return TRUE; return FALSE; } /** * nih_file_is_rcs: * @path: path to check. * * Determines whether @path represents a file or directory used by a * common revision control system, matching it against common patterns * for known RCSs. * * Returns: TRUE if it matches, FALSE otherwise. **/ int nih_file_is_rcs (const char *path) { const char *ptr; size_t len; nih_assert (path != NULL); ptr = strrchr (path, '/'); if (ptr) path = ptr + 1; len = strlen (path); ptr = path + len; /* Matches *,v; used by rcs and cvs */ if ((len >= 2) && (! strcmp (&ptr[-2], ",v"))) return TRUE; /* RCS; used by rcs */ if (! strcmp (path, "RCS")) return TRUE; /* CVS; used by cvs */ if (! strcmp (path, "CVS")) return TRUE; /* CVS.adm; used by cvs */ if (! strcmp (path, "CVS.adm")) return TRUE; /* SCCS; used by sccs */ if (! strcmp (path, "SCCS")) return TRUE; /* .bzr; used by bzr */ if (! strcmp (path, ".bzr")) return TRUE; /* .bzr.log; used by bzr */ if (! strcmp (path, ".bzr.log")) return TRUE; /* .hg; used by hg */ if (! strcmp (path, ".hg")) return TRUE; /* .git; used by git */ if (! strcmp (path, ".git")) return TRUE; /* .svn; used by subversion */ if (! strcmp (path, ".svn")) return TRUE; /* BitKeeper; used by BitKeeper */ if (! strcmp (path, "BitKeeper")) return TRUE; /* .arch-ids; used by tla */ if (! strcmp (path, ".arch-ids")) return TRUE; /* .arch-inventory; used by tla */ if (! strcmp (path, ".arch-inventory")) return TRUE; /* {arch}; used by tla */ if (! strcmp (path, "{arch}")) return TRUE; /* _darcs; used by darcs */ if (! strcmp (path, "_darcs")) return TRUE; return FALSE; } /** * nih_file_is_packaging: * @path: path to check. * * Determines whether @path represents a file or directory used by a * common package manager, matching it against common patterns. * * Returns: TRUE if it matches, FALSE otherwise. **/ int nih_file_is_packaging (const char *path) { const char *ptr; nih_assert (path != NULL); ptr = strrchr (path, '/'); if (ptr) path = ptr + 1; /* Matches *.dpkg-*; used by dpkg */ ptr = strrchr (path, '.'); if (ptr && (! strncmp (ptr, ".dpkg-", 6))) return TRUE; /* Matches *.rpm{save,orig,new}; used by rpm */ if (ptr && (! strncmp (ptr, ".rpmsave", 9))) return TRUE; if (ptr && (! strncmp (ptr, ".rpmorig", 9))) return TRUE; if (ptr && (! strncmp (ptr, ".rpmnew", 8))) return TRUE; /* Matches *;[a-fA-F0-9]{8}; used by rpm */ ptr = strrchr (path, ';'); if (ptr && (strspn (ptr + 1, "abcdefABCDEF0123456789") == 8) && (! ptr[9])) return TRUE; return FALSE; } /** * nih_file_ignore: * @data: data pointer, * @path: path to check. * * Determines whether @path should normally be ignored when walking a * directory tree. Files ignored are those that are hidden, represent * backup files, editor swap files and both files and directories used * by revision control systems. * * Returns: TRUE if it should be ignored, FALSE otherwise. **/ int nih_file_ignore (void *data, const char *path) { if (nih_file_is_hidden (path)) return TRUE; if (nih_file_is_backup (path)) return TRUE; if (nih_file_is_swap (path)) return TRUE; if (nih_file_is_rcs (path)) return TRUE; if (nih_file_is_packaging (path)) return TRUE; return FALSE; } /** * nih_dir_walk: * @path: path to walk, * @filter: path filter, * @visitor: function to call for each path, * @error: function to call on error, * @data: data to pass to @visitor. * * Iterates the directory tree starting at @path, calling @visitor for * each file, directory or other object found. Sub-directories are * descended into, and the same @visitor called for those. * * @visitor is not called for @path itself. * * @filter can be used to restrict both the sub-directories iterated and * the objects that @visitor is called for. It is passed the full path * of the object, and if it returns TRUE, the object is ignored. * * If @visitor returns a negative value, or there's an error obtaining * the listing for a particular sub-directory, then the @error function * will be called. This function should handle the error and return zero, * or raise an error again and return a negative value which causes the * entire walk to be aborted. If @error is NULL, then a warning is emitted * instead. * * Returns: zero on success, negative value on raised error. **/ int nih_dir_walk (const char *path, NihFileFilter filter, NihFileVisitor visitor, NihFileErrorHandler error, void *data) { nih_local NihList *dirs = NULL; struct stat statbuf; nih_local char **paths = NULL; char **subpath; int ret = 0; nih_assert (path != NULL); nih_assert (visitor != NULL); paths = nih_dir_walk_scan (path, filter, data); if (! paths) return -1; dirs = NIH_MUST (nih_list_new (NULL)); if (stat (path, &statbuf) == 0) { NihDirEntry *entry; entry = NIH_MUST (nih_new (dirs, NihDirEntry)); nih_list_init (&entry->entry); nih_alloc_set_destructor (entry, nih_list_destroy); entry->dev = statbuf.st_dev; entry->ino = statbuf.st_ino; nih_list_add (dirs, &entry->entry); } for (subpath = paths; *subpath; subpath++) { ret = nih_dir_walk_visit (path, dirs, *subpath, filter, visitor, error, data); if (ret < 0) break; } return ret; } /** * nih_dir_walk_sort: * @a: pointer to first path, * @b: pointer to second path. * * This function wraps the strcoll() function allowing it to be called * from qsort(). * * Returns: zero if strings are equal, otherwise integer less than zero * if @a is less than @b or integer greater than zero if @a is greater * than @b. **/ static int nih_dir_walk_sort (const void *a, const void *b) { const char * const *path_a; const char * const *path_b; nih_assert (a != NULL); nih_assert (b != NULL); path_a = a; path_b = b; return strcoll (*path_a, *path_b); } /** * nih_dir_walk_scan: * @path: path to scan, * @filter: path filter, * @data: data to pass to @filter. * * Reads the list of files in @path, removing ".", ".." and any for which * @filter return TRUE. * * Returns: NULL-terminated array of full paths to sub-paths or NULL on * raised error. **/ static char ** nih_dir_walk_scan (const char *path, NihFileFilter filter, void *data) { DIR *dir; struct dirent *ent; char **paths; size_t npaths; nih_assert (path != NULL); dir = opendir (path); if (! dir) nih_return_system_error (NULL); npaths = 0; paths = NIH_MUST (nih_str_array_new (NULL)); while ((ent = readdir (dir)) != NULL) { nih_local char *subpath = NULL; /* Always ignore '.' and '..' */ if ((! strcmp (ent->d_name, ".")) || (! strcmp (ent->d_name, ".."))) continue; subpath = NIH_MUST (nih_sprintf (NULL, "%s/%s", path, ent->d_name)); if (filter && filter (data, subpath, ent->d_type == DT_DIR)) continue; NIH_MUST (nih_str_array_addp (&paths, NULL, &npaths, subpath)); } closedir (dir); qsort (paths, npaths, sizeof (char *), nih_dir_walk_sort); return paths; } /** * nih_dir_walk_visit: * @dirname: top-level being walked, * @dirs: stack of visited directories, * @path: path being visited, * @filter: path filter, * @visitor: function to call for each path, * @error: function to call on error, * @data: data to pass to @visitor. * * Visits an individual @path found while iterating the directory tree * started at @dirname. Ensures that @visitor is called for @path, and * if @path is a directory, it is descended into and the same @visitor * called for each of those. * * @filter can be used to restrict both the sub-directories iterated and * the objects that @visitor is called for. It is passed the full path * of the object, and if it returns TRUE, the object is ignored. * * If @visitor returns a negative value, or there's an error obtaining * the listing for a particular sub-directory, then the @error function * will be called. This function should handle the error and return zero, * or raise an error again and return a negative value which causes the * entire walk to be aborted. If @error is NULL, then a warning is emitted * instead. * * Returns: zero on success, negative value on raised error. **/ static int nih_dir_walk_visit (const char *dirname, NihList *dirs, const char *path, NihFileFilter filter, NihFileVisitor visitor, NihFileErrorHandler error, void *data) { struct stat statbuf; nih_assert (dirname != NULL); nih_assert (dirs != NULL); nih_assert (path != NULL); nih_assert (visitor != NULL); /* Not much we can do here if we can't at least stat it */ if (stat (path, &statbuf) < 0) { nih_error_raise_system (); goto error; } /* Call the handler */ if (visitor (data, dirname, path, &statbuf) < 0) goto error; /* Iterate into sub-directories; first checking for directory loops. */ if (S_ISDIR (statbuf.st_mode)) { nih_local NihDirEntry *entry = NULL; nih_local char **paths = NULL; char **subpath; int ret = 0; NIH_LIST_FOREACH (dirs, iter) { NihDirEntry *entry = (NihDirEntry *)iter; if ((entry->dev == statbuf.st_dev) && (entry->ino == statbuf.st_ino)) { nih_error_raise (NIH_DIR_LOOP_DETECTED, _(NIH_DIR_LOOP_DETECTED_STR)); goto error; } } /* Grab the directory contents */ paths = nih_dir_walk_scan (path, filter, data); if (! paths) goto error; /* Record the device and inode numbers in the stack so that * we can detect directory loops. */ entry = NIH_MUST (nih_new (NULL, NihDirEntry)); nih_list_init (&entry->entry); nih_alloc_set_destructor (entry, nih_list_destroy); entry->dev = statbuf.st_dev; entry->ino = statbuf.st_ino; nih_list_add (dirs, &entry->entry); /* Iterate the paths found. If these calls return a negative * value, it means that an error handler decided to abort the * walk; so just abort right now. */ for (subpath = paths; *subpath; subpath++) { ret = nih_dir_walk_visit (dirname, dirs, *subpath, filter, visitor, error, data); if (ret < 0) break; } if (ret < 0) return ret; } return 0; error: if (error) { return error (data, dirname, path, &statbuf); } else { NihError *err; err = nih_error_get (); nih_warn ("%s: %s", path, err->message); nih_free (err); return 0; } } libnih-1.0.3/nih/tests/0000755000175000017500000000000011504742362011705 500000000000000libnih-1.0.3/nih/tests/test_string.c0000644000175000017500000007702511445765555014366 00000000000000/* libnih * * test_string.c - test suite for nih/string.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include void test_sprintf (void) { char *str1, *str2; TEST_FUNCTION ("nih_sprintf"); /* Check that we can create a formatted string with no parent, * it should be allocated with nih_alloc and be the right length. */ TEST_FEATURE ("with no parent"); TEST_ALLOC_FAIL { str1 = nih_sprintf (NULL, "this %s a test %d", "is", 54321); if (test_alloc_failed) { TEST_EQ_P (str1, NULL); continue; } TEST_ALLOC_PARENT (str1, NULL); TEST_ALLOC_SIZE (str1, strlen (str1) + 1); TEST_EQ_STR (str1, "this is a test 54321"); nih_free (str1); } /* Check that we can create a string with a parent. */ TEST_FEATURE ("with a parent"); str1 = nih_sprintf (NULL, "this %s a test %d", "is", 54321); TEST_ALLOC_FAIL { str2 = nih_sprintf (str1, "another %d test %s", 12345, "string"); if (test_alloc_failed) { TEST_EQ_P (str2, NULL); continue; } TEST_ALLOC_PARENT (str2, str1); TEST_ALLOC_SIZE (str2, strlen (str2) + 1); TEST_EQ_STR (str2, "another 12345 test string"); nih_free (str2); } nih_free (str1); } static char * my_vsprintf (void *parent, const char *format, ...) { char *str; va_list args; va_start (args, format); str = nih_vsprintf (parent, format, args); va_end (args); return str; } void test_vsprintf (void) { char *str1, *str2; TEST_FUNCTION ("nih_vsprintf"); /* Check that we can create a formatted string for a va_list, * first with no parent. */ TEST_FEATURE ("with no parent"); TEST_ALLOC_FAIL { str1 = my_vsprintf (NULL, "this %s a test %d", "is", 54321); if (test_alloc_failed) { TEST_EQ_P (str1, NULL); continue; } TEST_ALLOC_PARENT (str1, NULL); TEST_ALLOC_SIZE (str1, strlen (str1) + 1); TEST_EQ_STR (str1, "this is a test 54321"); nih_free (str1); } /* And then with a parent. */ TEST_FEATURE ("with a parent"); str1 = my_vsprintf (NULL, "this %s a test %d", "is", 54321); TEST_ALLOC_FAIL { str2 = my_vsprintf (str1, "another %d test %s", 12345, "string"); if (test_alloc_failed) { TEST_EQ_P (str2, NULL); continue; } TEST_ALLOC_PARENT (str2, str1); TEST_ALLOC_SIZE (str2, strlen (str2) + 1); TEST_EQ_STR (str2, "another 12345 test string"); nih_free (str2); } nih_free (str1); } void test_strdup (void) { char *str1, *str2; TEST_FUNCTION ("nih_strdup"); /* Check that we can create a duplicate of another string, * allocated with nih_alloc and no parent. */ TEST_FEATURE ("with no parent"); TEST_ALLOC_FAIL { str1 = nih_strdup (NULL, "this is a test"); if (test_alloc_failed) { TEST_EQ_P (str1, NULL); continue; } TEST_ALLOC_PARENT (str1, NULL); TEST_ALLOC_SIZE (str1, strlen (str1) + 1); TEST_EQ_STR (str1, "this is a test"); nih_free (str1); } /* And check we can allocate with a parent. */ TEST_FEATURE ("with a parent"); str1 = nih_strdup (NULL, "this is a test"); TEST_ALLOC_FAIL { str2 = nih_strdup (str1, "another test string"); if (test_alloc_failed) { TEST_EQ_P (str2, NULL); continue; } TEST_ALLOC_PARENT (str2, str1); TEST_ALLOC_SIZE (str2, strlen (str2) + 1); TEST_EQ_STR (str2, "another test string"); nih_free (str2); } nih_free (str1); } void test_strndup (void) { char *str1, *str2; TEST_FUNCTION ("nih_strndup"); /* Check that we can create a duplicate of the first portion of * another string, allocated with nih_alloc and no parent. The * new string should still include a NULL byte. */ TEST_FEATURE ("with no parent"); TEST_ALLOC_FAIL { str1 = nih_strndup (NULL, "this is a test", 7); if (test_alloc_failed) { TEST_EQ_P (str1, NULL); continue; } TEST_ALLOC_PARENT (str1, NULL); TEST_ALLOC_SIZE (str1, 8); TEST_EQ_STR (str1, "this is"); nih_free (str1); } /* Check that it works with a parent. */ TEST_FEATURE ("with a parent"); str1 = nih_strndup (NULL, "this is a test", 7); TEST_ALLOC_FAIL { str2 = nih_strndup (str1, "another test string", 12); if (test_alloc_failed) { TEST_EQ_P (str2, NULL); continue; } TEST_ALLOC_PARENT (str2, str1); TEST_ALLOC_SIZE (str2, 13); TEST_EQ_STR (str2, "another test"); nih_free (str2); } nih_free (str1); /* Check that the right thing happens if the length we give is * longer than the string, the returned size should be ample but * with the complete string copied in. */ TEST_FEATURE ("with larger length than string"); TEST_ALLOC_FAIL { str1 = nih_strndup (NULL, "small string", 20); if (test_alloc_failed) { TEST_EQ_P (str1, NULL); continue; } TEST_ALLOC_SIZE (str1, 21); TEST_EQ_STR (str1, "small string"); nih_free (str1); } } void test_strcat (void) { char *str, *ret; TEST_FUNCTION ("nih_strcat"); /* Check that we can extend a string with another, resulting in the * original string being modified and the new pointer stored in the * argument and returned. */ TEST_FEATURE ("with string"); TEST_ALLOC_FAIL { char *tmp; TEST_ALLOC_SAFE { str = nih_strdup (NULL, "this is a test"); } tmp = str; ret = nih_strcat (&str, NULL, " of strdup"); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_P (str, tmp); TEST_EQ_STR (str, "this is a test"); nih_free (str); continue; } TEST_NE (ret, NULL); TEST_EQ_P (ret, str); TEST_ALLOC_SIZE (str, 25); TEST_EQ_STR (str, "this is a test of strdup"); nih_free (str); } /* Check that when no string is passed, this behaves as strdup. */ TEST_FEATURE ("with NULL"); TEST_ALLOC_FAIL { str = NULL; ret = nih_strcat (&str, NULL, "test of strdup"); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_P (str, NULL); continue; } TEST_NE (ret, NULL); TEST_EQ_P (ret, str); TEST_ALLOC_SIZE (str, 15); TEST_EQ_STR (str, "test of strdup"); nih_free (str); } } void test_strncat (void) { char *str, *ret; TEST_FUNCTION ("nih_strncat"); /* Check that we can extend a string with the first number of bytes * from another, resulting in the original string being modified and * the new pointer stored in the argument and returned. */ TEST_FEATURE ("with larger string than length"); TEST_ALLOC_FAIL { char *tmp; TEST_ALLOC_SAFE { str = nih_strdup (NULL, "this is a test"); } tmp = str; ret = nih_strncat (&str, NULL, " of strndup", 3); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_P (str, tmp); TEST_EQ_STR (str, "this is a test"); nih_free (str); continue; } TEST_NE (ret, NULL); TEST_EQ_P (ret, str); TEST_ALLOC_SIZE (str, 18); TEST_EQ_STR (str, "this is a test of"); nih_free (str); } /* Check that if a longer length than the string is given, enough * space is reserved but the string copy stops at the NULL. */ TEST_FEATURE ("with larger length than string"); TEST_ALLOC_FAIL { char *tmp; TEST_ALLOC_SAFE { str = nih_strdup (NULL, "this is a test"); } tmp = str; ret = nih_strncat (&str, NULL, " of strndup", 21); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_P (str, tmp); TEST_EQ_STR (str, "this is a test"); nih_free (str); continue; } TEST_NE (ret, NULL); TEST_EQ_P (ret, str); TEST_ALLOC_SIZE (str, 36); TEST_EQ_STR (str, "this is a test of strndup"); nih_free (str); } /* Check that when no string is passed, this behaves as strndup. */ TEST_FEATURE ("with NULL"); TEST_ALLOC_FAIL { str = NULL; ret = nih_strncat (&str, NULL, "test of strndup", 12); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_P (str, NULL); continue; } TEST_NE (ret, NULL); TEST_EQ_P (ret, str); TEST_ALLOC_SIZE (str, 13); TEST_EQ_STR (str, "test of strn"); nih_free (str); } } void test_strcat_sprintf (void) { char *str, *ret; TEST_FUNCTION ("test_strcat_sprintf"); /* Check that we can extend a string with a formatted string, * resulting in the original string being modified and the new * pointer stored in the argument and returned. */ TEST_FEATURE ("with original string"); TEST_ALLOC_FAIL { char *tmp; TEST_ALLOC_SAFE { str = nih_strdup (NULL, "this"); } tmp = str; ret = nih_strcat_sprintf (&str, NULL, " %s a test %d", "is", 54321); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_P (str, tmp); TEST_EQ_STR (str, "this"); nih_free (str); continue; } TEST_NE (ret, NULL); TEST_EQ_P (ret, str); TEST_ALLOC_SIZE (str, 21); TEST_EQ_STR (str, "this is a test 54321"); nih_free (str); } /* Check that when no string is passed, this behaves as sprintf. */ TEST_FEATURE ("with NULL"); TEST_ALLOC_FAIL { str = NULL; ret = nih_strcat_sprintf (&str, NULL, "%s a test %d", "is", 54321); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_P (str, NULL); continue; } TEST_NE (ret, NULL); TEST_EQ_P (ret, str); TEST_ALLOC_SIZE (str, 15); TEST_EQ_STR (str, "is a test 54321"); nih_free (str); } } static char * my_strcat_vsprintf (char **str, const void *parent, const char *format, ...) { char *ret; va_list args; va_start (args, format); ret = nih_strcat_vsprintf (str, parent, format, args); va_end (args); return ret; } void test_strcat_vsprintf (void) { char *str, *ret; TEST_FUNCTION ("test_strcat_vsprintf"); /* Check that we can extend a string with a formatted string, * resulting in the original string being modified and the new * pointer stored in the argument and returned. */ TEST_FEATURE ("with original string"); TEST_ALLOC_FAIL { char *tmp; TEST_ALLOC_SAFE { str = nih_strdup (NULL, "this"); } tmp = str; ret = my_strcat_vsprintf (&str, NULL, " %s a test %d", "is", 54321); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_P (str, tmp); TEST_EQ_STR (str, "this"); nih_free (str); continue; } TEST_NE (ret, NULL); TEST_EQ_P (ret, str); TEST_ALLOC_SIZE (str, 21); TEST_EQ_STR (str, "this is a test 54321"); nih_free (str); } /* Check that when no string is passed, this behaves as sprintf. */ TEST_FEATURE ("with NULL"); TEST_ALLOC_FAIL { str = NULL; ret = my_strcat_vsprintf (&str, NULL, "%s a test %d", "is", 54321); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_P (str, NULL); continue; } TEST_NE (ret, NULL); TEST_EQ_P (ret, str); TEST_ALLOC_SIZE (str, 15); TEST_EQ_STR (str, "is a test 54321"); nih_free (str); } } void test_str_split (void) { char **array; int i; TEST_FUNCTION ("nih_str_split"); /* Check that we can split a string into a NULL-terminated array * at each matching character. The array should be allocated with * nih_alloc, and each element should also be with the array as * their parent. */ TEST_FEATURE ("with no repeat"); TEST_ALLOC_FAIL { array = nih_str_split (NULL, "this is a\ttest", " \t", FALSE); if (test_alloc_failed) { TEST_EQ_P (array, NULL); continue; } TEST_ALLOC_SIZE (array, sizeof (char *) * 6); for (i = 0; i < 5; i++) TEST_ALLOC_PARENT (array[i], array); TEST_EQ_STR (array[0], "this"); TEST_EQ_STR (array[1], "is"); TEST_EQ_STR (array[2], ""); TEST_EQ_STR (array[3], "a"); TEST_EQ_STR (array[4], "test"); TEST_EQ_P (array[5], NULL); nih_free (array); } /* Check that we can split a string treating multiple consecutive * matching characters as a single separator to be skipped. */ TEST_FEATURE ("with repeat"); TEST_ALLOC_FAIL { array = nih_str_split (NULL, "this is a\ttest", " \t", TRUE); if (test_alloc_failed) { TEST_EQ_P (array, NULL); continue; } TEST_ALLOC_SIZE (array, sizeof (char *) * 5); for (i = 0; i < 4; i++) TEST_ALLOC_PARENT (array[i], array); TEST_EQ_STR (array[0], "this"); TEST_EQ_STR (array[1], "is"); TEST_EQ_STR (array[2], "a"); TEST_EQ_STR (array[3], "test"); TEST_EQ_P (array[4], NULL); nih_free (array); } /* Check that we can give an empty string, and end up with a * one-element array that only contains a NULL pointer. */ TEST_FEATURE ("with empty string"); TEST_ALLOC_FAIL { array = nih_str_split (NULL, "", " ", FALSE); if (test_alloc_failed) { TEST_EQ_P (array, NULL); continue; } TEST_ALLOC_SIZE (array, sizeof (char *)); TEST_EQ_P (array[0], NULL); nih_free (array); } } void test_array_new (void) { char **array; /* Check that we can allocate a NULL-terminated array of strings using * nih_alloc(). */ TEST_FUNCTION ("nih_str_array_new"); TEST_ALLOC_FAIL { array = nih_str_array_new (NULL); if (test_alloc_failed) { TEST_EQ_P (array, NULL); continue; } TEST_ALLOC_SIZE (array, sizeof (char *)); TEST_EQ_P (array[0], NULL); nih_free (array); } } void test_array_add (void) { char **array, **ret; size_t len; /* Check that we can append strings to a NULL-terminated array. */ TEST_FUNCTION ("nih_str_array_add"); array = nih_str_array_new (NULL); len = 0; TEST_ALLOC_FAIL { ret = nih_str_array_add (&array, NULL, &len, "test"); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ (len, 1); TEST_EQ_STR (array[0], "test"); TEST_EQ_P (array[1], NULL); continue; } TEST_NE_P (ret, NULL); TEST_EQ (len, 1); TEST_ALLOC_PARENT (array[0], array); TEST_ALLOC_SIZE (array[0], 5); TEST_EQ_STR (array[0], "test"); TEST_EQ_P (array[1], NULL); } nih_free (array); } void test_array_addn (void) { char **array, **ret; size_t len; /* Check that we can append strings to a NULL-terminated array. */ TEST_FUNCTION ("nih_str_array_addn"); array = nih_str_array_new (NULL); len = 0; TEST_ALLOC_FAIL { ret = nih_str_array_addn (&array, NULL, &len, "testing", 4); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ (len, 1); TEST_EQ_STR (array[0], "test"); TEST_EQ_P (array[1], NULL); continue; } TEST_NE_P (ret, NULL); TEST_EQ (len, 1); TEST_ALLOC_PARENT (array[0], array); TEST_ALLOC_SIZE (array[0], 5); TEST_EQ_STR (array[0], "test"); TEST_EQ_P (array[1], NULL); } nih_free (array); } void test_array_addp (void) { char **array, **ret; char *ptr1 = NULL; char *ptr2 = NULL; size_t len; TEST_FUNCTION ("nih_str_array_addn"); /* Check that we can call the function with a NULL array pointer, * and get one allocated automatically. */ TEST_FEATURE ("with no array given"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { ptr1 = nih_alloc (NULL, 1024); memset (ptr1, ' ', 1024); } array = NULL; len = 0; ret = nih_str_array_addp (&array, NULL, &len, ptr1); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_P (array, NULL); TEST_EQ (len, 0); nih_free (ptr1); continue; } TEST_NE_P (ret, NULL); TEST_EQ (len, 1); TEST_EQ_P (array[0], ptr1); TEST_ALLOC_PARENT (array[0], array); TEST_EQ_P (array[1], NULL); nih_free (array); nih_free (ptr1); } /* Check that we can append allocated blocks to a * NULL-terminated array, and that the blocks are automatically * reparented. */ TEST_FEATURE ("with length given"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { array = nih_str_array_new (NULL); len = 0; ptr1 = nih_alloc (NULL, 1024); memset (ptr1, ' ', 1024); } ret = nih_str_array_addp (&array, NULL, &len, ptr1); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ (len, 0); TEST_EQ_P (array[0], NULL); nih_free (array); nih_free (ptr1); continue; } TEST_NE_P (ret, NULL); TEST_EQ (len, 1); TEST_EQ_P (array[0], ptr1); TEST_ALLOC_PARENT (array[0], array); TEST_EQ_P (array[1], NULL); nih_free (array); nih_free (ptr1); } /* Check that we can omit the length, and have it calculated. */ TEST_FEATURE ("with no length given"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { array = nih_str_array_new (NULL); len = 0; ptr1 = nih_alloc (NULL, 1024); memset (ptr1, ' ', 1024); assert (nih_str_array_addp (&array, NULL, NULL, ptr1)); ptr2 = nih_alloc (NULL, 512); memset (ptr2, ' ', 512); } ret = nih_str_array_addp (&array, NULL, NULL, ptr2); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_P (array[0], ptr1); TEST_EQ_P (array[1], NULL); nih_free (array); nih_free (ptr1); nih_free (ptr2); continue; } TEST_NE_P (ret, NULL); TEST_EQ_P (array[0], ptr1); TEST_ALLOC_PARENT (array[0], array); TEST_EQ_P (array[1], ptr2); TEST_ALLOC_PARENT (array[0], array); TEST_EQ_P (array[2], NULL); nih_free (array); nih_free (ptr1); nih_free (ptr2); } } void test_array_copy (void) { char **array, **args; size_t len; TEST_FUNCTION ("nih_str_array_copy"); args = NIH_MUST (nih_str_array_new (NULL)); NIH_MUST (nih_str_array_add (&args, NULL, NULL, "this")); NIH_MUST (nih_str_array_add (&args, NULL, NULL, "is")); NIH_MUST (nih_str_array_add (&args, NULL, NULL, "a")); NIH_MUST (nih_str_array_add (&args, NULL, NULL, "test")); /* Check that we can make a copy of an array, with each element * a copy of the last. */ TEST_FEATURE ("with length given"); TEST_ALLOC_FAIL { len = 0; array = nih_str_array_copy (NULL, &len, args); if (test_alloc_failed) { TEST_EQ_P (array, NULL); continue; } TEST_NE_P (array, NULL); TEST_EQ (len, 4); TEST_EQ_STR (array[0], "this"); TEST_ALLOC_PARENT (array[0], array); TEST_EQ_STR (array[1], "is"); TEST_ALLOC_PARENT (array[1], array); TEST_EQ_STR (array[2], "a"); TEST_ALLOC_PARENT (array[2], array); TEST_EQ_STR (array[3], "test"); TEST_ALLOC_PARENT (array[3], array); TEST_EQ_P (array[4], NULL); nih_free (array); } /* Check that we can omit the length, and have it calculated. */ TEST_FEATURE ("with no length given"); TEST_ALLOC_FAIL { array = nih_str_array_copy (NULL, NULL, args); if (test_alloc_failed) { TEST_EQ_P (array, NULL); continue; } TEST_NE_P (array, NULL); TEST_EQ_STR (array[0], "this"); TEST_ALLOC_PARENT (array[0], array); TEST_EQ_STR (array[1], "is"); TEST_ALLOC_PARENT (array[1], array); TEST_EQ_STR (array[2], "a"); TEST_ALLOC_PARENT (array[2], array); TEST_EQ_STR (array[3], "test"); TEST_ALLOC_PARENT (array[3], array); TEST_EQ_P (array[4], NULL); nih_free (array); } nih_free (args); /* Check that we can make a copy of an array with a single NULL * element and have the same returned. */ TEST_FEATURE ("with zero-length array"); args = NIH_MUST (nih_str_array_new (NULL)); TEST_ALLOC_FAIL { len = 0; array = nih_str_array_copy (NULL, &len, args); if (test_alloc_failed) { TEST_EQ_P (array, NULL); continue; } TEST_NE_P (array, NULL); TEST_EQ (len, 0); TEST_EQ_P (array[0], NULL); nih_free (array); } nih_free (args); } void test_array_append (void) { char **array, **args, **ret; size_t len; TEST_FUNCTION ("nih_str_array_append"); args = NIH_MUST (nih_str_array_new (NULL)); NIH_MUST (nih_str_array_add (&args, NULL, NULL, "this")); NIH_MUST (nih_str_array_add (&args, NULL, NULL, "is")); NIH_MUST (nih_str_array_add (&args, NULL, NULL, "a")); NIH_MUST (nih_str_array_add (&args, NULL, NULL, "test")); /* Check that we can append one array onto the end of the other, * and that the array is extended and each new element copied * into the new array. */ TEST_FEATURE ("with length given"); TEST_ALLOC_FAIL { len = 0; TEST_ALLOC_SAFE { array = nih_str_array_new (NULL); NIH_MUST (nih_str_array_add (&array, NULL, &len, "foo")); NIH_MUST (nih_str_array_add (&array, NULL, &len, "bar")); } ret = nih_str_array_append (&array, NULL, &len, args); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ (len, 2); TEST_EQ_STR (array[0], "foo"); TEST_EQ_STR (array[1], "bar"); TEST_EQ_P (array[2], NULL); nih_free (array); continue; } TEST_NE_P (ret, NULL); TEST_EQ (len, 6); TEST_EQ_STR (array[0], "foo"); TEST_ALLOC_PARENT (array[0], array); TEST_EQ_STR (array[1], "bar"); TEST_ALLOC_PARENT (array[1], array); TEST_EQ_STR (array[2], "this"); TEST_ALLOC_PARENT (array[2], array); TEST_EQ_STR (array[3], "is"); TEST_ALLOC_PARENT (array[3], array); TEST_EQ_STR (array[4], "a"); TEST_ALLOC_PARENT (array[4], array); TEST_EQ_STR (array[5], "test"); TEST_ALLOC_PARENT (array[5], array); TEST_EQ_P (array[6], NULL); nih_free (array); } /* Check that we can omit the length, and have it calculated. */ TEST_FEATURE ("with no length given"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { array = nih_str_array_new (NULL); NIH_MUST (nih_str_array_add (&array, NULL, NULL, "foo")); NIH_MUST (nih_str_array_add (&array, NULL, NULL, "bar")); } ret = nih_str_array_append (&array, NULL, NULL, args); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (array[0], "foo"); TEST_EQ_STR (array[1], "bar"); TEST_EQ_P (array[2], NULL); nih_free (array); continue; } TEST_NE_P (ret, NULL); TEST_EQ_STR (array[0], "foo"); TEST_ALLOC_PARENT (array[0], array); TEST_EQ_STR (array[1], "bar"); TEST_ALLOC_PARENT (array[1], array); TEST_EQ_STR (array[2], "this"); TEST_ALLOC_PARENT (array[2], array); TEST_EQ_STR (array[3], "is"); TEST_ALLOC_PARENT (array[3], array); TEST_EQ_STR (array[4], "a"); TEST_ALLOC_PARENT (array[4], array); TEST_EQ_STR (array[5], "test"); TEST_ALLOC_PARENT (array[5], array); TEST_EQ_P (array[6], NULL); nih_free (array); } /* Check that we can pass a NULL array to get a copy of it, with * the returned length containing the new length. */ TEST_FEATURE ("with NULL array and length"); TEST_ALLOC_FAIL { len = 0; array = NULL; ret = nih_str_array_append (&array, NULL, &len, args); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ (len, 0); TEST_EQ_P (array, NULL); continue; } TEST_NE_P (ret, NULL); TEST_EQ (len, 4); TEST_EQ_STR (array[0], "this"); TEST_ALLOC_PARENT (array[0], array); TEST_EQ_STR (array[1], "is"); TEST_ALLOC_PARENT (array[1], array); TEST_EQ_STR (array[2], "a"); TEST_ALLOC_PARENT (array[2], array); TEST_EQ_STR (array[3], "test"); TEST_ALLOC_PARENT (array[3], array); TEST_EQ_P (array[4], NULL); nih_free (array); } /* Check that we can pass a NULL array to get a copy of it, without * passing the length in. */ TEST_FEATURE ("with NULL array and no length"); TEST_ALLOC_FAIL { array = NULL; ret = nih_str_array_append (&array, NULL, NULL, args); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_P (array, NULL); continue; } TEST_NE_P (ret, NULL); TEST_EQ_STR (array[0], "this"); TEST_ALLOC_PARENT (array[0], array); TEST_EQ_STR (array[1], "is"); TEST_ALLOC_PARENT (array[1], array); TEST_EQ_STR (array[2], "a"); TEST_ALLOC_PARENT (array[2], array); TEST_EQ_STR (array[3], "test"); TEST_ALLOC_PARENT (array[3], array); TEST_EQ_P (array[4], NULL); nih_free (array); } nih_free (args); } void test_str_wrap (void) { char *str; TEST_FUNCTION ("nih_str_wrap"); /* Check that a string smaller than the wrap length is returned * unaltered. */ TEST_FEATURE ("with no wrapping"); TEST_ALLOC_FAIL { str = nih_str_wrap (NULL, "this is a test", 80, 0, 0); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "this is a test"); nih_free (str); } /* Check that a string with embedded new lines is returned with * the line breaks preserved. */ TEST_FEATURE ("with embedded newlines"); TEST_ALLOC_FAIL { str = nih_str_wrap (NULL, "this is\na test", 80, 0, 0); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "this is\na test"); nih_free (str); } /* Check that a smaller string is indented if one is given. */ TEST_FEATURE ("with no wrapping and indent"); TEST_ALLOC_FAIL { str = nih_str_wrap (NULL, "this is a test", 80, 2, 0); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, " this is a test"); nih_free (str); } /* Check that a string with embedded newlines gets an indent on * each new line. */ TEST_FEATURE ("with embedded newlines and indent"); TEST_ALLOC_FAIL { str = nih_str_wrap (NULL, "this is\na test", 80, 4, 2); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, " this is\n a test"); nih_free (str); } /* Check that a long string is split at the wrap point. */ TEST_FEATURE ("with simple wrapping"); TEST_ALLOC_FAIL { str = nih_str_wrap (NULL, "this is an example of a string " "that will need wrapping to fit the line " "length we set", 20, 0, 0); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, ("this is an example\n" "of a string that\n" "will need wrapping\n" "to fit the line\n" "length we set")); nih_free (str); } /* Check that a long string is split at the wrap point, and each * new line indented, with the first line given a different indent. */ TEST_FEATURE ("with wrapping and indents"); TEST_ALLOC_FAIL { str = nih_str_wrap (NULL, "this is an example of a string " "that will need wrapping to fit the line " "length we set", 20, 4, 2); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, (" this is an\n" " example of a\n" " string that will\n" " need wrapping to\n" " fit the line\n" " length we set")); nih_free (str); } /* Check that a long string that would be split inside a long word * is wrapepd before the word, and then split inside that word if it * is still too long. */ TEST_FEATURE ("with split inside word"); TEST_ALLOC_FAIL { str = nih_str_wrap (NULL, ("this string is supercalifragilis" "ticexpialidocious even though the " "sound of it is something quite " "atrocious"), 30, 0, 0); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, ("this string is\n" "supercalifragilisticexpialidoc\n" "ious even though the sound of\n" "it is something quite\n" "atrocious")); nih_free (str); } /* Check that an indent is still applied if the split occurs inside * a word. */ TEST_FEATURE ("with split inside word and indents"); TEST_ALLOC_FAIL { str = nih_str_wrap (NULL, ("this string is supercalifragilis" "ticexpialidocious even though the " "sound of it is something quite " "atrocious"), 30, 4, 2); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, (" this string is\n" " supercalifragilisticexpialid\n" " ocious even though the sound\n" " of it is something quite\n" " atrocious")); nih_free (str); } } void test_str_screen_width (void) { struct winsize winsize; int pty, pts; size_t len = 0; TEST_FUNCTION ("nih_str_screen_width"); unsetenv ("COLUMNS"); winsize.ws_row = 24; winsize.ws_col = 40; winsize.ws_xpixel = 0; winsize.ws_ypixel = 0; openpty (&pty, &pts, NULL, NULL, &winsize); /* Check that we can obtain the width of a screen, where one * is available. It should match the number of columns in the * pty we run this within. */ TEST_FEATURE ("with screen width"); TEST_DIVERT_STDOUT_FD (pts) { len = nih_str_screen_width (); } TEST_EQ (len, 40); /* Check that the COLUMNS environment variable overrides the width * of the screen that we detect. */ TEST_FEATURE ("with COLUMNS variable"); putenv ("COLUMNS=30"); TEST_DIVERT_STDOUT_FD (pts) { len = nih_str_screen_width (); } TEST_EQ (len, 30); /* Check that we ignore a COLUMNS variable that's not an integer */ TEST_FEATURE ("with illegal COLUMNS variable"); putenv ("COLUMNS=30pt"); TEST_DIVERT_STDOUT_FD (pts) { len = nih_str_screen_width (); } TEST_EQ (len, 40); unsetenv ("COLUMNS"); close (pts); close (pty); /* Check that we fallback to assuming 80 columns if we don't have * any luck with either the tty or COLUMNS variable. */ TEST_FEATURE ("with fallback to 80 columns"); pts = open ("/dev/null", O_RDWR | O_NOCTTY); TEST_DIVERT_STDOUT_FD (pts) { len = nih_str_screen_width (); } TEST_EQ (len, 80); close (pts); } void test_str_screen_wrap (void) { char *str = NULL; struct winsize winsize; int pty, pts; TEST_FUNCTION ("nih_str_screen_wrap"); unsetenv ("COLUMNS"); winsize.ws_row = 24; winsize.ws_col = 40; winsize.ws_xpixel = 0; winsize.ws_ypixel = 0; openpty (&pty, &pts, NULL, NULL, &winsize); /* Check that we correctly wrap text to the width of the screen * when it is available. */ TEST_FEATURE ("with screen width"); TEST_ALLOC_FAIL { TEST_DIVERT_STDOUT_FD (pts) { str = nih_str_screen_wrap ( NULL, ("this is a string that " "should need wrapping at " "any different screen width " "that we choose to set"), 0, 0); } if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, ("this is a string that should need\n" "wrapping at any different screen width\n" "that we choose to set")); nih_free (str); } /* Check that we wrap at the number specified in the COLUMNS * variable in preference to the width of the screen. */ TEST_FEATURE ("with COLUMNS variable"); putenv ("COLUMNS=30"); TEST_ALLOC_FAIL { TEST_DIVERT_STDOUT_FD (pts) { str = nih_str_screen_wrap ( NULL, ("this is a string that " "should need wrapping at " "any different screen width " "that we choose to set"), 0, 0); } if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, ("this is a string that should\n" "need wrapping at any\n" "different screen width that\n" "we choose to set")); nih_free (str); } unsetenv ("COLUMNS"); close (pts); close (pty); /* Check that we fallback to assuming 80 columns if we don't have * any luck with either the tty or COLUMNS variable. */ TEST_FEATURE ("with fallback to 80 columns"); pts = open ("/dev/null", O_RDWR | O_NOCTTY); TEST_ALLOC_FAIL { TEST_DIVERT_STDOUT_FD (pts) { str = nih_str_screen_wrap ( NULL, ("this is a string that " "should need wrapping at " "any different screen width " "that we choose to set"), 0, 0); } if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, ("this is a string that should need " "wrapping at any different screen width " "that\n" "we choose to set")); nih_free (str); } close (pts); } int main (int argc, char *argv[]) { test_sprintf (); test_vsprintf (); test_strdup (); test_strndup (); test_strcat (); test_strncat (); test_strcat_sprintf (); test_strcat_vsprintf (); test_str_split (); test_array_new (); test_array_add (); test_array_addn (); test_array_addp (); test_array_copy (); test_array_append (); test_str_wrap (); test_str_screen_width (); test_str_screen_wrap (); return 0; } libnih-1.0.3/nih/tests/test_main.c0000644000175000017500000003011411445765555013770 00000000000000/* libnih * * test_main.c - test suite for nih/main.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void test_init_gettext (void) { /* Check that the macro to initialise gettext sets the text domain to * the PACKAGE_NAME macro, and binds that to the LOCALEDIR macro. */ TEST_FUNCTION ("nih_main_init_gettext"); nih_main_init_gettext(); TEST_EQ_STR (textdomain (NULL), PACKAGE_NAME); TEST_EQ_STR (bindtextdomain (PACKAGE_NAME, NULL), LOCALEDIR); } void test_init (void) { TEST_FUNCTION ("nih_main_init_full"); /* Check that we can initialise the program with all of the arguments * and that they're all copied correctly into the globals. When the * program and package names are the same, the package string should * only contain one copy. */ TEST_FEATURE ("with same program and package names"); TEST_ALLOC_FAIL { nih_main_init_full ("test", "test", "1.0", "bugreport", "copyright"); TEST_EQ_STR (program_name, "test"); TEST_EQ_STR (package_name, "test"); TEST_EQ_STR (package_version, "1.0"); TEST_EQ_STR (package_bugreport, "bugreport"); TEST_EQ_STR (package_copyright, "copyright"); TEST_EQ_STR (package_string, "test 1.0"); } /* Check that when the program and package names differ, the * package string contains both. */ TEST_FEATURE ("with different program and package names"); TEST_ALLOC_FAIL { nih_main_init_full ("test", "wibble", "1.0", "bugreport", "copyright"); TEST_EQ_STR (program_name, "test"); TEST_EQ_STR (package_name, "wibble"); TEST_EQ_STR (package_version, "1.0"); TEST_EQ_STR (package_bugreport, "bugreport"); TEST_EQ_STR (package_copyright, "copyright"); TEST_EQ_STR (package_string, "test (wibble 1.0)"); } /* Check that we can pass NULL for both the bug report address and * the copyright message. */ TEST_FEATURE ("with missing arguments"); package_bugreport = package_copyright = NULL; nih_main_init_full ("argv0", "package", "1.0", NULL, NULL); TEST_EQ_P (package_bugreport, NULL); TEST_EQ_P (package_copyright, NULL); /* Check that the bug report address and copyright message are set * to NULL if empty strings are passed instead. */ TEST_FEATURE ("with empty arguments"); package_bugreport = package_copyright = NULL; nih_main_init_full ("argv0", "package", "1.0", "", ""); TEST_EQ_P (package_bugreport, NULL); TEST_EQ_P (package_copyright, NULL); /* Check that the program name contains only the basename of a * full path supplied, and this is replicated into the package * string. */ TEST_FEATURE ("with full program path"); TEST_ALLOC_FAIL { nih_main_init_full ("/usr/bin/argv0", "package", "1.0", "bugreport", "copyright"); TEST_EQ_STR (program_name, "argv0"); TEST_EQ_STR (package_name, "package"); TEST_EQ_STR (package_string, "argv0 (package 1.0)"); } /* Check that the program name contains only the actual name * of the program when it's supplied as a login shell path * (prefixed with a dash). */ TEST_FEATURE ("with login shell path"); TEST_ALLOC_FAIL { nih_main_init_full ("-argv0", "package", "1.0", "bugreport", "copyright"); TEST_EQ_STR (program_name, "argv0"); TEST_EQ_STR (package_name, "package"); TEST_EQ_STR (package_string, "argv0 (package 1.0)"); } /* Check that the nih_main_init macro passes all the arguments for * us, except the program name, which we pass. */ TEST_FUNCTION ("nih_main_init"); TEST_ALLOC_FAIL { nih_main_init ("argv[0]"); TEST_EQ_STR (program_name, "argv[0]"); TEST_EQ_STR (package_name, PACKAGE_NAME); TEST_EQ_STR (package_version, PACKAGE_VERSION); TEST_EQ_STR (package_bugreport, PACKAGE_BUGREPORT); TEST_EQ_STR (package_copyright, PACKAGE_COPYRIGHT); } } void test_suggest_help (void) { FILE *output; /* Check that the message to suggest help is placed on standard * error, and formatted as we expect. */ TEST_FUNCTION ("nih_main_suggest_help"); program_name = "test"; output = tmpfile (); TEST_DIVERT_STDERR (output) { nih_main_suggest_help (); } rewind (output); TEST_FILE_EQ (output, "Try `test --help' for more information.\n"); TEST_FILE_END (output); fclose (output); } void test_version (void) { FILE *output; /* Check that the version message is placed on standard output, * includes the package string, copyright message and GPL notice. */ TEST_FUNCTION ("nih_main_version"); nih_main_init_full ("test", "wibble", "1.0", NULL, "Copyright Message"); TEST_ALLOC_FAIL { unsetenv ("COLUMNS"); output = tmpfile (); TEST_DIVERT_STDOUT (output) { nih_main_version (); } rewind (output); TEST_FILE_EQ (output, "test (wibble 1.0)\n"); TEST_FILE_EQ (output, "Copyright Message\n"); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ_N (output, "This is free software;"); TEST_FILE_EQ_N (output, "warranty; not even for"); TEST_FILE_END (output); fclose (output); } } void test_daemonise (void) { pid_t pid; char result[2]; int status, fds[2]; /* Check that nih_main_daemonise does all of the right things, * our immediate child should exit with a zero status, and the * child within that should be run with a working directory of / */ TEST_FUNCTION ("nih_main_daemonise"); assert0 (pipe (fds)); TEST_CHILD (pid) { char buf[80]; int fd; program_name = "test"; fd = open ("/dev/null", O_WRONLY); assert (fd >= 0); assert (dup2 (fd, STDERR_FILENO) >= 0); assert0 (close (fd)); if (nih_main_daemonise () < 0) exit (50); assert (getcwd (buf, sizeof (buf))); if (strcmp (buf, "/")) { assert (write (fds[1], "wd", 2) == 2); exit (10); } assert (write (fds[1], "ok", 2) == 2); exit (10); } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); if (read (fds[0], result, 2) != 2) TEST_FAILED ("expected return code from child"); if (! memcmp (result, "wd", 2)) TEST_FAILED ("wrong working directory for child"); if (memcmp (result, "ok", 2)) TEST_FAILED ("wrong return code from child, expected 'ok' got '%.2s'", result); } void test_set_pidfile (void) { const char *filename, *ptr; TEST_FUNCTION ("nih_main_set_pidfile"); program_name = "test"; /* Check that we can set a pidfile for use, and have the string * copied and returned. */ TEST_FEATURE ("with new location"); filename = "/path/to/pid"; nih_main_set_pidfile (filename); ptr = nih_main_get_pidfile (); TEST_EQ_STR (ptr, filename); TEST_NE_P (ptr, filename); /* Check that we can pass NULL to have the default location set * instead. */ TEST_FEATURE ("with default location"); nih_main_set_pidfile (NULL); ptr = nih_main_get_pidfile (); TEST_EQ_STR (ptr, "/var/run/test.pid"); nih_main_set_pidfile (NULL); } void test_read_pidfile (void) { FILE *f; char filename[PATH_MAX]; TEST_FUNCTION ("nih_main_read_pidfile"); TEST_FILENAME (filename); nih_main_set_pidfile (filename); /* Check that reading from a valid pid file will return the pid * stored there. */ TEST_FEATURE ("with valid pid file"); f = fopen (filename, "w"); fprintf (f, "1234\n"); fclose (f); TEST_EQ (nih_main_read_pidfile (), 1234); /* Check that reading from a pid file without a newline will still * return the pid stored there. */ TEST_FEATURE ("with no newline in pid file"); f = fopen (filename, "w"); fprintf (f, "1234"); fclose (f); TEST_EQ (nih_main_read_pidfile (), 1234); /* Check that reading from an invalid pid file returns -1. */ TEST_FEATURE ("with invalid pid file"); f = fopen (filename, "w"); fprintf (f, "foo\n1234\n"); fclose (f); TEST_EQ (nih_main_read_pidfile (), -1); /* Check that reading from a non-existant pid file returns -1. */ TEST_FEATURE ("with non-existant pid file"); nih_main_unlink_pidfile (); TEST_EQ (nih_main_read_pidfile (), -1); nih_main_set_pidfile (NULL); } void test_write_pidfile (void) { FILE *f; NihError *err; char dirname[PATH_MAX], filename[PATH_MAX], tmpname[PATH_MAX]; int ret; TEST_FUNCTION ("nih_main_write_pidfile"); TEST_FILENAME (dirname); mkdir (dirname, 0755); strcpy (filename, dirname); strcat (filename, "/test.pid"); strcpy (tmpname, dirname); strcat (tmpname, "/.test.pid.tmp"); nih_main_set_pidfile (filename); /* Check that we can write a pid to the file, and have it appaer * on disk where we expect. */ TEST_FEATURE ("with successful write"); ret = nih_main_write_pidfile (1234); TEST_EQ (ret, 0); f = fopen (filename, "r"); TEST_FILE_EQ (f, "1234\n"); fclose (f); /* Check that we can overwrite an existing pid file with a new * value. */ TEST_FEATURE ("with overwrite of existing pid"); ret = nih_main_write_pidfile (5678); TEST_EQ (ret, 0); f = fopen (filename, "r"); TEST_FILE_EQ (f, "5678\n"); fclose (f); /* Check that an error writing to the temporary file does not result * in the replacement of the existing file and does not result in * the unlinking of the temporary file. */ TEST_FEATURE ("with failure to write to temporary file"); f = fopen (tmpname, "w"); fclose (f); chmod (tmpname, 0000); ret = nih_main_write_pidfile (1234); TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, EACCES); nih_free (err); f = fopen (filename, "r"); TEST_FILE_EQ (f, "5678\n"); fclose (f); TEST_EQ (chmod (tmpname, 0644), 0); nih_main_unlink_pidfile (); unlink (tmpname); rmdir (dirname); nih_main_set_pidfile (NULL); } static int callback_called = 0; static void *last_data = NULL; static void my_callback (void *data, NihMainLoopFunc *func) { callback_called++; last_data = data; } static void my_timeout (void *data, NihTimer *timer) { nih_main_term_signal (NULL, NULL); nih_main_loop_exit (42); } void test_main_loop (void) { NihMainLoopFunc *func; NihTimer *timer; int ret; /* Check that we can run through the main loop, and that the * callback function will be run. Also schedule an immediate * timeout and make sure that's run too, that'll terminate the * main loop with an exit value, make sure it's returned. */ TEST_FUNCTION ("nih_main_loop"); callback_called = 0; last_data = NULL; func = nih_main_loop_add_func (NULL, my_callback, &func); timer = nih_timer_add_timeout (NULL, 1, my_timeout, NULL); ret = nih_main_loop (); TEST_EQ (ret, 42); TEST_TRUE (callback_called); TEST_EQ_P (last_data, &func); nih_free (func); } void test_main_loop_add_func (void) { NihMainLoopFunc *func; /* Check that we can add a callback function to the main loop, * and that the structure returned is correctly populated and * placed in a list. */ TEST_FUNCTION ("nih_main_loop_add_func"); TEST_ALLOC_FAIL { func = nih_main_loop_add_func (NULL, my_callback, &func); if (test_alloc_failed) { TEST_EQ_P (func, NULL); continue; } TEST_ALLOC_SIZE (func, sizeof (NihMainLoopFunc)); TEST_LIST_NOT_EMPTY (&func->entry); TEST_EQ_P (func->callback, my_callback); TEST_EQ_P (func->data, &func); nih_free (func); } } int main (int argc, char *argv[]) { test_init_gettext (); test_init (); test_suggest_help (); test_version (); test_daemonise (); test_set_pidfile (); test_read_pidfile (); test_write_pidfile (); test_main_loop (); test_main_loop_add_func (); return 0; } libnih-1.0.3/nih/tests/test_signal.c0000644000175000017500000002105511445765555014325 00000000000000/* libnih * * test_signal.c - test suite for nih/signal.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #if HAVE_VALGRIND_VALGRIND_H #include #endif /* HAVE_VALGRIND_VALGRIND_H */ #include #include #include #include static void my_sig_handler (int signum) { } void test_set_handler (void) { struct sigaction act; int ret, i; TEST_FUNCTION ("nih_signal_set_handler"); /* Check that we can install a signal handler, and that the action * for that signal points to our handler, has the right flags and * an empty signal mask. */ TEST_FEATURE ("with valid signal"); ret = nih_signal_set_handler (SIGUSR1, my_sig_handler); TEST_EQ (ret, 0); sigaction (SIGUSR1, NULL, &act); TEST_EQ_P (act.sa_handler, my_sig_handler); TEST_TRUE (act.sa_flags & SA_RESTART); TEST_FALSE (act.sa_flags & SA_RESETHAND); for (i = 1; i < 32; i++) TEST_FALSE (sigismember (&act.sa_mask, i)); #if HAVE_VALGRIND_VALGRIND_H /* This test fails when running under valgrind; because for no * readily apparent reason, that lets us catch SIGKILL! */ if (! RUNNING_ON_VALGRIND) { #endif /* Check that attempting to set a handler for SIGKILL results in * -1 being returned. */ TEST_FEATURE ("with invalid signal"); ret = nih_signal_set_handler (SIGKILL, my_sig_handler); TEST_LT (ret, 0); #if HAVE_VALGRIND_VALGRIND_H } #endif } void test_set_default (void) { struct sigaction act; int ret, i; TEST_FUNCTION ("nih_signal_set_default"); /* Check that we can reset a signal to the default handling, which * should update the action properly. */ TEST_FEATURE ("with valid signal"); ret = nih_signal_set_default (SIGUSR1); TEST_EQ (ret, 0); sigaction (SIGUSR1, NULL, &act); TEST_EQ_P (act.sa_handler, SIG_DFL); TEST_FALSE (act.sa_flags & SA_RESTART); TEST_FALSE (act.sa_flags & SA_NOCLDSTOP); for (i = 1; i < 32; i++) TEST_FALSE (sigismember (&act.sa_mask, i)); #if HAVE_VALGRIND_VALGRIND_H /* This test fails when running under valgrind; because for no * readily apparent reason, that lets us catch SIGKILL! */ if (! RUNNING_ON_VALGRIND) { #endif /* Check that attempting to set a handler for SIGKILL results in * -1 being returned. */ TEST_FEATURE ("with invalid signal"); ret = nih_signal_set_default (SIGKILL); TEST_LT (ret, 0); #if HAVE_VALGRIND_VALGRIND_H } #endif } void test_set_ignore (void) { struct sigaction act; int ret, i; TEST_FUNCTION ("nih_signal_set_ignore"); /* Check that we can set a signal to be ignored, which should update * the action properly. */ TEST_FEATURE ("with valid signal"); ret = nih_signal_set_ignore (SIGUSR1); TEST_EQ (ret, 0); sigaction (SIGUSR1, NULL, &act); TEST_EQ_P (act.sa_handler, SIG_IGN); TEST_FALSE (act.sa_flags & SA_RESTART); TEST_FALSE (act.sa_flags & SA_NOCLDSTOP); for (i = 1; i < 32; i++) TEST_FALSE (sigismember (&act.sa_mask, i)); #if HAVE_VALGRIND_VALGRIND_H /* This test fails when running under valgrind; because for no * readily apparent reason, that lets us ignore SIGKILL! */ if (! RUNNING_ON_VALGRIND) { #endif /* Check that attempting to set a handler for SIGKILL results in * -1 being returned. */ TEST_FEATURE ("with invalid signal"); ret = nih_signal_set_ignore (SIGKILL); TEST_LT (ret, 0); #if HAVE_VALGRIND_VALGRIND_H } #endif } void test_reset (void) { struct sigaction act; int i; /* Check that we can reset all signals back to their defaults. */ TEST_FUNCTION ("nih_signal_reset"); nih_signal_set_ignore (SIGTERM); nih_signal_reset (); sigaction (SIGTERM, NULL, &act); TEST_EQ_P (act.sa_handler, SIG_DFL); TEST_FALSE (act.sa_flags & SA_RESTART); TEST_FALSE (act.sa_flags & SA_NOCLDSTOP); for (i = 1; i < 32; i++) TEST_FALSE (sigismember (&act.sa_mask, i)); } static int handler_called = 0; static void *last_data; static NihSignal *last_signal; static void my_handler (void *data, NihSignal *signal) { handler_called++; last_data = data; last_signal = signal; } void test_add_handler (void) { NihSignal *signal; /* Check that we can add a signal handling callback function, and * that the structure returned is properly populated and placed in * the callbacks list. */ TEST_FUNCTION ("nih_signal_add_handler"); nih_signal_poll (); TEST_ALLOC_FAIL { signal = nih_signal_add_handler (NULL, SIGUSR1, my_handler, &signal); if (test_alloc_failed) { TEST_EQ_P (signal, NULL); continue; } TEST_ALLOC_SIZE (signal, sizeof (NihSignal)); TEST_LIST_NOT_EMPTY (&signal->entry); TEST_EQ (signal->signum, SIGUSR1); TEST_EQ_P (signal->handler, my_handler); TEST_EQ_P (signal->data, &signal); nih_free (signal); } } void test_poll (void) { NihSignal *signal1, *signal2; TEST_FUNCTION ("nih_signal_poll"); signal1 = nih_signal_add_handler (NULL, SIGUSR1, my_handler, &signal1); signal2 = nih_signal_add_handler (NULL, SIGUSR2, my_handler, &signal2); /* Check that we can poll for a signal being caught, which should * result in only the callback for that signal being run. */ TEST_FEATURE ("with one signal"); handler_called = 0; last_data = NULL; last_signal = NULL; nih_signal_handler (SIGUSR1); nih_signal_poll (); TEST_EQ (handler_called, 1); TEST_EQ_P (last_signal, signal1); TEST_EQ_P (last_data, &signal1); /* Check that we can poll for only the other signal. */ TEST_FEATURE ("with different signal"); handler_called = 0; last_data = NULL; last_signal = NULL; nih_signal_handler (SIGUSR2); nih_signal_poll (); TEST_EQ (handler_called, 1); TEST_EQ_P (last_signal, signal2); TEST_EQ_P (last_data, &signal2); /* Check that we can poll for both signals. */ TEST_FEATURE ("with multiple signals"); handler_called = 0; nih_signal_handler (SIGUSR1); nih_signal_handler (SIGUSR2); nih_signal_poll (); TEST_EQ (handler_called, 2); /* Check what happens if a signal we have no callbacks for is * caught. This should run neither callback. */ TEST_FEATURE ("with unknown signal"); handler_called = 0; nih_signal_handler (SIGINT); nih_signal_poll (); TEST_EQ (handler_called, 0); nih_free (signal1); nih_free (signal2); } void test_to_name (void) { const char *name; TEST_FUNCTION ("nih_signal_to_name"); /* Check that we can obtain the name of a common signal. */ TEST_FEATURE ("with SIGTERM"); name = nih_signal_to_name (SIGTERM); TEST_EQ_STR (name, "TERM"); /* Check that we get CHLD for SIGCHLD */ TEST_FEATURE ("with SIGCHLD"); name = nih_signal_to_name (SIGCHLD); TEST_EQ_STR (name, "CHLD"); /* Check that we get IO for SIGIO */ TEST_FEATURE ("with SIGIO"); name = nih_signal_to_name (SIGIO); TEST_EQ_STR (name, "IO"); /* Check that we get NULL for an unknown signal */ TEST_FEATURE ("with unknown signal"); name = nih_signal_to_name (32); TEST_EQ_P (name, NULL); } void test_from_name (void) { int signum; TEST_FUNCTION ("nih_signal_from_name"); /* Check that we can convert a common signal into its number. */ TEST_FEATURE ("with SIGTERM"); signum = nih_signal_from_name ("SIGTERM"); TEST_EQ (signum, SIGTERM); /* Check that we can omit the SIG from the front. */ TEST_FEATURE ("with TERM"); signum = nih_signal_from_name ("TERM"); TEST_EQ (signum, SIGTERM); /* Check that we get SIGCHLD for SIGCHLD */ TEST_FEATURE ("with SIGCHLD"); signum = nih_signal_from_name ("SIGCHLD"); TEST_EQ (signum, SIGCHLD); /* Check that we get SIGIO for SIGIO */ TEST_FEATURE ("with SIGIO"); signum = nih_signal_from_name ("SIGIO"); TEST_EQ (signum, SIGIO); /* Check that we get a negative number for an unknown signal */ TEST_FEATURE ("with unknown signal"); signum = nih_signal_from_name ("SIGSNARF"); TEST_LT (signum, 0); } int main (int argc, char *argv[]) { test_set_handler (); test_set_default (); test_set_ignore (); test_reset (); test_add_handler (); test_poll (); test_to_name (); test_from_name (); return 0; } libnih-1.0.3/nih/tests/test_hash.c0000644000175000017500000003557011445765555014002 00000000000000/* libnih * * test_hash.c - test suite for nih/hash.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include typedef struct hash_entry { NihList list; const char *key; } HashEntry; static NihList * new_entry (void *parent, const char *key) { HashEntry *entry; entry = nih_new (parent, HashEntry); nih_list_init (&entry->list); entry->key = key; return (NihList *)entry; } static const void * my_key_function (NihList *entry) { return "foo"; } static uint32_t my_hash_function (const void *key) { static uint32_t hash = 0; return hash++; } static int my_cmp_function (const void *key1, const void *key2) { return 0; } void test_new (void) { NihHash *hash; size_t i; TEST_FUNCTION ("nih_hash_new"); /* Check that we can create a small hash table; a small prime number * should be selected for the actual size, and that number of empty * bins should be allocated as a child of the hash table. */ TEST_FEATURE ("with zero size"); TEST_ALLOC_FAIL { hash = nih_hash_new (NULL, 0, my_key_function, my_hash_function, my_cmp_function); if (test_alloc_failed) { TEST_EQ_P (hash, NULL); continue; } TEST_ALLOC_SIZE (hash, sizeof(NihHash)); TEST_EQ_P (hash->key_function, my_key_function); TEST_EQ_P (hash->hash_function, my_hash_function); TEST_EQ_P (hash->cmp_function, my_cmp_function); TEST_EQ (hash->size, 17); TEST_NE_P (hash->bins, NULL); TEST_ALLOC_PARENT (hash->bins, hash); for (i = 0; i < hash->size; i++) TEST_LIST_EMPTY (&hash->bins[i]); nih_free (hash); } /* Check again with a medium size, which should pick a medium prime * number. */ TEST_FEATURE ("with medium size"); TEST_ALLOC_FAIL { hash = nih_hash_new (NULL, 600, my_key_function, my_hash_function, my_cmp_function); if (test_alloc_failed) { TEST_EQ_P (hash, NULL); continue; } TEST_EQ (hash->size, 331); TEST_NE_P (hash->bins, NULL); TEST_ALLOC_PARENT (hash->bins, hash); for (i = 0; i < hash->size; i++) TEST_LIST_EMPTY (&hash->bins[i]); nih_free (hash); } /* Check with a much larger size, which should pick the largest prime * that we know of. */ TEST_FEATURE ("with large size"); TEST_ALLOC_FAIL { hash = nih_hash_new (NULL, 40000000, my_key_function, my_hash_function, my_cmp_function); if (test_alloc_failed) { TEST_EQ_P (hash, NULL); continue; } TEST_EQ (hash->size, 10250323); TEST_NE_P (hash->bins, NULL); TEST_ALLOC_PARENT (hash->bins, hash); for (i = 0; i < hash->size; i++) TEST_LIST_EMPTY (&hash->bins[i]); nih_free (hash); } } void test_string_new (void) { NihHash *hash; size_t i; /* Check that we can create a small hash table; a small prime number * should be selected for the actual size, and that number of empty * bins should be allocated as a child of the hash table. */ TEST_FUNCTION ("nih_hash_string_new"); TEST_ALLOC_FAIL { hash = nih_hash_string_new (NULL, 0); if (test_alloc_failed) { TEST_EQ_P (hash, NULL); continue; } TEST_ALLOC_SIZE (hash, sizeof(NihHash)); TEST_EQ_P (hash->key_function, (NihKeyFunction)nih_hash_string_key); TEST_EQ_P (hash->hash_function, (NihHashFunction)nih_hash_string_hash); TEST_EQ_P (hash->cmp_function, (NihCmpFunction)nih_hash_string_cmp); TEST_EQ (hash->size, 17); TEST_NE_P (hash->bins, NULL); TEST_ALLOC_PARENT (hash->bins, hash); for (i = 0; i < hash->size; i++) TEST_LIST_EMPTY (&hash->bins[i]); nih_free (hash); } } void test_add (void) { NihHash *hash; NihList *entry1, *entry2, *entry3, *entry4, *ptr; TEST_FUNCTION ("nih_hash_add"); hash = nih_hash_string_new (NULL, 0); entry1 = new_entry (hash, "entry 1"); entry2 = new_entry (hash, "entry 2"); entry3 = new_entry (hash, "entry 1"); entry4 = new_entry (hash, "entry 4"); /* Check that we can add an entry to an empty hash table; it should * be returned and turn up in the appropriate bin. */ TEST_FEATURE ("with empty hash"); ptr = nih_hash_add (hash, entry1); TEST_EQ_P (ptr, entry1); TEST_EQ_P (hash->bins[15].next, entry1); TEST_EQ_P (entry1->next, &hash->bins[15]); TEST_EQ_P (hash->bins[15].prev, entry1); TEST_EQ_P (entry1->prev, &hash->bins[15]); /* Check that we can add an entry to a populated hash table. */ TEST_FEATURE ("with non-empty hash"); nih_hash_add (hash, entry2); TEST_EQ_P (hash->bins[14].next, entry2); TEST_EQ_P (entry2->next, &hash->bins[14]); TEST_EQ_P (hash->bins[14].prev, entry2); TEST_EQ_P (entry2->prev, &hash->bins[14]); /* Check that we can add an entry with a duplicate key, and it is * added to the end of the same bin as the previous entry with that * key. */ TEST_FEATURE ("with duplicate key"); nih_hash_add (hash, entry3); TEST_EQ_P (hash->bins[15].next, entry1); TEST_EQ_P (entry1->next, entry3); TEST_EQ_P (entry3->next, &hash->bins[15]); TEST_EQ_P (hash->bins[15].prev, entry3); TEST_EQ_P (entry3->prev, entry1); TEST_EQ_P (entry1->prev, &hash->bins[15]); /* Check that nih_hash_add can rip an entry out of an existing list * and place it in the hash table. */ TEST_FEATURE ("with entry already in a list"); ptr = nih_list_new (NULL); nih_list_add (ptr, entry4); nih_hash_add (hash, entry4); TEST_EQ_P (ptr->next, ptr); TEST_EQ_P (ptr->prev, ptr); TEST_EQ_P (hash->bins[3].next, entry4); TEST_EQ_P (entry4->next, &hash->bins[3]); TEST_EQ_P (hash->bins[3].prev, entry4); TEST_EQ_P (entry4->prev, &hash->bins[3]); nih_free (hash); nih_free (ptr); } void test_add_unique (void) { NihHash *hash; NihList *entry1, *entry2, *entry3, *entry4, *ptr; TEST_FUNCTION ("nih_hash_add_unique"); hash = nih_hash_string_new (NULL, 0); entry1 = new_entry (hash, "entry 1"); entry2 = new_entry (hash, "entry 2"); entry3 = new_entry (hash, "entry 1"); entry4 = new_entry (hash, "entry 4"); /* Check that we can add an entry to an empty hash table; it should * be returned and turn up in the appropriate bin. */ TEST_FEATURE ("with empty hash"); ptr = nih_hash_add_unique (hash, entry1); TEST_EQ_P (ptr, entry1); TEST_EQ_P (hash->bins[15].next, entry1); TEST_EQ_P (entry1->next, &hash->bins[15]); TEST_EQ_P (hash->bins[15].prev, entry1); TEST_EQ_P (entry1->prev, &hash->bins[15]); /* Check that we can add an entry to a populated hash table. */ TEST_FEATURE ("with non-empty hash"); nih_hash_add_unique (hash, entry2); TEST_EQ_P (hash->bins[14].next, entry2); TEST_EQ_P (entry2->next, &hash->bins[14]); TEST_EQ_P (hash->bins[14].prev, entry2); TEST_EQ_P (entry2->prev, &hash->bins[14]); /* Check that we get NULL if we try and add an entry with a * duplicate key, and that the hash table is not altered. */ TEST_FEATURE ("with duplicate key"); ptr = nih_hash_add_unique (hash, entry3); TEST_EQ_P (ptr, NULL); TEST_EQ_P (hash->bins[15].next, entry1); TEST_EQ_P (entry1->next, &hash->bins[15]); TEST_EQ_P (hash->bins[15].prev, entry1); TEST_EQ_P (entry1->prev, &hash->bins[15]); /* Check that nih_hash_add can rip an entry out of an existing list * and place it in the hash table. */ TEST_FEATURE ("with entry already in a list"); ptr = nih_list_new (NULL); nih_list_add (ptr, entry4); nih_hash_add_unique (hash, entry4); TEST_EQ_P (ptr->next, ptr); TEST_EQ_P (ptr->prev, ptr); TEST_EQ_P (hash->bins[3].next, entry4); TEST_EQ_P (entry4->next, &hash->bins[3]); TEST_EQ_P (hash->bins[3].prev, entry4); TEST_EQ_P (entry4->prev, &hash->bins[3]); nih_free (hash); nih_free (ptr); } void test_replace (void) { NihHash *hash; NihList *entry1, *entry2, *entry3, *entry4, *ptr; TEST_FUNCTION ("nih_hash_replace"); hash = nih_hash_string_new (NULL, 0); entry1 = new_entry (hash, "entry 1"); entry2 = new_entry (hash, "entry 2"); entry3 = new_entry (hash, "entry 1"); entry4 = new_entry (hash, "entry 4"); /* Check that we can add an entry to an empty hash table; NULL should * be returned (nothing replaced) and the entry should turn up in the * appropriate bin. */ TEST_FEATURE ("with empty hash"); ptr = nih_hash_replace (hash, entry1); TEST_EQ_P (ptr, NULL); TEST_EQ_P (hash->bins[15].next, entry1); TEST_EQ_P (entry1->next, &hash->bins[15]); TEST_EQ_P (hash->bins[15].prev, entry1); TEST_EQ_P (entry1->prev, &hash->bins[15]); /* Check that we can add an entry to a populated hash table. */ TEST_FEATURE ("with non-empty hash"); nih_hash_replace (hash, entry2); TEST_EQ_P (hash->bins[14].next, entry2); TEST_EQ_P (entry2->next, &hash->bins[14]); TEST_EQ_P (hash->bins[14].prev, entry2); TEST_EQ_P (entry2->prev, &hash->bins[14]); /* Check that we can add an entry with a duplicate key, replacing * the existing one in the hash. The replaced entry should be * returned, and removed from the bin. */ TEST_FEATURE ("with duplicate key"); ptr = nih_hash_replace (hash, entry3); TEST_EQ_P (ptr, entry1); TEST_EQ_P (entry1->next, entry1); TEST_EQ_P (entry1->prev, entry1); TEST_EQ_P (hash->bins[15].next, entry3); TEST_EQ_P (entry3->next, &hash->bins[15]); TEST_EQ_P (hash->bins[15].prev, entry3); TEST_EQ_P (entry3->prev, &hash->bins[15]); /* Check that nih_hash_add can rip an entry out of an existing list * and place it in the hash table. */ TEST_FEATURE ("with entry already in a list"); ptr = nih_list_new (NULL); nih_list_add (ptr, entry4); nih_hash_replace (hash, entry4); TEST_EQ_P (ptr->next, ptr); TEST_EQ_P (ptr->prev, ptr); TEST_EQ_P (hash->bins[3].next, entry4); TEST_EQ_P (entry4->next, &hash->bins[3]); TEST_EQ_P (hash->bins[3].prev, entry4); TEST_EQ_P (entry4->prev, &hash->bins[3]); nih_free (hash); nih_free (ptr); } void test_search (void) { NihHash *hash; NihList *entry1, *entry2, *entry3, *ptr; TEST_FUNCTION ("nih_hash_search"); hash = nih_hash_string_new (NULL, 0); entry1 = nih_hash_add (hash, new_entry (hash, "entry 1")); entry2 = nih_hash_add (hash, new_entry (hash, "entry 2")); entry3 = nih_hash_add (hash, new_entry (hash, "entry 2")); /* Check that we find the sole matching entry. */ ptr = nih_hash_search (hash, "entry 1", NULL); TEST_EQ_P (ptr, entry1); /* Searching again should find nothing */ ptr = nih_hash_search (hash, "entry 1", ptr); TEST_EQ_P (ptr, NULL); /* Check that where there's multiple matches, we find the first one. */ TEST_FEATURE ("with multiple matches"); ptr = nih_hash_search (hash, "entry 2", NULL); TEST_EQ_P (ptr, entry2); /* And that searching again finds the second one. */ ptr = nih_hash_search (hash, "entry 2", ptr); TEST_EQ_P (ptr, entry3); /* And again finds nothing. */ ptr = nih_hash_search (hash, "entry 2", ptr); TEST_EQ_P (ptr, NULL); /* Check that we get NULL if there are no matches. */ TEST_FEATURE ("with no matches"); ptr = nih_hash_search (hash, "entry 3", NULL); TEST_EQ_P (ptr, NULL); nih_free (hash); } void test_lookup (void) { NihHash *hash; NihList *entry1, *entry2, *entry3, *ptr; TEST_FUNCTION ("nih_hash_lookup"); hash = nih_hash_string_new (NULL, 0); entry1 = nih_hash_add (hash, new_entry (hash, "entry 1")); entry2 = nih_hash_add (hash, new_entry (hash, "entry 2")); entry3 = new_entry (hash, "entry 3"); /* Check that we find a single matching entry. */ TEST_FEATURE ("with single match"); ptr = nih_hash_lookup (hash, "entry 1"); TEST_EQ_P (ptr, entry1); /* Check that we find the first matching entry. */ TEST_FEATURE ("with multiple matches"); ptr = nih_hash_lookup (hash, "entry 2"); TEST_EQ_P (ptr, entry2); /* Check that we get NULL when there are no matching entries. */ TEST_FEATURE ("with no matches"); ptr = nih_hash_lookup (hash, "entry 3"); TEST_EQ_P (ptr, NULL); nih_free (hash); } void test_foreach (void) { NihHash *hash; NihList *entry[4], *entry0, *entry1, *entry2, *entry3; int i; /* Check that NIH_HASH_FOREACH iterates the hash correctly in order, * visiting each entry in each bin. Note that we stage the entries * in the hash in the order we expect them to come out in, but add * them in a different order for sanity. */ TEST_FUNCTION ("NIH_HASH_FOREACH"); hash = nih_hash_string_new (NULL, 0); entry0 = entry[2] = new_entry (hash, "entry 1"); entry1 = entry[1] = new_entry (hash, "entry 2"); entry2 = entry[3] = new_entry (hash, "entry 1"); entry3 = entry[0] = new_entry (hash, "entry 4"); nih_hash_add (hash, entry0); nih_hash_add (hash, entry1); nih_hash_add (hash, entry2); nih_hash_add (hash, entry3); i = 0; NIH_HASH_FOREACH (hash, iter) { if (i > 3) TEST_FAILED ("wrong number of iterations, expected %d got %d", 4, i + 1); if (iter != entry[i]) TEST_FAILED ("wrong list entry, expected %p got %p", entry[i], iter); i++; } nih_free (hash); } void test_foreach_safe (void) { NihHash *hash; NihList *entry[4], *entry0, *entry1, *entry2, *entry3; int i; /* Check that NIH_HASH_FOREACH_SAFE iterates the hash correctly in * order, visiting each entry in each bin; and that it's safe to * remove the entries while doing so. */ TEST_FUNCTION ("NIH_HASH_FOREACH_SAFE"); hash = nih_hash_string_new (NULL, 0); entry0 = entry[2] = new_entry (hash, "entry 1"); entry1 = entry[1] = new_entry (hash, "entry 2"); entry2 = entry[3] = new_entry (hash, "entry 1"); entry3 = entry[0] = new_entry (hash, "entry 4"); nih_hash_add (hash, entry0); nih_hash_add (hash, entry1); nih_hash_add (hash, entry2); nih_hash_add (hash, entry3); i = 0; NIH_HASH_FOREACH_SAFE (hash, iter) { if (i > 3) TEST_FAILED ("wrong number of iterations, expected %d got %d", 4, i + 1); if (iter != entry[i]) TEST_FAILED ("wrong list entry, expected %p got %p", entry[i], iter); nih_list_remove (entry[i]); i++; } nih_free (hash); } void test_string_key (void) { NihList *entry; const char *key; /* Check that the string key function returns a pointer to the * key in our test structure. */ TEST_FUNCTION ("nih_hash_string_key"); entry = new_entry (NULL, "my entry"); key = nih_hash_string_key (entry); TEST_EQ_P (key, ((HashEntry *)entry)->key); TEST_EQ_STR (key, "my entry"); nih_free (entry); } int main (int argc, char *argv[]) { test_new (); test_string_new (); test_add (); test_add_unique (); test_replace (); test_search (); test_lookup (); test_foreach (); test_foreach_safe (); test_string_key (); return 0; } libnih-1.0.3/nih/tests/test_io.c0000644000175000017500000022244211445765555013462 00000000000000/* libnih * * test_io.c - test suite for nih/io.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static int watcher_called = 0; static void *last_data = NULL; static NihIoWatch *last_watch = NULL; static NihIoEvents last_events = 0; static void my_watcher (void *data, NihIoWatch *watch, NihIoEvents events) { watcher_called++; last_data = data; last_watch = watch; last_events = events; } void test_add_watch (void) { NihIoWatch *watch; fd_set readfds, writefds, exceptfds; int nfds, fds[2]; /* Check that we can add a watch on a file descriptor and that the * structure is properly filled in and placed in a list. */ TEST_FUNCTION ("nih_io_add_watch"); nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); TEST_ALLOC_FAIL { assert0 (pipe (fds)); watch = nih_io_add_watch (NULL, fds[0], NIH_IO_READ, my_watcher, &watch); if (test_alloc_failed) { TEST_EQ_P (watch, NULL); continue; } TEST_ALLOC_SIZE (watch, sizeof (NihIoWatch)); TEST_EQ (watch->fd, fds[0]); TEST_EQ (watch->events, NIH_IO_READ); TEST_EQ_P (watch->watcher, my_watcher); TEST_EQ_P (watch->data, &watch); nih_free (watch); close (fds[0]); close (fds[1]); } } void test_select_fds (void) { NihIoWatch *watch1, *watch2, *watch3; fd_set readfds, writefds, exceptfds; int nfds, fds[2]; /* Check that the select file descriptor sets are correctly filled * based on a set of watches we add. */ TEST_FUNCTION ("nih_io_select_fds"); assert0 (pipe (fds)); watch1 = nih_io_add_watch (NULL, fds[0], NIH_IO_READ, my_watcher, &watch1); watch2 = nih_io_add_watch (NULL, fds[1], NIH_IO_WRITE, my_watcher, &watch2); watch3 = nih_io_add_watch (NULL, fds[0], NIH_IO_EXCEPT, my_watcher, &watch3); nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); TEST_EQ (nfds, nih_max (fds[0], fds[1]) + 1); TEST_TRUE (FD_ISSET (fds[0], &readfds)); TEST_FALSE (FD_ISSET (fds[0], &writefds)); TEST_TRUE (FD_ISSET (fds[0], &exceptfds)); TEST_FALSE (FD_ISSET (fds[1], &readfds)); TEST_TRUE (FD_ISSET (fds[1], &writefds)); TEST_FALSE (FD_ISSET (fds[1], &exceptfds)); nih_free (watch1); nih_free (watch2); nih_free (watch3); close (fds[0]); close (fds[1]); } void test_handle_fds (void) { NihIoWatch *watch1, *watch2, *watch3; fd_set readfds, writefds, exceptfds; int fds[2]; TEST_FUNCTION ("nih_io_handle_fds"); assert0 (pipe (fds)); watch1 = nih_io_add_watch (NULL, fds[0], NIH_IO_READ, my_watcher, &watch1); watch2 = nih_io_add_watch (NULL, fds[1], NIH_IO_WRITE, my_watcher, &watch2); watch3 = nih_io_add_watch (NULL, fds[0], NIH_IO_EXCEPT, my_watcher, &watch3); FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); /* Check that something watching a file descriptor for readability * is called, with the right arguments passed; and that another * watch on the same file descriptor for different events is not * called. */ TEST_FEATURE ("with select for read"); watcher_called = 0; last_data = NULL; last_watch = NULL; last_events = 0; FD_SET (fds[0], &readfds); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_EQ (watcher_called, 1); TEST_EQ (last_events, NIH_IO_READ); TEST_EQ_P (last_watch, watch1); TEST_EQ_P (last_data, &watch1); /* Check that something watching a file descriptor for an exception * is called, and that the watch on the same descriptor for reading * is not called. */ TEST_FEATURE ("with select for exception"); watcher_called = 0; last_data = NULL; last_watch = NULL; last_events = 0; FD_ZERO (&readfds); FD_SET (fds[0], &exceptfds); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_EQ (watcher_called, 1); TEST_EQ (last_events, NIH_IO_EXCEPT); TEST_EQ_P (last_watch, watch3); TEST_EQ_P (last_data, &watch3); /* Check that nothing is called if the file descriptor and events * being polled don't match anything. */ TEST_FEATURE ("with unwatched select"); watcher_called = 0; FD_ZERO (&exceptfds); FD_SET (fds[1], &exceptfds); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_EQ (watcher_called, 0); nih_free (watch1); nih_free (watch2); nih_free (watch3); close (fds[0]); close (fds[1]); } void test_buffer_new (void) { NihIoBuffer *buf; /* Check that we can create a new empty buffer, and that the * structure members are correct. */ TEST_FUNCTION ("nih_io_buffer_new"); TEST_ALLOC_FAIL { buf = nih_io_buffer_new (NULL); if (test_alloc_failed) { TEST_EQ_P (buf, NULL); continue; } TEST_ALLOC_SIZE (buf, sizeof (NihIoBuffer)); TEST_EQ_P (buf->buf, NULL); TEST_EQ (buf->size, 0); TEST_EQ (buf->len, 0); nih_free (buf); } } void test_buffer_resize (void) { NihIoBuffer *buf; int ret; TEST_FUNCTION ("nih_io_buffer_resize"); /* Check that we can resize a NULL buffer; we ask for half a page * and expect to get a full page allocated as a child of the buffer * itself. */ TEST_FEATURE ("with empty buffer and half increase"); buf = nih_io_buffer_new (NULL); TEST_ALLOC_FAIL { buf->size = 0; ret = nih_io_buffer_resize (buf, BUFSIZ / 2); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_ALLOC_PARENT (buf->buf, buf); TEST_ALLOC_SIZE (buf->buf, BUFSIZ); TEST_EQ (buf->size, BUFSIZ); TEST_EQ (buf->len, 0); } /* Check that we can increase the size by a full page, and not * have anything change because there's no space used yet. */ TEST_FEATURE ("with empty but alloc'd buffer and full increase"); TEST_ALLOC_FAIL { buf->size = BUFSIZ; ret = nih_io_buffer_resize (buf, BUFSIZ); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (buf->buf, BUFSIZ); TEST_EQ (buf->size, BUFSIZ); } /* Check that we can increase the size beyond a full page, and * get another page of allocated space. */ TEST_FEATURE ("with empty but alloc'd buffer and larger increase"); TEST_ALLOC_FAIL { buf->size = BUFSIZ; ret = nih_io_buffer_resize (buf, BUFSIZ + BUFSIZ / 2); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (buf->buf, BUFSIZ * 2); TEST_EQ (buf->size, BUFSIZ * 2); } /* Check that we can drop the size of an allocated but empty buffer * back to zero and have the buffer freed. */ TEST_FEATURE ("with alloc'd buffer and no data"); TEST_ALLOC_FAIL { buf->size = BUFSIZ * 2; ret = nih_io_buffer_resize (buf, 0); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_EQ (buf->size, 0); TEST_EQ_P (buf->buf, NULL); } /* Check that asking for a page more space when we claim to be * using half a page gives us a full two pages of space. */ TEST_FEATURE ("with part-full buffer and increase"); TEST_ALLOC_FAIL { buf->size = 0; buf->len = BUFSIZ / 2; ret = nih_io_buffer_resize (buf, BUFSIZ); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (buf->buf, BUFSIZ * 2); TEST_EQ (buf->size, BUFSIZ * 2); TEST_EQ (buf->len, BUFSIZ / 2); } /* Check that asking for an increase smaller than the difference * between the buffer size and length has no effect. */ TEST_FEATURE ("with no change"); TEST_ALLOC_FAIL { buf->size = BUFSIZ * 2; buf->len = BUFSIZ + BUFSIZ / 2; ret = nih_io_buffer_resize (buf, 80); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (buf->buf, BUFSIZ * 2); TEST_EQ (buf->size, BUFSIZ * 2); TEST_EQ (buf->len, BUFSIZ + BUFSIZ / 2); } nih_free (buf); } void test_buffer_pop (void) { NihIoBuffer *buf; char *str; size_t len; TEST_FUNCTION ("nih_io_buffer_pop"); buf = nih_io_buffer_new (NULL); assert0 (nih_io_buffer_push (buf, "this is a test of the buffer code", 33)); /* Check that we can pop some bytes out of a buffer, and have a * NULL-terminated string returned that is allocated with nih_alloc. * The buffer should be shrunk appropriately and moved up. */ TEST_FEATURE ("with full buffer"); TEST_ALLOC_FAIL { len = 14; str = nih_io_buffer_pop (NULL, buf, &len); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (buf->len, 19); TEST_EQ_MEM (buf->buf, " of the buffer code", 19); continue; } TEST_EQ (len, 14); TEST_ALLOC_SIZE (str, 15); TEST_EQ (str[14], '\0'); TEST_EQ_STR (str, "this is a test"); TEST_EQ (buf->len, 19); TEST_EQ_MEM (buf->buf, " of the buffer code", 19); nih_free (str); } /* Check that we can empty the buffer and the buffer is freed. */ TEST_FEATURE ("with request to empty buffer"); TEST_ALLOC_FAIL { len = 19; str = nih_io_buffer_pop (NULL, buf, &len); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (buf->len, 0); TEST_EQ (buf->size, 0); TEST_EQ_P (buf->buf, NULL); continue; } TEST_EQ (len, 19); TEST_ALLOC_SIZE (str, 20); TEST_EQ (str[19], '\0'); TEST_EQ_STR (str, " of the buffer code"); TEST_EQ (buf->len, 0); TEST_EQ (buf->size, 0); TEST_EQ_P (buf->buf, NULL); nih_free (str); } /* Check that we can request more data than is in the buffer. * We should get everything's there, and len should be updated to * indicate the shortfall. */ TEST_FEATURE ("with request for more than buffer size"); assert0 (nih_io_buffer_push (buf, "another test", 12)); TEST_ALLOC_FAIL { len = 20; str = nih_io_buffer_pop (NULL, buf, &len); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (buf->len, 0); TEST_EQ (buf->size, 0); TEST_EQ_P (buf->buf, NULL); continue; } TEST_EQ (len, 12); TEST_ALLOC_SIZE (str, 13); TEST_EQ (str[12], '\0'); TEST_EQ_STR (str, "another test"); TEST_EQ (buf->len, 0); TEST_EQ (buf->size, 0); TEST_EQ_P (buf->buf, NULL); nih_free (str); } nih_free (buf); } void test_buffer_shrink (void) { NihIoBuffer *buf; TEST_FUNCTION ("nih_io_buffer_shrink"); buf = nih_io_buffer_new (NULL); assert0 (nih_io_buffer_push (buf, "this is a test of the buffer code", 33)); /* Check that we can shrink the buffer by a small number of bytes. */ TEST_FEATURE ("with full buffer"); TEST_ALLOC_FAIL { nih_io_buffer_shrink (buf, 14); TEST_EQ (buf->len, 19); TEST_EQ_MEM (buf->buf, " of the buffer code", 19); } /* Check that we can empty the buffer and the buffer is freed. */ TEST_FEATURE ("with request to empty buffer"); TEST_ALLOC_FAIL { nih_io_buffer_shrink (buf, 19); TEST_EQ (buf->len, 0); TEST_EQ (buf->size, 0); TEST_EQ_P (buf->buf, NULL); } /* Check that we can shrink the buffer by more bytes than its length * and just end up freeing it. */ TEST_FEATURE ("with request larger than buffer size"); assert0 (nih_io_buffer_push (buf, "another test", 12)); TEST_ALLOC_FAIL { nih_io_buffer_shrink (buf, 20); TEST_EQ (buf->len, 0); TEST_EQ (buf->size, 0); TEST_EQ_P (buf->buf, NULL); } nih_free (buf); } void test_buffer_push (void) { NihIoBuffer *buf; int ret; TEST_FUNCTION ("nih_io_buffer_push"); buf = nih_io_buffer_new (NULL); /* Check that we can push data into an empty buffer, which will * store it in the buffer. */ TEST_FEATURE ("with empty buffer"); TEST_ALLOC_FAIL { buf->len = 0; buf->size = 0; ret = nih_io_buffer_push (buf, "test", 4); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (buf->buf, BUFSIZ); TEST_EQ (buf->size, BUFSIZ); TEST_EQ (buf->len, 4); TEST_EQ_MEM (buf->buf, "test", 4); } /* Check that we can push more data into that buffer, which will * append it to the data already there. */ TEST_FEATURE ("with data in the buffer"); TEST_ALLOC_FAIL { buf->len = 4; buf->size = BUFSIZ; ret = nih_io_buffer_push (buf, "ing the buffer code", 14); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (buf->buf, BUFSIZ); TEST_EQ (buf->size, BUFSIZ); TEST_EQ (buf->len, 18); TEST_EQ_MEM (buf->buf, "testing the buffer code", 18); } nih_free (buf); } void test_message_new (void) { NihIoMessage *msg; /* Check that we can create a new empty message, that doesn't appear * in any list and with the structure and msghdr members correct. */ TEST_FUNCTION ("nih_io_message_new"); TEST_ALLOC_FAIL { msg = nih_io_message_new (NULL); if (test_alloc_failed) { TEST_EQ_P (msg, NULL); continue; } TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_LIST_EMPTY (&msg->entry); TEST_EQ_P (msg->addr, NULL); TEST_EQ (msg->addrlen, 0); TEST_ALLOC_SIZE (msg->data, sizeof (NihIoBuffer)); TEST_ALLOC_PARENT (msg->data, msg); TEST_ALLOC_SIZE (msg->control, sizeof (struct cmsghdr *)); TEST_ALLOC_PARENT (msg->control, msg); TEST_EQ_P (msg->control[0], NULL); nih_free (msg); } } void test_message_add_control (void) { NihIoMessage *msg; struct ucred cred; int ret, value; TEST_FUNCTION ("nih_io_message_add_control"); test_alloc_failed = 0; msg = nih_io_message_new (NULL); /* Check that we can add a control message header to a message that * doesn't yet have one. The array should be increased in size and * the messages should be children of it underneath. */ TEST_FEATURE ("with empty message"); TEST_ALLOC_FAIL { value = 0; ret = nih_io_message_add_control (msg, SOL_SOCKET, SCM_RIGHTS, sizeof (int), &value); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_ALLOC_PARENT (msg->control, msg); TEST_ALLOC_SIZE (msg->control, sizeof (struct cmsghdr *) * 2); TEST_ALLOC_PARENT (msg->control[0], msg->control); TEST_ALLOC_SIZE (msg->control[0], CMSG_SPACE (sizeof (int))); TEST_EQ (msg->control[0]->cmsg_level, SOL_SOCKET); TEST_EQ (msg->control[0]->cmsg_type, SCM_RIGHTS); TEST_EQ (msg->control[0]->cmsg_len, CMSG_LEN (sizeof (int))); TEST_EQ_MEM (CMSG_DATA (msg->control[0]), &value, sizeof (int)); TEST_EQ_P (msg->control[1], NULL); } /* Check that we can append more control data onto the end of an * existing message. The array should include both messages. */ TEST_FEATURE ("with existing control data"); TEST_ALLOC_FAIL { cred.pid = cred.uid = cred.gid = 1; ret = nih_io_message_add_control (msg, SOL_SOCKET, SCM_CREDENTIALS, sizeof (cred), &cred); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_ALLOC_PARENT (msg->control, msg); TEST_ALLOC_SIZE (msg->control, sizeof (struct cmsghdr *) * 3); TEST_ALLOC_PARENT (msg->control[0], msg->control); TEST_ALLOC_SIZE (msg->control[0], CMSG_SPACE (sizeof (int))); TEST_EQ (msg->control[0]->cmsg_level, SOL_SOCKET); TEST_EQ (msg->control[0]->cmsg_type, SCM_RIGHTS); TEST_EQ (msg->control[0]->cmsg_len, CMSG_LEN (sizeof (int))); TEST_EQ_MEM (CMSG_DATA (msg->control[0]), &value, sizeof (int)); TEST_ALLOC_PARENT (msg->control[1], msg->control); TEST_ALLOC_SIZE (msg->control[1], CMSG_SPACE (sizeof (cred))); TEST_EQ (msg->control[1]->cmsg_level, SOL_SOCKET); TEST_EQ (msg->control[1]->cmsg_type, SCM_CREDENTIALS); TEST_EQ (msg->control[1]->cmsg_len, CMSG_LEN (sizeof (cred))); TEST_EQ_MEM (CMSG_DATA (msg->control[1]), &cred, sizeof (cred)); TEST_EQ_P (msg->control[2], NULL); } nih_free (msg); } void test_message_recv (void) { NihError *err; NihIoMessage *msg; struct sockaddr_un addr0, addr1; size_t addr0len, addr1len, len; struct msghdr msghdr; struct iovec iov[1]; char buf[BUFSIZ * 2], cbuf[CMSG_SPACE(sizeof (int))]; struct cmsghdr *cmsg; int fds[2], *fdptr; TEST_FUNCTION ("nih_io_message_recv"); nih_error_init (); socketpair (PF_UNIX, SOCK_DGRAM, 0, fds); msghdr.msg_name = NULL; msghdr.msg_namelen = 0; msghdr.msg_iov = iov; msghdr.msg_iovlen = 1; msghdr.msg_control = NULL; msghdr.msg_controllen = 0; msghdr.msg_flags = 0; iov[0].iov_base = buf; iov[0].iov_len = sizeof (buf); /* Check that we can receive a message from a socket with just * text, and no control data. The message structure should be * allocated and filled properly. If we run out of memory, NULL * should be returned, and the message should be left in the socket. */ TEST_FEATURE ("with no control data"); TEST_ALLOC_FAIL { memcpy (buf, "test", 4); iov[0].iov_len = 4; sendmsg (fds[0], &msghdr, 0); len = 0; msg = nih_io_message_recv (NULL, fds[1], &len); if (test_alloc_failed) { TEST_EQ_P (msg, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ (read (fds[1], buf, sizeof (buf)), 4); continue; } TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_LIST_EMPTY (&msg->entry); TEST_EQ (len, 4); TEST_EQ (msg->data->len, 4); TEST_EQ_MEM (msg->data->buf, "test", 4); nih_free (msg); } /* Check that we can receive a message that contains control data, * and that it's put in the structure. */ TEST_FEATURE ("with control data"); TEST_ALLOC_FAIL { msghdr.msg_control = cbuf; msghdr.msg_controllen = sizeof (cbuf); cmsg = CMSG_FIRSTHDR (&msghdr); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_len = CMSG_LEN (sizeof (int)); fdptr = (int *)CMSG_DATA (cmsg); memcpy (fdptr, &fds[0], sizeof (int)); msghdr.msg_controllen = cmsg->cmsg_len; sendmsg (fds[0], &msghdr, 0); len = 0; msg = nih_io_message_recv (NULL, fds[1], &len); /* 8th alloc onwards is control data, and we mandate that * always succeeds. */ if (test_alloc_failed && (test_alloc_failed < 8)) { TEST_EQ_P (msg, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ (read (fds[1], buf, sizeof (buf)), 4); continue; } TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_LIST_EMPTY (&msg->entry); TEST_EQ (len, 4); TEST_EQ (msg->data->len, 4); TEST_EQ_MEM (msg->data->buf, "test", 4); TEST_ALLOC_SIZE (msg->control, sizeof (struct cmsghdr *) * 2); TEST_ALLOC_PARENT (msg->control, msg); TEST_ALLOC_SIZE (msg->control[0], CMSG_SPACE (sizeof (int))); TEST_ALLOC_PARENT (msg->control[0], msg->control); TEST_EQ (msg->control[0]->cmsg_level, SOL_SOCKET); TEST_EQ (msg->control[0]->cmsg_type, SCM_RIGHTS); TEST_EQ (msg->control[0]->cmsg_len, CMSG_LEN (sizeof (int))); TEST_EQ_P (msg->control[1], NULL); nih_free (msg); msghdr.msg_control = NULL; msghdr.msg_controllen = 0; } /* Check that we can get messages larger than the usual buffer size */ TEST_FEATURE ("with message that would be truncated"); TEST_ALLOC_FAIL { memset (buf, ' ', BUFSIZ * 2); iov[0].iov_len = BUFSIZ * 2; sendmsg (fds[0], &msghdr, 0); len = 0; msg = nih_io_message_recv (NULL, fds[1], &len); if (test_alloc_failed) { TEST_EQ_P (msg, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ (read (fds[1], buf, sizeof (buf)), BUFSIZ * 2); continue; } TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_LIST_EMPTY (&msg->entry); TEST_EQ (len, BUFSIZ * 2); TEST_EQ (msg->data->len, BUFSIZ * 2); nih_free (msg); } /* Check that we can receive a message from a non-specific source * over an unconnected socket. */ TEST_FEATURE ("with unconnected AF_UNIX sockets"); addr0.sun_family = AF_UNIX; addr0.sun_path[0] = '\0'; addr0len = offsetof (struct sockaddr_un, sun_path) + 1; addr0len += snprintf (addr0.sun_path + 1, sizeof (addr0.sun_path) - 1, "/com/netsplit/libnih/test_io/%d.0", getpid ()); fds[0] = socket (PF_UNIX, SOCK_DGRAM, 0); bind (fds[0], (struct sockaddr *)&addr0, addr0len); addr1.sun_family = AF_UNIX; addr1.sun_path[0] = '\0'; addr1len = offsetof (struct sockaddr_un, sun_path) + 1; addr1len += snprintf (addr1.sun_path + 1, sizeof (addr1.sun_path) - 1, "/com/netsplit/libnih/test_io/%d.1", getpid ()); fds[1] = socket (PF_UNIX, SOCK_DGRAM, 0); bind (fds[1], (struct sockaddr *)&addr1, addr1len); msghdr.msg_name = (struct sockaddr *)&addr1; msghdr.msg_namelen = addr1len; memcpy (buf, "test", 4); iov[0].iov_len = 4; TEST_ALLOC_FAIL { sendmsg (fds[0], &msghdr, 0); len = 0; msg = nih_io_message_recv (NULL, fds[1], &len); if (test_alloc_failed) { TEST_EQ_P (msg, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ (read (fds[1], buf, sizeof (buf)), 4); continue; } TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_LIST_EMPTY (&msg->entry); TEST_EQ (msg->data->len, 4); TEST_EQ_MEM (msg->data->buf, "test", 4); TEST_EQ (msg->addrlen, addr0len); TEST_EQ (msg->addr->sa_family, PF_UNIX); TEST_EQ_MEM (((struct sockaddr_un *)msg->addr)->sun_path, addr0.sun_path, addr0len - offsetof (struct sockaddr_un, sun_path)); nih_free (msg); } close (fds[0]); close (fds[1]); /* Check that we get an error if the socket is closed. */ TEST_FEATURE ("with closed socket"); nih_error_push_context (); TEST_ALLOC_FAIL { len = 0; msg = nih_io_message_recv (NULL, fds[1], &len); TEST_EQ_P (msg, NULL); err = nih_error_get (); if (test_alloc_failed && (test_alloc_failed < 7)) { TEST_EQ (err->number, ENOMEM); } else { TEST_EQ (err->number, EBADF); } nih_free (err); } nih_error_pop_context (); } void test_message_send (void) { NihError *err; NihIoMessage *msg; struct sockaddr_un addr; size_t addrlen; struct msghdr msghdr; struct iovec iov[1]; char buf[BUFSIZ], cbuf[CMSG_SPACE(sizeof (int))]; struct cmsghdr *cmsg; ssize_t len, ret; int fds[2]; TEST_FUNCTION ("nih_io_message_send"); socketpair (PF_UNIX, SOCK_DGRAM, 0, fds); msghdr.msg_name = NULL; msghdr.msg_namelen = 0; msghdr.msg_iov = iov; msghdr.msg_iovlen = 1; msghdr.msg_control = NULL; msghdr.msg_controllen = 0; msghdr.msg_flags = 0; iov[0].iov_base = buf; iov[0].iov_len = sizeof (buf); /* Check that we can send a message down a socket with just the * ordinary text, and no control data. */ TEST_FEATURE ("with no control data"); msg = nih_io_message_new (NULL); assert0 (nih_io_buffer_push (msg->data, "test", 4)); TEST_ALLOC_FAIL { ret = nih_io_message_send (msg, fds[0]); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (ret, 4); len = recvmsg (fds[1], &msghdr, 0); TEST_EQ (len, 4); TEST_EQ_MEM (buf, "test", 4); } /* Check that we can include control message information in the * message, and have it come out the other end. */ TEST_FEATURE ("with control data"); assert0 (nih_io_message_add_control (msg, SOL_SOCKET, SCM_RIGHTS, sizeof (int), &fds[0])); TEST_ALLOC_FAIL { ret = nih_io_message_send (msg, fds[0]); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (ret, 4); msghdr.msg_control = cbuf; msghdr.msg_controllen = sizeof (cbuf); len = recvmsg (fds[1], &msghdr, 0); TEST_EQ (len, 4); TEST_EQ_MEM (buf, "test", 4); cmsg = CMSG_FIRSTHDR (&msghdr); TEST_EQ (cmsg->cmsg_level, SOL_SOCKET); TEST_EQ (cmsg->cmsg_type, SCM_RIGHTS); TEST_EQ (cmsg->cmsg_len, CMSG_LEN (sizeof (int))); } close (fds[0]); close (fds[1]); nih_free (msg->control[0]); msg->control[0] = NULL; /* Check that we can send a message to a specific destination over * an unconnected socket. */ TEST_FEATURE ("with unconnected sockets"); addr.sun_family = AF_UNIX; addr.sun_path[0] = '\0'; addrlen = offsetof (struct sockaddr_un, sun_path) + 1; addrlen += snprintf (addr.sun_path + 1, sizeof (addr.sun_path) - 1, "/com/netsplit/libnih/test_io/%d", getpid ()); fds[0] = socket (PF_UNIX, SOCK_DGRAM, 0); fds[1] = socket (PF_UNIX, SOCK_DGRAM, 0); bind (fds[1], (struct sockaddr *)&addr, addrlen); msg->addr = (struct sockaddr *)&addr; msg->addrlen = addrlen; TEST_ALLOC_FAIL { ret = nih_io_message_send (msg, fds[0]); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (ret, 4); msghdr.msg_control = NULL; msghdr.msg_controllen = 0; len = recvmsg (fds[1], &msghdr, 0); TEST_EQ (len, 4); TEST_EQ_MEM (buf, "test", 4); } nih_free (msg); close (fds[0]); close (fds[1]); /* Check that we get an error if the socket is closed. */ TEST_FEATURE ("with closed socket"); nih_error_push_context (); msg = nih_io_message_new (NULL); assert0 (nih_io_buffer_push (msg->data, "test", 4)); TEST_ALLOC_FAIL { ret = nih_io_message_send (msg, fds[0]); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (test_alloc_failed < 2)) { TEST_EQ (err->number, ENOMEM); } else { TEST_EQ (err->number, EBADF); } nih_free (err); } nih_free (msg); nih_error_pop_context (); } static int read_called = 0; static int close_called = 0; static int error_called = 0; static NihError *last_error = NULL; static const char *last_str = NULL; static size_t last_len = 0; static int remove_message = 0; static void my_reader (void *data, NihIo *io, const char *str, size_t len) { read_called++; if (remove_message) { nih_free (nih_io_read_message (NULL, io)); remove_message = 0; return; } if (! data) nih_free (io); last_data = data; last_str = str; last_len = len; } static void my_close_handler (void *data, NihIo *io) { last_data = data; close_called++; } static void my_error_handler (void *data, NihIo *io) { last_data = data; last_error = nih_error_get (); error_called++; } void test_reopen (void) { NihIo *io; int fds[2]; struct sigaction oldact; NihError *err; TEST_FUNCTION ("nih_io_reopen"); /* Check that we can create a stream mode NihIo structure from an * existing file descriptor; the structure should be correctly * populated and assigned an NihIoWatch. The file descriptor * should be altered so that it is non-blocking. */ TEST_FEATURE ("with stream mode"); TEST_ALLOC_FAIL { assert0 (pipe (fds)); io = nih_io_reopen (NULL, fds[0], NIH_IO_STREAM, my_reader, my_close_handler, my_error_handler, &io); if (test_alloc_failed) { TEST_EQ_P (io, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_ALLOC_SIZE (io, sizeof (NihIo)); TEST_ALLOC_PARENT (io->send_buf, io); TEST_ALLOC_SIZE (io->send_buf, sizeof (NihIoBuffer)); TEST_ALLOC_PARENT (io->recv_buf, io); TEST_ALLOC_SIZE (io->recv_buf, sizeof (NihIoBuffer)); TEST_EQ (io->type, NIH_IO_STREAM); TEST_EQ_P (io->reader, my_reader); TEST_EQ_P (io->close_handler, my_close_handler); TEST_EQ_P (io->error_handler, my_error_handler); TEST_EQ_P (io->data, &io); TEST_FALSE (io->shutdown); TEST_EQ_P (io->free, NULL); TEST_ALLOC_PARENT (io->watch, io); TEST_EQ (io->watch->fd, fds[0]); TEST_EQ (io->watch->events, NIH_IO_READ); TEST_TRUE (fcntl (fds[0], F_GETFL) & O_NONBLOCK); nih_free (io); close (fds[1]); } /* Check that we can create a message mode NihIo structure from an * existing file descriptor; the structure should be correctly * populated and assigned an NihIoWatch. The file descriptor * should be altered so that it is non-blocking. */ TEST_FEATURE ("with message mode"); TEST_ALLOC_FAIL { assert0 (pipe (fds)); io = nih_io_reopen (NULL, fds[0], NIH_IO_MESSAGE, my_reader, my_close_handler, my_error_handler, &io); if (test_alloc_failed) { TEST_EQ_P (io, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_ALLOC_SIZE (io, sizeof (NihIo)); TEST_ALLOC_PARENT (io->send_q, io); TEST_ALLOC_SIZE (io->send_q, sizeof (NihList)); TEST_ALLOC_PARENT (io->recv_q, io); TEST_ALLOC_SIZE (io->recv_q, sizeof (NihList)); TEST_EQ (io->type, NIH_IO_MESSAGE); TEST_EQ_P (io->reader, my_reader); TEST_EQ_P (io->close_handler, my_close_handler); TEST_EQ_P (io->error_handler, my_error_handler); TEST_EQ_P (io->data, &io); TEST_FALSE (io->shutdown); TEST_EQ_P (io->free, NULL); TEST_ALLOC_PARENT (io->watch, io); TEST_EQ (io->watch->fd, fds[0]); TEST_EQ (io->watch->events, NIH_IO_READ); TEST_TRUE (fcntl (fds[0], F_GETFL) & O_NONBLOCK); nih_free (io); close (fds[1]); } /* Check that the SIGPIPE signal will now be ignored */ sigaction (SIGPIPE, NULL, &oldact); TEST_EQ (oldact.sa_handler, SIG_IGN); /* Check that we get EBADF raised if we try and reopen a file that * is closed. */ TEST_FEATURE ("with closed file"); nih_error_push_context (); assert0 (pipe (fds)); close (fds[0]); close (fds[1]); io = nih_io_reopen (NULL, fds[0], NIH_IO_MESSAGE, my_reader, my_close_handler, my_error_handler, &io); TEST_EQ_P (io, NULL); err = nih_error_get (); TEST_EQ (err->number, EBADF); nih_free (err); nih_error_pop_context (); } void test_shutdown (void) { NihIo *io; NihIoMessage *msg; int fds[2]; fd_set readfds, writefds, exceptfds; TEST_FUNCTION ("nih_io_shutdown"); assert0 (pipe (fds)); io = nih_io_reopen (NULL, fds[0], NIH_IO_STREAM, NULL, NULL, NULL, NULL); assert0 (nih_io_buffer_push (io->recv_buf, "some data", 9)); TEST_FREE_TAG (io); /* Check that shutting down a socket with data in the buffer * merely marks it as shutdown and neither closes the socket or * frees the structure. */ TEST_FEATURE ("with data in the buffer"); nih_io_shutdown (io); TEST_TRUE (io->shutdown); TEST_NOT_FREE (io); TEST_GE (fcntl (fds[0], F_GETFD), 0); /* Check that handling the data in the buffer, emptying it, causes * the shutdown socket to be closed and the structure to be freed. */ TEST_FEATURE ("with data being handled"); FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); FD_SET (fds[0], &readfds); nih_io_buffer_shrink (io->recv_buf, 9); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_FREE (io); TEST_LT (fcntl (fds[0], F_GETFD), 0); TEST_EQ (errno, EBADF); close (fds[1]); /* Check that shutting down a socket with no data in the buffer * results in it being immediately closed and freed. */ TEST_FEATURE ("with no data in the buffer"); assert0 (pipe (fds)); close (fds[1]); io = nih_io_reopen (NULL, fds[0], NIH_IO_STREAM, NULL, NULL, NULL, NULL); TEST_FREE_TAG (io); nih_io_shutdown (io); TEST_FREE (io); TEST_LT (fcntl (fds[0], F_GETFD), 0); TEST_EQ (errno, EBADF); /* Check that shutting down a socket with a message in the receive * queue merely marks it as shutdown and neither closes the socket * or frees the structure. */ TEST_FEATURE ("with message in the queue"); socketpair (PF_UNIX, SOCK_DGRAM, 0, fds); close (fds[1]); io = nih_io_reopen (NULL, fds[0], NIH_IO_MESSAGE, NULL, NULL, NULL, NULL); msg = nih_io_message_new (io); assert0 (nih_io_buffer_push (msg->data, "some data", 9)); nih_list_add (io->recv_q, &msg->entry); TEST_FREE_TAG (io); nih_io_shutdown (io); TEST_NOT_FREE (io); TEST_TRUE (io->shutdown); TEST_GE (fcntl (fds[0], F_GETFD), 0); /* Check that removing the message from the queue, emptying it, causes * the shutdown socket to be closed and the structure to be freed. */ TEST_FEATURE ("with message being handled"); nih_free (msg); FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); FD_SET (fds[0], &readfds); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_FREE (io); TEST_LT (fcntl (fds[0], F_GETFD), 0); TEST_EQ (errno, EBADF); /* Check that shutting down a socket with no message in the queue * results in it being immediately closed and freed. */ TEST_FEATURE ("with no message in the queue"); socketpair (PF_UNIX, SOCK_DGRAM, 0, fds); io = nih_io_reopen (NULL, fds[0], NIH_IO_MESSAGE, NULL, NULL, NULL, NULL); TEST_FREE_TAG (io); nih_io_shutdown (io); TEST_FREE (io); TEST_LT (fcntl (fds[0], F_GETFD), 0); TEST_EQ (errno, EBADF); close (fds[1]); } void test_destroy (void) { NihIo *io; int fds[2]; TEST_FUNCTION ("nih_io_destroy"); /* Check that freeing an open file descriptor doesn't call the error * handler, and just closes the fd and frees the structure. */ TEST_FEATURE ("with open file descriptor"); nih_error_push_context (); assert0 (pipe (fds)); error_called = 0; io = nih_io_reopen (NULL, fds[0], NIH_IO_STREAM, NULL, NULL, my_error_handler, &io); nih_free (io); TEST_FALSE (error_called); TEST_LT (fcntl (fds[0], F_GETFD), 0); TEST_EQ (errno, EBADF); close (fds[1]); nih_error_pop_context (); /* Check that closing a file descriptor that's already closed * results in the error handler being called with an EBADF system * error and the data pointer, followed by the structure being * freed. */ TEST_FEATURE ("with closed file descriptor"); nih_error_push_context (); assert0 (pipe (fds)); error_called = 0; last_data = NULL; last_error = NULL; io = nih_io_reopen (NULL, fds[0], NIH_IO_STREAM, NULL, NULL, my_error_handler, &io); close (fds[0]); nih_free (io); TEST_TRUE (error_called); TEST_EQ (last_error->number, EBADF); TEST_EQ_P (last_data, &io); nih_free (last_error); close (fds[1]); nih_error_pop_context (); } void test_watcher (void) { NihIo *io; NihIoMessage *msg, *msg2; int fds[2]; ssize_t len; struct msghdr msghdr; struct iovec iov[1]; char buf[BUFSIZ * 2]; fd_set readfds, writefds, exceptfds; FILE *output; TEST_FUNCTION ("nih_io_watcher"); /* Check that data to be read on a socket watched by NihIo ends up * in the receive buffer, and results in the reader function being * called with the right arguments. */ TEST_FEATURE ("with data to read"); assert0 (pipe (fds)); io = nih_io_reopen (NULL, fds[0], NIH_IO_STREAM, my_reader, my_close_handler, my_error_handler, &io); TEST_ALLOC_FAIL { io->recv_buf->len = 0; io->recv_buf->size = 0; assert (write (fds[1], "this is a test", 14) == 14); FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); FD_SET (fds[0], &readfds); read_called = 0; last_data = NULL; last_str = NULL; last_len = 0; nih_io_handle_fds (&readfds, &writefds, &exceptfds); if (test_alloc_failed == 1) { TEST_FALSE (read_called); TEST_EQ (read (fds[0], buf, sizeof (buf)), 14); continue; } TEST_TRUE (read_called); TEST_EQ_P (last_data, &io); TEST_EQ_P (last_str, io->recv_buf->buf); TEST_EQ (last_len, io->recv_buf->len); TEST_EQ (io->recv_buf->len, 14); TEST_EQ_MEM (io->recv_buf->buf, "this is a test", 14); } /* Check that the reader function is called again when more data * comes in, and that the buffer contains both sets of data. This * should be true even if we're out of memory. */ TEST_FEATURE ("with more data to read"); TEST_ALLOC_FAIL { io->recv_buf->len = 14; io->recv_buf->size = BUFSIZ; assert (write (fds[1], " of the callback code", 19) == 19); read_called = 0; last_data = NULL; last_str = NULL; last_len = 0; nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_TRUE (read_called); TEST_EQ_P (last_data, &io); TEST_EQ_P (last_str, io->recv_buf->buf); TEST_EQ (last_len, io->recv_buf->len); TEST_EQ (io->recv_buf->len, 33); TEST_EQ_MEM (io->recv_buf->buf, "this is a test of the callback code", 33); } /* Check that the reader function can call nih_free(), resulting * in the structure being closed once it has finished the watcher * function. */ TEST_FEATURE ("with free called in reader"); io->data = NULL; TEST_FREE_TAG (io); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_FREE (io); TEST_LT (fcntl (fds[0], F_GETFD), 0); TEST_EQ (errno, EBADF); close (fds[1]); /* Check that the reader function is also called when the remote end * has been closed; along with the close function. */ TEST_FEATURE ("with remote end closed"); nih_error_push_context (); assert0 (pipe (fds)); io = nih_io_reopen (NULL, fds[0], NIH_IO_STREAM, my_reader, my_close_handler, my_error_handler, &io); assert0 (nih_io_buffer_push (io->recv_buf, "this is a test of the callback code", 33)); read_called = 0; close_called = 0; last_data = NULL; last_str = NULL; last_len = 0; FD_ZERO (&readfds); FD_SET (fds[0], &readfds); close (fds[1]); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_TRUE (read_called); TEST_TRUE (close_called); TEST_EQ_P (last_data, &io); TEST_EQ_P (last_str, io->recv_buf->buf); TEST_EQ (last_len, io->recv_buf->len); TEST_EQ (io->recv_buf->len, 33); TEST_EQ_MEM (io->recv_buf->buf, "this is a test of the callback code", 33); nih_error_pop_context (); /* Check that the reader function and error handler are called if * the local end gets closed. The error should be EBADF. */ TEST_FEATURE ("with local end closed"); nih_error_push_context (); read_called = 0; error_called = 0; last_data = NULL; last_str = NULL; last_len = 0; last_error = NULL; close (fds[0]); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_TRUE (error_called); TEST_EQ (last_error->number, EBADF); TEST_TRUE (read_called); TEST_EQ_P (last_data, &io); TEST_EQ_P (last_str, io->recv_buf->buf); TEST_EQ (last_len, io->recv_buf->len); TEST_EQ (io->recv_buf->len, 33); TEST_EQ_MEM (io->recv_buf->buf, "this is a test of the callback code", 33); nih_free (last_error); error_called = 0; last_error = NULL; nih_free (io); TEST_TRUE (error_called); TEST_EQ (last_error->number, EBADF); nih_free (last_error); nih_error_pop_context (); /* Check that if the remote end closes and there's no close handler, * the file descriptor is closed and the structure freed. */ TEST_FEATURE ("with no close handler"); nih_error_push_context (); assert0 (pipe (fds)); io = nih_io_reopen (NULL, fds[0], NIH_IO_STREAM, my_reader, NULL, NULL, &io); TEST_FREE_TAG (io); FD_ZERO (&readfds); FD_SET (fds[0], &readfds); close (fds[1]); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_FREE (io); TEST_LT (fcntl (fds[0], F_GETFD), 0); TEST_EQ (errno, EBADF); nih_error_pop_context (); /* Check that if the local end closes and there's no error handler * that the structure is freed. */ TEST_FEATURE ("with no error handler"); nih_error_push_context (); assert0 (pipe (fds)); io = nih_io_reopen (NULL, fds[0], NIH_IO_STREAM, my_reader, NULL, NULL, &io); TEST_FREE_TAG (io); FD_ZERO (&readfds); FD_SET (fds[0], &readfds); nih_log_set_priority (NIH_LOG_FATAL); close (fds[0]); close (fds[1]); nih_io_handle_fds (&readfds, &writefds, &exceptfds); nih_log_set_priority (NIH_LOG_MESSAGE); TEST_FREE (io); nih_error_pop_context (); /* Check that data in the send buffer is written to the file * descriptor if it's pollable for writing. Once the data has been * written, the watch should no longer be checking for writability. */ TEST_FEATURE ("with data to write"); output = tmpfile (); io = nih_io_reopen (NULL, fileno (output), NIH_IO_STREAM, NULL, my_close_handler, my_error_handler, &io); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { assert0 (nih_io_printf (io, "this is a test\n")); } FD_ZERO (&readfds); FD_SET (fileno (output), &writefds); nih_io_handle_fds (&readfds, &writefds, &exceptfds); rewind (output); TEST_FILE_EQ (output, "this is a test\n"); TEST_FILE_END (output); TEST_EQ (io->send_buf->len, 0); TEST_EQ (io->send_buf->size, 0); TEST_EQ_P (io->send_buf->buf, NULL); TEST_FALSE (io->watch->events & NIH_IO_WRITE); } /* Check that we can write more data and that is send out to the * file descriptor as well. */ TEST_FEATURE ("with more data to write"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { assert0 (nih_io_printf (io, "so is this\n")); } nih_io_handle_fds (&readfds, &writefds, &exceptfds); rewind (output); TEST_FILE_EQ (output, "this is a test\n"); TEST_FILE_EQ (output, "so is this\n"); TEST_FILE_END (output); TEST_EQ (io->send_buf->len, 0); TEST_EQ (io->send_buf->size, 0); TEST_EQ_P (io->send_buf->buf, NULL); TEST_FALSE (io->watch->events & NIH_IO_WRITE); } fclose (output); /* Check that an attempt to write to a closed file results in the * error handler being called directly, rather than needing to wait * for a read again. */ TEST_FEATURE ("with closed file"); nih_error_push_context (); error_called = 0; last_data = NULL; last_error = NULL; assert0 (nih_io_printf (io, "this write fails\n")); FD_ZERO (&writefds); FD_SET (fds[0], &writefds); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_EQ (io->send_buf->len, 17); TEST_EQ_MEM (io->send_buf->buf, "this write fails\n", 17); TEST_TRUE (error_called); TEST_EQ (last_error->number, EBADF); TEST_EQ_P (last_data, &io); nih_free (last_error); error_called = 0; last_error = NULL; nih_free (io); TEST_TRUE (error_called); TEST_EQ (last_error->number, EBADF); nih_free (last_error); nih_error_pop_context (); /* Check that a message to be read on a socket watched by NihIo ends * up in the receive queue, and results in the reader function being * called just once with the right arguments. */ TEST_FEATURE ("with message to read"); socketpair (PF_UNIX, SOCK_DGRAM, 0, fds); io = nih_io_reopen (NULL, fds[0], NIH_IO_MESSAGE, my_reader, my_close_handler, my_error_handler, &io); TEST_ALLOC_FAIL { msghdr.msg_name = NULL; msghdr.msg_namelen = 0; msghdr.msg_iov = iov; msghdr.msg_iovlen = 1;; msghdr.msg_control = NULL; msghdr.msg_controllen = 0; msghdr.msg_flags = 0; iov[0].iov_base = buf; iov[0].iov_len = sizeof (buf); memcpy (buf, "this is a test", 14); iov[0].iov_len = 14; sendmsg (fds[1], &msghdr, 0); FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); FD_SET (fds[0], &readfds); read_called = 0; last_data = NULL; last_str = NULL; last_len = 0; nih_io_handle_fds (&readfds, &writefds, &exceptfds); if (test_alloc_failed && (test_alloc_failed < 8)) { TEST_EQ (recvmsg (fds[0], &msghdr, 0), 14); continue; } else if (test_alloc_failed) { msg = (NihIoMessage *)io->recv_q->prev; nih_free (msg); continue; } TEST_LIST_NOT_EMPTY (io->recv_q); msg = (NihIoMessage *)io->recv_q->next; TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_ALLOC_PARENT (msg, io); TEST_EQ (msg->data->len, 14); TEST_EQ_MEM (msg->data->buf, "this is a test", 14); TEST_EQ (read_called, 1); TEST_EQ_P (last_data, &io); TEST_EQ_P (last_str, msg->data->buf); TEST_EQ (last_len, msg->data->len); } /* Check that the reader function is called again when more data * comes in, but that it is only called once with the data in * the older message, not the newer. */ TEST_FEATURE ("with another message to read"); memcpy (buf, "another test", 12); iov[0].iov_len = 12; sendmsg (fds[1], &msghdr, 0); read_called = 0; last_data = NULL; last_str = NULL; last_len = 0; nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_LIST_NOT_EMPTY (io->recv_q); msg = (NihIoMessage *)io->recv_q->next; TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_ALLOC_PARENT (msg, io); TEST_EQ (msg->data->len, 14); TEST_EQ_MEM (msg->data->buf, "this is a test", 14); TEST_EQ (read_called, 1); TEST_EQ_P (last_data, &io); TEST_EQ_P (last_str, msg->data->buf); TEST_EQ (last_len, msg->data->len); msg = (NihIoMessage *)io->recv_q->next->next; TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_ALLOC_PARENT (msg, io); TEST_EQ (msg->data->len, 12); TEST_EQ_MEM (msg->data->buf, "another test", 12); /* Check that the reader is called twice if the first invocation * removes the oldest message, the second invocation should be with * the new message. */ TEST_FEATURE ("with message removed during call"); read_called = 0; remove_message = 1; nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_LIST_NOT_EMPTY (io->recv_q); msg = (NihIoMessage *)io->recv_q->next; TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_ALLOC_PARENT (msg, io); TEST_EQ (msg->data->len, 12); TEST_EQ_MEM (msg->data->buf, "another test", 12); TEST_EQ (read_called, 2); TEST_EQ_P (last_data, &io); TEST_EQ_P (last_str, msg->data->buf); TEST_EQ (last_len, msg->data->len); /* Check that the reader is only called once if the message is * removed, and that has no ill effect. */ TEST_FEATURE ("with last message removed during call"); read_called = 0; remove_message = 1; nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_LIST_EMPTY (io->recv_q); TEST_EQ (read_called, 1); /* Check that the reader function can call nih_free(), resulting * in the structure being closed once it has finished the watcher * function. */ TEST_FEATURE ("with close called in reader for message"); io->data = NULL; TEST_FREE_TAG (io); memcpy (buf, "test with close", 15); iov[0].iov_len = 15; sendmsg (fds[1], &msghdr, 0); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_FREE (io); TEST_LT (fcntl (fds[0], F_GETFD), 0); TEST_EQ (errno, EBADF); close (fds[1]); /* Check that the error handler is called if the local end of a * socket is closed (we should get EBADF). The reader should also * be called with the oldest message currently in the queue. */ TEST_FEATURE ("with local end closed"); nih_error_push_context (); socketpair (PF_UNIX, SOCK_DGRAM, 0, fds); io = nih_io_reopen (NULL, fds[0], NIH_IO_MESSAGE, my_reader, my_close_handler, my_error_handler, &io); msg = nih_io_message_new (io); assert0 (nih_io_buffer_push (msg->data, "this is a test", 14)); nih_list_add (io->recv_q, &msg->entry); error_called = 0; last_error = NULL; read_called = 0; last_data = NULL; last_str = NULL; last_len = 0; close (fds[0]); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_LIST_NOT_EMPTY (io->recv_q); msg = (NihIoMessage *)io->recv_q->next; TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_ALLOC_PARENT (msg, io); TEST_EQ (msg->data->len, 14); TEST_EQ_MEM (msg->data->buf, "this is a test", 14); TEST_EQ (read_called, 1); TEST_EQ_P (last_data, &io); TEST_EQ_P (last_str, msg->data->buf); TEST_EQ (last_len, msg->data->len); TEST_TRUE (error_called); TEST_EQ (last_error->number, EBADF); nih_free (last_error); error_called = 0; last_error = NULL; nih_free (io); TEST_TRUE (error_called); TEST_EQ (last_error->number, EBADF); nih_free (last_error); nih_error_pop_context (); /* Check that if the local end of a socket is closed, and there's * no error handler, the structure freed. */ TEST_FEATURE ("with no error handler"); nih_error_push_context (); socketpair (PF_UNIX, SOCK_DGRAM, 0, fds); io = nih_io_reopen (NULL, fds[0], NIH_IO_MESSAGE, my_reader, NULL, NULL, &io); TEST_FREE_TAG (io); FD_ZERO (&readfds); FD_SET (fds[0], &readfds); nih_log_set_priority (NIH_LOG_FATAL); close (fds[0]); close (fds[1]); nih_io_handle_fds (&readfds, &writefds, &exceptfds); nih_log_set_priority (NIH_LOG_MESSAGE); TEST_FREE (io); nih_error_pop_context (); /* Check that a message in the send queue is written to the socket * if it's pollable for writing, removed from the queue and that * the socket is no longer watched for writability. */ TEST_FEATURE ("with message to write"); socketpair (PF_UNIX, SOCK_DGRAM, 0, fds); io = nih_io_reopen (NULL, fds[0], NIH_IO_MESSAGE, my_reader, my_close_handler, my_error_handler, &io); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { msg = nih_io_message_new (NULL); assert0 (nih_io_buffer_push (msg->data, "this is a test", 14)); nih_io_send_message (io, msg); nih_discard (msg); } TEST_FREE_TAG (msg); FD_ZERO (&readfds); FD_ZERO (&writefds); FD_SET (fds[0], &writefds); nih_io_handle_fds (&readfds, &writefds, &exceptfds); if (test_alloc_failed) { TEST_LIST_NOT_EMPTY (io->send_q); TEST_TRUE (io->watch->events & NIH_IO_WRITE); TEST_NOT_FREE (msg); nih_free (msg); continue; } iov[0].iov_base = buf; iov[0].iov_len = sizeof (buf); TEST_LIST_EMPTY (io->send_q); TEST_FALSE (io->watch->events & NIH_IO_WRITE); TEST_FREE (msg); len = recvmsg (fds[1], &msghdr, 0); TEST_EQ (len, 14); TEST_EQ_MEM (buf, "this is a test\n", 14); } /* Check that we can write another message to the send queue, which * should also go straight out and have the writability cleared. */ TEST_FEATURE ("with another message to write"); msg = nih_io_message_new (NULL); assert0 (nih_io_buffer_push (msg->data, "another test", 12)); nih_io_send_message (io, msg); nih_discard (msg); TEST_FREE_TAG (msg); FD_ZERO (&writefds); FD_SET (fds[0], &writefds); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_LIST_EMPTY (io->send_q); TEST_FALSE (io->watch->events & NIH_IO_WRITE); TEST_FREE (msg); len = recvmsg (fds[1], &msghdr, 0); TEST_EQ (len, 12); TEST_EQ_MEM (buf, "another test", 12); /* Check that we can place multiple messages in the send queue and * have them all go straight out. */ TEST_FEATURE ("with multiple messages to write"); msg = nih_io_message_new (NULL); assert0 (nih_io_buffer_push (msg->data, "this is a test", 14)); nih_io_send_message (io, msg); nih_discard (msg); TEST_FREE_TAG (msg); msg2 = nih_io_message_new (NULL); assert0 (nih_io_buffer_push (msg2->data, "another test", 12)); nih_io_send_message (io, msg2); nih_discard (msg2); TEST_FREE_TAG (msg2); FD_ZERO (&writefds); FD_SET (fds[0], &writefds); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_LIST_EMPTY (io->send_q); TEST_FALSE (io->watch->events & NIH_IO_WRITE); TEST_FREE (msg); TEST_FREE (msg2); len = recvmsg (fds[1], &msghdr, 0); TEST_EQ (len, 14); TEST_EQ_MEM (buf, "this is a test", 14); len = recvmsg (fds[1], &msghdr, 0); TEST_EQ (len, 12); TEST_EQ_MEM (buf, "another test", 12); /* Check that an attempt to write to a closed descriptor results in * the error handler being called directly, rather than needing to * wait for a read again. */ TEST_FEATURE ("with closed socket"); nih_error_push_context (); error_called = 0; last_data = NULL; last_error = NULL; msg = nih_io_message_new (NULL); assert0 (nih_io_buffer_push (msg->data, "one more test", 13)); nih_io_send_message (io, msg); nih_discard (msg); TEST_FREE_TAG (msg); FD_ZERO (&writefds); FD_SET (fds[0], &writefds); close (fds[0]); close (fds[1]); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_NOT_FREE (msg); TEST_LIST_NOT_EMPTY (io->send_q); TEST_EQ_P (io->send_q->next, &msg->entry); TEST_TRUE (io->watch->events & NIH_IO_WRITE); TEST_TRUE (error_called); TEST_EQ (last_error->number, EBADF); TEST_EQ_P (last_data, &io); nih_free (last_error); error_called = 0; last_error = NULL; nih_free (io); TEST_TRUE (error_called); TEST_EQ (last_error->number, EBADF); nih_free (last_error); nih_error_pop_context (); } void test_read_message (void) { NihIo *io; NihIoMessage *msg, *ptr; int fds[2]; TEST_FUNCTION ("nih_io_read_message"); assert0 (pipe (fds)); close (fds[1]); io = nih_io_reopen (NULL, fds[0], NIH_IO_MESSAGE, NULL, NULL, NULL, NULL); msg = nih_io_message_new (io); assert0 (nih_io_buffer_push (msg->data, "this is a test", 14)); nih_list_add (io->recv_q, &msg->entry); /* Check that we can read a message in the NihIo receive queue, * the message returned should be the same message we queued and * should be reparented as well as removed from the queue. */ TEST_FEATURE ("with message in queue"); ptr = nih_io_read_message (NULL, io); TEST_EQ_P (ptr, msg); TEST_ALLOC_PARENT (msg, NULL); TEST_LIST_EMPTY (&msg->entry); TEST_LIST_EMPTY (io->recv_q); /* Check that we get NULL when the receive queue is empty. */ TEST_FEATURE ("with empty queue"); ptr = nih_io_read_message (NULL, io); TEST_EQ_P (ptr, NULL); /* Check that the socket is closed and the structure freed when * we take the last data from a shutdown socket. */ TEST_FEATURE ("with shutdown socket"); TEST_FREE_TAG (io); nih_ref (msg, io); nih_list_add (io->recv_q, &msg->entry); nih_io_shutdown (io); ptr = nih_io_read_message (NULL, io); TEST_EQ_P (ptr, msg); TEST_FREE (io); TEST_LT (fcntl (fds[0], F_GETFD), 0); TEST_EQ (errno, EBADF); nih_free (msg); } void test_send_message (void) { NihIo *io; NihIoMessage *msg1, *msg2; int fds[2]; TEST_FUNCTION ("nih_io_send_message"); assert0 (pipe (fds)); close (fds[0]); io = nih_io_reopen (NULL, fds[1], NIH_IO_MESSAGE, NULL, NULL, NULL, NULL); /* Check that we can send a message into the empty send queue, it * should be added directly to the send queue, and a reference * taken. */ TEST_FEATURE ("with empty send queue"); msg1 = nih_io_message_new (NULL); assert0 (nih_io_buffer_push (msg1->data, "this is a test", 14)); nih_io_send_message (io, msg1); TEST_EQ_P (io->send_q->next, &msg1->entry); TEST_ALLOC_PARENT (msg1, io); TEST_TRUE (io->watch->events & NIH_IO_WRITE); /* Check that we can send a message when there's already one in * the send queue, it should be appended to the queue. */ TEST_FEATURE ("with message already in send queue"); msg2 = nih_io_message_new (NULL); assert0 (nih_io_buffer_push (msg2->data, "this is a test", 14)); nih_io_send_message (io, msg2); TEST_EQ_P (io->send_q->next, &msg1->entry); TEST_EQ_P (io->send_q->prev, &msg2->entry); nih_free (msg1); nih_free (msg2); nih_free (io); } void test_read (void) { NihIo *io; NihIoMessage *msg; char *str; size_t len; int fds[2]; TEST_FUNCTION ("nih_io_read"); assert0 (pipe (fds)); close (fds[1]); io = nih_io_reopen (NULL, fds[0], NIH_IO_STREAM, NULL, NULL, NULL, NULL); assert0 (nih_io_buffer_push (io->recv_buf, "this is a test of the io code", 29)); /* Check that we can read data in the NihIo receive buffer, and the * data is returned NULL-terminated, allocated with nih_alloc and * removed from the front of the receive buffer itself. */ TEST_FEATURE ("with full buffer"); TEST_ALLOC_FAIL { len = 14; str = nih_io_read (NULL, io, &len); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ (len, 14); TEST_ALLOC_SIZE (str, 15); TEST_EQ (str[14], '\0'); TEST_EQ_STR (str, "this is a test"); TEST_EQ (io->recv_buf->len, 15); TEST_EQ_MEM (io->recv_buf->buf, " of the io code", 15); nih_free (str); } /* Check that we can empty all of the data from the NihIo receive * buffer, which results in the buffer being freed. */ TEST_FEATURE ("with request to empty buffer"); TEST_ALLOC_FAIL { len = 15; str = nih_io_read (NULL, io, &len); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ (len, 15); TEST_ALLOC_SIZE (str, 16); TEST_EQ (str[15], '\0'); TEST_EQ_STR (str, " of the io code"); TEST_EQ (io->recv_buf->len, 0); TEST_EQ (io->recv_buf->size, 0); TEST_EQ_P (io->recv_buf->buf, NULL); nih_free (str); } /* Check that we can request more data than is in the buffer, and * get a short read with len updated. */ TEST_FEATURE ("with larger request than buffer"); assert0 (nih_io_buffer_push (io->recv_buf, "another test", 12)); TEST_ALLOC_FAIL { len = 20; str = nih_io_read (NULL, io, &len); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ (len, 12); TEST_ALLOC_SIZE (str, 13); TEST_EQ (str[12], '\0'); TEST_EQ_STR (str, "another test"); TEST_EQ (io->recv_buf->len, 0); TEST_EQ (io->recv_buf->size, 0); TEST_EQ_P (io->recv_buf->buf, NULL); nih_free (str); } /* Check that the socket is closed and the structure freed when * we take the last data from a shutdown socket. */ TEST_FEATURE ("with shutdown socket and last data"); TEST_FREE_TAG (io); assert0 (nih_io_buffer_push (io->recv_buf, "this is a test", 14)); nih_io_shutdown (io); len = 14; str = nih_io_read (NULL, io, &len); TEST_EQ (len, 14); TEST_NE_P (str, NULL); TEST_FREE (io); TEST_LT (fcntl (fds[0], F_GETFD), 0); TEST_EQ (errno, EBADF); nih_free (str); /* Check that we can request data while in message mode, and receive * data from the first message; which should have its buffer shrunk. */ TEST_FEATURE ("with full message in queue"); assert0 (pipe (fds)); close (fds[1]); io = nih_io_reopen (NULL, fds[0], NIH_IO_MESSAGE, NULL, NULL, NULL, NULL); msg = nih_io_message_new (io); assert0 (nih_io_buffer_push (msg->data, "this is a test of the io code", 29)); nih_list_add (io->recv_q, &msg->entry); TEST_ALLOC_FAIL { len = 14; str = nih_io_read (NULL, io, &len); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ (len, 14); TEST_ALLOC_SIZE (str, 15); TEST_EQ (str[14], '\0'); TEST_EQ_STR (str, "this is a test"); TEST_EQ (msg->data->len, 15); TEST_EQ_MEM (msg->data->buf, " of the io code", 15); nih_free (str); } /* Check that when we empty the buffer of the message, it is freed * and removed from the receive queue. */ TEST_FEATURE ("with request to empty message buffer"); TEST_FREE_TAG (msg); TEST_ALLOC_FAIL { len = 15; str = nih_io_read (NULL, io, &len); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ (len, 15); TEST_ALLOC_SIZE (str, 16); TEST_EQ (str[15], '\0'); TEST_EQ_STR (str, " of the io code"); TEST_FREE (msg); TEST_LIST_EMPTY (io->recv_q); nih_free (str); } /* Check that we receive a zero-length string and len is set to * zero if there is no message in the queue. */ TEST_FEATURE ("with empty message queue"); TEST_ALLOC_FAIL { len = 10; str = nih_io_read (NULL, io, &len); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ (len, 0); TEST_ALLOC_SIZE (str, 1); TEST_EQ (str[0], '\0'); nih_free (str); } /* Check that the socket is closed and the structure freed when * we take the last data from a shutdown socket. */ TEST_FEATURE ("with shutdown socket and last message"); TEST_FREE_TAG (io); msg = nih_io_message_new (io); assert0 (nih_io_buffer_push (msg->data, "this is a test", 14)); nih_list_add (io->recv_q, &msg->entry); nih_io_shutdown (io); len = 14; str = nih_io_read (NULL, io, &len); TEST_EQ (len, 14); TEST_NE_P (str, NULL); TEST_FREE (io); TEST_LT (fcntl (fds[0], F_GETFD), 0); TEST_EQ (errno, EBADF); nih_free (str); } void test_write (void) { NihIo *io; NihIoMessage *msg; int ret, fds[2]; TEST_FUNCTION ("nih_io_write"); assert0 (pipe (fds)); close (fds[0]); io = nih_io_reopen (NULL, fds[1], NIH_IO_STREAM, NULL, NULL, NULL, NULL); /* Check that we can write data into the NihIo send buffer, the * buffer should contain the data and be a page in size. The * watch should also now be looking for writability. */ TEST_FEATURE ("with empty buffer"); TEST_ALLOC_FAIL { io->send_buf->len = 0; io->send_buf->size = 0; ret = nih_io_write (io, "test", 4); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (io->send_buf->buf, BUFSIZ); TEST_EQ (io->send_buf->size, BUFSIZ); TEST_EQ (io->send_buf->len, 4); TEST_EQ_MEM (io->send_buf->buf, "test", 4); TEST_TRUE (io->watch->events & NIH_IO_WRITE); } /* Check that we can write more data onto the end of the NihIo * send buffer, which increases its size. */ TEST_FEATURE ("with data in the buffer"); TEST_ALLOC_FAIL { io->send_buf->len = 4; io->send_buf->size = BUFSIZ; ret = nih_io_write (io, "ing the io code", 10); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_EQ (io->send_buf->len, 14); TEST_EQ_MEM (io->send_buf->buf, "testing the io", 14); nih_free (io); } /* Check that we can write data into a message mode NihIo, and * have it made into a new message in the send queue. */ TEST_FEATURE ("with empty send queue"); assert0 (pipe (fds)); close (fds[0]); io = nih_io_reopen (NULL, fds[1], NIH_IO_MESSAGE, NULL, NULL, NULL, NULL); TEST_ALLOC_FAIL { ret = nih_io_write (io, "test", 4); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_LIST_NOT_EMPTY (io->send_q); msg = (NihIoMessage *)io->send_q->next; TEST_ALLOC_PARENT (msg, io); TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_ALLOC_SIZE (msg->data->buf, BUFSIZ); TEST_EQ (msg->data->size, BUFSIZ); TEST_EQ (msg->data->len, 4); TEST_EQ_MEM (msg->data->buf, "test", 4); TEST_TRUE (io->watch->events & NIH_IO_WRITE); } /* Check that we can write more data as another new message onto * the send queue. */ TEST_FEATURE ("with message in the send queue"); TEST_ALLOC_FAIL { ret = nih_io_write (io, "ing the io code", 10); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_LIST_NOT_EMPTY (io->send_q); msg = (NihIoMessage *)io->send_q->next; TEST_EQ (msg->data->len, 4); TEST_EQ_MEM (msg->data->buf, "test", 4); msg = (NihIoMessage *)io->send_q->next->next; TEST_ALLOC_PARENT (msg, io); TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_ALLOC_SIZE (msg->data->buf, BUFSIZ); TEST_EQ (msg->data->size, BUFSIZ); TEST_EQ (msg->data->len, 10); TEST_EQ_MEM (msg->data->buf, "ing the io code", 10); TEST_TRUE (io->watch->events & NIH_IO_WRITE); } nih_free (io); } void test_get (void) { NihIo *io; NihIoMessage *msg; char *str; int fds[2]; TEST_FUNCTION ("nih_io_get"); assert0 (pipe (fds)); close (fds[1]); io = nih_io_reopen (NULL, fds[0], NIH_IO_STREAM, NULL, NULL, NULL, NULL); assert0 (nih_io_buffer_push (io->recv_buf, "some data\n", 10)); assert0 (nih_io_buffer_push (io->recv_buf, "and another line\n", 17)); assert0 (nih_io_buffer_push (io->recv_buf, "incomplete", 10)); /* Check that we can take data from the front of a buffer up until * the first embedded new line (which isn't returned), and have the * buffer shuffled up. */ TEST_FEATURE ("with full buffer"); TEST_ALLOC_FAIL { str = nih_io_get (NULL, io, "\n"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (io->recv_buf->len, 27); TEST_EQ_MEM (io->recv_buf->buf, "and another line\nincomplete", 27); continue; } TEST_ALLOC_SIZE (str, 10); TEST_EQ_STR (str, "some data"); TEST_EQ (io->recv_buf->len, 27); TEST_EQ_MEM (io->recv_buf->buf, "and another line\nincomplete", 27); nih_free (str); } /* Check that we can read up to the next line line. */ TEST_FEATURE ("with part-full buffer"); TEST_ALLOC_FAIL { str = nih_io_get (NULL, io, "\n"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (io->recv_buf->len, 10); TEST_EQ_MEM (io->recv_buf->buf, "incomplete", 10); continue; } TEST_ALLOC_SIZE (str, 17); TEST_EQ_STR (str, "and another line"); TEST_EQ (io->recv_buf->len, 10); TEST_EQ_MEM (io->recv_buf->buf, "incomplete", 10); nih_free (str); } /* Check that NULL is returned if the data in the buffer doesn't * contain the delimeter or a NULL terminator. */ TEST_FEATURE ("with incomplete line in buffer"); str = nih_io_get (NULL, io, "\n"); TEST_EQ_P (str, NULL); TEST_EQ (io->recv_buf->len, 10); TEST_EQ_MEM (io->recv_buf->buf, "incomplete", 10); /* Check that a NULL terminator is sufficient to return the data * in the buffer, which should now be empty. */ TEST_FEATURE ("with null-terminated string in buffer"); assert0 (nih_io_buffer_push (io->recv_buf, "\0", 1)); str = nih_io_get (NULL, io, "\n"); TEST_ALLOC_SIZE (str, 11); TEST_EQ_STR (str, "incomplete"); TEST_EQ (io->recv_buf->len, 0); nih_free (str); /* Check that if we empty the buffer of a shutdown socket, the * socket is closed and freed. */ TEST_FEATURE ("with shutdown socket and emptied buffer"); TEST_FREE_TAG (io); assert0 (nih_io_buffer_push (io->recv_buf, "some data\n", 10)); nih_io_shutdown (io); str = nih_io_get (NULL, io, "\n"); TEST_ALLOC_SIZE (str, 10); TEST_EQ_STR (str, "some data"); TEST_FREE (io); TEST_LT (fcntl (fds[0], F_GETFD), 0); TEST_EQ (errno, EBADF); nih_free (str); /* Check that we can operate in message mode and receive data from * the oldest message. */ TEST_FEATURE ("with full message in queue"); assert0 (pipe (fds)); close (fds[1]); io = nih_io_reopen (NULL, fds[0], NIH_IO_MESSAGE, NULL, NULL, NULL, NULL); msg = nih_io_message_new (io); assert0 (nih_io_buffer_push (msg->data, "some data\n", 10)); assert0 (nih_io_buffer_push (msg->data, "and another line\n", 17)); assert0 (nih_io_buffer_push (msg->data, "incomplete", 10)); nih_list_add (io->recv_q, &msg->entry); TEST_ALLOC_FAIL { str = nih_io_get (NULL, io, "\n"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (msg->data->len, 27); TEST_EQ_MEM (msg->data->buf, "and another line\nincomplete", 27); continue; } TEST_ALLOC_SIZE (str, 10); TEST_EQ_STR (str, "some data"); TEST_EQ (msg->data->len, 27); TEST_EQ_MEM (msg->data->buf, "and another line\nincomplete", 27); nih_free (str); } /* Check that we can read up to the next line line. */ TEST_FEATURE ("with part-full message in queue"); TEST_ALLOC_FAIL { str = nih_io_get (NULL, io, "\n"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (msg->data->len, 10); TEST_EQ_MEM (msg->data->buf, "incomplete", 10); continue; } TEST_ALLOC_SIZE (str, 17); TEST_EQ_STR (str, "and another line"); TEST_EQ (msg->data->len, 10); TEST_EQ_MEM (msg->data->buf, "incomplete", 10); nih_free (str); } /* Check that NULL is returned if the data in the buffer doesn't * contain the delimeter or a NULL terminator. */ TEST_FEATURE ("with incomplete line in message"); str = nih_io_get (NULL, io, "\n"); TEST_EQ_P (str, NULL); TEST_EQ (msg->data->len, 10); TEST_EQ_MEM (msg->data->buf, "incomplete", 10); /* Check that a NULL terminator is sufficient to return the data * in the buffer, which should now be empty. This should result * in the message being removed from the queue and freed. */ TEST_FEATURE ("with null-terminated string in message"); TEST_FREE_TAG (msg); assert0 (nih_io_buffer_push (msg->data, "\0", 1)); str = nih_io_get (NULL, io, "\n"); TEST_ALLOC_SIZE (str, 11); TEST_EQ_STR (str, "incomplete"); TEST_FREE (msg); TEST_LIST_EMPTY (io->recv_q); nih_free (str); /* Check that we get NULL if there is no message in the queue. */ TEST_FEATURE ("with empty message queue"); str = nih_io_get (NULL, io, "\n"); TEST_EQ_P (str, NULL); /* Check that if we empty the buffer of a shutdown socket, the * socket is closed and freed. */ TEST_FEATURE ("with shutdown socket and emptied message"); TEST_FREE_TAG (io); msg = nih_io_message_new (io); assert0 (nih_io_buffer_push (msg->data, "some data\n", 10)); nih_list_add (io->recv_q, &msg->entry); nih_io_shutdown (io); str = nih_io_get (NULL, io, "\n"); TEST_ALLOC_SIZE (str, 10); TEST_EQ_STR (str, "some data"); TEST_FREE (io); TEST_LT (fcntl (fds[0], F_GETFD), 0); TEST_EQ (errno, EBADF); nih_free (str); } void test_printf (void) { NihIo *io; NihIoMessage *msg; int ret, fds[2]; TEST_FUNCTION ("nih_io_printf"); assert0 (pipe (fds)); close (fds[0]); io = nih_io_reopen (NULL, fds[1], NIH_IO_STREAM, NULL, NULL, NULL, NULL); /* Check that we can write a line of formatted data into the send * buffer, which should be written without a NULL terminator. * The watch should also look for writability. */ TEST_FEATURE ("with empty buffer"); TEST_ALLOC_FAIL { io->send_buf->len = 0; io->send_buf->size = 0; ret = nih_io_printf (io, "this is a %d %s test\n", 4, "format"); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (io->send_buf->buf, BUFSIZ); TEST_EQ (io->send_buf->size, BUFSIZ); TEST_EQ (io->send_buf->len, 24); TEST_EQ_MEM (io->send_buf->buf, "this is a 4 format test\n", 24); TEST_TRUE (io->watch->events & NIH_IO_WRITE); } /* Check that we can append a further line of formatted data into * the send buffer */ TEST_FEATURE ("with data in the buffer"); TEST_ALLOC_FAIL { io->send_buf->len = 24; io->send_buf->size = BUFSIZ; ret = nih_io_printf (io, "and this is %s line\n", "another"); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_EQ (io->send_buf->len, 49); TEST_EQ_MEM (io->send_buf->buf, ("this is a 4 format test\n" "and this is another line\n"), 49); } nih_free (io); /* Check that we can write a line of formatted data when we're in * message mode, and have it put in a new message and placed into * the send queue. */ TEST_FEATURE ("with empty send queue"); assert0 (pipe (fds)); close (fds[0]); io = nih_io_reopen (NULL, fds[1], NIH_IO_MESSAGE, NULL, NULL, NULL, NULL); TEST_ALLOC_FAIL { ret = nih_io_printf (io, "this is a %d %s test\n", 4, "format"); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_LIST_NOT_EMPTY (io->send_q); msg = (NihIoMessage *)io->send_q->next; TEST_ALLOC_PARENT (msg, io); TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_ALLOC_SIZE (msg->data->buf, BUFSIZ); TEST_EQ (msg->data->size, BUFSIZ); TEST_EQ (msg->data->len, 24); TEST_EQ_MEM (msg->data->buf, "this is a 4 format test\n", 24); TEST_TRUE (io->watch->events & NIH_IO_WRITE); } /* Check that we can append a further line of formatted data into * the send queue as another new message. */ TEST_FEATURE ("with message in the queue"); TEST_ALLOC_FAIL { ret = nih_io_printf (io, "and this is %s line\n", "another"); if (test_alloc_failed) { TEST_LT (ret, 0); continue; } TEST_EQ (ret, 0); TEST_LIST_NOT_EMPTY (io->send_q); msg = (NihIoMessage *)io->send_q->next; TEST_EQ (msg->data->len, 24); TEST_EQ_MEM (msg->data->buf, "this is a 4 format test\n", 24); msg = (NihIoMessage *)io->send_q->next->next; TEST_ALLOC_PARENT (msg, io); TEST_ALLOC_SIZE (msg, sizeof (NihIoMessage)); TEST_ALLOC_SIZE (msg->data->buf, BUFSIZ); TEST_EQ (msg->data->size, BUFSIZ); TEST_EQ (msg->data->len, 25); TEST_EQ_MEM (msg->data->buf, "and this is another line\n", 25); TEST_TRUE (io->watch->events & NIH_IO_WRITE); } nih_free (io); } void test_set_nonblock (void) { int fds[2], ret; TEST_FUNCTION ("nih_io_set_nonblock"); /* Check that we can trivially mark a socket to be non-blocking. */ TEST_FEATURE ("with valid descriptor"); assert0 (pipe (fds)); ret = nih_io_set_nonblock (fds[0]); TEST_EQ (ret, 0); TEST_TRUE (fcntl (fds[0], F_GETFL) & O_NONBLOCK); close (fds[0]); close (fds[1]); /* Check that we get -1 if the file descriptor is closed. */ TEST_FEATURE ("with closed descriptor"); ret = nih_io_set_nonblock (fds[0]); TEST_LT (ret, 0); } void test_set_cloexec (void) { int fds[2], ret; TEST_FUNCTION ("nih_io_set_cloexec"); /* Check that we can trivially mark a socket to be closed on exec. */ TEST_FEATURE ("with valid descriptor"); assert0 (pipe (fds)); ret = nih_io_set_cloexec (fds[0]); TEST_EQ (ret, 0); TEST_TRUE (fcntl (fds[0], F_GETFD) & FD_CLOEXEC); close (fds[0]); close (fds[1]); /* Check that we get -1 if the file descriptor is closed. */ TEST_FEATURE ("with closed descriptor"); ret = nih_io_set_cloexec (fds[0]); TEST_LT (ret, 0); } void test_get_family (void) { int fd; TEST_FUNCTION ("nih_io_get_family"); /* Check that we can obtain the family of a UNIX socket. */ fd = socket (PF_UNIX, SOCK_STREAM, 0); if (fd < 0) { printf ("SKIP: unix not available\n"); } else { TEST_EQ (nih_io_get_family (fd), PF_UNIX); close (fd); } /* Check that we can obtain the family of an IPv4 socket. */ fd = socket (PF_INET, SOCK_STREAM, 0); if (fd < 0) { printf ("SKIP: inet not available\n"); } else { TEST_EQ (nih_io_get_family (fd), PF_INET); close (fd); } /* Check that we can obtain the family of an IPv6 socket. */ fd = socket (PF_INET6, SOCK_STREAM, 0); if (fd < 0) { printf ("SKIP: inet6 not available\n"); } else { TEST_EQ (nih_io_get_family (fd), PF_INET6); close (fd); } /* Check that we get -1 on error. */ fd = open ("/dev/null", O_RDONLY); close (fd); TEST_LT (nih_io_get_family (fd), 0); } int main (int argc, char *argv[]) { test_add_watch (); test_select_fds (); test_handle_fds (); test_buffer_new (); test_buffer_resize (); test_buffer_pop (); test_buffer_shrink (); test_buffer_push (); test_message_new (); test_message_add_control (); test_message_recv (); test_message_send (); test_reopen (); test_shutdown (); test_destroy (); test_watcher (); test_read_message (); test_send_message (); test_read (); test_write (); test_get (); test_printf (); test_set_nonblock (); test_set_cloexec (); test_get_family (); return 0; } libnih-1.0.3/nih/tests/test_file.c0000644000175000017500000007342211445765555013774 00000000000000/* libnih * * test_file.c - test suite for nih/file.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void test_read (void) { FILE *fd; char filename[PATH_MAX], *file; size_t length; NihError *err; TEST_FUNCTION ("nih_file_read"); nih_error_init (); /* Check that we can read a file into memory, and that the memory * contents match the file. */ TEST_FEATURE ("with existing file"); TEST_FILENAME (filename); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); TEST_ALLOC_FAIL { length = 0; file = nih_file_read (NULL, filename, &length); if (test_alloc_failed) { TEST_EQ_P (file, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_ALLOC_SIZE (file, 5); TEST_NE_P (file, NULL); TEST_EQ (length, 5); TEST_EQ_MEM (file, "test\n", 5); nih_free (file); } unlink (filename); /* Check that if we try and read a non-existant file, we get an * error raised. */ TEST_FEATURE ("with non-existant file"); length = 0; file = nih_file_read (NULL, filename, &length); TEST_EQ_P (file, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOENT); nih_free (err); } void test_map (void) { FILE *fd; char filename[PATH_MAX], text[80], *map; size_t length; NihError *err; TEST_FUNCTION ("nih_file_map"); /* Check that we can map a file into memory for reading, and that * the memory contents match the file. */ TEST_FEATURE ("with read mode"); TEST_FILENAME (filename); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); length = 0; map = nih_file_map (filename, O_RDONLY, &length); TEST_NE_P (map, NULL); TEST_EQ (length, 5); TEST_EQ_MEM (map, "test\n", 5); munmap (map, length); unlink (filename); /* Check that if we try and map a non-existant file for reading, we * get an error raised. */ TEST_FEATURE ("with non-existant file"); length = 0; map = nih_file_map (filename, O_RDONLY, &length); TEST_EQ_P (map, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOENT); nih_free (err); /* Check that we can map a file for both reading and writing, the * memory contents should match the file. */ TEST_FEATURE ("with read/write mode"); TEST_FILENAME (filename); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); length = 0; map = nih_file_map (filename, O_RDWR, &length); TEST_NE_P (map, NULL); TEST_EQ (length, 5); TEST_EQ_MEM (map, "test\n", 5); /* Check that we can alter the memory at that address, and have the * file altered. */ memcpy (map, "cool\n", 5); TEST_EQ_MEM (map, "cool\n", 5); munmap (map, length); fd = fopen (filename, "r"); if (! fgets (text, sizeof (text), fd)) TEST_FAILED ("unexpected eof on file"); TEST_EQ_STR (text, "cool\n"); fclose (fd); unlink (filename); } void test_unmap (void) { FILE *fd; char filename[PATH_MAX], *map; size_t length; int ret; /* Check that we can unmap a file that we mapped with nih_map. * Mostly just make sure it returns zero. */ TEST_FUNCTION ("nih_file_unmap"); TEST_FILENAME (filename); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); length = 0; map = nih_file_map (filename, O_RDONLY, &length); ret = nih_file_unmap (map, length); TEST_EQ (ret, 0); unlink (filename); } void test_is_hidden (void) { int ret; TEST_FUNCTION ("nih_file_is_hidden"); /* Check that a plain file beginning with a dot is hidden. */ TEST_FEATURE ("with plain dot file"); ret = nih_file_is_hidden (".foo"); TEST_TRUE (ret); /* Check that a path with a file beginning with a dot is hidden. */ TEST_FEATURE ("with path to dot file"); ret = nih_file_is_hidden ("/path/to/.foo"); TEST_TRUE (ret); /* Check that a path containing a dot directory is not hidden, * since we're already walking it. */ TEST_FEATURE ("with hidden path to non-dot file"); ret = nih_file_is_hidden ("/path/.to/foo"); TEST_FALSE (ret); /* Check that a plain non-dot file is not hidden. */ TEST_FEATURE ("with plain non-dot file"); ret = nih_file_is_hidden ("foo"); TEST_FALSE (ret); /* Check that a file containing a dot is not hidden. */ TEST_FEATURE ("with ordinary file"); ret = nih_file_is_hidden ("foo.txt"); TEST_FALSE (ret); } void test_is_backup (void) { int ret; TEST_FUNCTION ("nih_file_is_backup"); /* Check that a plain file ending with a tilde is a backup file. */ TEST_FEATURE ("with plain backup file"); ret = nih_file_is_backup ("foo~"); TEST_TRUE (ret); /* Check that a path with a file ending with a tilde is a * backup file. */ TEST_FEATURE ("with path to backup file"); ret = nih_file_is_backup ("/path/to/foo~"); TEST_TRUE (ret); /* Check that a path containing a tilde directory is not backup, * since we're already walking it. */ TEST_FEATURE ("with backup path to non-backup file"); ret = nih_file_is_backup ("/path/to~/foo"); TEST_FALSE (ret); /* Check that a file containing a tilde is not backup. */ TEST_FEATURE ("with file containing tilde"); ret = nih_file_is_backup ("foo~txt"); TEST_FALSE (ret); /* Check that a plain non-backup file is not matched. */ TEST_FEATURE ("with plain non-backup file"); ret = nih_file_is_backup ("foo"); TEST_FALSE (ret); /* Check that a file ending with .bak is a backup file. */ TEST_FEATURE ("with dos-style backup file"); ret = nih_file_is_backup ("foo.bak"); TEST_TRUE (ret); /* Check that a file ending with .BAK is a backup file. */ TEST_FEATURE ("with dos/fat-style backup file"); ret = nih_file_is_backup ("foo.BAK"); TEST_TRUE (ret); /* Check that an emacs-style backup file is matched. */ TEST_FEATURE ("with emacs-style backup file"); ret = nih_file_is_backup ("#foo#"); TEST_TRUE (ret); /* Check that a file beginning with a # is not matched. */ TEST_FEATURE ("with file beginning with hash"); ret = nih_file_is_backup ("#foo"); TEST_FALSE (ret); /* Check that a file ending with a # is not matched. */ TEST_FEATURE ("with file ending with hash"); ret = nih_file_is_backup ("foo#"); TEST_FALSE (ret); } void test_is_swap (void) { int ret; TEST_FUNCTION ("nih_file_is_swap"); /* Check that a plain file beginning with .# is a swap file. */ TEST_FEATURE ("with emacs-style swap file"); ret = nih_file_is_swap (".#foo"); TEST_TRUE (ret); /* Check that a path with a file beginning with .# is a swap file. */ TEST_FEATURE ("with path to emacs-style swap file"); ret = nih_file_is_swap ("/path/to/.#foo"); TEST_TRUE (ret); /* Check that a path containing an emacs-style swap directory is * not swap, since we're already walking it. */ TEST_FEATURE ("with emacs-style swap path to non-swap file"); ret = nih_file_is_swap ("/path/.#to/foo"); TEST_FALSE (ret); /* Check that a file containing the signature is not swap. */ TEST_FEATURE ("with file containing .#"); ret = nih_file_is_swap ("foo.#txt"); TEST_FALSE (ret); /* Check that a plain non-swap file is not matched. */ TEST_FEATURE ("with plain non-swap file"); ret = nih_file_is_swap ("foo"); TEST_FALSE (ret); /* Check that a file ending with .swp is a swap file. */ TEST_FEATURE ("with vi-style .swp file"); ret = nih_file_is_swap ("foo.swp"); TEST_TRUE (ret); /* Check that a file ending with .swo is a swap file. */ TEST_FEATURE ("with vi-style .swo file"); ret = nih_file_is_swap ("foo.swo"); TEST_TRUE (ret); /* Check that a file ending with .swn is a swap file. */ TEST_FEATURE ("with vi-style .swn file"); ret = nih_file_is_swap ("foo.swn"); TEST_TRUE (ret); } void test_is_rcs (void) { int ret; TEST_FUNCTION ("nih_file_is_rcs"); /* Check that a plain file ending with ,v is an RCS file. */ TEST_FEATURE ("with rcs-style file"); ret = nih_file_is_rcs ("foo,v"); TEST_TRUE (ret); /* Check that a path with a file ending with ,v an RCS file. */ TEST_FEATURE ("with path to rcs-style file"); ret = nih_file_is_rcs ("/path/to/foo,v"); TEST_TRUE (ret); /* Check that a path containing an RCS-style directory is not matched, * since we're already walking it. */ TEST_FEATURE ("with rcs-style path to non-rcs file"); ret = nih_file_is_rcs ("/path/to,v/foo"); TEST_FALSE (ret); /* Check that a file containing the signature is not rcs. */ TEST_FEATURE ("with file containing ,v"); ret = nih_file_is_rcs ("foo,vtxt"); TEST_FALSE (ret); /* Check that a plain non-rcs file is not matched. */ TEST_FEATURE ("with plain non-rcs file"); ret = nih_file_is_rcs ("foo"); TEST_FALSE (ret); /* Check that an RCS directory is matched. */ TEST_FEATURE ("with rcs directory name"); ret = nih_file_is_rcs ("RCS"); TEST_TRUE (ret); /* Check that a CVS directory is matched. */ TEST_FEATURE ("with cvs directory name"); ret = nih_file_is_rcs ("CVS"); TEST_TRUE (ret); /* Check that a CVS admin directory is matched. */ TEST_FEATURE ("with cvs admin directory name"); ret = nih_file_is_rcs ("CVS.adm"); TEST_TRUE (ret); /* Check that an SCCS directory is matched. */ TEST_FEATURE ("with sccs directory name"); ret = nih_file_is_rcs ("SCCS"); TEST_TRUE (ret); /* Check that a bazaar directory is matched. */ TEST_FEATURE ("with bzr directory name"); ret = nih_file_is_rcs (".bzr"); TEST_TRUE (ret); /* Check that a bazaar log file is matched. */ TEST_FEATURE ("with bzr log filename"); ret = nih_file_is_rcs (".bzr.log"); TEST_TRUE (ret); /* Check that a mercurial directory is matched. */ TEST_FEATURE ("with mercurial directory name"); ret = nih_file_is_rcs (".hg"); TEST_TRUE (ret); /* Check that a git directory is matched. */ TEST_FEATURE ("with git directory name"); ret = nih_file_is_rcs (".git"); TEST_TRUE (ret); /* Check that a subversion directory is matched. */ TEST_FEATURE ("with subversion directory name"); ret = nih_file_is_rcs (".svn"); TEST_TRUE (ret); /* Check that a BitKeeper directory is matched. */ TEST_FEATURE ("with BitKeeper directory name"); ret = nih_file_is_rcs ("BitKeeper"); TEST_TRUE (ret); /* Check that an arch ids file is matched. */ TEST_FEATURE ("with arch ids filename"); ret = nih_file_is_rcs (".arch-ids"); TEST_TRUE (ret); /* Check that an arch inventory file is matched. */ TEST_FEATURE ("with arch inventory filename"); ret = nih_file_is_rcs (".arch-inventory"); TEST_TRUE (ret); /* Check that an arch directory is matched. */ TEST_FEATURE ("with arch directory name"); ret = nih_file_is_rcs ("{arch}"); TEST_TRUE (ret); /* Check that a darcs directory is matched. */ TEST_FEATURE ("with darcs directory name"); ret = nih_file_is_rcs ("_darcs"); TEST_TRUE (ret); } void test_is_packaging (void) { int ret; TEST_FUNCTION ("nih_file_is_packaging"); /* Check that a plain file ending with a dpkg name is packaging. */ TEST_FEATURE ("with plain dpkg file"); ret = nih_file_is_packaging ("foo.dpkg-new"); TEST_TRUE (ret); /* Check that a path with a file ending with a dpkg name * is packaging */ TEST_FEATURE ("with path to dpkg file"); ret = nih_file_is_packaging ("/path/to/foo.dpkg-bak"); TEST_TRUE (ret); /* Check that a path containing a dpkg directory is not packaging, * since we're already walking it. */ TEST_FEATURE ("with dpkg path to non-packaging file"); ret = nih_file_is_packaging ("/path/to.dpkg-bak/foo"); TEST_FALSE (ret); /* Check that a plain file is not packaging. */ TEST_FEATURE ("with plain file"); ret = nih_file_is_packaging ("foo.txt"); TEST_FALSE (ret); } void test_ignore (void) { int ret; TEST_FUNCTION ("nih_test_ignore"); /* Check that a hidden file is to be ignored. */ TEST_FEATURE ("with hidden file"); ret = nih_file_ignore (NULL, ".foo"); TEST_TRUE (ret); /* Check that a backup file is to be ignored. */ TEST_FEATURE ("with backup file"); ret = nih_file_ignore (NULL, "foo~"); TEST_TRUE (ret); /* Check that a swap file is to be ignored. */ TEST_FEATURE ("with swap file"); ret = nih_file_ignore (NULL, "foo.swp"); TEST_TRUE (ret); /* Check that an RCS file is to be ignored. */ TEST_FEATURE ("with rcs file"); ret = nih_file_ignore (NULL, "CVS"); TEST_TRUE (ret); /* Check that a packaging file is to be ignored. */ TEST_FEATURE ("with packaging file"); ret = nih_file_ignore (NULL, "foo.dpkg-new"); TEST_TRUE (ret); /* Check that an ordinary file isn't ignored. */ TEST_FEATURE ("with ordinary file"); ret = nih_file_ignore (NULL, "foo.txt"); TEST_FALSE (ret); } typedef struct visited { NihList entry; void *data; char *dirname; char *path; } Visited; static NihList *visited = NULL; static int visitor_called = 0; static int my_visitor (void *data, const char *dirname, const char *path, struct stat *statbuf) { Visited *v; visitor_called++; TEST_ALLOC_SAFE { v = nih_new (visited, Visited); nih_list_init (&v->entry); nih_alloc_set_destructor (v, nih_list_destroy); v->data = data; v->dirname = nih_strdup (v, dirname); v->path = nih_strdup (v, path); nih_list_add (visited, &v->entry); } if (data == (void *)-1) { errno = EINVAL; nih_return_system_error (-1); } return 0; } static int error_called = 0; static char *last_error_path = NULL; static int last_error = -1; static int my_error_handler (void *data, const char *dirname, const char *path, struct stat *statbuf) { NihError *err; error_called++; err = nih_error_get (); last_error = err->number; if (last_error_path) free (last_error_path); last_error_path = strdup (path); if (data == (void *)-2) { return -1; } nih_free (err); return 0; } static int my_filter (void *data, const char *path, int is_dir) { char *slash; slash = strrchr (path, '/'); if (! strcmp (slash, "/frodo")) return TRUE; return FALSE; } static int logger_called = 0; static int my_logger (NihLogLevel priority, const char *message) { logger_called++; return 0; } void test_dir_walk (void) { FILE *fd; char dirname[PATH_MAX], filename[PATH_MAX]; int ret; Visited *v; NihError *err; TEST_FUNCTION ("nih_dir_walk"); TEST_FILENAME (dirname); mkdir (dirname, 0755); strcpy (filename, dirname); strcat (filename, "/foo"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); strcpy (filename, dirname); strcat (filename, "/bar"); mkdir (filename, 0755); strcpy (filename, dirname); strcat (filename, "/bar/frodo"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); strcpy (filename, dirname); strcat (filename, "/bar/bilbo"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); strcpy (filename, dirname); strcat (filename, "/baz"); mkdir (filename, 0755); strcpy (filename, dirname); strcat (filename, "/frodo"); mkdir (filename, 0755); strcpy (filename, dirname); strcat (filename, "/frodo/baggins"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); /* Check that when called without a filter, the visitor is called * for all paths found underneath the tree; getting passed the * correct data pointer, top-level path and path name, */ TEST_FEATURE ("with no filter"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { visitor_called = 0; visited = nih_list_new (NULL); } ret = nih_dir_walk (dirname, NULL, my_visitor, NULL, &ret); TEST_EQ (ret, 0); TEST_EQ (visitor_called, 7); v = (Visited *)visited->next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar/bilbo"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar/frodo"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/baz"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/foo"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/frodo"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/frodo/baggins"); TEST_EQ_STR (v->path, filename); nih_free (visited); } /* Check that a filter can be used to restrict the names of * objects visited and descended into. */ TEST_FEATURE ("with filter"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { visitor_called = 0; visited = nih_list_new (NULL); } ret = nih_dir_walk (dirname, my_filter, my_visitor, NULL, &ret); TEST_EQ (ret, 0); TEST_EQ (visitor_called, 4); v = (Visited *)visited->next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar/bilbo"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/baz"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/foo"); TEST_EQ_STR (v->path, filename); nih_free (visited); } /* Check that failing to stat a file or directory in the tree with * no error handler set results in a warning being emitted and us * stepping over it. */ TEST_FEATURE ("with stat failure and no error handler"); strcpy (filename, dirname); strcat (filename, "/bar"); chmod (filename, 0644); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { visitor_called = 0; visited = nih_list_new (NULL); } logger_called = 0; nih_log_set_logger (my_logger); ret = nih_dir_walk (dirname, my_filter, my_visitor, NULL, &ret); nih_log_set_logger (nih_logger_printf); TEST_EQ (logger_called, 1); TEST_EQ (ret, 0); TEST_EQ (visitor_called, 3); v = (Visited *)visited->next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/baz"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/foo"); TEST_EQ_STR (v->path, filename); nih_free (visited); } strcpy (filename, dirname); strcat (filename, "/bar"); chmod (filename, 0755); /* Check that failing to stat a file or directory in the tree with * an error handler set results in the handler being called. */ TEST_FEATURE ("with stat failure and error handler"); strcpy (filename, dirname); strcat (filename, "/bar"); chmod (filename, 0644); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { visitor_called = 0; visited = nih_list_new (NULL); } error_called = 0; last_error = -1; last_error_path = NULL; ret = nih_dir_walk (dirname, my_filter, my_visitor, my_error_handler, &ret); TEST_EQ (error_called, 1); TEST_EQ (last_error, EACCES); strcpy (filename, dirname); strcat (filename, "/bar/bilbo"); TEST_EQ_STR (last_error_path, filename); free (last_error_path); TEST_EQ (ret, 0); TEST_EQ (visitor_called, 3); v = (Visited *)visited->next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/baz"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/foo"); TEST_EQ_STR (v->path, filename); nih_free (visited); } strcpy (filename, dirname); strcat (filename, "/bar"); chmod (filename, 0755); /* Check that the error handler can return a negative value and * raised error to abort the directory walk. */ TEST_FEATURE ("with error from error handler"); strcpy (filename, dirname); strcat (filename, "/bar"); chmod (filename, 0644); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { visitor_called = 0; visited = nih_list_new (NULL); } error_called = 0; last_error = -1; last_error_path = NULL; ret = nih_dir_walk (dirname, my_filter, my_visitor, my_error_handler, (void *)-2); TEST_EQ (error_called, 1); TEST_EQ (last_error, EACCES); strcpy (filename, dirname); strcat (filename, "/bar/bilbo"); TEST_EQ_STR (last_error_path, filename); free (last_error_path); err = nih_error_get (); TEST_EQ (err->number, EACCES); nih_free (err); TEST_EQ (ret, -1); TEST_EQ (visitor_called, 1); v = (Visited *)visited->next; TEST_EQ (v->data, (void *)-2); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar"); TEST_EQ_STR (v->path, filename); nih_free (visited); } strcpy (filename, dirname); strcat (filename, "/bar"); chmod (filename, 0755); /* Check that a complete failure to walk a sub-directory underneath * the tree also results in the error handler being called. */ TEST_FEATURE ("with inability to walk a sub-directory"); strcpy (filename, dirname); strcat (filename, "/bar"); chmod (filename, 0000); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { visitor_called = 0; visited = nih_list_new (NULL); } error_called = 0; last_error = -1; last_error_path = NULL; ret = nih_dir_walk (dirname, my_filter, my_visitor, my_error_handler, &ret); TEST_EQ (error_called, 1); TEST_EQ (last_error, EACCES); strcpy (filename, dirname); strcat (filename, "/bar"); TEST_EQ_STR (last_error_path, filename); free (last_error_path); TEST_EQ (ret, 0); TEST_EQ (visitor_called, 3); v = (Visited *)visited->next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/baz"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/foo"); TEST_EQ_STR (v->path, filename); nih_free (visited); } strcpy (filename, dirname); strcat (filename, "/bar"); chmod (filename, 0755); /* Check that a warning is emitted if the visitor raises an error * when there is no error handler set. */ TEST_FEATURE ("with error in visitor"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { visitor_called = 0; visited = nih_list_new (NULL); } logger_called = 0; nih_log_set_logger (my_logger); ret = nih_dir_walk (dirname, my_filter, my_visitor, NULL, (void *)-1); nih_log_set_logger (nih_logger_printf); TEST_EQ (logger_called, 3); TEST_EQ (ret, 0); TEST_EQ (visitor_called, 3); v = (Visited *)visited->next; TEST_EQ (v->data, (void *)-1); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, (void *)-1); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/baz"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, (void *)-1); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/foo"); TEST_EQ_STR (v->path, filename); nih_free (visited); } /* Check that the error handled is called if the visitor raises * an error. */ TEST_FEATURE ("with error in visitor and handler"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { visitor_called = 0; visited = nih_list_new (NULL); } error_called = 0; last_error = -1; last_error_path = NULL; ret = nih_dir_walk (dirname, my_filter, my_visitor, my_error_handler, (void *)-1); TEST_EQ (error_called, 3); free (last_error_path); TEST_EQ (ret, 0); TEST_EQ (visitor_called, 3); v = (Visited *)visited->next; TEST_EQ (v->data, (void *)-1); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, (void *)-1); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/baz"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, (void *)-1); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/foo"); TEST_EQ_STR (v->path, filename); nih_free (visited); } /* Check that we get a ENOTDIR error if we try and walk a file * and there's no error handler set. */ TEST_FEATURE ("with non-directory and no error handler"); strcpy (filename, dirname); strcat (filename, "/foo"); TEST_ALLOC_FAIL { visitor_called = 0; ret = nih_dir_walk (filename, my_filter, my_visitor, NULL, &ret); TEST_EQ (ret, -1); TEST_EQ (visitor_called, 0); err = nih_error_get (); TEST_EQ (err->number, ENOTDIR); nih_free (err); } /* Check that we still get a ENOTDIR error if we try and walk a file * and there is an error handler set. */ TEST_FEATURE ("with non-directory and error handler"); strcpy (filename, dirname); strcat (filename, "/foo"); TEST_ALLOC_FAIL { visitor_called = 0; error_called = 0; ret = nih_dir_walk (filename, my_filter, my_visitor, my_error_handler, &ret); TEST_EQ (ret, -1); TEST_EQ (visitor_called, 0); TEST_EQ (error_called, 0); err = nih_error_get (); TEST_EQ (err->number, ENOTDIR); nih_free (err); } /* Check that we can detect the simplest kind of directory loop, and * have it treated as an ordinary error while visiting. */ TEST_FEATURE ("with simple directory loop"); strcpy (filename, dirname); strcat (filename, "/bar/loop"); assert0 (symlink (dirname, filename)); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { visitor_called = 0; visited = nih_list_new (NULL); } error_called = 0; last_error = -1; last_error_path = NULL; ret = nih_dir_walk (dirname, my_filter, my_visitor, my_error_handler, &ret); TEST_EQ (error_called, 1); TEST_EQ (last_error, NIH_DIR_LOOP_DETECTED); strcpy (filename, dirname); strcat (filename, "/bar/loop"); TEST_EQ_STR (last_error_path, filename); free (last_error_path); TEST_EQ (ret, 0); TEST_EQ (visitor_called, 5); v = (Visited *)visited->next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar/bilbo"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/bar/loop"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/baz"); TEST_EQ_STR (v->path, filename); v = (Visited *)v->entry.next; TEST_EQ (v->data, &ret); TEST_EQ_STR (v->dirname, dirname); strcpy (filename, dirname); strcat (filename, "/foo"); TEST_EQ_STR (v->path, filename); nih_free (visited); } strcpy (filename, dirname); strcat (filename, "/bar/loop"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/foo"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/bar/frodo"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/bar/bilbo"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/bar"); rmdir (filename); strcpy (filename, dirname); strcat (filename, "/baz"); rmdir (filename); strcpy (filename, dirname); strcat (filename, "/frodo/baggins"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/frodo"); rmdir (filename); rmdir (dirname); } int main (int argc, char *argv[]) { test_read (); test_map (); test_unmap (); test_is_hidden (); test_is_backup (); test_is_swap (); test_is_rcs (); test_is_packaging (); test_ignore (); test_dir_walk (); return 0; } libnih-1.0.3/nih/tests/test_command.c0000644000175000017500000005414411445765555014473 00000000000000/* libnih * * test_command.c - test suite for nih/command.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include static int dry_run = 0; static int wobble = 0; static int was_called = 0; static NihCommand *last_command = NULL; static char *last_arg0 = NULL; static char *last_arg1 = NULL; static int my_action (NihCommand *command, char * const *args) { was_called++; last_command = malloc (sizeof (NihCommand)); memcpy (last_command, command, sizeof (NihCommand)); if (args[0]) { last_arg0 = strdup (args[0]); if (args[1]) { last_arg1 = strdup (args[1]); } else { last_arg1 = NULL; } if (! strcmp (args[0], "fail")) return -1; } else { last_arg0 = NULL; last_arg1 = NULL; } return 0; } static NihOption options[] = { { 'n', "dry-run", N_("simulate and output actions only"), NULL, NULL, &dry_run, NULL }, NIH_OPTION_LAST }; static NihOption wibble_options[] = { { 0, "wobble", N_("wobble file while wibbling"), NULL, NULL, &wobble, NULL }, NIH_OPTION_LAST }; static NihCommandGroup test_group1 = { "First test group" }; static NihCommandGroup test_group2 = { "Second test group" }; static NihCommand commands[] = { { "foo", NULL, N_("do something fooish"), NULL, &test_group1, NULL, my_action }, { "bar", N_("FILE"), N_("do something barish to a file"), NULL, &test_group1, NULL, my_action }, { "baz", NULL, N_("do something bazish"), NULL, &test_group2, NULL, my_action }, { "wibble", N_("SRC DEST"), N_("wibble a file from one place to another"), N_("Takes the file from SRC, wibbles it until any loose pieces " "fall off, and until it reaches DEST. SRC and DEST may not " "be the same location."), NULL, wibble_options, my_action }, NIH_COMMAND_LAST }; static NihCommand commands2[] = { { "really-overly-long-command-name", NULL, N_("does something irrelevant, and the synopsis is long enough to " "wrap across multiple lines"), NULL, NULL, NULL, NULL }, { "hidden", NULL, NULL, NULL, NULL, NULL, NULL }, NIH_COMMAND_LAST }; void test_parser (void) { FILE *output; char *argv[16]; int argc, ret = 0; TEST_FUNCTION ("nih_command_parser"); program_name = "test"; output = tmpfile (); /* Check that the command parser calls the command function, and * when there are no arguments, just passes in a NULL array. */ TEST_FEATURE ("with just command"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "foo"; argv[argc] = NULL; was_called = 0; last_command = NULL; last_arg0 = NULL; last_arg1 = NULL; ret = nih_command_parser (NULL, argc, argv, options, commands); TEST_EQ (ret, 0); TEST_TRUE (was_called); TEST_EQ_STR (last_command->command, "foo"); TEST_EQ_P (last_arg0, NULL); free (last_command); } /* Check that a global option that appears before a command is * honoured. */ TEST_FEATURE ("with global option followed by command"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-n"; argv[argc++] = "foo"; argv[argc] = NULL; dry_run = 0; was_called = 0; last_command = NULL; last_arg0 = NULL; last_arg1 = NULL; ret = nih_command_parser (NULL, argc, argv, options, commands); TEST_EQ (ret, 0); TEST_TRUE (dry_run); TEST_TRUE (was_called); TEST_EQ_STR (last_command->command, "foo"); TEST_EQ_P (last_arg0, NULL); free (last_command); } /* Check that a global option that appears after a command is * still honoured, despite not being in the command's own options. */ TEST_FEATURE ("with command followed by global option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "foo"; argv[argc++] = "-n"; argv[argc] = NULL; dry_run = 0; was_called = 0; last_command = NULL; last_arg0 = NULL; last_arg1 = NULL; ret = nih_command_parser (NULL, argc, argv, options, commands); TEST_EQ (ret, 0); TEST_TRUE (dry_run); TEST_TRUE (was_called); TEST_EQ_STR (last_command->command, "foo"); TEST_EQ_P (last_arg0, NULL); free (last_command); } /* Check that a command's own options are also honoured. */ TEST_FEATURE ("with command followed by specific option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "wibble"; argv[argc++] = "--wobble"; argv[argc] = NULL; wobble = 0; was_called = 0; last_command = NULL; last_arg0 = NULL; last_arg1 = NULL; ret = nih_command_parser (NULL, argc, argv, options, commands); TEST_EQ (ret, 0); TEST_TRUE (wobble); TEST_TRUE (was_called); TEST_EQ_STR (last_command->command, "wibble"); TEST_EQ_P (last_arg0, NULL); free (last_command); } /* Check that global options and command-specific options can be * both given at once. */ TEST_FEATURE ("with global option, command, then specific option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--dry-run"; argv[argc++] = "wibble"; argv[argc++] = "--wobble"; argv[argc] = NULL; wobble = 0; dry_run = 0; was_called = 0; last_command = NULL; last_arg0 = NULL; last_arg1 = NULL; ret = nih_command_parser (NULL, argc, argv, options, commands); TEST_EQ (ret, 0); TEST_TRUE (wobble); TEST_TRUE (dry_run); TEST_TRUE (was_called); TEST_EQ_STR (last_command->command, "wibble"); TEST_EQ_P (last_arg0, NULL); free (last_command); } /* Check that a double-dash terminator may appear before a command, * which only terminates the global options, not the command-specific * ones. */ TEST_FEATURE ("with terminator before command"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--dry-run"; argv[argc++] = "--"; argv[argc++] = "wibble"; argv[argc++] = "--wobble"; argv[argc] = NULL; wobble = 0; dry_run = 0; was_called = 0; last_command = NULL; last_arg0 = NULL; last_arg1 = NULL; ret = nih_command_parser (NULL, argc, argv, options, commands); TEST_EQ (ret, 0); TEST_TRUE (wobble); TEST_TRUE (dry_run); TEST_TRUE (was_called); TEST_EQ_STR (last_command->command, "wibble"); TEST_EQ_P (last_arg0, NULL); free (last_command); } /* Check that a double-dash terminator may appear after a command, * which terminates the option processing for that command as well. * Any option-like argument is passed to the function as an ordinary * argument in the array. */ TEST_FEATURE ("with terminator before and after command"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--dry-run"; argv[argc++] = "--"; argv[argc++] = "wibble"; argv[argc++] = "--"; argv[argc++] = "--wobble"; argv[argc] = NULL; wobble = 0; dry_run = 0; was_called = 0; last_command = NULL; last_arg0 = NULL; last_arg1 = NULL; ret = nih_command_parser (NULL, argc, argv, options, commands); TEST_EQ (ret, 0); TEST_FALSE (wobble); TEST_TRUE (dry_run); TEST_TRUE (was_called); TEST_EQ_STR (last_command->command, "wibble"); TEST_EQ_STR (last_arg0, "--wobble"); TEST_EQ_P (last_arg1, NULL); free (last_arg0); free (last_command); } /* Check that non-option arguments may follow a command, they're * collected and passed to the function in a NULL-terminated array. */ TEST_FEATURE ("with command and single argument"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "bar"; argv[argc++] = "snarf"; argv[argc] = NULL; was_called = 0; last_command = NULL; last_arg0 = NULL; last_arg1 = NULL; ret = nih_command_parser (NULL, argc, argv, options, commands); TEST_EQ (ret, 0); TEST_TRUE (was_called); TEST_EQ_STR (last_command->command, "bar"); TEST_EQ_STR (last_arg0, "snarf"); TEST_EQ_P (last_arg1, NULL); free (last_arg0); free (last_command); } /* Check that multiple arguments after the command are all passed * in the array. */ TEST_FEATURE ("with command and multiple arguments"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "wibble"; argv[argc++] = "snarf"; argv[argc++] = "lick"; argv[argc] = NULL; was_called = 0; last_command = NULL; last_arg0 = NULL; last_arg1 = NULL; ret = nih_command_parser (NULL, argc, argv, options, commands); TEST_EQ (ret, 0); TEST_TRUE (was_called); TEST_EQ_STR (last_command->command, "wibble"); TEST_EQ_STR (last_arg0, "snarf"); TEST_EQ_STR (last_arg1, "lick"); free (last_arg0); free (last_arg1); free (last_command); } /* Check that an invalid global option appearing results in the * parser returning a negative number and outputting an error * message to stderr with a suggestion about help. */ TEST_FEATURE ("with invalid global option before command"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-z"; argv[argc++] = "foo"; argv[argc] = NULL; was_called = 0; TEST_DIVERT_STDERR (output) { ret = nih_command_parser (NULL, argc, argv, options, commands); } rewind (output); TEST_LT (ret, 0); TEST_FALSE (was_called); TEST_FILE_EQ (output, "test: invalid option: -z\n"); TEST_FILE_EQ (output, "Try `test --help' for more information.\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid option appearing after the command also * results in the parser returning an error without running the * command function. */ TEST_FEATURE ("with invalid option after command"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "foo"; argv[argc++] = "-z"; argv[argc] = NULL; was_called = 0; TEST_DIVERT_STDERR (output) { ret = nih_command_parser (NULL, argc, argv, options, commands); } rewind (output); TEST_LT (ret, 0); TEST_FALSE (was_called); TEST_FILE_EQ (output, "test: invalid option: -z\n"); TEST_FILE_EQ (output, "Try `test --help' for more information.\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a missing command entirely results in the parser * terminating with an error and outputting a message. */ TEST_FEATURE ("with missing command"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc] = NULL; was_called = 0; TEST_DIVERT_STDERR (output) { ret = nih_command_parser (NULL, argc, argv, options, commands); } rewind (output); TEST_LT (ret, 0); TEST_FALSE (was_called); TEST_FILE_EQ (output, "test: missing command\n"); TEST_FILE_EQ (output, "Try `test --help' for more information.\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid command results in the parser returning * an error and outputting a message. */ TEST_FEATURE ("with invalid command"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "lick"; argv[argc] = NULL; was_called = 0; TEST_DIVERT_STDERR (output) { ret = nih_command_parser (NULL, argc, argv, options, commands); } rewind (output); TEST_LT (ret, 0); TEST_FALSE (was_called); TEST_FILE_EQ (output, "test: invalid command: lick\n"); TEST_FILE_EQ (output, "Try `test --help' for more information.\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that the command may appear in the program name instead, * in which case all arguments are used including the first, and * all options considered to be both global and command options. */ TEST_FEATURE ("with command in program name"); TEST_ALLOC_FAIL { program_name = "wibble"; argc = 0; argv[argc++] = "ignored"; argv[argc++] = "snarf"; argv[argc++] = "lick"; argv[argc++] = "--wobble"; argv[argc++] = "-n"; argv[argc] = NULL; dry_run = 0; wobble = 0; was_called = 0; last_command = NULL; last_arg0 = NULL; last_arg1 = NULL; ret = nih_command_parser (NULL, argc, argv, options, commands); TEST_EQ (ret, 0); TEST_TRUE (dry_run); TEST_TRUE (wobble); TEST_TRUE (was_called); TEST_EQ_STR (last_command->command, "wibble"); TEST_EQ_STR (last_arg0, "snarf"); TEST_EQ_STR (last_arg1, "lick"); free (last_arg0); free (last_arg1); free (last_command); } fclose (output); } void test_help (void) { FILE *output; char *argv[4]; pid_t pid; int argc, status; TEST_FUNCTION ("nih_command_help"); output = tmpfile (); /* Check that we can obtain a list of command using the "help" * command; which terminates the process with exit code 0. The * output should be grouped according to the command group, and * each command indented with the text alongside and wrapped. */ TEST_FEATURE ("with multiple groups"); nih_main_init_full ("test", "wibble", "1.0", "foo@bar.com", "Copyright Message"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "help"; argv[argc] = NULL; TEST_CHILD (pid) { unsetenv ("COLUMNS"); TEST_DIVERT_STDOUT (output) { nih_command_parser (NULL, argc, argv, options, commands); exit (1); } } waitpid (pid, &status, 0); rewind (output); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_FILE_EQ (output, "First test group commands:\n"); TEST_FILE_EQ (output, (" foo " "do something fooish\n")); TEST_FILE_EQ (output, (" bar " "do something barish to a file\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "Second test group commands:\n"); TEST_FILE_EQ (output, (" baz " "do something bazish\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "Other commands:\n"); TEST_FILE_EQ (output, (" wibble " "wibble a file from one place to " "another\n")); TEST_FILE_EQ (output, (" help " "display list of commands\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, ("For more information on a command, " "try `test COMMAND --help'.\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that if there's only a single group, the title is different; * also check that an overly long command name is wrapped properly, * synopsis is wrapped to multiple lines and a command without a * synopsis is not output at all. */ TEST_FEATURE ("with single group and long name"); nih_main_init_full ("test", "wibble", "1.0", "foo@bar.com", "Copyright Message"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "help"; argv[argc] = NULL; TEST_CHILD (pid) { unsetenv ("COLUMNS"); TEST_DIVERT_STDOUT (output) { nih_command_parser (NULL, argc, argv, options, commands2); exit (1); } } waitpid (pid, &status, 0); rewind (output); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_FILE_EQ (output, "Commands:\n"); TEST_FILE_EQ (output, " really-overly-long-command-name\n"); TEST_FILE_EQ (output, (" " "does something irrelevant, and the " "synopsis is\n")); TEST_FILE_EQ (output, (" " "long enough to wrap across multiple " "lines\n")); TEST_FILE_EQ (output, (" help " "display list of commands\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, ("For more information on a command, " "try `test COMMAND --help'.\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that the command functions sufficiently wrap the * nih_option_help function such that we can obtain help for the * program as a whole and get a message saying how to see the * commands list. */ TEST_FUNCTION ("nih_option_help"); TEST_FEATURE ("with no command"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--help"; argv[argc] = NULL; nih_option_set_synopsis ("This is my program"); nih_option_set_help ("Some help text"); TEST_CHILD (pid) { unsetenv ("COLUMNS"); TEST_DIVERT_STDOUT (output) { nih_command_parser (NULL, argc, argv, options, commands); exit (1); } } waitpid (pid, &status, 0); rewind (output); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_FILE_EQ (output, ("Usage: test [OPTION]... " "COMMAND [OPTION]... [ARG]...\n")); TEST_FILE_EQ (output, "This is my program\n"); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "Options:\n"); TEST_FILE_EQ (output, (" -n, --dry-run " "simulate and output actions only\n")); TEST_FILE_EQ (output, (" -q, --quiet " "reduce output to errors only\n")); TEST_FILE_EQ (output, (" -v, --verbose " "increase output to include " "informational messages\n")); TEST_FILE_EQ (output, (" --help " "display this help and exit\n")); TEST_FILE_EQ (output, (" --version " "output version information and " "exit\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "Some help text\n"); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, ("For a list of commands, " "try `test help'.\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "Report bugs to \n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that the wrapping is sufficient that following a command * with the --help option outputs help for that option, including * the global options in the list. */ TEST_FEATURE ("with a command"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "wibble"; argv[argc++] = "--help"; argv[argc] = NULL; TEST_CHILD (pid) { unsetenv ("COLUMNS"); TEST_DIVERT_STDOUT (output) { nih_command_parser (NULL, argc, argv, options, commands); exit (1); } } waitpid (pid, &status, 0); rewind (output); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_FILE_EQ (output, ("Usage: test wibble [OPTION]... " "SRC DEST\n")); TEST_FILE_EQ (output, ("wibble a file from one place " "to another\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "Options:\n"); TEST_FILE_EQ (output, (" --wobble " "wobble file while wibbling\n")); TEST_FILE_EQ (output, (" -n, --dry-run " "simulate and output actions only\n")); TEST_FILE_EQ (output, (" -q, --quiet " "reduce output to errors only\n")); TEST_FILE_EQ (output, (" -v, --verbose " "increase output to include " "informational messages\n")); TEST_FILE_EQ (output, (" --help " "display this help and exit\n")); TEST_FILE_EQ (output, (" --version " "output version information " "and exit\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, ("Takes the file from SRC, wibbles it " "until any loose pieces fall off, and " "until\n")); TEST_FILE_EQ (output, ("it reaches DEST. SRC and DEST may " "not be the same location.\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "Report bugs to \n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that --help works if the program name itself is the name * of the command, it should behave as if the real binary were * called with the command as the first argument, except all of the * usage strings, etc. should make sense. */ TEST_FEATURE ("with command in program_name"); TEST_ALLOC_FAIL { program_name = "wibble"; argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--help"; argv[argc] = NULL; TEST_CHILD (pid) { unsetenv ("COLUMNS"); TEST_DIVERT_STDOUT (output) { nih_command_parser (NULL, argc, argv, options, commands); exit (1); } } waitpid (pid, &status, 0); rewind (output); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_FILE_EQ (output, "Usage: wibble [OPTION]... SRC DEST\n"); TEST_FILE_EQ (output, ("wibble a file from one place to " "another\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "Options:\n"); TEST_FILE_EQ (output, (" --wobble " "wobble file while wibbling\n")); TEST_FILE_EQ (output, (" -n, --dry-run " "simulate and output actions only\n")); TEST_FILE_EQ (output, (" -q, --quiet " "reduce output to errors only\n")); TEST_FILE_EQ (output, (" -v, --verbose " "increase output to include " "informational messages\n")); TEST_FILE_EQ (output, (" --help " "display this help and exit\n")); TEST_FILE_EQ (output, (" --version " "output version information and " "exit\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, ("Takes the file from SRC, wibbles it " "until any loose pieces fall off, and " "until\n")); TEST_FILE_EQ (output, ("it reaches DEST. SRC and DEST may " "not be the same location.\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "Report bugs to \n"); TEST_FILE_END (output); } fclose (output); } int main (int argc, char *argv[]) { test_parser (); test_help (); return 0; } libnih-1.0.3/nih/tests/test_option.c0000644000175000017500000012034411445765555014361 00000000000000/* libnih * * test_option.c - test suite for nih/option.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include static int daemonise = 0; static int recursive = 0; static char *filename = NULL; static char *wibble = NULL; static char *option = NULL; static int was_called = 0; static NihOption *last_option = NULL; static const char *last_arg = NULL; static int my_setter (NihOption *option, const char *arg) { was_called++; last_option = malloc (sizeof (NihOption)); memcpy (last_option, option, sizeof (NihOption)); last_arg = arg; if (arg && (! strcmp (arg, "fail"))) return -1; return 0; } static NihOptionGroup test_group1 = { "First test group" }; static NihOptionGroup test_group2 = { "Second test group" }; static NihOption options[] = { { 'd', NULL, "become daemon", &test_group1, NULL, &daemonise, NULL }, { 'f', "filename", "read this file", &test_group1, "FILENAME", &filename, NULL }, { 'R', "recursive", "descend into sub-directories", &test_group2, NULL, &recursive, NULL }, { 0, "wibble", "bored of inventing names", &test_group2, NULL, &wibble, NULL }, { 'o', "option", "extended options", &test_group2, "OPTION", &option, NULL }, { 's', "special", "something with special treatment", &test_group2, "SPECIAL-LONG-ARGUMENT-NAME", NULL, my_setter }, { 'x', "execute", ("run something, give this a really long help " "message so that it word wraps"), &test_group1, NULL, NULL, my_setter }, { 'I', NULL, "add directory to include list", &test_group1, "DIRECTORY", NULL, NULL }, NIH_OPTION_LAST }; static NihOption catch_options[] = { { '-', "--", NULL, NULL, NULL, NULL, NULL }, NIH_OPTION_LAST }; void test_parser (void) { FILE *output; char *argv[16], **args = NULL; int argc; TEST_FUNCTION ("nih_option_parser"); output = tmpfile (); program_name = "test"; /* Check that the option parser can be called with no arguments, * which results in a single-element array being returned with * NULL in the array. */ TEST_FEATURE ("with no arguments"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc] = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); nih_free (args); } /* Check that all non-option arguments are passed through into the * returned NULL-terminated array. */ TEST_FEATURE ("with all non-option arguments"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "foo"; argv[argc++] = "bar"; argv[argc++] = "baz"; argv[argc] = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "foo"); TEST_EQ_STR (args[1], "bar"); TEST_EQ_STR (args[2], "baz"); TEST_EQ_P (args[3], NULL); nih_free (args); } /* Check that a dash on its own is not taken from the arguments. */ TEST_FEATURE ("with lone dash"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-"; argv[argc] = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "-"); TEST_EQ_P (args[1], NULL); nih_free (args); } /* Check that a single short option is taken from the arguments and * the appropriate variable set. */ TEST_FEATURE ("with single short option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-d"; argv[argc] = NULL; daemonise = 0; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_TRUE (daemonise); nih_free (args); } /* Check that all short options are taken from the arguments and * all of the appropriate variables set. */ TEST_FEATURE ("with multiple short options"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-d"; argv[argc++] = "-R"; argv[argc] = NULL; daemonise = 0; recursive = 0; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_TRUE (daemonise); TEST_TRUE (recursive); nih_free (args); } /* Check that multiple short options can be combined into a single * argument, and that they're all handled. */ TEST_FEATURE ("with combined short options"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-dR"; argv[argc] = NULL; daemonise = 0; recursive = 0; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_TRUE (daemonise); TEST_TRUE (recursive); nih_free (args); } /* Check that short options and ordinary arguments can be intermixed, * the arguments are returned in the array and the option values set. */ TEST_FEATURE ("with intermixed short options and arguments"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "foo"; argv[argc++] = "-d"; argv[argc++] = "bar"; argv[argc++] = "-R"; argv[argc++] = "baz"; argv[argc] = NULL; daemonise = 0; recursive = 0; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "foo"); TEST_EQ_STR (args[1], "bar"); TEST_EQ_STR (args[2], "baz"); TEST_EQ_P (args[3], NULL); TEST_TRUE (daemonise); TEST_TRUE (recursive); nih_free (args); } /* Check that the first non-option argument can terminate the * processing of other options when in command mode, and that the * remaining options are returned in the array and the values NOT * set. */ TEST_FEATURE ("with command-mode short options and arguments"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "foo"; argv[argc++] = "-d"; argv[argc++] = "bar"; argv[argc++] = "-R"; argv[argc++] = "baz"; argv[argc] = NULL; daemonise = 0; recursive = 0; args = nih_option_parser (NULL, argc, argv, options, TRUE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "foo"); TEST_EQ_STR (args[1], "-d"); TEST_EQ_STR (args[2], "bar"); TEST_EQ_STR (args[3], "-R"); TEST_EQ_STR (args[4], "baz"); TEST_EQ_P (args[5], NULL); TEST_FALSE (daemonise); TEST_FALSE (recursive); nih_free (args); } /* Check that option processing can be terminated by a double-dash, * and that following options are placed in the arguments and the * values NOT set. */ TEST_FEATURE ("with short options and terminator"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "foo"; argv[argc++] = "-d"; argv[argc++] = "--"; argv[argc++] = "bar"; argv[argc++] = "-R"; argv[argc++] = "baz"; argv[argc] = NULL; daemonise = 0; recursive = 0; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "foo"); TEST_EQ_STR (args[1], "bar"); TEST_EQ_STR (args[2], "-R"); TEST_EQ_STR (args[3], "baz"); TEST_EQ_P (args[4], NULL); TEST_TRUE (daemonise); TEST_FALSE (recursive); nih_free (args); } /* Check that a short option can eat the next non-option argument * as its own argument, which is stored in its value and not * returned in the array. */ TEST_FEATURE ("with short argument option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-f"; argv[argc++] = "foo"; argv[argc] = NULL; filename = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_EQ_STR (filename, "foo"); nih_free (filename); nih_free (args); } /* Check that a short option with an argument can be specified * multiple times, with only the last one being kept. */ TEST_FEATURE ("with repeated short argument option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-f"; argv[argc++] = "foo"; argv[argc++] = "-f"; argv[argc++] = "bar"; argv[argc] = NULL; filename = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_EQ_STR (filename, "bar"); nih_free (filename); nih_free (args); } /* Check that only the next non-option argument is eaten, and the * rest of the arguments are returned in the array. */ TEST_FEATURE ("with short argument option and other arguments"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-f"; argv[argc++] = "foo"; argv[argc++] = "bar"; argv[argc++] = "baz"; argv[argc] = NULL; filename = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "bar"); TEST_EQ_STR (args[1], "baz"); TEST_EQ_P (args[2], NULL); TEST_EQ_STR (filename, "foo"); nih_free (filename); nih_free (args); } /* Stress test all the various ways of dealing with short options * at once; in particular check that an option that takes an argument * eats the first argument after the terminator. */ TEST_FEATURE ("with random mix of short options and arguments"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "wibble"; argv[argc++] = "-df"; argv[argc++] = "--"; argv[argc++] = "foo"; argv[argc++] = "-R"; argv[argc++] = "bar"; argv[argc++] = "baz"; argv[argc] = NULL; daemonise = 0; recursive = 0; filename = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "wibble"); TEST_EQ_STR (args[1], "-R"); TEST_EQ_STR (args[2], "bar"); TEST_EQ_STR (args[3], "baz"); TEST_EQ_P (args[4], NULL); TEST_TRUE (daemonise); TEST_FALSE (recursive); TEST_EQ_STR (filename, "foo"); nih_free (filename); nih_free (args); } /* Check that the argument for a short option can immediately * follow it, combined into one word. Check that the characters * of this word aren't treated as options. */ TEST_FEATURE ("with short option and embedded argument"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-fROOT"; argv[argc] = NULL; filename = NULL; recursive = 0; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_EQ_STR (filename, "ROOT"); TEST_FALSE (recursive); nih_free (filename); nih_free (args); } /* Check that the short option may be inside a sequence of short * options in one argument, and then only the next non-option argument * is considered, not the remainder of the option argument. */ TEST_FEATURE ("with short option and non-embedded argument"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-dfR"; argv[argc++] = "foo"; argv[argc] = NULL; filename = NULL; daemonise = 0; recursive = 0; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_TRUE (daemonise); TEST_TRUE (recursive); TEST_EQ_STR (filename, "foo"); nih_free (filename); nih_free (args); } /* Check that multiple short options which accept arguments each * take the next non-option argument, not themselves or the same * argument. */ TEST_FEATURE ("with multiple short argument options"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-f"; argv[argc++] = "-o"; argv[argc++] = "foo"; argv[argc++] = "bar"; argv[argc] = NULL; filename = NULL; option = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_EQ_STR (filename, "foo"); TEST_EQ_STR (option, "bar"); nih_free (filename); nih_free (option); nih_free (args); } /* Check that a single long option is taken from the arguments and * the appropriate variable set. */ TEST_FEATURE ("with single long option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--wibble"; argv[argc] = NULL; wibble = 0; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_TRUE (wibble); nih_free (args); } /* Check that multiple long options are taken from the arguments * and the appropriate variables set. */ TEST_FEATURE ("with multiple long options"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--wibble"; argv[argc++] = "--recursive"; argv[argc] = NULL; wibble = 0; recursive = 0; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_TRUE (wibble); TEST_TRUE (recursive); nih_free (args); } /* Check that only the long options are taken from the arguments, * and the non-option arguments are returned in the array. */ TEST_FEATURE ("with intermixed long options and arguments"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "foo"; argv[argc++] = "--wibble"; argv[argc++] = "bar"; argv[argc++] = "--recursive"; argv[argc++] = "baz"; argv[argc] = NULL; wibble = 0; recursive = 0; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "foo"); TEST_EQ_STR (args[1], "bar"); TEST_EQ_STR (args[2], "baz"); TEST_EQ_P (args[3], NULL); TEST_TRUE (wibble); TEST_TRUE (recursive); nih_free (args); } /* Check that long options after the first non-option argument can * be ignored when in command mode, and returned in the array with * their value NOT being set. */ TEST_FEATURE ("with command-mode long options and arguments"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "foo"; argv[argc++] = "--wibble"; argv[argc++] = "bar"; argv[argc++] = "--recursive"; argv[argc++] = "baz"; argv[argc] = NULL; wibble = 0; recursive = 0; args = nih_option_parser (NULL, argc, argv, options, TRUE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "foo"); TEST_EQ_STR (args[1], "--wibble"); TEST_EQ_STR (args[2], "bar"); TEST_EQ_STR (args[3], "--recursive"); TEST_EQ_STR (args[4], "baz"); TEST_EQ_P (args[5], NULL); TEST_FALSE (wibble); TEST_FALSE (recursive); nih_free (args); } /* Check that long options after the double-dash terminator are * ignored and returned in the array without their value being set. */ TEST_FEATURE ("with long options and terminator"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "foo"; argv[argc++] = "--wibble"; argv[argc++] = "--"; argv[argc++] = "bar"; argv[argc++] = "--recursive"; argv[argc++] = "baz"; argv[argc] = NULL; wibble = 0; recursive = 0; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "foo"); TEST_EQ_STR (args[1], "bar"); TEST_EQ_STR (args[2], "--recursive"); TEST_EQ_STR (args[3], "baz"); TEST_EQ_P (args[4], NULL); TEST_TRUE (wibble); TEST_FALSE (recursive); nih_free (args); } /* Check that a long option may take an argument, which eats the * next non-option argument and stores that in the value instead. */ TEST_FEATURE ("with long argument option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--filename"; argv[argc++] = "foo"; argv[argc] = NULL; filename = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_EQ_STR (filename, "foo"); nih_free (filename); nih_free (args); } /* Check that a long option with an argument may be repeated, * with only the lat value being taken. */ TEST_FEATURE ("with repeated long argument option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--filename"; argv[argc++] = "foo"; argv[argc++] = "--filename"; argv[argc++] = "bar"; argv[argc] = NULL; filename = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_EQ_STR (filename, "bar"); nih_free (filename); nih_free (args); } /* Check that only the first non-option argument is eaten by a long * option, and subsequent arguments are stilled returned in the * array. */ TEST_FEATURE ("with long argument option and other arguments"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--filename"; argv[argc++] = "foo"; argv[argc++] = "bar"; argv[argc++] = "baz"; argv[argc] = NULL; filename = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "bar"); TEST_EQ_STR (args[1], "baz"); TEST_EQ_P (args[2], NULL); TEST_EQ_STR (filename, "foo"); nih_free (filename); nih_free (args); } /* Stress test all the various ways of dealing with long options * at once; in particular check that an option that takes an argument * eats the first argument after the terminator. */ TEST_FEATURE ("with random mix of long options and arguments"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "wibble"; argv[argc++] = "--wibble"; argv[argc++] = "--filename"; argv[argc++] = "--"; argv[argc++] = "foo"; argv[argc++] = "--recursive"; argv[argc++] = "bar"; argv[argc++] = "baz"; argv[argc] = NULL; wibble = 0; recursive = 0; filename = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "wibble"); TEST_EQ_STR (args[1], "--recursive"); TEST_EQ_STR (args[2], "bar"); TEST_EQ_STR (args[3], "baz"); TEST_EQ_P (args[4], NULL); TEST_TRUE (wibble); TEST_FALSE (recursive); TEST_EQ_STR (filename, "foo"); nih_free (filename); nih_free (args); } /* Check that the argument to a long option may be embedded into * it, following an equals sign. */ TEST_FEATURE ("with long option and embedded argument"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--filename=ROOT"; argv[argc] = NULL; filename = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_EQ_STR (filename, "ROOT"); nih_free (filename); nih_free (args); } /* Check that multiple long options with arguments each eat the * next non-option argument, not the same one. */ TEST_FEATURE ("with multiple long argument options"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--filename"; argv[argc++] = "--option"; argv[argc++] = "foo"; argv[argc++] = "bar"; argv[argc] = NULL; filename = NULL; option = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_EQ_STR (filename, "foo"); TEST_EQ_STR (option, "bar"); nih_free (filename); nih_free (option); nih_free (args); } /* Check that an invalid short option causes an error message to * be output with a suggestion of help, and NULL to be returned. */ TEST_FEATURE ("with invalid short option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-z"; argv[argc] = NULL; TEST_DIVERT_STDERR (output) { args = nih_option_parser (NULL, argc, argv, options, FALSE); } rewind (output); TEST_EQ_P (args, NULL); TEST_FILE_EQ (output, "test: invalid option: -z\n"); TEST_FILE_EQ (output, "Try `test --help' for more information.\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid short option is ignored if there's a * catch-all option in the list. */ TEST_FEATURE ("with invalid short option and catch-all"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-z"; argv[argc] = NULL; args = nih_option_parser (NULL, argc, argv, catch_options, FALSE); TEST_NE_P (args, NULL); nih_free (args); } /* Check that an invalid long option causes an error message to * be output with a suggestion of help, and NULL to be returned. */ TEST_FEATURE ("with invalid long option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--zoiks"; argv[argc] = NULL; TEST_DIVERT_STDERR (output) { args = nih_option_parser (NULL, argc, argv, options, FALSE); } rewind (output); TEST_EQ_P (args, NULL); TEST_FILE_EQ (output, "test: invalid option: --zoiks\n"); TEST_FILE_EQ (output, "Try `test --help' for more information.\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid long option is ignored if there's a * catch-all option in the list. */ TEST_FEATURE ("with invalid long option and catch-all"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--zoiks"; argv[argc] = NULL; args = nih_option_parser (NULL, argc, argv, catch_options, FALSE); TEST_NE_P (args, NULL); nih_free (args); } /* Check that an unexpected argument to a long option causes an * error message to be output with a suggestion of help, and NULL * to be returned. */ TEST_FEATURE ("with unexpected long option argument"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--wibble=woo"; argv[argc] = NULL; TEST_DIVERT_STDERR (output) { args = nih_option_parser (NULL, argc, argv, options, FALSE); } rewind (output); TEST_EQ_P (args, NULL); TEST_FILE_EQ (output, "test: unexpected argument: --wibble=woo\n"); TEST_FILE_EQ (output, "Try `test --help' for more information.\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an missing argument to a short option causes an error * message to be output with a suggestion of help, and NULL to be * returned. */ TEST_FEATURE ("with missing short option argument"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-f"; argv[argc] = NULL; TEST_DIVERT_STDERR (output) { args = nih_option_parser (NULL, argc, argv, options, FALSE); } rewind (output); TEST_EQ_P (args, NULL); TEST_FILE_EQ (output, "test: missing argument: -f\n"); TEST_FILE_EQ (output, "Try `test --help' for more information.\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an missing argument to a long option causes an error * message to be output with a suggestion of help, and NULL to be * returned. */ TEST_FEATURE ("with missing long option argument"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--filename"; argv[argc] = NULL; TEST_DIVERT_STDERR (output) { args = nih_option_parser (NULL, argc, argv, options, FALSE); } rewind (output); TEST_EQ_P (args, NULL); TEST_FILE_EQ (output, "test: missing argument: --filename\n"); TEST_FILE_EQ (output, "Try `test --help' for more information.\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a short option may result in a function call, and * that the arguments to that call are correct. */ TEST_FEATURE ("with short setter option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-x"; argv[argc++] = "foo"; argv[argc] = NULL; was_called = 0; last_option = NULL; last_arg = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "foo"); TEST_EQ_P (args[1], NULL); TEST_TRUE (was_called); TEST_EQ (last_option->option, options[6].option); TEST_EQ_P (last_arg, NULL); nih_free (args); free (last_option); } /* Check that a short option that takens an argument can result in * a function call, and that the argument is also passed to the * function call. */ TEST_FEATURE ("with short setter argument option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-s"; argv[argc++] = "foo"; argv[argc] = NULL; was_called = 0; last_option = NULL; last_arg = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_TRUE (was_called); TEST_EQ (last_option->option, options[5].option); TEST_EQ_STR (last_arg, "foo"); nih_free (args); free (last_option); } /* Check that the setter function is stilled correctly if the * argument to the short option is embedded within it. */ TEST_FEATURE ("with short setter embedded argument option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-sfoo"; argv[argc] = NULL; was_called = 0; last_option = NULL; last_arg = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_TRUE (was_called); TEST_EQ (last_option->option, options[5].option); TEST_EQ_STR (last_arg, "foo"); nih_free (args); free (last_option); } /* Check that a long option may result in a function call, and * that the arguments to that call are correct. */ TEST_FEATURE ("with long setter option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--execute"; argv[argc++] = "foo"; argv[argc] = NULL; was_called = 0; last_option = NULL; last_arg = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_STR (args[0], "foo"); TEST_EQ_P (args[1], NULL); TEST_TRUE (was_called); TEST_EQ (last_option->option, options[6].option); TEST_EQ_P (last_arg, NULL); nih_free (args); free (last_option); } /* Check that a short option that takens an argument can result in * a function call, and that the argument is also passed to the * function call. */ TEST_FEATURE ("with long setter argument option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--special"; argv[argc++] = "foo"; argv[argc] = NULL; was_called = 0; last_option = NULL; last_arg = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_TRUE (was_called); TEST_EQ (last_option->option, options[5].option); TEST_EQ_STR (last_arg, "foo"); nih_free (args); free (last_option); } /* Check that the setter function is stilled correctly if the * argument to the short option is embedded within it. */ TEST_FEATURE ("with long setter embedded argument option"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--special=foo"; argv[argc] = NULL; was_called = 0; last_option = NULL; last_arg = NULL; args = nih_option_parser (NULL, argc, argv, options, FALSE); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_TRUE (was_called); TEST_EQ (last_option->option, options[5].option); TEST_EQ_STR (last_arg, "foo"); nih_free (args); free (last_option); } /* Check that an error code returned from a setter function for a * short option results in NULL being returned by the parser, but * no error message output (that's left up to the function). */ TEST_FEATURE ("with short setter embedded argument error"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-sfail"; argv[argc] = NULL; was_called = 0; last_option = NULL; last_arg = NULL; TEST_DIVERT_STDERR (output) { args = nih_option_parser (NULL, argc, argv, options, FALSE); } rewind (output); TEST_EQ_P (args, NULL); TEST_TRUE (was_called); TEST_EQ (last_option->option, options[5].option); TEST_EQ_STR (last_arg, "fail"); TEST_FILE_END (output); TEST_FILE_RESET (output); free (last_option); } /* Check that an error code returned from a setter function for a * long option results in NULL being returned by the parser, but * no error message output (that's left up to the function). */ TEST_FEATURE ("with long setter embedded argument error"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--special=fail"; argv[argc] = NULL; was_called = 0; last_option = NULL; last_arg = NULL; TEST_DIVERT_STDERR (output) { args = nih_option_parser (NULL, argc, argv, options, FALSE); } rewind (output); TEST_EQ_P (args, NULL); TEST_TRUE (was_called); TEST_EQ (last_option->option, options[5].option); TEST_EQ_STR (last_arg, "fail"); TEST_FILE_END (output); free (last_option); } fclose (output); } void test_count (void) { NihOption opt; int ret, value = 0; TEST_FUNCTION ("nih_option_count"); /* Check that the count function treats the option value as an * integer pointer, and increments it. */ TEST_FEATURE ("with zero value"); opt.value = &value; ret = nih_option_count (&opt, NULL); TEST_EQ (ret, 0); TEST_EQ (value, 1); /* Check that calling again increments the value to two. */ TEST_FEATURE ("with non-zero value"); ret = nih_option_count (&opt, NULL); TEST_EQ (ret, 0); TEST_EQ (value, 2); } void test_int (void) { FILE *output; NihOption opt; int ret, value = 0; TEST_FUNCTION ("nih_option_int"); opt.value = &value; output = tmpfile (); program_name = "test"; /* Check that the int function treats the option value as an * integer pointer, and sets it. */ TEST_FEATURE ("with positive value"); ret = nih_option_int (&opt, "42"); TEST_EQ (ret, 0); TEST_EQ (value, 42); /* Check that a negative number can be parsed. */ TEST_FEATURE ("with negative value"); ret = nih_option_int (&opt, "-14"); TEST_EQ (ret, 0); TEST_EQ (value, -14); /* Check that a zero value can be parsed. */ TEST_FEATURE ("with zero value"); ret = nih_option_int (&opt, "0"); TEST_EQ (ret, 0); TEST_EQ (value, 0); /* Check that a non-numeric argument results in an error. */ TEST_FEATURE ("with non-numeric argument"); TEST_DIVERT_STDERR (output) { ret = nih_option_int (&opt, "foo"); } rewind (output); TEST_LT (ret, 0); TEST_FILE_EQ (output, "test: illegal argument: foo\n"); TEST_FILE_EQ (output, "Try `test --help' for more information.\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); /* Check that a partially non-numeric argument results in an error. */ TEST_FEATURE ("with partially non-numeric argument"); TEST_DIVERT_STDERR (output) { ret = nih_option_int (&opt, "15foo"); } rewind (output); TEST_LT (ret, 0); TEST_FILE_EQ (output, "test: illegal argument: 15foo\n"); TEST_FILE_EQ (output, "Try `test --help' for more information.\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); fclose (output); } static int logger_called = 0; static int my_logger (NihLogLevel priority, const char *message) { logger_called++; return 0; } void test_quiet (void) { char *argv[3], **args; int argc; TEST_FUNCTION ("nih_option_quiet"); program_name = "test"; nih_log_set_logger (my_logger); /* Check that the --quiet option is automatically understood, and * sets the log level such that only the error message is output. */ TEST_FEATURE ("with long option"); argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--quiet"; argv[argc] = NULL; logger_called = 0; nih_log_set_priority (NIH_LOG_MESSAGE); args = nih_option_parser (NULL, argc, argv, options, FALSE); nih_debug ("test message"); nih_info ("test message"); nih_message ("test message"); nih_warn ("test message"); nih_error ("test message"); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_EQ (logger_called, 1); nih_free (args); /* Check that the -q option has the same effect. */ TEST_FEATURE ("with short option"); argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-q"; argv[argc] = NULL; logger_called = 0; nih_log_set_priority (NIH_LOG_MESSAGE); args = nih_option_parser (NULL, argc, argv, options, FALSE); nih_debug ("test message"); nih_info ("test message"); nih_message ("test message"); nih_warn ("test message"); nih_error ("test message"); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_EQ (logger_called, 1); nih_free (args); nih_log_set_priority (NIH_LOG_MESSAGE); nih_log_set_logger (nih_logger_printf); } void test_verbose (void) { char *argv[3], **args; int argc; TEST_FUNCTION ("nih_option_verbose"); program_name = "test"; nih_log_set_logger (my_logger); /* Check that the --verbose option is automatically understood, * and sets the log level such that messages of info, warn and * error priority are output. */ TEST_FEATURE ("with long option"); argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--verbose"; argv[argc] = NULL; logger_called = 0; nih_log_set_priority (NIH_LOG_MESSAGE); args = nih_option_parser (NULL, argc, argv, options, FALSE); nih_debug ("test message"); nih_info ("test message"); nih_message ("test message"); nih_warn ("test message"); nih_error ("test message"); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_EQ (logger_called, 4); nih_free (args); /* Check that the -v option has the same effect. */ TEST_FEATURE ("with short option"); argc = 0; argv[argc++] = "ignored"; argv[argc++] = "-v"; argv[argc] = NULL; logger_called = 0; nih_log_set_priority (NIH_LOG_MESSAGE); args = nih_option_parser (NULL, argc, argv, options, FALSE); nih_debug ("test message"); nih_info ("test message"); nih_message ("test message"); nih_warn ("test message"); nih_error ("test message"); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_EQ (logger_called, 4); nih_free (args); nih_log_set_priority (NIH_LOG_MESSAGE); nih_log_set_logger (nih_logger_printf); } void test_debug (void) { char *argv[3], **args; int argc; /* Check that the --debug option is automatically understood, * and sets the log level such that messages of all priorities * are output. */ TEST_FUNCTION ("nih_option_debug"); program_name = "test"; nih_log_set_logger (my_logger); argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--debug"; argv[argc] = NULL; logger_called = 0; nih_log_set_priority (NIH_LOG_MESSAGE); args = nih_option_parser (NULL, argc, argv, options, FALSE); nih_debug ("test message"); nih_info ("test message"); nih_message ("test message"); nih_warn ("test message"); nih_error ("test message"); TEST_NE_P (args, NULL); TEST_EQ_P (args[0], NULL); TEST_EQ (logger_called, 5); nih_free (args); nih_log_set_priority (NIH_LOG_MESSAGE); nih_log_set_logger (nih_logger_printf); } void test_version (void) { FILE *output; char *argv[3]; pid_t pid; int argc, status; /* Check that the --version option is caught, dealt with by outputting * version information to standard output, and terminating the process * with a zero exit code. */ TEST_FUNCTION ("nih_option_version"); nih_main_init_full ("test", "wibble", "1.0", "foo@bar.com", "Copyright Message"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--version"; argv[argc] = NULL; output = tmpfile (); TEST_CHILD (pid) { TEST_DIVERT_STDOUT (output) { char **args; args = nih_option_parser (NULL, argc, argv, options, FALSE); exit (1); } } waitpid (pid, &status, 0); rewind (output); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_FILE_EQ (output, "test (wibble 1.0)\n"); TEST_FILE_EQ (output, "Copyright Message\n"); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ_N (output, "This is free software;"); TEST_FILE_EQ_N (output, "warranty; not even for"); TEST_FILE_END (output); fclose (output); } } void test_help (void) { FILE *output; char *argv[3]; pid_t pid; int argc, status; /* Check that these functions set their appropriate string, this * is only possible by checking the help output, so we call them * and do the tests later. */ TEST_FUNCTION ("nih_option_set_usage_stem"); nih_option_set_usage_stem ("[OPT]..."); TEST_FUNCTION ("nih_option_set_usage"); nih_option_set_usage ("CMD [ARG]..."); TEST_FUNCTION ("nih_option_set_synopsis"); nih_option_set_synopsis ("Frobnicates bars carefully, taking into " "account things that are important when " "doing that"); TEST_FUNCTION ("nih_option_set_help"); nih_option_set_help ("This is the help text for the bar frobnication " "program.\n\n" "It is also wrapped to the screen width, so it " "can be as long as we like, and can also include " "paragraph breaks and stuff."); TEST_FUNCTION ("nih_option_set_footer"); nih_option_set_footer ("Go away!"); /* Check that the --help option is caught, dealt with by outputting * information about the options to standard output, and terminating * the process with a zero exit code. */ TEST_FUNCTION ("nih_option_help"); nih_main_init_full ("test", "wibble", "1.0", "foo@bar.com", "Copyright Message"); TEST_ALLOC_FAIL { argc = 0; argv[argc++] = "ignored"; argv[argc++] = "--help"; argv[argc] = NULL; output = tmpfile (); TEST_CHILD (pid) { unsetenv ("COLUMNS"); TEST_DIVERT_STDOUT (output) { char **args; args = nih_option_parser (NULL, argc, argv, options, FALSE); exit (1); } } waitpid (pid, &status, 0); rewind (output); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_FILE_EQ (output, "Usage: test [OPT]... CMD [ARG]...\n"); TEST_FILE_EQ (output, ("Frobnicates bars carefully, taking " "into account things that are " "important when\n")); TEST_FILE_EQ (output, ("doing that\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "First test group options:\n"); TEST_FILE_EQ (output, (" -d " "become daemon\n")); TEST_FILE_EQ (output, (" -f, --filename=FILENAME " "read this file\n")); TEST_FILE_EQ (output, (" -x, --execute " "run something, give this a really " "long help\n")); TEST_FILE_EQ (output, (" " " message so that it word wraps\n")); TEST_FILE_EQ (output, (" -I DIRECTORY " "add directory to include list\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "Second test group options:\n"); TEST_FILE_EQ (output, (" -R, --recursive " "descend into sub-directories\n")); TEST_FILE_EQ (output, (" --wibble " "bored of inventing names\n")); TEST_FILE_EQ (output, (" -o, --option=OPTION " "extended options\n")); TEST_FILE_EQ (output, (" -s, --special=SPECIAL-LONG-" "ARGUMENT-NAME\n")); TEST_FILE_EQ (output, (" " "something with special treatment\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "Other options:\n"); TEST_FILE_EQ (output, (" -q, --quiet " "reduce output to errors only\n")); TEST_FILE_EQ (output, (" -v, --verbose " "increase output to include " "informational messages\n")); TEST_FILE_EQ (output, (" --help " "display this help and exit\n")); TEST_FILE_EQ (output, (" --version " "output version information and " "exit\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, ("This is the help text for the bar " "frobnication program.\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, ("It is also wrapped to the screen " "width, so it can be as long as " "we like, and\n")); TEST_FILE_EQ (output, ("can also include paragraph breaks " "and stuff.\n")); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "Go away!\n"); TEST_FILE_EQ (output, "\n"); TEST_FILE_EQ (output, "Report bugs to \n"); TEST_FILE_END (output); fclose (output); } } int main (int argc, char *argv[]) { test_parser (); test_count (); test_int (); test_quiet (); test_verbose (); test_debug (); test_version (); test_help (); return 0; } libnih-1.0.3/nih/tests/test_list.c0000644000175000017500000002751411445765555014031 00000000000000/* libnih * * test_list.c - test suite for nih/list.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include void test_init (void) { NihList entry; /* Check that nih_list_init correctly initialises an empty list, * with both pointers pointing back to the entry itself. */ TEST_FUNCTION ("nih_list_init"); nih_list_init (&entry); TEST_EQ_P (entry.prev, &entry); TEST_EQ_P (entry.next, &entry); } void test_new (void) { NihList *list; /* Check that nih_list_new allocates a new empty list with nih_alloc * and that it is initialised with pointers pointing to itself. If * allocation fails, we should get NULL returned. */ TEST_FUNCTION ("nih_list_new"); TEST_ALLOC_FAIL { list = nih_list_new (NULL); if (test_alloc_failed) { TEST_EQ_P (list, NULL); continue; } TEST_ALLOC_SIZE (list, sizeof (NihList)); TEST_EQ_P (list->prev, list); TEST_EQ_P (list->next, list); nih_free (list); } } void test_entry_new (void) { NihListEntry *list; /* Check that nih_list_entry_new allocates a new empty list entry with * nih_alloc and that it is initialised with pointers pointing to * itself. If allocation fails, we should get NULL returned. */ TEST_FUNCTION ("nih_list_entry_new"); TEST_ALLOC_FAIL { list = nih_list_entry_new (NULL); if (test_alloc_failed) { TEST_EQ_P (list, NULL); continue; } TEST_ALLOC_SIZE (list, sizeof (NihListEntry)); TEST_EQ_P (list->entry.prev, &list->entry); TEST_EQ_P (list->entry.next, &list->entry); TEST_EQ_P (list->data, NULL); nih_free (list); } } void test_add (void) { NihList *list, *entry1, *entry2, *ptr; TEST_FUNCTION ("nih_list_add"); list = nih_list_new (NULL); entry1 = nih_list_new (NULL); entry2 = nih_list_new (NULL); /* Check that nih_list_add can add a single entry to an empty list; * the added entry should be returned and the pointers should all * chain up. */ TEST_FEATURE ("with single-entry list"); ptr = nih_list_add (list, entry1); TEST_EQ_P (ptr, entry1); TEST_EQ_P (list->next, entry1); TEST_EQ_P (entry1->next, list); TEST_EQ_P (list->prev, entry1); TEST_EQ_P (entry1->prev, list); /* Check that we can now add another entry to that two entry list, * and the pointers are still all right. */ TEST_FEATURE ("with multi-entry list"); nih_list_add (list, entry2); TEST_EQ_P (list->next, entry1); TEST_EQ_P (entry1->next, entry2); TEST_EQ_P (entry2->next, list); TEST_EQ_P (list->prev, entry2); TEST_EQ_P (entry2->prev, entry1); TEST_EQ_P (entry1->prev, list); /* Check that we can use nih_list_add to swap two entries that are * in the same list. */ TEST_FEATURE ("with two entries from same list"); nih_list_add (entry1, entry2); TEST_EQ_P (list->next, entry2); TEST_EQ_P (entry2->next, entry1); TEST_EQ_P (entry1->next, list); TEST_EQ_P (list->prev, entry1); TEST_EQ_P (entry1->prev, entry2); TEST_EQ_P (entry2->prev, list); /* Check that we can rip an entry out of its list and place it in * a new empty one. */ TEST_FEATURE ("with entry from other list"); ptr = nih_list_new (NULL); nih_list_add (ptr, entry2); TEST_EQ_P (list->next, entry1); TEST_EQ_P (entry1->next, list); TEST_EQ_P (list->prev, entry1); TEST_EQ_P (entry1->prev, list); TEST_EQ_P (ptr->next, entry2); TEST_EQ_P (entry2->next, ptr); TEST_EQ_P (ptr->prev, entry2); TEST_EQ_P (entry2->prev, ptr); nih_free (list); nih_free (entry1); nih_free (entry2); nih_free (ptr); } void test_add_after (void) { NihList *list, *entry1, *entry2, *ptr; TEST_FUNCTION ("nih_list_add_after"); list = nih_list_new (NULL); entry1 = nih_list_new (NULL); entry2 = nih_list_new (NULL); /* Check that nih_list_add_after can add a single entry to an empty * list, the result should be the same as nih_list_add. */ TEST_FEATURE ("with single-entry list"); ptr = nih_list_add_after (list, entry1); TEST_EQ_P (ptr, entry1); TEST_EQ_P (list->next, entry1); TEST_EQ_P (entry1->next, list); TEST_EQ_P (list->prev, entry1); TEST_EQ_P (entry1->prev, list); /* Check that when adding an entry to a list with multiple entries, * nih_list_add_after adds the entry immediately after the entry * given, not before (as nih_list_add does) */ TEST_FEATURE ("with multi-entry list"); nih_list_add_after (list, entry2); TEST_EQ_P (list->next, entry2); TEST_EQ_P (entry2->next, entry1); TEST_EQ_P (entry1->next, list); TEST_EQ_P (list->prev, entry1); TEST_EQ_P (entry1->prev, entry2); TEST_EQ_P (entry2->prev, list); /* Check that nih_list_add_after can be used to swap two entries * around. */ TEST_FEATURE ("with two entries from same list"); nih_list_add_after (entry1, entry2); TEST_EQ_P (list->next, entry1); TEST_EQ_P (entry1->next, entry2); TEST_EQ_P (entry2->next, list); TEST_EQ_P (list->prev, entry2); TEST_EQ_P (entry2->prev, entry1); TEST_EQ_P (entry1->prev, list); /* Check that nih_list_add_after can rip an entry out of its * containing list, and add it to a new one. */ TEST_FEATURE ("with entry from other list"); ptr = nih_list_new (NULL); nih_list_add_after (ptr, entry1); TEST_EQ_P (list->next, entry2); TEST_EQ_P (entry2->next, list); TEST_EQ_P (list->prev, entry2); TEST_EQ_P (entry2->prev, list); TEST_EQ_P (ptr->next, entry1); TEST_EQ_P (entry1->next, ptr); TEST_EQ_P (ptr->prev, entry1); TEST_EQ_P (entry1->prev, ptr); nih_free (list); nih_free (entry1); nih_free (entry2); nih_free (ptr); } void test_empty (void) { NihList *list, *entry; TEST_FUNCTION ("NIH_LIST_EMPTY"); /* Check that NIH_LIST_EMPTY is TRUE on an empty list */ TEST_FEATURE ("with empty list"); list = nih_list_new (NULL); TEST_LIST_EMPTY (list); /* Check that NIH_LIST_EMPTY is FALSE on a non-empty list */ TEST_FEATURE ("with non-empty list"); entry = nih_list_new (NULL); nih_list_add (list, entry); TEST_LIST_NOT_EMPTY (list); TEST_LIST_NOT_EMPTY (entry); nih_free (list); nih_free (entry); } void test_foreach (void) { NihList *list, *entry[3]; int i; /* Check that NIH_LIST_FOREACH iterates the list correctly in * order, visiting each entry. */ TEST_FUNCTION ("NIH_LIST_FOREACH"); list = nih_list_new (NULL); entry[0] = nih_list_add (list, nih_list_new (NULL)); entry[1] = nih_list_add (list, nih_list_new (NULL)); entry[2] = nih_list_add (list, nih_list_new (NULL)); i = 0; NIH_LIST_FOREACH (list, iter) { if (i > 2) TEST_FAILED ("wrong number of iterations, expected %d got %d", 3, i + 1); if (iter != entry[i]) TEST_FAILED ("wrong list entry, expected %p got %p", entry[i], iter); i++; } nih_free (list); nih_free (entry[0]); nih_free (entry[1]); nih_free (entry[2]); } void test_foreach_safe (void) { NihList *list, *entry[3]; int i; TEST_FUNCTION ("NIH_LIST_FOREACH_SAFE"); /* Check that NIH_LIST_FOREACH_SAFE iterates the list correctly in * order, visiting each entry. */ TEST_FEATURE ("with ordinary iteration"); list = nih_list_new (NULL); entry[0] = nih_list_add (list, nih_list_new (NULL)); entry[1] = nih_list_add (list, nih_list_new (NULL)); entry[2] = nih_list_add (list, nih_list_new (NULL)); i = 0; NIH_LIST_FOREACH_SAFE (list, iter) { if (i > 2) TEST_FAILED ("wrong number of iterations, expected %d got %d", 3, i + 1); if (iter != entry[i]) TEST_FAILED ("wrong list entry, expected %p got %p", entry[i], iter); i++; } nih_free (list); nih_free (entry[0]); nih_free (entry[1]); nih_free (entry[2]); /* Check that NIH_LIST_FOREACH_SAFE iterates the list correctly in * order, visiting each entry; and that it's safe to remove entries * while doing so. */ TEST_FEATURE ("with removal of visited node"); list = nih_list_new (NULL); entry[0] = nih_list_add (list, nih_list_new (NULL)); entry[1] = nih_list_add (list, nih_list_new (NULL)); entry[2] = nih_list_add (list, nih_list_new (NULL)); i = 0; NIH_LIST_FOREACH_SAFE (list, iter) { if (i > 2) TEST_FAILED ("wrong number of iterations, expected %d got %d", 3, i + 1); if (iter != entry[i]) TEST_FAILED ("wrong list entry, expected %p got %p", entry[i], iter); nih_list_remove (entry[i]); i++; } /* Check that the list is now empty */ TEST_LIST_EMPTY (list); nih_free (list); nih_free (entry[0]); nih_free (entry[1]); nih_free (entry[2]); /* Check that NIH_LIST_FOREACH_SAFE iterates the list correctly in * order, visiting each entry; and that it's safe to remove the * next entry while doing so. */ TEST_FEATURE ("with removal of next node"); list = nih_list_new (NULL); entry[0] = nih_list_add (list, nih_list_new (NULL)); entry[1] = nih_list_add (list, nih_list_new (NULL)); entry[2] = nih_list_add (list, nih_list_new (NULL)); i = 0; NIH_LIST_FOREACH_SAFE (list, iter) { if (i > 2) TEST_FAILED ("wrong number of iterations, expected %d got %d", 3, i + 1); if (iter != entry[i]) TEST_FAILED ("wrong list entry, expected %p got %p", entry[i], iter); if (i == 0) nih_list_remove (entry[1]); /* Next entry visited should be 2 */ i += 2; } nih_free (list); nih_free (entry[0]); nih_free (entry[1]); nih_free (entry[2]); } void test_remove (void) { NihList *list, *entry, *tail, *ptr; TEST_FUNCTION ("nih_list_remove"); list = nih_list_new (NULL); entry = nih_list_add (list, nih_list_new (NULL)); tail = nih_list_add (list, nih_list_new (NULL)); /* Check that nih_list_remove works, returning the entry that was * removed and adjusting both sets of pointers in the lists. */ TEST_FEATURE ("with two-entry list"); ptr = nih_list_remove (entry); TEST_EQ_P (ptr, entry); TEST_EQ_P (list->next, tail); TEST_EQ_P (tail->next, list); TEST_EQ_P (list->prev, tail); TEST_EQ_P (tail->prev, list); TEST_EQ_P (entry->next, entry); TEST_EQ_P (entry->prev, entry); /* Check that nih_list_remove works if there is only one entry in the * list that's not the head, the pointers should both curl in. */ TEST_FEATURE ("with one-entry list"); ptr = nih_list_remove (tail); TEST_EQ_P (list->next, list); TEST_EQ_P (list->prev, list); TEST_EQ_P (tail->next, tail); TEST_EQ_P (tail->prev, tail); /* Check that it works on an empty list, this should do nothing. */ TEST_FEATURE ("with empty list"); ptr = nih_list_remove (tail); TEST_EQ_P (tail->next, tail); TEST_EQ_P (tail->prev, tail); nih_free (list); nih_free (entry); nih_free (tail); } void test_destroy (void) { NihList *list, *entry, *tail; int ret; /* Check that the function removes the entry from its containing * list, it needn't bother updating the entry itself seeing as it's * being freed anyway. */ TEST_FUNCTION ("nih_list_destroy"); list = nih_list_new (NULL); entry = nih_list_add (list, nih_list_new (NULL)); tail = nih_list_add (list, nih_list_new (NULL)); ret = nih_list_destroy (entry); TEST_EQ (ret, 0); TEST_EQ_P (list->next, tail); TEST_EQ_P (tail->next, list); TEST_EQ_P (list->prev, tail); TEST_EQ_P (tail->prev, list); nih_free (entry); nih_free (list); nih_free (tail); } int main (int argc, char *argv[]) { test_init (); test_new (); test_entry_new (); test_add (); test_add_after (); test_empty (); test_foreach (); test_foreach_safe (); test_remove (); test_destroy (); return 0; } libnih-1.0.3/nih/tests/test_child.c0000644000175000017500000003474511445765555014145 00000000000000/* libnih * * test_child.c - test suite for nih/child.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #if HAVE_VALGRIND_VALGRIND_H #include #endif /* HAVE_VALGRIND_VALGRIND_H */ #include #include #include #include #include #include #include #include #include #include static int handler_called = 0; static void *last_data = NULL; static pid_t last_pid; static NihChildEvents last_event = -1; static int last_status; static void my_handler (void *data, pid_t pid, NihChildEvents event, int status) { handler_called++; last_data = data; last_pid = pid; last_event = event; last_status = status; } void test_add_watch (void) { NihChildWatch *watch; TEST_FUNCTION ("nih_child_add_watch"); nih_child_poll (); /* Check that we can add a watch on a specific pid, and that the * structure is filled in correctly and part of a list. */ TEST_FEATURE ("with pid"); TEST_ALLOC_FAIL { watch = nih_child_add_watch (NULL, getpid (), NIH_CHILD_EXITED, my_handler, &watch); if (test_alloc_failed) { TEST_EQ_P (watch, NULL); continue; } TEST_ALLOC_SIZE (watch, sizeof (NihChildWatch)); TEST_EQ (watch->pid, getpid ()); TEST_EQ (watch->events, NIH_CHILD_EXITED); TEST_EQ_P (watch->handler, my_handler); TEST_EQ_P (watch->data, &watch); TEST_LIST_NOT_EMPTY (&watch->entry); nih_free (watch); } /* Check that we can add a watch on a pid of -1, which represents * any child. */ TEST_FEATURE ("with -1 for pid"); TEST_ALLOC_FAIL { watch = nih_child_add_watch (NULL, -1, NIH_CHILD_ALL, my_handler, &watch); if (test_alloc_failed) { TEST_EQ_P (watch, NULL); continue; } TEST_ALLOC_SIZE (watch, sizeof (NihChildWatch)); TEST_EQ (watch->pid, -1); TEST_EQ (watch->events, NIH_CHILD_ALL); TEST_EQ_P (watch->handler, my_handler); TEST_EQ_P (watch->data, &watch); TEST_LIST_NOT_EMPTY (&watch->entry); nih_free (watch); } } void test_poll (void) { NihChildWatch *watch; siginfo_t siginfo; pid_t pid, child; unsigned long data; char corefile[PATH_MAX + 1]; TEST_FUNCTION ("nih_child_poll"); /* Check that when a child exits normally, the handler receives * an exited event and the zero status code and is then removed from * the list and freed. */ TEST_FEATURE ("with normal termination"); TEST_CHILD (pid) { exit (0); } watch = nih_child_add_watch (NULL, pid, NIH_CHILD_EXITED, my_handler, &watch); TEST_FREE_TAG (watch); handler_called = 0; last_data = NULL; last_pid = 0; last_event = -1; last_status = 0; waitid (P_PID, pid, &siginfo, WEXITED | WNOWAIT); nih_child_poll (); TEST_TRUE (handler_called); TEST_EQ (last_pid, pid); TEST_EQ (last_event, NIH_CHILD_EXITED); TEST_EQ (last_status, 0); TEST_FREE (watch); /* Check that when a child exits with a non-zero status code, the * reaper receives an exited event and the status code and is then * removed from the list and freed. */ TEST_FEATURE ("with normal non-zero termination"); TEST_CHILD (pid) { exit (123); } watch = nih_child_add_watch (NULL, pid, NIH_CHILD_EXITED, my_handler, &watch); TEST_FREE_TAG (watch); handler_called = 0; last_data = NULL; last_pid = 0; last_event = -1; last_status = 0; waitid (P_PID, pid, &siginfo, WEXITED | WNOWAIT); nih_child_poll (); TEST_TRUE (handler_called); TEST_EQ (last_pid, pid); TEST_EQ (last_event, NIH_CHILD_EXITED); TEST_EQ (last_status, 123); TEST_FREE (watch); /* Check that when a child is killed by a signal, the reaper receives * a killed event with the signal in the status field before being * removed from the list and freed. */ TEST_FEATURE ("with termination by signal"); TEST_CHILD (pid) { pause (); } watch = nih_child_add_watch (NULL, pid, NIH_CHILD_KILLED | NIH_CHILD_DUMPED, my_handler, &watch); TEST_FREE_TAG (watch); handler_called = 0; last_data = NULL; last_pid = 0; last_event = -1; last_status = 0; kill (pid, SIGTERM); waitid (P_PID, pid, &siginfo, WEXITED | WNOWAIT); nih_child_poll (); TEST_TRUE (handler_called); TEST_EQ (last_pid, pid); TEST_EQ (last_event, NIH_CHILD_KILLED); TEST_EQ (last_status, SIGTERM); TEST_FREE (watch); /* Check that when a child is killed by aborting, the reaper receives * a dumped event with the signal in the status field before being * removed from the list and freed. */ TEST_FEATURE ("with termination by abort"); TEST_CHILD (pid) { abort (); } watch = nih_child_add_watch (NULL, pid, NIH_CHILD_KILLED | NIH_CHILD_DUMPED, my_handler, &watch); TEST_FREE_TAG (watch); handler_called = 0; last_data = NULL; last_pid = 0; last_event = -1; last_status = 0; waitid (P_PID, pid, &siginfo, WEXITED | WNOWAIT); nih_child_poll (); TEST_TRUE (handler_called); TEST_EQ (last_pid, pid); /* We might get killed if we never dumped core... fiddling with * the limit doesn't help, since we might be under gdb and that * never lets us dump core. */ if (last_event != NIH_CHILD_KILLED) TEST_EQ (last_event, NIH_CHILD_DUMPED); TEST_EQ (last_status, SIGABRT); TEST_FREE (watch); unlink ("core"); sprintf (corefile, "core.%d", pid); unlink (corefile); sprintf (corefile, "vgcore.%d", pid); unlink (corefile); /* Check that when a child emits the stopped signal, the reaper * receives a stopped event with nothing relevant in the status field. * It should not be removed from the list, since the child hasn't * gone anyway. */ TEST_FEATURE ("with stopped child"); TEST_CHILD (pid) { raise (SIGSTOP); pause (); exit (0); } watch = nih_child_add_watch (NULL, pid, NIH_CHILD_STOPPED | NIH_CHILD_CONTINUED, my_handler, &watch); TEST_FREE_TAG (watch); handler_called = 0; last_data = NULL; last_pid = 0; last_event = -1; last_status = 0; waitid (P_PID, pid, &siginfo, WSTOPPED | WNOWAIT); nih_child_poll (); TEST_TRUE (handler_called); TEST_EQ (last_pid, pid); TEST_EQ (last_event, NIH_CHILD_STOPPED); TEST_EQ (last_status, SIGSTOP); TEST_NOT_FREE (watch); /* Check that when the child is continued again, the reaper * receives a continued event with nothing relevant in the status * field. It should still not be removed from the list since the * child still hasn't gone away. */ TEST_FEATURE ("with continued child"); handler_called = 0; last_data = NULL; last_pid = 0; last_event = -1; last_status = 0; kill (pid, SIGCONT); waitid (P_PID, pid, &siginfo, WCONTINUED | WNOWAIT); nih_child_poll (); TEST_TRUE (handler_called); TEST_EQ (last_pid, pid); TEST_EQ (last_event, NIH_CHILD_CONTINUED); TEST_EQ (last_status, SIGCONT); TEST_NOT_FREE (watch); kill (pid, SIGTERM); waitid (P_PID, pid, &siginfo, WEXITED); nih_free (watch); /* Check that a signal raised from a traced child causes the reaper * to be called with a traced event and the event in the status * field. It should not be removed from the list since the child * hasn't gone away. */ TEST_FEATURE ("with signal from traced child"); TEST_CHILD (pid) { assert0 (ptrace (PTRACE_TRACEME, 0, NULL, NULL)); raise (SIGSTOP); raise (SIGCHLD); pause (); exit (0); } waitid (P_PID, pid, &siginfo, WSTOPPED); assert0 (ptrace (PTRACE_SETOPTIONS, pid, NULL, PTRACE_O_TRACESYSGOOD)); assert0 (ptrace (PTRACE_CONT, pid, NULL, SIGCONT)); waitid (P_PID, pid, &siginfo, WSTOPPED | WNOWAIT); watch = nih_child_add_watch (NULL, pid, NIH_CHILD_TRAPPED, my_handler, &watch); TEST_FREE_TAG (watch); handler_called = 0; last_data = NULL; last_pid = 0; last_event = -1; last_status = 0; nih_child_poll (); TEST_TRUE (handler_called); TEST_EQ (last_pid, pid); TEST_EQ (last_event, NIH_CHILD_TRAPPED); TEST_EQ (last_status, SIGCHLD); TEST_NOT_FREE (watch); assert0 (ptrace (PTRACE_DETACH, pid, NULL, 0)); kill (pid, SIGTERM); waitid (P_PID, pid, &siginfo, WEXITED); nih_free (watch); #if HAVE_VALGRIND_VALGRIND_H /* These tests fail when running under valgrind. */ if (! RUNNING_ON_VALGRIND) { #endif /* Check that when a traced child forks it causes the reaper * to be called with a ptrace event and the fork event in the * status field. It should not be removed from the list since the * child hasn't gone away. */ TEST_FEATURE ("with fork by traced child"); TEST_CHILD (pid) { assert0 (ptrace (PTRACE_TRACEME, 0, NULL, NULL)); raise (SIGSTOP); child = fork (); assert (child >= 0); pause (); exit (0); } waitid (P_PID, pid, &siginfo, WSTOPPED); assert0 (ptrace (PTRACE_SETOPTIONS, pid, NULL, PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEFORK)); assert0 (ptrace (PTRACE_CONT, pid, NULL, SIGCONT)); /* Wait for ptrace to stop the parent (signalling the fork) */ waitid (P_PID, pid, &siginfo, WSTOPPED | WNOWAIT); /* Will be able to get the child pid now, we have to do it here * because we want to wait on it to ensure the test is synchronous; * otherwise nih_child_poll() could actually eat the child event * before it returns -- normally we'd do this inside the handler, * so things would probably work (we iter the handlers for each * event, so you can add one). */ data = 0; assert0 (ptrace (PTRACE_GETEVENTMSG, pid, NULL, &data)); assert (data != 0); child = (pid_t)data; /* Wait for ptrace to stop the child, otherwise it might not be * ready for us to actually detach from. */ waitid (P_PID, child, &siginfo, WSTOPPED | WNOWAIT); watch = nih_child_add_watch (NULL, pid, NIH_CHILD_PTRACE, my_handler, &watch); TEST_FREE_TAG (watch); handler_called = 0; last_data = NULL; last_pid = 0; last_event = -1; last_status = 0; nih_child_poll (); TEST_TRUE (handler_called); TEST_EQ (last_pid, pid); TEST_EQ (last_event, NIH_CHILD_PTRACE); TEST_EQ (last_status, PTRACE_EVENT_FORK); TEST_NOT_FREE (watch); assert0 (ptrace (PTRACE_DETACH, child, NULL, SIGCONT)); kill (child, SIGTERM); assert0 (ptrace (PTRACE_DETACH, pid, NULL, SIGCONT)); kill (pid, SIGTERM); waitid (P_PID, pid, &siginfo, WEXITED); nih_free (watch); /* Check that when a traced child execs it causes the reaper * to be called with a ptrace event and the exec event in the * status field. It should not be removed from the list since the * child hasn't gone away. */ TEST_FEATURE ("with exec by traced child"); TEST_CHILD (pid) { assert0 (ptrace (PTRACE_TRACEME, 0, NULL, NULL)); raise (SIGSTOP); execl ("/bin/true", "true", NULL); exit (255); } waitid (P_PID, pid, &siginfo, WSTOPPED); assert0 (ptrace (PTRACE_SETOPTIONS, pid, NULL, PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXEC)); assert0 (ptrace (PTRACE_CONT, pid, NULL, SIGCONT)); waitid (P_PID, pid, &siginfo, WSTOPPED | WNOWAIT); watch = nih_child_add_watch (NULL, pid, NIH_CHILD_PTRACE, my_handler, &watch); TEST_FREE_TAG (watch); handler_called = 0; last_data = NULL; last_pid = 0; last_event = -1; last_status = 0; nih_child_poll (); TEST_TRUE (handler_called); TEST_EQ (last_pid, pid); TEST_EQ (last_event, NIH_CHILD_PTRACE); TEST_EQ (last_status, PTRACE_EVENT_EXEC); TEST_NOT_FREE (watch); assert0 (ptrace (PTRACE_DETACH, pid, NULL, SIGCONT)); waitid (P_PID, pid, &siginfo, WEXITED); nih_free (watch); #if HAVE_VALGRIND_VALGRIND_H } #endif /* Check that we can watch for events from any process, which * shouldn't be freed when the child dies. */ TEST_FEATURE ("with generic watcher"); TEST_CHILD (pid) { pause (); } watch = nih_child_add_watch (NULL, -1, NIH_CHILD_ALL, my_handler, &watch); TEST_FREE_TAG (watch); handler_called = 0; last_data = NULL; last_pid = 0; last_event = -1; last_status = 0; kill (pid, SIGTERM); waitid (P_PID, pid, &siginfo, WEXITED | WNOWAIT); nih_child_poll (); TEST_TRUE (handler_called); TEST_EQ (last_pid, pid); TEST_EQ (last_event, NIH_CHILD_KILLED); TEST_EQ (last_status, SIGTERM); TEST_NOT_FREE (watch); nih_free (watch); /* Check that if we poll with an unknown pid, and no catch-all, * nothing is triggered and the watch is not removed. */ TEST_FEATURE ("with pid-specific watcher and wrong pid"); TEST_CHILD (pid) { pause (); } watch = nih_child_add_watch (NULL, pid - 1, NIH_CHILD_ALL, my_handler, &watch); TEST_FREE_TAG (watch); handler_called = 0; last_data = NULL; last_pid = 0; last_event = -1; last_status = 0; kill (pid, SIGTERM); waitid (P_PID, pid, &siginfo, WEXITED | WNOWAIT); nih_child_poll (); TEST_FALSE (handler_called); TEST_NOT_FREE (watch); nih_free (watch); /* Check that if we poll with a known pid but for a different event * set, nothing is triggered and the watch is not removed. */ TEST_FEATURE ("with event-specific watcher and wrong event"); TEST_CHILD (pid) { pause (); } watch = nih_child_add_watch (NULL, pid, NIH_CHILD_STOPPED, my_handler, &watch); TEST_FREE_TAG (watch); handler_called = 0; last_data = NULL; last_pid = 0; last_event = -1; last_status = 0; kill (pid, SIGTERM); waitid (P_PID, pid, &siginfo, WEXITED | WNOWAIT); nih_child_poll (); TEST_FALSE (handler_called); TEST_NOT_FREE (watch); nih_free (watch); /* Check that a poll when nothing has died does nothing. */ TEST_FEATURE ("with nothing dead"); TEST_CHILD (pid) { pause (); } watch = nih_child_add_watch (NULL, -1, NIH_CHILD_ALL, my_handler, &watch); TEST_FREE_TAG (watch); handler_called = 0; nih_child_poll (); TEST_FALSE (handler_called); TEST_NOT_FREE (watch); kill (pid, SIGTERM); waitpid (pid, NULL, 0); /* Check that a poll when there are no child processes does nothing */ TEST_FEATURE ("with no children"); handler_called = 0; nih_child_poll (); TEST_FALSE (handler_called); TEST_NOT_FREE (watch); nih_free (watch); } int main (int argc, char *argv[]) { test_add_watch (); test_poll (); return 0; } libnih-1.0.3/nih/tests/test_alloc.c0000644000175000017500000004317411445765555014150 00000000000000/* libnih * * test_alloc.c - test suite for nih/alloc.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include static void * malloc_null (size_t size) { return NULL; } void test_new (void) { void *ptr1; void *ptr2; TEST_FUNCTION ("nih_new"); /* Check that nih_new works if we don't give it a parent, the block * should be allocated with the size of the type given. */ TEST_FEATURE ("with no parent"); ptr1 = nih_new (NULL, int); TEST_ALLOC_SIZE (ptr1, sizeof (int)); TEST_ALLOC_PARENT (ptr1, NULL); /* Check that nih_new works if we do give a parent. */ TEST_FEATURE ("with parent"); ptr2 = nih_new (ptr1, char); TEST_ALLOC_SIZE (ptr2, sizeof (char)); TEST_ALLOC_PARENT (ptr2, ptr1); nih_free (ptr1); /* Check that nih_new returns NULL if allocation fails. */ TEST_FEATURE ("with failed allocation"); __nih_malloc = malloc_null; ptr1 = nih_new (NULL, int); __nih_malloc = malloc; TEST_EQ_P (ptr1, NULL); } void test_alloc (void) { void *ptr1; void *ptr2; TEST_FUNCTION ("nih_alloc"); /* Check allocation remembers the size, and is possible without * a parent. */ TEST_FEATURE ("with no parent"); ptr1 = nih_alloc (NULL, 8096); memset (ptr1, 'x', 8096); TEST_ALLOC_SIZE (ptr1, 8096); TEST_ALLOC_PARENT (ptr1, NULL); /* Check that allocation with a parent remembers the parent */ TEST_FEATURE ("with a parent"); ptr2 = nih_alloc (ptr1, 10); memset (ptr2, 'x', 10); TEST_ALLOC_SIZE (ptr2, 10); TEST_ALLOC_PARENT (ptr2, ptr1); nih_free (ptr1); /* Check that nih_alloc returns NULL if allocation fails. */ TEST_FEATURE ("with failed allocation"); __nih_malloc = malloc_null; ptr1 = nih_new (NULL, int); __nih_malloc = malloc; TEST_EQ_P (ptr1, NULL); } static void * realloc_null (void * ptr, size_t size) { return NULL; } void test_realloc (void) { void *ptr1; void *ptr2; void *ptr3; TEST_FUNCTION ("nih_realloc"); /* Check that nih_realloc behaves like nih_alloc if the pointer is * NULL (it should, in fact, just call it) */ TEST_FEATURE ("as nih_alloc"); ptr1 = nih_realloc (NULL, NULL, 4096); memset (ptr1, 'x', 4096); TEST_ALLOC_SIZE (ptr1, 4096); TEST_ALLOC_PARENT (ptr1, NULL); nih_free (ptr1); /* Check that nih_realloc works if the block doesn't have a parent. */ TEST_FEATURE ("with no parent"); ptr1 = nih_alloc (NULL, 4096); memset (ptr1, 'x', 4096); ptr1 = nih_realloc (ptr1, NULL, 8096); memset (ptr1, 'x', 8096); TEST_ALLOC_SIZE (ptr1, 8096); TEST_ALLOC_PARENT (ptr1, NULL); /* Check that nih_realloc works if the block has a parent, the size * should change but the parent should remain the same. */ TEST_FEATURE ("with a parent"); ptr2 = nih_alloc (ptr1, 5); memset (ptr2, 'x', 5); ptr2 = nih_realloc (ptr2, ptr1, 10); memset (ptr2, 'x', 10); TEST_ALLOC_SIZE (ptr2, 10); TEST_ALLOC_PARENT (ptr2, ptr1); nih_free (ptr1); /* Check that nih_realloc works if the block being reallocated has * a child. This is fiddly as they need their parent pointers * adjusted. */ TEST_FEATURE ("with a child"); ptr1 = nih_alloc (NULL, 128); memset (ptr1, 'x', 128); ptr2 = nih_alloc (ptr1, 512); memset (ptr2, 'x', 512); ptr3 = nih_realloc (ptr1, NULL, 1024); memset (ptr3, 'x', 1024); TEST_ALLOC_PARENT (ptr2, ptr3); nih_free (ptr3); /* Check that nih_realloc returns NULL and doesn't alter the block * if the allocator fails. */ TEST_FEATURE ("with failing realloc"); ptr1 = nih_alloc (NULL, 10); assert (ptr1); memset (ptr1, 'x', 10); __nih_realloc = realloc_null; ptr2 = nih_realloc (ptr1, NULL, 200); __nih_realloc = realloc; TEST_EQ_P (ptr2, NULL); TEST_ALLOC_SIZE (ptr1, 10); nih_free (ptr1); } static int destructor_was_called; static int destructor_called (void *ptr) { destructor_was_called++; return 2; } static int child_destructor_was_called; static int child_destructor_called (void *ptr) { child_destructor_was_called++; return 20; } typedef struct child { NihList entry; int invalid; } Child; typedef struct parent { NihList *list; Child * child; } Parent; static void *list_head_ptr = NULL; static int list_head_free = FALSE; static void * my_list_head_malloc (size_t size) { list_head_ptr = malloc (size); list_head_free = FALSE; return list_head_ptr; } static void my_list_head_free (void *ptr) { if (ptr == list_head_ptr) list_head_free = TRUE; free (ptr); } static int child_destructor_test (Child *child) { TEST_FALSE (list_head_free); return 0; } void test_free (void) { void * ptr1; void * ptr2; Parent *parent; int ret; TEST_FUNCTION ("nih_free"); /* Check that nih_free works if the block has no parent. The * destructor should get called and nih_free should return that * return value. */ TEST_FEATURE ("with no parent"); ptr1 = nih_alloc (NULL, 10); nih_alloc_set_destructor (ptr1, destructor_called); destructor_was_called = 0; ret = nih_free (ptr1); TEST_TRUE (destructor_was_called); TEST_EQ (ret, 2); /* Check that nih_free works if the block has a parent. The * destructor should get called and nih_free should return that * return value. */ TEST_FEATURE ("with parent"); ptr2 = nih_alloc (NULL, 20); ptr1 = nih_alloc (ptr2, 10); nih_alloc_set_destructor (ptr1, destructor_called); destructor_was_called = 0; ret = nih_free (ptr1); TEST_TRUE (destructor_was_called); TEST_EQ (ret, 2); nih_free (ptr2); /* Check that the destructor on any children also gets called, which * is as good a indication as any that the children are being freed. */ TEST_FEATURE ("with destructor on child"); ptr1 = nih_alloc (NULL, 10); ptr2 = nih_alloc (ptr1, 10); nih_alloc_set_destructor (ptr2, child_destructor_called); child_destructor_was_called = 0; ret = nih_free (ptr1); TEST_TRUE (child_destructor_was_called); TEST_EQ (ret, 0); /* Check that both destructors on parent and children are called, * and that the return value from nih_free is that of the parent's. */ TEST_FEATURE ("with child and destructors"); ptr1 = nih_alloc (NULL, 10); ptr2 = nih_alloc (ptr1, 10); nih_alloc_set_destructor (ptr1, destructor_called); nih_alloc_set_destructor (ptr2, child_destructor_called); destructor_was_called = 0; child_destructor_was_called = 0; ret = nih_free (ptr1); TEST_TRUE (destructor_was_called); TEST_TRUE (child_destructor_was_called); TEST_EQ (ret, 2); /* Check that a child of an object may be included in a sibling * linked list allocated earlier. At the point the child destructor * is called, the sibling must not have been freed otherwise it * cannot cut itself out. */ TEST_FEATURE ("with child in older sibling list"); parent = nih_new (NULL, Parent); __nih_malloc = my_list_head_malloc; parent->list = nih_new (parent, NihList); nih_list_init (parent->list); __nih_malloc = malloc; parent->child = nih_new (parent, Child); nih_list_init (&parent->child->entry); nih_list_add (parent->list, &parent->child->entry); nih_alloc_set_destructor (parent->child, child_destructor_test); __nih_free = my_list_head_free; nih_free (parent); __nih_free = free; /* Check that a child of an object may be included in a sibling * linked list allocated later. At the point the child destructor * is called, the sibling must not have been freed otherwise it * cannot cut itself out. */ TEST_FEATURE ("with child in younger sibling list"); parent = nih_new (NULL, Parent); parent->child = nih_new (parent, Child); nih_list_init (&parent->child->entry); __nih_malloc = my_list_head_malloc; parent->list = nih_new (parent, NihList); nih_list_init (parent->list); __nih_malloc = malloc; nih_list_add (parent->list, &parent->child->entry); nih_alloc_set_destructor (parent->child, child_destructor_test); __nih_free = my_list_head_free; nih_free (parent); __nih_free = free; } void test_discard (void) { void *ptr1; void *ptr2; int ret; TEST_FUNCTION ("nih_discard"); /* Check that nih_discard works if the block has no parent, freeing * the object. The destructor should get called and nih_discard * should return that return value. */ TEST_FEATURE ("with no parent"); ptr1 = nih_alloc (NULL, 10); nih_alloc_set_destructor (ptr1, destructor_called); destructor_was_called = 0; ret = nih_discard (ptr1); TEST_TRUE (destructor_was_called); TEST_EQ (ret, 2); /* Check that nih_discard does nothing it the block has a parent. */ TEST_FEATURE ("with parent"); ptr2 = nih_alloc (NULL, 20); ptr1 = nih_alloc (ptr2, 10); nih_alloc_set_destructor (ptr1, destructor_called); destructor_was_called = 0; ret = nih_discard (ptr1); TEST_FALSE (destructor_was_called); TEST_EQ (ret, 0); nih_free (ptr2); /* Check that the destructor on any children also gets called, which * is as good a indication as any that the children are being freed. */ TEST_FEATURE ("with destructor on child"); ptr1 = nih_alloc (NULL, 10); ptr2 = nih_alloc (ptr1, 10); nih_alloc_set_destructor (ptr2, child_destructor_called); child_destructor_was_called = 0; ret = nih_discard (ptr1); TEST_TRUE (child_destructor_was_called); TEST_EQ (ret, 0); /* Check that both destructors on parent and children are called, * and that the return value from nih_discard is that of the parent's. */ TEST_FEATURE ("with child and destructors"); ptr1 = nih_alloc (NULL, 10); ptr2 = nih_alloc (ptr1, 10); nih_alloc_set_destructor (ptr1, destructor_called); nih_alloc_set_destructor (ptr2, child_destructor_called); destructor_was_called = 0; child_destructor_was_called = 0; ret = nih_discard (ptr1); TEST_TRUE (destructor_was_called); TEST_TRUE (child_destructor_was_called); TEST_EQ (ret, 2); } void test_ref (void) { void *ptr1; void *ptr2; void *ptr3; TEST_FUNCTION ("nih_ref"); /* Check that we can add a reference to an object that has no * parent, and this does not remove the NULL reference. */ TEST_FEATURE ("with no parent"); ptr1 = nih_alloc (NULL, 100); memset (ptr1, 'x', 100); ptr2 = nih_alloc (NULL, 100); memset (ptr2, 'y', 100); nih_ref (ptr1, ptr2); TEST_ALLOC_PARENT (ptr1, ptr2); TEST_ALLOC_PARENT (ptr1, NULL); nih_free (ptr1); nih_free (ptr2); /* Check that we can add a reference to an object that already has * a parent, and that both shall be parents afterwards. */ TEST_FEATURE ("with existing parent"); ptr1 = nih_alloc (NULL, 100); memset (ptr1, 'x', 100); ptr2 = nih_alloc (ptr1, 100); memset (ptr2, 'y', 100); ptr3 = nih_alloc (NULL, 100); memset (ptr2, 'z', 100); nih_ref (ptr2, ptr3); TEST_ALLOC_PARENT (ptr2, ptr1); TEST_ALLOC_PARENT (ptr2, ptr3); nih_free (ptr1); nih_free (ptr3); /* Check that we can add a new NULL reference to an object that * already has a parent, and that both shall be parents afterwards. */ TEST_FEATURE ("with existing parent and new NULL"); ptr1 = nih_alloc (NULL, 100); memset (ptr1, 'x', 100); ptr2 = nih_alloc (ptr1, 100); memset (ptr2, 'y', 100); nih_ref (ptr2, NULL); TEST_ALLOC_PARENT (ptr2, ptr1); TEST_ALLOC_PARENT (ptr2, NULL); nih_free (ptr1); nih_free (ptr2); /* Check that we can add a second NULL reference to an object that * already has one. */ TEST_FEATURE ("with additional NULL parent"); ptr1 = nih_alloc (NULL, 100); memset (ptr1, 'x', 100); nih_ref (ptr1, NULL); TEST_ALLOC_PARENT (ptr1, NULL); nih_free (ptr1); /* Check that we can add a second reference to an object that already * has a reference from the same parent. */ TEST_FEATURE ("with additional existing parent"); ptr1 = nih_alloc (NULL, 100); memset (ptr1, 'x', 100); ptr2 = nih_alloc (ptr1, 100); memset (ptr2, 'y', 100); nih_ref (ptr2, ptr1); TEST_ALLOC_PARENT (ptr2, ptr1); nih_free (ptr2); nih_free (ptr1); } void test_unref (void) { void *ptr1; void *ptr2; void *ptr3; TEST_FUNCTION ("nih_unref"); /* Check that we can remove a reference from an object with multiple * parents, which means the object will not be freed. */ TEST_FEATURE ("with multiple parents"); ptr1 = nih_alloc (NULL, 100); memset (ptr1, 'x', 100); ptr2 = nih_alloc (ptr1, 100); memset (ptr2, 'y', 100); ptr3 = nih_alloc (NULL, 100); memset (ptr2, 'z', 100); nih_ref (ptr2, ptr3); nih_alloc_set_destructor (ptr2, destructor_called); destructor_was_called = 0; nih_unref (ptr2, ptr1); TEST_FALSE (destructor_was_called); TEST_ALLOC_PARENT (ptr2, ptr3); nih_free (ptr1); nih_free (ptr3); /* Check that when we remove the last reference from an object, * the object is freed. */ TEST_FEATURE ("with last parent"); ptr1 = nih_alloc (NULL, 100); memset (ptr1, 'x', 100); ptr2 = nih_alloc (ptr1, 100); memset (ptr2, 'y', 100); nih_alloc_set_destructor (ptr2, destructor_called); destructor_was_called = 0; nih_unref (ptr2, ptr1); TEST_TRUE (destructor_was_called); nih_free (ptr1); /* Check that we have to remove the NULL reference from an object * for it to be freed. */ TEST_FEATURE ("with only NULL parent"); ptr1 = nih_alloc (NULL, 100); memset (ptr1, 'x', 100); nih_alloc_set_destructor (ptr1, destructor_called); destructor_was_called = 0; nih_unref (ptr1, NULL); TEST_TRUE (destructor_was_called); /* Check that we can remove the NULL reference leaving a reference * to a different object. */ TEST_FEATURE ("with no parent and other parent"); ptr1 = nih_alloc (NULL, 100); memset (ptr1, 'x', 100); ptr2 = nih_alloc (NULL, 100); memset (ptr2, 'y', 100); nih_ref (ptr2, ptr1); nih_alloc_set_destructor (ptr2, destructor_called); destructor_was_called = 0; nih_unref (ptr2, NULL); TEST_FALSE (destructor_was_called); TEST_ALLOC_PARENT (ptr2, ptr1); TEST_FALSE (nih_alloc_parent (ptr2, NULL)); nih_free (ptr1); /* Check that an object with multiple NULL references must have * them both removed before it will be freed. */ TEST_FEATURE ("with multiple NULL parents"); ptr1 = nih_alloc (NULL, 100); memset (ptr1, 'x', 100); nih_ref (ptr1, NULL); nih_alloc_set_destructor (ptr1, destructor_called); destructor_was_called = 0; nih_unref (ptr1, NULL); TEST_FALSE (destructor_was_called); nih_unref (ptr1, NULL); TEST_TRUE (destructor_was_called); /* Check that an object with multiple identical references must have * them both removed before it will be freed. */ TEST_FEATURE ("with multiple identical parents"); ptr1 = nih_alloc (NULL, 100); memset (ptr1, 'x', 100); ptr2 = nih_alloc (ptr1, 100); memset (ptr2, 'y', 100); nih_ref (ptr2, ptr1); nih_alloc_set_destructor (ptr2, destructor_called); destructor_was_called = 0; nih_unref (ptr2, ptr1); TEST_FALSE (destructor_was_called); nih_unref (ptr2, ptr1); TEST_TRUE (destructor_was_called); nih_free (ptr1); } void test_parent (void) { void *ptr1; void *ptr2; void *ptr3; TEST_FUNCTION ("nih_alloc_parent"); /* Check that nih_alloc_parent returns TRUE when the passed object * is a child of the passed parent. */ TEST_FEATURE ("with child and parent"); ptr1 = nih_alloc (NULL, 10); ptr2 = nih_alloc (ptr1, 10); TEST_TRUE (nih_alloc_parent (ptr2, ptr1)); nih_free (ptr1); /* Check that nih_alloc_parent returns TRUE when the passed object * is a child of the NULL parent. */ TEST_FEATURE ("with child and NULL parent"); ptr1 = nih_alloc (NULL, 10); TEST_TRUE (nih_alloc_parent (ptr1, NULL)); nih_free (ptr1); /* Check that nih_alloc_parent returns FALSE when the passed object * is a child but not of the passed parent. */ TEST_FEATURE ("with child and wrong parent"); ptr1 = nih_alloc (NULL, 10); ptr2 = nih_alloc (ptr1, 10); ptr3 = nih_alloc (NULL, 10); TEST_FALSE (nih_alloc_parent (ptr2, ptr3)); nih_free (ptr1); nih_free (ptr3); /* Check that nih_alloc_parent returns FALSE when the passed object * is an orphan. */ TEST_FEATURE ("with orphan"); ptr1 = nih_alloc (NULL, 10); ptr2 = nih_alloc (NULL, 10); TEST_FALSE (nih_alloc_parent (ptr2, ptr1)); nih_free (ptr1); nih_free (ptr2); } void test_local (void) { void *parent; void *_ptr; TEST_GROUP ("nih_local"); /* Make sure that when a variable goes out of scope, it's freed. */ TEST_FEATURE ("with variable going out of scope"); do { nih_local void *ptr; ptr = nih_alloc (NULL, 100); nih_alloc_set_destructor (ptr, destructor_called); destructor_was_called = 0; } while (0); TEST_TRUE (destructor_was_called); /* Make sure that if a variable is referenced while in scope, it * is not freed. */ TEST_FEATURE ("with referenced variable"); parent = nih_alloc (NULL, 100); do { nih_local void *ptr; ptr = nih_alloc (NULL, 100); nih_ref (ptr, parent); _ptr = ptr; nih_alloc_set_destructor (ptr, destructor_called); destructor_was_called = 0; } while (0); TEST_FALSE (destructor_was_called); TEST_ALLOC_PARENT (_ptr, parent); nih_free (parent); /* Make sure we don't need to allocate the variable. */ TEST_FEATURE ("with NULL variable"); do { nih_local void *ptr = NULL; } while (0); } int main (int argc, char *argv[]) { test_new (); test_alloc (); test_realloc (); test_free (); test_discard (); test_ref (); test_unref (); test_parent (); test_local (); return 0; } libnih-1.0.3/nih/tests/test_error.c0000644000175000017500000002550511445765555014205 00000000000000/* libnih * * test_error.c - test suite for nih/error.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include void test_raise (void) { NihError *error; /* Check that after raising an error, we can get it again, and that * the number and message are what we gave. */ TEST_FUNCTION ("nih_error_raise"); nih_error_push_context (); TEST_ALLOC_FAIL { nih_error_raise (0x20001, "Test error"); error = nih_error_get (); TEST_EQ (error->number, 0x20001); TEST_EQ_STR (error->message, "Test error"); nih_free (error); } nih_error_pop_context (); } void test_raise_printf (void) { NihError *error; /* Check that we can raise an error with a formatted string, and * that when we get it, the message is formatted appropriately and * that the string is a child of the error object. */ TEST_FUNCTION ("nih_error_raise_printf"); nih_error_push_context (); TEST_ALLOC_FAIL { nih_error_raise_printf (0x20002, "This is a %s error %d", "test", 123); error = nih_error_get (); TEST_EQ (error->number, 0x20002); TEST_EQ_STR (error->message, "This is a test error 123"); TEST_ALLOC_PARENT (error->message, error); nih_free (error); } nih_error_pop_context (); } void test_raise_system (void) { NihError *error; /* Check that we can raise a system error, which takes the number and * message from the errno table. */ TEST_FUNCTION ("nih_error_raise_system"); nih_error_push_context (); TEST_ALLOC_FAIL { errno = ENOENT; nih_error_raise_system (); error = nih_error_get (); TEST_EQ (error->number, ENOENT); TEST_EQ_STR (error->message, strerror (ENOENT)); TEST_ALLOC_PARENT (error->message, error); nih_free (error); } nih_error_pop_context (); } void test_raise_no_memory (void) { NihError *error; /* Check that we can raise a no memory error. */ TEST_FUNCTION ("nih_error_raise_no_memory"); nih_error_push_context (); TEST_ALLOC_FAIL { nih_error_raise_no_memory (); error = nih_error_get (); TEST_EQ (error->number, ENOMEM); TEST_EQ_STR (error->message, strerror (ENOMEM)); nih_free (error); } nih_error_pop_context (); } void test_raise_error (void) { NihError *error1 = NULL; NihError *error2 = NULL; pid_t pid = 0; int status; FILE * output; char corefile[PATH_MAX + 1]; TEST_FUNCTION ("nih_error_raise_error"); output = tmpfile (); /* Check that we can raise an arbitrary error object, and that we * get the exact pointer we raised. */ TEST_FEATURE ("with no current error"); nih_error_push_context (); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { error1 = nih_new (NULL, NihError); error1->number = ENOENT; error1->message = strerror (ENOENT); } nih_error_raise_error (error1); error2 = nih_error_get (); TEST_EQ_P (error2, error1); nih_free (error1); } nih_error_pop_context (); /* Check that an error raised while there's already an unhandled * error causes an assertion. */ TEST_FEATURE ("with unhandled error"); nih_error_push_context (); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { error1 = nih_new (NULL, NihError); error1->number = ENOENT; error1->message = strerror (ENOENT); } TEST_FREE_TAG (error1); nih_error_raise_error (error1); TEST_ALLOC_SAFE { error2 = nih_new (NULL, NihError); error2->number = ENODEV; error2->message = strerror (ENODEV); } TEST_DIVERT_STDERR (output) { TEST_CHILD (pid) { nih_error_raise_error (error2); exit (0); } } waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGABRT); rewind (output); TEST_FILE_MATCH (output, ("test:*tests/test_error.c:[0-9]*: " "Unhandled error from test_raise_error: " "No such file or directory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); unlink ("core"); sprintf (corefile, "core.%d", pid); unlink (corefile); sprintf (corefile, "vgcore.%d", pid); unlink (corefile); nih_free (error1); nih_free (error2); } nih_error_pop_context (); fclose (output); } static int call_return_error (int ret, int number, const char *message) { nih_return_error (ret, number, message); return 254; } void test_return_error (void) { NihError *error; int ret; /* Check that the macro to raise an error and return from a * function does just that. */ TEST_FUNCTION ("nih_return_error"); nih_error_push_context (); TEST_ALLOC_FAIL { ret = call_return_error (-1, 0x20001, "Test error"); error = nih_error_get (); TEST_EQ (ret, -1); TEST_EQ (error->number, 0x20001); TEST_EQ_STR (error->message, "Test error"); nih_free (error); } nih_error_pop_context (); } static int call_return_system_error (int ret) { nih_return_system_error (ret); } void test_return_system_error (void) { NihError *error; int ret; /* Check that the macro to raise an error based on the value of * errno and return from a function does just that. */ TEST_FUNCTION ("nih_return_system_error"); nih_error_push_context (); TEST_ALLOC_FAIL { errno = ENOENT; ret = call_return_system_error (-1); error = nih_error_get (); TEST_EQ (ret, -1); TEST_EQ (error->number, ENOENT); TEST_EQ_STR (error->message, strerror (ENOENT)); nih_free (error); } nih_error_pop_context (); } static int call_return_no_memory_error (int ret) { nih_return_no_memory_error (ret); } void test_return_no_memory_error (void) { NihError *error; int ret; /* Check that the macro to raise an ENOMEM error return from a * function does just that without modifying errno. */ TEST_FUNCTION ("nih_return_no_memory_error"); nih_error_push_context (); TEST_ALLOC_FAIL { errno = ENOENT; ret = call_return_no_memory_error (-1); error = nih_error_get (); TEST_EQ (ret, -1); TEST_EQ (error->number, ENOMEM); TEST_EQ_STR (error->message, strerror (ENOMEM)); if (! test_alloc_failed) TEST_EQ (errno, ENOENT); nih_free (error); } nih_error_pop_context (); } void test_steal (void) { NihError *error1; NihError *error2; TEST_FUNCTION ("nih_error_steal"); /* Check that after raising an error, we can steal it, and raise * another error in its place without freeing the original error. */ TEST_FEATURE ("with same context"); nih_error_push_context (); TEST_ALLOC_FAIL { nih_error_raise (0x20001, "Test error"); error1 = nih_error_steal (); TEST_EQ (error1->number, 0x20001); TEST_EQ_STR (error1->message, "Test error"); TEST_FREE_TAG (error1); nih_error_raise (0x20002, "Different error"); error2 = nih_error_get (); TEST_NE_P (error2, error1); TEST_NOT_FREE (error1); TEST_EQ (error2->number, 0x20002); TEST_EQ_STR (error2->message, "Different error"); nih_free (error2); nih_free (error1); } nih_error_pop_context (); /* Check that nih_error_steal() can be used to raise an error from * one context into another. */ TEST_FEATURE ("with different contexts"); nih_error_push_context (); TEST_ALLOC_FAIL { nih_error_push_context (); nih_error_raise (0x20001, "Test error"); error1 = nih_error_steal (); TEST_EQ (error1->number, 0x20001); TEST_EQ_STR (error1->message, "Test error"); TEST_FREE_TAG (error1); nih_error_pop_context (); TEST_NOT_FREE (error1); nih_error_raise_error (error1); error2 = nih_error_get (); TEST_EQ_P (error2, error1); TEST_NOT_FREE (error1); TEST_EQ (error2->number, 0x20001); TEST_EQ_STR (error2->message, "Test error"); nih_free (error1); } nih_error_pop_context (); } void test_push_context (void) { NihError *error; /* Check that we can push an error context over the top of a * handled error, and that if we try and raise then get an error * afterwards, we get the newer one. */ TEST_FUNCTION ("nih_error_push_context"); TEST_ALLOC_FAIL { nih_error_raise (0x20003, "Error in default context"); nih_error_push_context (); nih_error_raise (0x20004, "Error in new context"); error = nih_error_get (); TEST_EQ (error->number, 0x20004); nih_free (error); nih_error_pop_context (); nih_free (nih_error_get ()); } } void test_pop_context (void) { NihError *error; FILE * output; pid_t pid = 0; int status; char corefile[PATH_MAX + 1]; TEST_FUNCTION ("nih_error_pop_context"); output = tmpfile (); /* Check that we can pop the error context; when doing so, if an * unhandled error exists then an assertion is raised. */ TEST_FEATURE ("with unhandled error in context"); TEST_ALLOC_FAIL { TEST_DIVERT_STDERR (output) { TEST_CHILD (pid) { nih_error_push_context (); nih_error_raise (0x20004, "Error in new context"); error = nih_error_get (); nih_error_pop_context (); exit (0); } } waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGABRT); rewind (output); TEST_FILE_MATCH (output, ("test:*tests/test_error.c:[0-9]*: " "Unhandled error from test_pop_context: " "Error in new context\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); unlink ("core"); sprintf (corefile, "core.%d", pid); unlink (corefile); sprintf (corefile, "vgcore.%d", pid); unlink (corefile); } /* Check that once popped, any unhandled error in lower contexts * is available again. */ TEST_FEATURE ("with unhandled error beneath context"); TEST_ALLOC_FAIL { nih_error_raise (0x20003, "Error in default context"); nih_error_push_context (); nih_error_raise (0x20004, "Error in new context"); error = nih_error_get (); TEST_EQ (error->number, 0x20004); nih_free (error); nih_error_pop_context (); error = nih_error_get (); TEST_EQ (error->number, 0x20003); nih_free (error); } fclose (output); } int main (int argc, char *argv[]) { program_name = "test"; nih_error_init (); test_raise (); test_raise_printf (); test_raise_system (); test_raise_no_memory (); test_raise_error (); test_return_error (); test_return_system_error (); test_return_no_memory_error (); test_steal (); test_push_context (); test_pop_context (); return 0; } libnih-1.0.3/nih/tests/test_timer.c0000644000175000017500000001524211445765555014171 00000000000000/* libnih * * test_timer.c - test suite for nih/timer.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include static int callback_called = 0; static void *last_data; static NihTimer *last_timer; static void my_callback (void *data, NihTimer *timer) { callback_called++; last_data = data; last_timer = timer; } void test_add_timeout (void) { NihTimer * timer; struct timespec t1; struct timespec t2; /* Check that we can add a timeout function and that the structure * returned is correctly populated and placed in the timers list. */ TEST_FUNCTION ("nih_timer_add_timeout"); nih_timer_poll (); TEST_ALLOC_FAIL { assert0 (clock_gettime (CLOCK_MONOTONIC, &t1)); timer = nih_timer_add_timeout (NULL, 10, my_callback, &timer); assert0 (clock_gettime (CLOCK_MONOTONIC, &t2)); if (test_alloc_failed) { TEST_EQ_P (timer, NULL); continue; } TEST_ALLOC_SIZE (timer, sizeof (NihTimer)); TEST_LIST_NOT_EMPTY (&timer->entry); TEST_EQ (timer->type, NIH_TIMER_TIMEOUT); TEST_GE (timer->due, t1.tv_sec + 10); TEST_LE (timer->due, t2.tv_sec + 10); TEST_EQ (timer->timeout, 10); TEST_EQ_P (timer->callback, my_callback); TEST_EQ_P (timer->data, &timer); /* Check that the timer is the next one due. */ TEST_EQ_P (nih_timer_next_due (), timer); nih_free (timer); } } void test_add_periodic (void) { NihTimer * timer; struct timespec t1; struct timespec t2; /* Check that we can add a periodic function and that the structure * returned is correctly populated and placed in the timers list. */ TEST_FUNCTION ("nih_timer_add_periodic"); nih_timer_poll (); TEST_ALLOC_FAIL { assert0 (clock_gettime (CLOCK_MONOTONIC, &t1)); timer = nih_timer_add_periodic (NULL, 25, my_callback, &timer); assert0 (clock_gettime (CLOCK_MONOTONIC, &t2)); if (test_alloc_failed) { TEST_EQ_P (timer, NULL); continue; } TEST_ALLOC_SIZE (timer, sizeof (NihTimer)); TEST_LIST_NOT_EMPTY (&timer->entry); TEST_EQ (timer->type, NIH_TIMER_PERIODIC); TEST_GE (timer->due, t1.tv_sec + 25); TEST_LE (timer->due, t2.tv_sec + 25); TEST_EQ (timer->timeout, 25); TEST_EQ_P (timer->callback, my_callback); TEST_EQ_P (timer->data, &timer); /* Check that the timer is the next one due. */ TEST_EQ_P (nih_timer_next_due (), timer); nih_free (timer); } } void test_add_scheduled (void) { NihTimerSchedule schedule; NihTimer * timer; struct timespec t1; struct timespec t2; /* Check that we can add a scheduled timer and that the structure * returned is correctly populated, including copying the schedule * from the structure we gave and placed in the timers list. */ TEST_FUNCTION ("nih_timer_add_scheduled"); nih_timer_poll (); TEST_ALLOC_FAIL { memset (&schedule, 0, sizeof (NihTimerSchedule)); assert0 (clock_gettime (CLOCK_MONOTONIC, &t1)); timer = nih_timer_add_scheduled (NULL, &schedule, my_callback, &timer); assert0 (clock_gettime (CLOCK_MONOTONIC, &t2)); if (test_alloc_failed) { TEST_EQ_P (timer, NULL); continue; } TEST_ALLOC_SIZE (timer, sizeof (NihTimer)); TEST_LIST_NOT_EMPTY (&timer->entry); TEST_EQ (timer->type, NIH_TIMER_SCHEDULED); TEST_EQ (timer->schedule.minutes, schedule.minutes); TEST_EQ (timer->schedule.hours, schedule.hours); TEST_EQ (timer->schedule.mdays, schedule.mdays); TEST_EQ (timer->schedule.months, schedule.months); TEST_EQ (timer->schedule.wdays, schedule.wdays); TEST_EQ_P (timer->callback, my_callback); TEST_EQ_P (timer->data, &timer); /* Check that the timer is the next one due. */ TEST_EQ_P (nih_timer_next_due (), timer); nih_free (timer); } } void test_next_due (void) { NihTimer *timer1, *timer2, *timer3; /* Check that timers become due in the correct order by scheduling * three in a random order, and then iterating through until there * are no more left. */ TEST_FUNCTION ("nih_timer_next_due"); timer1 = nih_timer_add_timeout (NULL, 10, my_callback, &timer1); timer2 = nih_timer_add_timeout (NULL, 5, my_callback, &timer2); timer3 = nih_timer_add_timeout (NULL, 15, my_callback, &timer3); TEST_EQ_P (nih_timer_next_due (), timer2); nih_free (timer2); TEST_EQ_P (nih_timer_next_due (), timer1); nih_free (timer1); TEST_EQ_P (nih_timer_next_due (), timer3); nih_free (timer3); TEST_EQ_P (nih_timer_next_due (), NULL); } void test_poll (void) { NihTimer * timer1; NihTimer * timer2; struct timespec now; struct timespec t1; struct timespec t2; TEST_FUNCTION ("nih_timer_poll"); timer1 = nih_timer_add_timeout (NULL, 10, my_callback, &timer1); timer2 = nih_timer_add_periodic (NULL, 20, my_callback, &timer2); TEST_FREE_TAG (timer1); TEST_FREE_TAG (timer2); /* Check that we can poll for timers to be triggered, and have the * first timeout run. Once run, the timer should be destroyed. */ TEST_FEATURE ("with timeout"); callback_called = 0; last_data = NULL; last_timer = NULL; assert0 (clock_gettime (CLOCK_MONOTONIC, &now)); timer1->due = now.tv_sec - 5; nih_timer_poll (); TEST_EQ (callback_called, 1); TEST_EQ_P (last_timer, timer1); TEST_EQ_P (last_data, &timer1); TEST_FREE (timer1); /* Check that we can poll again and have the periodic timer run, * that should be rescheduled instead of destroyed. */ TEST_FEATURE ("with periodic timer"); callback_called = 0; last_data = NULL; last_timer = NULL; assert0 (clock_gettime (CLOCK_MONOTONIC, &now)); timer2->due = now.tv_sec - 5; assert0 (clock_gettime (CLOCK_MONOTONIC, &t1)); nih_timer_poll (); assert0 (clock_gettime (CLOCK_MONOTONIC, &t2)); TEST_EQ (callback_called, 1); TEST_EQ_P (last_timer, timer2); TEST_EQ_P (last_data, &timer2); TEST_NOT_FREE (timer2); TEST_GE (timer2->due, t1.tv_sec + 20); TEST_LE (timer2->due, t2.tv_sec + 20); nih_free (timer2); } int main (int argc, char *argv[]) { test_add_timeout (); test_add_periodic (); test_add_scheduled (); test_next_due (); test_poll (); return 0; } libnih-1.0.3/nih/tests/test_logging.c0000644000175000017500000002520011445765555014472 00000000000000/* libnih * * test_logging.c - test suite for nih/logging.c * * Copyright © 2010 Scott James Remnant . * Copyright © 2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include extern char *__abort_msg __attribute__ ((weak)); static NihLogLevel last_priority = NIH_LOG_UNKNOWN; static char * last_message = NULL; static int my_logger (NihLogLevel priority, const char *message) { TEST_ALLOC_SAFE { last_priority = priority; last_message = strdup (message); } if (! strcmp (message, "this should error")) return -1; return 0; } void test_set_logger (void) { /* Check that we can change the logger function, and that the * function is called for the logging macros that follow. */ TEST_FUNCTION ("nih_log_set_logger"); TEST_ALLOC_FAIL { nih_log_set_priority (NIH_LOG_MESSAGE); nih_log_set_logger (my_logger); last_priority = NIH_LOG_UNKNOWN; nih_fatal ("some message"); TEST_EQ (last_priority, NIH_LOG_FATAL); free (last_message); nih_log_set_logger (nih_logger_printf); } } void test_set_priority (void) { /* Check that we reduce the minimum priority and end up getting * log messages we wouldn't have previously received. */ TEST_FUNCTION ("nih_log_set_priority"); TEST_ALLOC_FAIL { nih_log_set_logger (my_logger); nih_log_set_priority (NIH_LOG_DEBUG); last_priority = NIH_LOG_UNKNOWN; nih_debug ("some message"); TEST_EQ (last_priority, NIH_LOG_DEBUG); free (last_message); nih_log_set_logger (nih_logger_printf); nih_log_set_priority (NIH_LOG_MESSAGE); } } void test_log_message (void) { char *msg = NULL; int ret; TEST_FUNCTION ("nih_log_message"); nih_log_set_logger (my_logger); /* Check that a message with high enough priority makes it through * to the logger. */ TEST_FEATURE ("with message of high enough priority"); TEST_ALLOC_FAIL { last_priority = NIH_LOG_UNKNOWN; last_message = NULL; ret = nih_log_message (NIH_LOG_FATAL, "message with %s %d formatting", "some", 20); TEST_EQ (ret, 0); TEST_EQ (last_priority, NIH_LOG_FATAL); TEST_EQ_STR (last_message, "message with some 20 formatting"); free (last_message); } /* Check that a message with insufficient priority does not make it * through to the logger. */ TEST_FEATURE ("with message of insufficient priority"); TEST_ALLOC_FAIL { last_priority = NIH_LOG_UNKNOWN; last_message = NULL; ret = nih_log_message (NIH_LOG_DEBUG, "not high enough"); TEST_GT (ret, 0); TEST_EQ (last_priority, NIH_LOG_UNKNOWN); TEST_EQ_P (last_message, NULL); } /* Check that an error code returned from the logger is returned * by the function. */ TEST_FEATURE ("with error code returned from logger"); TEST_ALLOC_FAIL { ret = nih_log_message (NIH_LOG_FATAL, "this should error"); TEST_LT (ret, 0); free (last_message); } /* Check that a fatal message is also stored in the glibc __abort_msg * variable. */ if (&__abort_msg) { TEST_FEATURE ("with fatal message"); TEST_ALLOC_FAIL { __abort_msg = NULL; last_priority = NIH_LOG_UNKNOWN; last_message = NULL; ret = nih_log_message (NIH_LOG_FATAL, "message with %s %d formatting", "some", 20); TEST_EQ (ret, 0); TEST_EQ (last_priority, NIH_LOG_FATAL); TEST_EQ_STR (last_message, "message with some 20 formatting"); TEST_NE_P (__abort_msg, NULL); TEST_ALLOC_PARENT (__abort_msg, NULL); TEST_EQ_STR (__abort_msg, "message with some 20 formatting"); free (last_message); } /* Check that a fatal message can safely overwrite one already stored * in the glibc __abort_msg variable. */ TEST_FEATURE ("with second fatal message"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { msg = nih_strdup (NULL, "test"); } __abort_msg = msg; TEST_FREE_TAG (msg); last_priority = NIH_LOG_UNKNOWN; last_message = NULL; ret = nih_log_message (NIH_LOG_FATAL, "message with %s %d formatting", "some", 20); TEST_EQ (ret, 0); TEST_EQ (last_priority, NIH_LOG_FATAL); TEST_EQ_STR (last_message, "message with some 20 formatting"); TEST_FREE (msg); TEST_NE_P (__abort_msg, NULL); TEST_ALLOC_PARENT (__abort_msg, NULL); TEST_EQ_STR (__abort_msg, "message with some 20 formatting"); free (last_message); } } else { printf ("SKIP: __abort_msg not available\n"); } /* Check that the nih_debug macro wraps the call properly and * includes the function in which the message occurred. */ TEST_FUNCTION ("nih_debug"); TEST_ALLOC_FAIL { last_priority = NIH_LOG_UNKNOWN; last_message = NULL; nih_log_set_priority (NIH_LOG_DEBUG); ret = nih_debug ("%s debugging message", "a"); TEST_EQ (ret, 0); TEST_EQ (last_priority, NIH_LOG_DEBUG); TEST_EQ_STR (last_message, "test_log_message: a debugging message"); free (last_message); } /* Check that the nih_info macro wraps the call properly. */ TEST_FUNCTION ("nih_info"); TEST_ALLOC_FAIL { last_priority = NIH_LOG_UNKNOWN; last_message = NULL; ret = nih_info ("%d formatted %s", 47, "message"); TEST_EQ (ret, 0); TEST_EQ (last_priority, NIH_LOG_INFO); TEST_EQ_STR (last_message, "47 formatted message"); free (last_message); } /* Check that the nih_warn macro wraps the call properly. */ TEST_FUNCTION ("nih_warn"); TEST_ALLOC_FAIL { last_priority = NIH_LOG_UNKNOWN; last_message = NULL; ret = nih_warn ("%d formatted %s", -2, "text"); TEST_EQ (ret, 0); TEST_EQ (last_priority, NIH_LOG_WARN); TEST_EQ_STR (last_message, "-2 formatted text"); free (last_message); } /* Check that the nih_message macro wraps the call properly. */ TEST_FUNCTION ("nih_message"); TEST_ALLOC_FAIL { last_priority = NIH_LOG_UNKNOWN; last_message = NULL; ret = nih_message ("%d formatted %s", -24, "string"); TEST_EQ (ret, 0); TEST_EQ (last_priority, NIH_LOG_MESSAGE); TEST_EQ_STR (last_message, "-24 formatted string"); free (last_message); } /* Check that the nih_error macro wraps the call properly. */ TEST_FUNCTION ("nih_error"); TEST_ALLOC_FAIL { last_priority = NIH_LOG_UNKNOWN; last_message = NULL; ret = nih_error ("formatted %d %s", 42, "text"); TEST_EQ (ret, 0); TEST_EQ (last_priority, NIH_LOG_ERROR); TEST_EQ_STR (last_message, "formatted 42 text"); free (last_message); } /* Check that the nih_fatal macro wraps the call properly. */ TEST_FUNCTION ("nih_fatal"); TEST_ALLOC_FAIL { last_priority = NIH_LOG_UNKNOWN; last_message = NULL; ret = nih_fatal ("%s message %d", "formatted", 999); TEST_EQ (ret, 0); TEST_EQ (last_priority, NIH_LOG_FATAL); TEST_EQ_STR (last_message, "formatted message 999"); free (last_message); } nih_log_set_priority (NIH_LOG_MESSAGE); nih_log_set_logger (nih_logger_printf); } void test_logger_printf (void) { FILE *output; int ret = 0; TEST_FUNCTION ("nih_logger_printf"); output = tmpfile (); nih_log_set_priority (NIH_LOG_DEBUG); /* Check that a low priority message is output to stdout and formatted * correctly, without the program name prefixed to the front. */ TEST_FEATURE ("with low priority message"); TEST_ALLOC_FAIL { TEST_DIVERT_STDOUT (output) { ret = nih_log_message (NIH_LOG_DEBUG, "message with %s %d formatting", "some", 20); } rewind (output); TEST_EQ (ret, 0); TEST_FILE_EQ (output, "message with some 20 formatting\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that ordinary messages are output on stdout and formatted * correctly, without the program name prefixed on the front. */ TEST_FEATURE ("with ordinary message"); TEST_ALLOC_FAIL { TEST_DIVERT_STDOUT (output) { ret = nih_log_message (NIH_LOG_MESSAGE, "message with %s %d formatting", "some", 20); } rewind (output); TEST_EQ (ret, 0); TEST_FILE_EQ (output, "message with some 20 formatting\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that warning messages are output on stderr and formatted * correctly, with the program name prefixed on the front. */ TEST_FEATURE ("with ordinary message"); TEST_ALLOC_FAIL { TEST_DIVERT_STDERR (output) { ret = nih_log_message (NIH_LOG_WARN, "message with %s %d formatting", "some", 20); } rewind (output); TEST_EQ (ret, 0); TEST_FILE_EQ (output, "test: message with some 20 formatting\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a high priority message is output to stderr and formatted * correctly, with the program name prefixed on the front. */ TEST_FEATURE ("with high priority message"); TEST_ALLOC_FAIL { TEST_DIVERT_STDERR (output) { ret = nih_log_message (NIH_LOG_FATAL, "%s message %d formatted", "error", -1); } rewind (output); TEST_EQ (ret, 0); TEST_FILE_EQ (output, "test: error message -1 formatted\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a message with a GNU-style filename prefix is correctly * formatted, with no space between the program name and the message. */ TEST_FEATURE ("with prefixed message"); TEST_ALLOC_FAIL { TEST_DIVERT_STDERR (output) { ret = nih_log_message (NIH_LOG_FATAL, "%s:%d: some error or other", "example.txt", 303); } rewind (output); TEST_EQ (ret, 0); TEST_FILE_EQ (output, "test:example.txt:303: some error or other\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an error code is returned if the output stream is * closed. */ TEST_FEATURE ("with closed stream"); TEST_ALLOC_FAIL { TEST_DIVERT_STDERR (output) { close (STDERR_FILENO); ret = nih_log_message (NIH_LOG_FATAL, "an error message"); } TEST_LT (ret, 0); } fclose (output); nih_log_set_priority (NIH_LOG_MESSAGE); } int main (int argc, char *argv[]) { program_name = "test"; test_set_logger (); test_set_priority (); test_log_message (); test_logger_printf (); return 0; } libnih-1.0.3/nih/tests/test_watch.c0000644000175000017500000011036211445765555014156 00000000000000/* libnih * * test_watch.c - test suite for nih/watch.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static int my_filter (void *data, const char *path, int is_dir) { char *slash; slash = strrchr (path, '/'); if (! strcmp (slash, "/frodo")) return TRUE; return FALSE; } static int create_called = 0; static int modify_called = 0; static int delete_called = 0; static NihWatch *last_watch = NULL; static char *last_path = NULL; static void *last_data = NULL; static void my_create_handler (void *data, NihWatch *watch, const char *path, struct stat *statbuf) { create_called++; last_data = data; last_watch = watch; if (last_path) { char *old; old = last_path; last_path = NIH_MUST (nih_sprintf (NULL, "%s::%s", old, path)); nih_free (old); } else { last_path = NIH_MUST (nih_strdup (NULL, path)); } } static void my_modify_handler (void *data, NihWatch *watch, const char *path, struct stat *statbuf) { modify_called++; last_data = data; last_watch = watch; if (last_path) nih_free (last_path); last_path = NIH_MUST (nih_strdup (NULL, path)); } static void my_delete_handler (void *data, NihWatch *watch, const char *path) { delete_called++; last_data = data; last_watch = watch; if (last_path) nih_free (last_path); if (path) { last_path = NIH_MUST (nih_strdup (NULL, path)); if (! strcmp (path, watch->path)) nih_free (watch); } else { last_path = NULL; } } static int logger_called = 0; static int my_logger (NihLogLevel priority, const char *message) { logger_called++; return 0; } void test_new (void) { FILE *fd; char dirname[PATH_MAX], filename[PATH_MAX]; NihWatch *watch; NihWatchHandle *handle; NihError *err; TEST_FUNCTION ("nih_watch_new"); nih_io_init (); TEST_FILENAME (dirname); mkdir (dirname, 0755); strcpy (filename, dirname); strcat (filename, "/foo"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); strcpy (filename, dirname); strcat (filename, "/bar"); mkdir (filename, 0755); strcpy (filename, dirname); strcat (filename, "/bar/frodo"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); strcpy (filename, dirname); strcat (filename, "/bar/bilbo"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); strcpy (filename, dirname); strcat (filename, "/baz"); mkdir (filename, 0755); strcpy (filename, dirname); strcat (filename, "/frodo"); mkdir (filename, 0755); strcpy (filename, dirname); strcat (filename, "/frodo/baggins"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); /* Check that nih_watch_new returns a newly allocated structure with * each of the members filled in; an inotify instance should have * been added, and a watch on the parent stored in the watches list. */ TEST_FEATURE ("with file"); nih_error_push_context (); TEST_ALLOC_FAIL { strcpy (filename, dirname); strcat (filename, "/frodo/baggins"); watch = nih_watch_new (NULL, filename, FALSE, FALSE, my_filter, my_create_handler, my_modify_handler, my_delete_handler, &watch); TEST_ALLOC_SIZE (watch, sizeof (NihWatch)); TEST_ALLOC_SIZE (watch->path, strlen (filename) + 1); TEST_ALLOC_PARENT (watch->path, watch); TEST_EQ_STR (watch->path, filename); TEST_EQ (watch->subdirs, FALSE); TEST_EQ_P (watch->filter, my_filter); TEST_EQ_P (watch->create_handler, my_create_handler); TEST_EQ_P (watch->modify_handler, my_modify_handler); TEST_EQ_P (watch->delete_handler, my_delete_handler); TEST_ALLOC_SIZE (watch->created, sizeof (NihHash)); TEST_ALLOC_PARENT (watch->created, watch); TEST_EQ_P (watch->data, &watch); TEST_GE (fcntl (watch->fd, F_GETFD), 0); TEST_ALLOC_SIZE (watch->io, sizeof (NihIo)); TEST_ALLOC_PARENT (watch->io, watch); TEST_EQ (watch->io->type, NIH_IO_STREAM); TEST_EQ (watch->io->watch->fd, watch->fd); TEST_LIST_NOT_EMPTY (&watch->watches); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); TEST_LIST_EMPTY (&watch->watches); nih_free (watch); } nih_error_pop_context (); /* Check that if we add a sub-directory, but subdirs is FALSE, we * only get a watch for that directory added. */ TEST_FEATURE ("with directory only"); TEST_ALLOC_FAIL { strcpy (filename, dirname); strcat (filename, "/frodo"); watch = nih_watch_new (NULL, filename, FALSE, FALSE, my_filter, my_create_handler, my_modify_handler, my_delete_handler, &watch); TEST_ALLOC_SIZE (watch, sizeof (NihWatch)); TEST_ALLOC_SIZE (watch->path, strlen (filename) + 1); TEST_ALLOC_PARENT (watch->path, watch); TEST_EQ_STR (watch->path, filename); TEST_EQ (watch->subdirs, FALSE); TEST_EQ_P (watch->filter, my_filter); TEST_EQ_P (watch->create_handler, my_create_handler); TEST_EQ_P (watch->modify_handler, my_modify_handler); TEST_EQ_P (watch->delete_handler, my_delete_handler); TEST_ALLOC_SIZE (watch->created, sizeof (NihHash)); TEST_ALLOC_PARENT (watch->created, watch); TEST_EQ_P (watch->data, &watch); TEST_GE (fcntl (watch->fd, F_GETFD), 0); TEST_ALLOC_SIZE (watch->io, sizeof (NihIo)); TEST_ALLOC_PARENT (watch->io, watch); TEST_EQ (watch->io->type, NIH_IO_STREAM); TEST_EQ (watch->io->watch->fd, watch->fd); TEST_LIST_NOT_EMPTY (&watch->watches); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); TEST_LIST_EMPTY (&watch->watches); nih_free (watch); } /* Check that if we add a directory with subdirs, we get a watch for * each directory underneath (but not any files, or anything matching * the filter). */ TEST_FEATURE ("with directory and sub-directories"); TEST_ALLOC_FAIL { watch = nih_watch_new (NULL, dirname, TRUE, FALSE, my_filter, my_create_handler, my_modify_handler, my_delete_handler, &watch); TEST_ALLOC_SIZE (watch, sizeof (NihWatch)); TEST_ALLOC_SIZE (watch->path, strlen (dirname) + 1); TEST_ALLOC_PARENT (watch->path, watch); TEST_EQ_STR (watch->path, dirname); TEST_EQ (watch->subdirs, TRUE); TEST_EQ_P (watch->filter, my_filter); TEST_EQ_P (watch->create_handler, my_create_handler); TEST_EQ_P (watch->modify_handler, my_modify_handler); TEST_EQ_P (watch->delete_handler, my_delete_handler); TEST_ALLOC_SIZE (watch->created, sizeof (NihHash)); TEST_ALLOC_PARENT (watch->created, watch); TEST_EQ_P (watch->data, &watch); TEST_GE (fcntl (watch->fd, F_GETFD), 0); TEST_ALLOC_SIZE (watch->io, sizeof (NihIo)); TEST_ALLOC_PARENT (watch->io, watch); TEST_EQ (watch->io->type, NIH_IO_STREAM); TEST_EQ (watch->io->watch->fd, watch->fd); TEST_LIST_NOT_EMPTY (&watch->watches); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (dirname) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, dirname); nih_list_remove (&handle->entry); strcpy (filename, dirname); strcat (filename, "/bar"); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); strcpy (filename, dirname); strcat (filename, "/baz"); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); TEST_LIST_EMPTY (&watch->watches); nih_free (watch); } /* Check that the create handler can be called for each file and * directory found at the point we add things. */ TEST_FEATURE ("with create handler"); TEST_ALLOC_FAIL { create_called = 0; last_watch = NULL; last_data = NULL; last_path = NULL; watch = nih_watch_new (NULL, dirname, TRUE, TRUE, my_filter, my_create_handler, my_modify_handler, my_delete_handler, &watch); TEST_ALLOC_SIZE (watch, sizeof (NihWatch)); TEST_ALLOC_SIZE (watch->path, strlen (dirname) + 1); TEST_ALLOC_PARENT (watch->path, watch); TEST_EQ_STR (watch->path, dirname); TEST_EQ (watch->subdirs, TRUE); TEST_EQ_P (watch->filter, my_filter); TEST_EQ_P (watch->create_handler, my_create_handler); TEST_EQ_P (watch->modify_handler, my_modify_handler); TEST_EQ_P (watch->delete_handler, my_delete_handler); TEST_ALLOC_SIZE (watch->created, sizeof (NihHash)); TEST_ALLOC_PARENT (watch->created, watch); TEST_EQ_P (watch->data, &watch); TEST_GE (fcntl (watch->fd, F_GETFD), 0); TEST_ALLOC_SIZE (watch->io, sizeof (NihIo)); TEST_ALLOC_PARENT (watch->io, watch); TEST_EQ (watch->io->type, NIH_IO_STREAM); TEST_EQ (watch->io->watch->fd, watch->fd); TEST_LIST_NOT_EMPTY (&watch->watches); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (dirname) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, dirname); nih_list_remove (&handle->entry); strcpy (filename, dirname); strcat (filename, "/bar"); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); strcpy (filename, dirname); strcat (filename, "/baz"); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); TEST_LIST_EMPTY (&watch->watches); TEST_EQ (create_called, 4); TEST_EQ (last_data, &watch); TEST_EQ (last_watch, watch); strcpy (filename, dirname); strcat (filename, "/bar"); strcat (filename, "::"); strcat (filename, dirname); strcat (filename, "/bar/bilbo"); strcat (filename, "::"); strcat (filename, dirname); strcat (filename, "/baz"); strcat (filename, "::"); strcat (filename, dirname); strcat (filename, "/foo"); TEST_EQ_STR (last_path, filename); nih_free (last_path); nih_free (watch); } /* Check that an error with the path given results in an error * being raised and NULL returned. */ TEST_FEATURE ("with non-existant path"); TEST_ALLOC_FAIL { strcpy (filename, dirname); strcat (filename, "/drogo"); watch = nih_watch_new (NULL, filename, TRUE, FALSE, my_filter, my_create_handler, my_modify_handler, my_delete_handler, &watch); TEST_EQ_P (watch, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOENT); nih_free (err); } /* Check that an error with a sub-directory results in a warning * being emitted, but the directory recursing carrying on. */ TEST_FEATURE ("with error with sub-directory"); strcpy (filename, dirname); strcat (filename, "/bar"); chmod (filename, 0000); TEST_ALLOC_FAIL { logger_called = 0; nih_log_set_logger (my_logger); watch = nih_watch_new (NULL, dirname, TRUE, FALSE, NULL, my_create_handler, my_modify_handler, my_delete_handler, &watch); nih_log_set_logger (nih_logger_printf); TEST_TRUE (logger_called); TEST_ALLOC_SIZE (watch, sizeof (NihWatch)); TEST_ALLOC_SIZE (watch->path, strlen (dirname) + 1); TEST_ALLOC_PARENT (watch->path, watch); TEST_EQ_STR (watch->path, dirname); TEST_ALLOC_SIZE (watch->created, sizeof (NihHash)); TEST_ALLOC_PARENT (watch->created, watch); TEST_LIST_NOT_EMPTY (&watch->watches); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (dirname) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, dirname); nih_list_remove (&handle->entry); strcpy (filename, dirname); strcat (filename, "/baz"); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); strcpy (filename, dirname); strcat (filename, "/frodo"); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); TEST_LIST_EMPTY (&watch->watches); nih_free (watch); } strcpy (filename, dirname); strcat (filename, "/bar"); chmod (filename, 0755); strcpy (filename, dirname); strcat (filename, "/foo"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/bar/frodo"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/bar/bilbo"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/bar"); rmdir (filename); strcpy (filename, dirname); strcat (filename, "/baz"); rmdir (filename); strcpy (filename, dirname); strcat (filename, "/frodo/baggins"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/frodo"); rmdir (filename); rmdir (dirname); } void test_add (void) { FILE *fd; char dirname[PATH_MAX], filename[PATH_MAX]; NihWatch *watch; NihWatchHandle *handle; NihError *err; int ret; TEST_FUNCTION ("nih_watch_add"); nih_error_init (); TEST_FILENAME (dirname); mkdir (dirname, 0755); strcpy (filename, dirname); strcat (filename, "/foo"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); strcpy (filename, dirname); strcat (filename, "/bar"); mkdir (filename, 0755); strcpy (filename, dirname); strcat (filename, "/bar/frodo"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); strcpy (filename, dirname); strcat (filename, "/bar/bilbo"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); strcpy (filename, dirname); strcat (filename, "/baz"); mkdir (filename, 0755); strcpy (filename, dirname); strcat (filename, "/frodo"); mkdir (filename, 0755); strcpy (filename, dirname); strcat (filename, "/frodo/baggins"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); strcpy (filename, dirname); strcat (filename, "/frodo/baggins"); watch = nih_watch_new (NULL, filename, FALSE, FALSE, my_filter, my_create_handler, my_modify_handler, my_delete_handler, &watch); handle = (NihWatchHandle *)watch->watches.next; nih_list_remove (&handle->entry); /* Check that we can add a single path to an existing watch, and * have a new handle added with the the appropriate details. */ TEST_FEATURE ("with file"); TEST_ALLOC_FAIL { strcpy (filename, dirname); strcat (filename, "/bar/bilbo"); ret = nih_watch_add (watch, filename, TRUE); TEST_EQ (ret, 0); TEST_LIST_NOT_EMPTY (&watch->watches); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); TEST_LIST_EMPTY (&watch->watches); } /* Check that if we add a sub-directory, but subdirs is FALSE, we * only get a watch handle for that directory added. */ TEST_FEATURE ("with directory only"); TEST_ALLOC_FAIL { strcpy (filename, dirname); strcat (filename, "/frodo"); ret = nih_watch_add (watch, filename, FALSE); TEST_EQ (ret, 0); TEST_LIST_NOT_EMPTY (&watch->watches); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); TEST_LIST_EMPTY (&watch->watches); } /* Check that if we add a directory with subdirs, we get a watch for * each directory underneath (but not any files, or anything matching * the filter). */ TEST_FEATURE ("with directory and sub-directories"); TEST_ALLOC_FAIL { ret = nih_watch_add (watch, dirname, TRUE); TEST_EQ (ret, 0); TEST_LIST_NOT_EMPTY (&watch->watches); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (dirname) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, dirname); nih_list_remove (&handle->entry); strcpy (filename, dirname); strcat (filename, "/bar"); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); strcpy (filename, dirname); strcat (filename, "/baz"); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); TEST_LIST_EMPTY (&watch->watches); } /* Check that repeated call with the same path does not increase the * size of the watches list. */ TEST_FEATURE ("with path already being watched"); TEST_ALLOC_FAIL { strcpy (filename, dirname); strcat (filename, "/frodo/baggins"); ret = nih_watch_add (watch, filename, FALSE); TEST_EQ (ret, 0); ret = nih_watch_add (watch, filename, FALSE); TEST_EQ (ret, 0); TEST_LIST_NOT_EMPTY (&watch->watches); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); TEST_LIST_EMPTY (&watch->watches); } /* Check that an error with the path given results in an error * being raised and NULL returned. */ TEST_FEATURE ("with non-existant path"); TEST_ALLOC_FAIL { strcpy (filename, dirname); strcat (filename, "/drogo"); ret = nih_watch_add (watch, filename, TRUE); TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOENT); nih_free (err); } /* Check that an error with a sub-directory results in a warning * being emitted, but the directory recursing carrying on. */ TEST_FEATURE ("with error with sub-directory"); strcpy (filename, dirname); strcat (filename, "/bar"); chmod (filename, 0000); TEST_ALLOC_FAIL { logger_called = 0; nih_log_set_logger (my_logger); ret = nih_watch_add (watch, dirname, TRUE); nih_log_set_logger (nih_logger_printf); TEST_TRUE (logger_called); TEST_LIST_NOT_EMPTY (&watch->watches); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (dirname) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, dirname); nih_list_remove (&handle->entry); strcpy (filename, dirname); strcat (filename, "/baz"); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_ALLOC_SIZE (handle->path, strlen (filename) + 1); TEST_ALLOC_PARENT (handle->path, handle); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); TEST_LIST_EMPTY (&watch->watches); } strcpy (filename, dirname); strcat (filename, "/bar"); chmod (filename, 0755); nih_free (watch); strcpy (filename, dirname); strcat (filename, "/foo"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/bar/frodo"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/bar/bilbo"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/bar"); rmdir (filename); strcpy (filename, dirname); strcat (filename, "/baz"); rmdir (filename); strcpy (filename, dirname); strcat (filename, "/frodo/baggins"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/frodo"); rmdir (filename); rmdir (dirname); } void test_destroy (void) { NihWatch *watch; int ret, fd, caught_free; /* Check that the free flag is set and that the inotify descriptor * is closed. */ TEST_FUNCTION ("nih_watch_destroy"); watch = nih_watch_new (NULL, "/", FALSE, FALSE, NULL, NULL, NULL, NULL, NULL); fd = watch->fd; caught_free = FALSE; watch->free = &caught_free; ret = nih_free (watch); TEST_EQ (ret, 0); TEST_LT (fcntl (fd, F_GETFD), 0); TEST_EQ (errno, EBADF); TEST_TRUE (caught_free); } void test_reader (void) { FILE *fd; NihWatch *watch; NihWatchHandle *handle, *ptr; char dirname[PATH_MAX], filename[PATH_MAX]; char newname[PATH_MAX]; fd_set readfds, writefds, exceptfds; int nfds = 0; TEST_FUNCTION ("nih_watch_reader"); nih_error_init (); TEST_FILENAME (dirname); mkdir (dirname, 0755); watch = nih_watch_new (NULL, dirname, TRUE, TRUE, my_filter, my_create_handler, my_modify_handler, my_delete_handler, &watch); /* Check that creating a file within the directory being watched * results in the create handler being called, and passed the full * path of the created file to it. */ TEST_FEATURE ("with new file"); strcpy (filename, dirname); strcat (filename, "/foo"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); create_called = 0; last_watch = NULL; last_path = NULL; last_data = NULL; nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_TRUE (create_called); TEST_EQ_P (last_watch, watch); TEST_EQ_STR (last_path, filename); TEST_EQ_P (last_data, &watch); nih_free (last_path); /* Check that a new file opened on disk doesn't result in the create * handler being called until the file has been closed. */ TEST_FEATURE ("with new still-open file"); strcpy (filename, dirname); strcat (filename, "/meep"); create_called = 0; last_watch = NULL; last_path = NULL; last_data = NULL; fd = fopen (filename, "w"); nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_FALSE (create_called); TEST_NE_P (nih_hash_lookup (watch->created, filename), NULL); fprintf (fd, "test\n"); fclose (fd); nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_TRUE (create_called); TEST_EQ_P (last_watch, watch); TEST_EQ_STR (last_path, filename); TEST_EQ_P (last_data, &watch); nih_free (last_path); last_path = NULL; unlink (filename); nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); nih_free (last_path); /* Check that removing a file that was newly created but then * immediately removed doesn't get a handler at all. */ TEST_FEATURE ("with removal of still-open file"); strcpy (filename, dirname); strcat (filename, "/flep"); create_called = 0; modify_called = 0; delete_called = 0; last_watch = NULL; last_path = NULL; last_data = NULL; fd = fopen (filename, "w"); nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_FALSE (create_called); TEST_FALSE (modify_called); TEST_FALSE (delete_called); TEST_NE_P (nih_hash_lookup (watch->created, filename), NULL); unlink (filename); nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_FALSE (create_called); TEST_FALSE (modify_called); TEST_FALSE (delete_called); TEST_EQ_P (nih_hash_lookup (watch->created, filename), NULL); fclose (fd); /* Check that modifying that file results in the modify handler * being called and passed the full path of the created file. */ TEST_FEATURE ("with modified file"); strcpy (filename, dirname); strcat (filename, "/foo"); fd = fopen (filename, "w"); fprintf (fd, "further test\n"); fclose (fd); modify_called = 0; last_watch = NULL; last_path = NULL; last_data = NULL; nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_TRUE (modify_called); TEST_EQ_P (last_watch, watch); TEST_EQ_STR (last_path, filename); TEST_EQ_P (last_data, &watch); nih_free (last_path); /* Check that we can rename the file, we should get the delete * handler called followed by the create handler. */ TEST_FEATURE ("with renamed file"); strcpy (filename, dirname); strcat (filename, "/foo"); strcpy (newname, dirname); strcat (newname, "/bar"); rename (filename, newname); delete_called = 0; create_called = 0; last_watch = NULL; last_path = NULL; last_data = NULL; nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); strcpy (filename, dirname); strcat (filename, "/foo"); strcat (filename, "::"); strcat (filename, dirname); strcat (filename, "/bar"); TEST_TRUE (delete_called); TEST_TRUE (create_called); TEST_EQ_P (last_watch, watch); TEST_EQ_STR (last_path, filename); TEST_EQ_P (last_data, &watch); nih_free (last_path); /* Check that deleting the file results in the delete handler * being called and passed the full filename. */ TEST_FEATURE ("with deleted file"); strcpy (filename, dirname); strcat (filename, "/bar"); unlink (filename); delete_called = 0; last_watch = NULL; last_path = NULL; last_data = NULL; nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_TRUE (delete_called); TEST_EQ_P (last_watch, watch); TEST_EQ_STR (last_path, filename); TEST_EQ_P (last_data, &watch); nih_free (last_path); /* Check that if we create a file that matches the filter, the handler * is not called for it. */ TEST_FEATURE ("with filtered file"); strcpy (filename, dirname); strcat (filename, "/frodo"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); fd = fopen (filename, "w"); fprintf (fd, "another test\n"); fclose (fd); unlink (filename); create_called = 0; modify_called = 0; delete_called = 0; last_watch = NULL; last_path = NULL; last_data = NULL; nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_FALSE (create_called); TEST_FALSE (modify_called); TEST_FALSE (delete_called); /* Check that we can create a new directory, and given that subdirs * is TRUE, have a new watch added for that directory automatically. */ TEST_FEATURE ("with new sub-directory"); strcpy (filename, dirname); strcat (filename, "/bleep"); mkdir (filename, 0755); create_called = 0; last_watch = NULL; last_path = NULL; last_data = NULL; nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_TRUE (create_called); TEST_EQ_P (last_watch, watch); TEST_EQ_STR (last_path, filename); TEST_EQ_P (last_data, &watch); nih_free (last_path); ptr = (NihWatchHandle *)watch->watches.next; nih_list_remove (&ptr->entry); TEST_LIST_NOT_EMPTY (&watch->watches); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); TEST_LIST_EMPTY (&watch->watches); nih_list_add (&watch->watches, &ptr->entry); nih_list_add (&watch->watches, &handle->entry); /* Check that we can remove a watched sub-directory, and have it * automatically handled with the handle going away. */ TEST_FEATURE ("with removal of sub-directory"); strcpy (filename, dirname); strcat (filename, "/bleep"); rmdir (filename); delete_called = 0; last_watch = NULL; last_path = NULL; last_data = NULL; nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_TRUE (delete_called); TEST_EQ_P (last_watch, watch); TEST_EQ_STR (last_path, filename); TEST_EQ_P (last_data, &watch); nih_free (last_path); ptr = (NihWatchHandle *)watch->watches.next; nih_list_remove (&ptr->entry); TEST_LIST_EMPTY (&watch->watches); nih_list_add (&watch->watches, &ptr->entry); /* Check that we can create a new directory with bad permissions, * and have it warn that it cannot watch them. */ TEST_FEATURE ("with new unsearchable sub-directory"); strcpy (filename, dirname); strcat (filename, "/splat"); mkdir (filename, 0000); create_called = 0; last_watch = NULL; last_path = NULL; last_data = NULL; nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); logger_called = 0; nih_log_set_logger (my_logger); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); nih_log_set_logger (nih_logger_printf); TEST_EQ (logger_called, 1); TEST_TRUE (create_called); TEST_EQ_P (last_watch, watch); TEST_EQ_STR (last_path, filename); TEST_EQ_P (last_data, &watch); nih_free (last_path); ptr = (NihWatchHandle *)watch->watches.next; nih_list_remove (&ptr->entry); TEST_LIST_EMPTY (&watch->watches); nih_list_add (&watch->watches, &ptr->entry); rmdir (filename); delete_called = 0; last_path = NULL; nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_TRUE (delete_called); TEST_NE_P (last_path, NULL); nih_free (last_path); /* Check that we can create a new directory, and given that subdirs * and create are TRUE, have a new watch added automatically and * create_handler called for all files in that directory. */ TEST_FEATURE ("with new sub-directory"); strcpy (filename, dirname); strcat (filename, "/woo"); mkdir (filename, 0755); strcpy (filename, dirname); strcat (filename, "/woo/whee"); fd = fopen (filename, "w"); fprintf (fd, "test\n"); fclose (fd); create_called = 0; last_watch = NULL; last_path = NULL; last_data = NULL; nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_TRUE (create_called); TEST_EQ_P (last_watch, watch); strcpy (filename, dirname); strcat (filename, "/woo"); strcat (filename, "::"); strcat (filename, dirname); strcat (filename, "/woo/whee"); TEST_EQ_STR (last_path, filename); TEST_EQ_P (last_data, &watch); nih_free (last_path); ptr = (NihWatchHandle *)watch->watches.next; nih_list_remove (&ptr->entry); TEST_LIST_NOT_EMPTY (&watch->watches); handle = (NihWatchHandle *)watch->watches.next; TEST_ALLOC_SIZE (handle, sizeof (NihWatchHandle)); TEST_ALLOC_PARENT (handle, watch); strcpy (filename, dirname); strcat (filename, "/woo"); TEST_EQ_STR (handle->path, filename); nih_list_remove (&handle->entry); TEST_LIST_EMPTY (&watch->watches); nih_list_add (&watch->watches, &ptr->entry); nih_list_add (&watch->watches, &handle->entry); strcpy (filename, dirname); strcat (filename, "/woo/whee"); unlink (filename); strcpy (filename, dirname); strcat (filename, "/woo"); rmdir (filename); delete_called = 0; last_path = NULL; nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_TRUE (delete_called); TEST_NE_P (last_path, NULL); nih_free (last_path); /* Check that we can handle the directory itself being deleted, * the delete_handler should be called with the top-level path. * It should be safe to delete the entire watch this way. */ TEST_FEATURE ("with removal of directory"); rmdir (dirname); TEST_FREE_TAG (watch); delete_called = 0; last_watch = NULL; last_path = NULL; last_data = NULL; nfds = 0; FD_ZERO (&readfds); FD_ZERO (&writefds); FD_ZERO (&exceptfds); nih_io_select_fds (&nfds, &readfds, &writefds, &exceptfds); select (nfds, &readfds, &writefds, &exceptfds, NULL); nih_io_handle_fds (&readfds, &writefds, &exceptfds); TEST_TRUE (delete_called); TEST_EQ_P (last_watch, watch); TEST_EQ_STR (last_path, dirname); TEST_EQ_P (last_data, &watch); TEST_FREE (watch); nih_free (last_path); } int main (int argc, char *argv[]) { int fd; /* Make sure we have inotify before performing these tests */ fd = inotify_init (); if (fd < 0) { printf ("SKIP: inotify not available\n"); return 0; } test_new (); test_add (); test_destroy (); test_reader (); return 0; } libnih-1.0.3/nih/tests/test_tree.c0000644000175000017500000016075211445765555014017 00000000000000/* libnih * * test_tree.c - test suite for nih/tree.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include void test_init (void) { NihTree node; /* Check that nih_tree_init correctly initialises an empty tree * node with all three pointers set to NULL. */ TEST_FUNCTION ("nih_tree_init"); nih_tree_init (&node); TEST_EQ_P (node.parent, NULL); TEST_EQ_P (node.left, NULL); TEST_EQ_P (node.right, NULL); } void test_new (void) { NihTree *tree; /* Check that nih_tree_new allocates a new empty tree node with * nih_alloc and that it is initialised with all three pointers * set to NULL. If allocation fails, we should get NULL returned. */ TEST_FUNCTION ("nih_tree_new"); TEST_ALLOC_FAIL { tree = nih_tree_new (NULL); if (test_alloc_failed) { TEST_EQ_P (tree, NULL); continue; } TEST_ALLOC_SIZE (tree, sizeof (NihTree)); TEST_EQ_P (tree->parent, NULL); TEST_EQ_P (tree->left, NULL); TEST_EQ_P (tree->right, NULL); nih_free (tree); } } void test_entry_new (void) { NihTreeEntry *tree; /* Check that nih_tree_entry_new allocates a new empty tree node with * nih_alloc and that it is initialised with all three pointers * set to NULL. If allocation fails, we should get NULL returned. */ TEST_FUNCTION ("nih_tree_entry_new"); TEST_ALLOC_FAIL { tree = nih_tree_entry_new (NULL); if (test_alloc_failed) { TEST_EQ_P (tree, NULL); continue; } TEST_ALLOC_SIZE (tree, sizeof (NihTreeEntry)); TEST_EQ_P (tree->node.parent, NULL); TEST_EQ_P (tree->node.left, NULL); TEST_EQ_P (tree->node.right, NULL); TEST_EQ_P (tree->data, NULL); nih_free (tree); } } void test_add (void) { NihTree *tree, *node1, *node2, *node3, *node4, *ptr; TEST_FUNCTION ("nih_tree_add"); tree = nih_tree_new (NULL); /* Check that we can add a node as a left-hand child of another node, * where no child existed before. */ TEST_FEATURE ("as left-hand child"); node1 = nih_tree_new (tree); ptr = nih_tree_add (tree, node1, NIH_TREE_LEFT); TEST_EQ_P (ptr, NULL); TEST_EQ_P (node1->parent, tree); TEST_EQ_P (tree->left, node1); /* Check that we can add a node as a right-child of another node, * where no child existing before. */ TEST_FEATURE ("as right-hand child"); node2 = nih_tree_new (tree); ptr = nih_tree_add (node1, node2, NIH_TREE_RIGHT); TEST_EQ_P (ptr, NULL); TEST_EQ_P (node2->parent, node1); TEST_EQ_P (node1->right, node2); /* Check that we can add a node as a left-child of another node, * replacing the child in that slot already. We should have the * replaced child returned. */ TEST_FEATURE ("as replacement left-hand child"); node3 = nih_tree_new (tree); ptr = nih_tree_add (tree, node3, NIH_TREE_LEFT); TEST_EQ_P (ptr, node1); TEST_EQ_P (ptr->parent, NULL); TEST_EQ_P (node3->parent, tree); TEST_EQ_P (tree->left, node3); /* Check that we can add a node as a right-child of another node, * replacing the child in that slot already. We should have the * replaced child returned. */ TEST_FEATURE ("as replacement right-hand child"); node4 = nih_tree_new (tree); ptr = nih_tree_add (node1, node4, NIH_TREE_RIGHT); TEST_EQ_P (ptr, node2); TEST_EQ_P (ptr->parent, NULL); TEST_EQ_P (node4->parent, node1); TEST_EQ_P (node1->right, node4); /* Check that we can swap a node within a tree from one child to * another, getting the node that was replaced in return. */ TEST_FEATURE ("within same tree"); nih_tree_add (tree, node1, NIH_TREE_RIGHT); nih_tree_add (node1, node2, NIH_TREE_LEFT); ptr = nih_tree_add (tree, node1, NIH_TREE_LEFT); TEST_EQ_P (ptr, node3); TEST_EQ_P (ptr->parent, NULL); TEST_EQ_P (node1->parent, tree); TEST_EQ_P (tree->left, node1); /* Check that we can perform a tree rotation with just two calls * on the add function. */ TEST_FEATURE ("with tree rotation"); nih_tree_add (tree, node3, NIH_TREE_RIGHT); ptr = nih_tree_add (tree, tree->left->right, NIH_TREE_LEFT); TEST_EQ_P (ptr, node1); TEST_EQ_P (ptr->parent, NULL); TEST_EQ_P (ptr->right, NULL); TEST_EQ_P (tree->left, node4); TEST_EQ_P (node4->parent, tree); ptr = nih_tree_add (ptr, tree, NIH_TREE_RIGHT); TEST_EQ_P (ptr, NULL); TEST_EQ_P (node1->parent, NULL); TEST_EQ_P (node1->left, node2); TEST_EQ_P (node2->parent, node1); TEST_EQ_P (node2->left, NULL); TEST_EQ_P (node2->right, NULL); TEST_EQ_P (node1->right, tree); TEST_EQ_P (tree->parent, node1); TEST_EQ_P (tree->left, node4); TEST_EQ_P (node4->parent, tree); TEST_EQ_P (tree->right, node3); TEST_EQ_P (node3->parent, tree); /* Check that a node may replace itself, with no damage; and that * NULL should be returned since the replacement was a no-op. */ TEST_FEATURE ("as replacement for itself"); ptr = nih_tree_add (node1, node2, NIH_TREE_LEFT); TEST_EQ_P (ptr, NULL); TEST_EQ_P (node2->parent, node1); TEST_EQ_P (node1->left, node2); /* Likewise check that moving a node within the tree to somewhere * else in the tree, without replacing, just performs the move. */ TEST_FEATURE ("as move"); ptr = nih_tree_add (node3, node4, NIH_TREE_LEFT); TEST_EQ_P (ptr, NULL); TEST_EQ_P (node3->left, node4); TEST_EQ_P (node4->parent, node3); TEST_EQ_P (tree->left, NULL); nih_free (tree); } void test_remove (void) { NihTree *tree, *node1, *node2, *ptr; TEST_FUNCTION ("nih_tree_remove"); /* Check that we can remove a node from its containing tree, but that * the node remains linked to its children. */ TEST_FEATURE ("with child node"); tree = nih_tree_new (NULL); node1 = nih_tree_new (tree); node2 = nih_tree_new (tree); nih_tree_add (tree, node1, NIH_TREE_LEFT); nih_tree_add (node1, node2, NIH_TREE_RIGHT); ptr = nih_tree_remove (node1); TEST_EQ_P (ptr, node1); TEST_EQ_P (tree->left, NULL); TEST_EQ_P (node1->parent, NULL); TEST_EQ_P (node1->right, node2); TEST_EQ_P (node2->parent, node1); /* Check that an attempt to remove a root node has no effect. */ TEST_FEATURE ("with root node"); ptr = nih_tree_remove (node1); TEST_EQ_P (ptr, node1); TEST_EQ_P (node1->parent, NULL); TEST_EQ_P (node1->right, node2); TEST_EQ_P (node2->parent, node1); nih_free (tree); } void test_unlink (void) { NihTree *tree, *node1, *node2, *ptr; TEST_FUNCTION ("nih_tree_unlink"); /* Check that we can unlink a node from its containing tree, and * also have its children cast adrift. */ TEST_FEATURE ("with child node"); tree = nih_tree_new (NULL); node1 = nih_tree_new (tree); node2 = nih_tree_new (tree); nih_tree_add (tree, node1, NIH_TREE_LEFT); nih_tree_add (node1, node2, NIH_TREE_RIGHT); ptr = nih_tree_unlink (node1); TEST_EQ_P (ptr, node1); TEST_EQ_P (tree->left, NULL); TEST_EQ_P (node1->parent, NULL); TEST_EQ_P (node1->left, NULL); TEST_EQ_P (node1->right, NULL); TEST_EQ_P (node2->parent, NULL); /* Check that an attempt to unlink a root node with children only * unlinks the children. */ TEST_FEATURE ("with root node"); nih_tree_add (tree, node1, NIH_TREE_LEFT); nih_tree_add (tree, node2, NIH_TREE_RIGHT); ptr = nih_tree_unlink (tree); TEST_EQ_P (ptr, tree); TEST_EQ_P (tree->parent, NULL); TEST_EQ_P (tree->left, NULL); TEST_EQ_P (tree->right, NULL); TEST_EQ_P (node1->parent, NULL); TEST_EQ_P (node2->parent, NULL); nih_free (tree); } void test_destroy (void) { NihTree *tree, *node1, *node2; int ret; TEST_FUNCTION ("nih_tree_destroy"); /* Check that we can unlink a node from its containing tree, and * also have its children cast adrift. */ TEST_FEATURE ("with child node"); tree = nih_tree_new (NULL); node1 = nih_tree_new (tree); node2 = nih_tree_new (tree); nih_tree_add (tree, node1, NIH_TREE_LEFT); nih_tree_add (node1, node2, NIH_TREE_RIGHT); ret = nih_tree_destroy (node1); TEST_EQ (ret, 0); TEST_EQ_P (tree->left, NULL); TEST_EQ_P (node1->parent, NULL); TEST_EQ_P (node1->left, NULL); TEST_EQ_P (node1->right, NULL); TEST_EQ_P (node2->parent, NULL); /* Check that an attempt to unlink a root node with children only * unlinks the children. */ TEST_FEATURE ("with root node"); nih_tree_add (tree, node1, NIH_TREE_LEFT); nih_tree_add (tree, node2, NIH_TREE_RIGHT); ret = nih_tree_destroy (tree); TEST_EQ (ret, 0); TEST_EQ_P (tree->parent, NULL); TEST_EQ_P (tree->left, NULL); TEST_EQ_P (tree->right, NULL); TEST_EQ_P (node1->parent, NULL); TEST_EQ_P (node2->parent, NULL); nih_free (tree); } /* * For the following tests, we use a specific tree as detailed below: * * a * / \ * / \ * b c * / / \ * d e f * / \ / \ * g h i k * m' p' * * We place each node in order, with node 'a' implicitly placed as the root. */ void test_next (void) { NihTree *node[12], *expect[13], *ptr; int i; TEST_FUNCTION ("nih_tree_next"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can in-order iterate a reasonably complex tree, * and that nih_tree_next returns the right pointer in each case * until it finally returns NULL. */ TEST_FEATURE ("with full tree"); expect[0] = node['k' - 97]; expect[1] = node['g' - 97]; expect[2] = node['d' - 97]; expect[3] = node['b' - 97]; expect[4] = node['a' - 97]; expect[5] = node['e' - 97]; expect[6] = node['l' - 97]; expect[7] = node['h' - 97]; expect[8] = node['c' - 97]; expect[9] = node['i' - 97]; expect[10] = node['f' - 97]; expect[11] = node['j' - 97]; expect[12] = NULL; i = 0; ptr = NULL; do { if (i > 12) TEST_FAILED ("wrong number of iterations, expected %d got %d", 13, i + 1); ptr = nih_tree_next (node['a' - 97], ptr); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['e' - 97]; expect[1] = node['l' - 97]; expect[2] = node['h' - 97]; expect[3] = node['c' - 97]; expect[4] = node['i' - 97]; expect[5] = node['f' - 97]; expect[6] = node['j' - 97]; expect[7] = NULL; i = 0; ptr = NULL; do { if (i > 7) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); ptr = nih_tree_next (node['c' - 97], ptr); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); for (i = 0; i < 12; i++) nih_free (node[i]); /* Check that we can iterate a tree with a single node. */ TEST_FEATURE ("with single node"); node[0] = nih_tree_new (NULL); ptr = nih_tree_next (node[0], NULL); TEST_EQ_P (ptr, node[0]); ptr = nih_tree_next (node[0], ptr); TEST_EQ_P (ptr, NULL); nih_free (node[0]); } void test_foreach (void) { NihTree *node[12], *expect[13]; int i; TEST_FUNCTION ("NIH_TREE_FOREACH"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can in-order iterate a reasonably complex tree, * and that NIH_TREE_FOREACH sets the iterator to the right nodes * in turn. */ TEST_FEATURE ("with full tree"); expect[0] = node['k' - 97]; expect[1] = node['g' - 97]; expect[2] = node['d' - 97]; expect[3] = node['b' - 97]; expect[4] = node['a' - 97]; expect[5] = node['e' - 97]; expect[6] = node['l' - 97]; expect[7] = node['h' - 97]; expect[8] = node['c' - 97]; expect[9] = node['i' - 97]; expect[10] = node['f' - 97]; expect[11] = node['j' - 97]; expect[12] = NULL; i = 0; NIH_TREE_FOREACH (node['a' - 97], iter) { if (i > 11) TEST_FAILED ("wrong number of iterations, expected %d got %d", 12, i + 1); if (iter != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], iter); i++; } /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['e' - 97]; expect[1] = node['l' - 97]; expect[2] = node['h' - 97]; expect[3] = node['c' - 97]; expect[4] = node['i' - 97]; expect[5] = node['f' - 97]; expect[6] = node['j' - 97]; expect[7] = NULL; i = 0; NIH_TREE_FOREACH (node['c' - 97], iter) { if (i > 7) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); if (iter != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], iter); i++; } for (i = 0; i < 12; i++) nih_free (node[i]); } void test_prev (void) { NihTree *node[12], *expect[13], *ptr; int i; TEST_FUNCTION ("nih_tree_prev"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can reverse in-order iterate a reasonably complex * tree, and that nih_tree_prev returns the right pointer in * each case until it finally returns NULL. */ TEST_FEATURE ("with full tree"); expect[0] = node['j' - 97]; expect[1] = node['f' - 97]; expect[2] = node['i' - 97]; expect[3] = node['c' - 97]; expect[4] = node['h' - 97]; expect[5] = node['l' - 97]; expect[6] = node['e' - 97]; expect[7] = node['a' - 97]; expect[8] = node['b' - 97]; expect[9] = node['d' - 97]; expect[10] = node['g' - 97]; expect[11] = node['k' - 97]; expect[12] = NULL; i = 0; ptr = NULL; do { if (i > 12) TEST_FAILED ("wrong number of iterations, expected %d got %d", 13, i + 1); ptr = nih_tree_prev (node['a' - 97], ptr); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['j' - 97]; expect[1] = node['f' - 97]; expect[2] = node['i' - 97]; expect[3] = node['c' - 97]; expect[4] = node['h' - 97]; expect[5] = node['l' - 97]; expect[6] = node['e' - 97]; expect[7] = NULL; i = 0; ptr = NULL; do { if (i > 7) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); ptr = nih_tree_prev (node['c' - 97], ptr); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); for (i = 0; i < 12; i++) nih_free (node[i]); /* Check that we can iterate a tree with a single node. */ TEST_FEATURE ("with single node"); node[0] = nih_tree_new (NULL); ptr = nih_tree_prev (node[0], NULL); TEST_EQ_P (ptr, node[0]); ptr = nih_tree_prev (node[0], ptr); TEST_EQ_P (ptr, NULL); nih_free (node[0]); } void test_next_pre (void) { NihTree *node[12], *expect[13], *ptr; int i; TEST_FUNCTION ("nih_tree_next_pre"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can pre-order iterate a reasonably complex tree, * and that nih_tree_next_pre returns the right pointer in each case * until it finally returns NULL. */ TEST_FEATURE ("with full tree"); expect[0] = node['a' - 97]; expect[1] = node['b' - 97]; expect[2] = node['d' - 97]; expect[3] = node['g' - 97]; expect[4] = node['k' - 97]; expect[5] = node['c' - 97]; expect[6] = node['e' - 97]; expect[7] = node['h' - 97]; expect[8] = node['l' - 97]; expect[9] = node['f' - 97]; expect[10] = node['i' - 97]; expect[11] = node['j' - 97]; expect[12] = NULL; i = 0; ptr = NULL; do { if (i > 12) TEST_FAILED ("wrong number of iterations, expected %d got %d", 13, i + 1); ptr = nih_tree_next_pre (node['a' - 97], ptr); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['c' - 97]; expect[1] = node['e' - 97]; expect[2] = node['h' - 97]; expect[3] = node['l' - 97]; expect[4] = node['f' - 97]; expect[5] = node['i' - 97]; expect[6] = node['j' - 97]; expect[7] = NULL; i = 0; ptr = NULL; do { if (i > 7) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); ptr = nih_tree_next_pre (node['c' - 97], ptr); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); for (i = 0; i < 12; i++) nih_free (node[i]); /* Check that we can iterate a tree with a single node. */ TEST_FEATURE ("with single node"); node[0] = nih_tree_new (NULL); ptr = nih_tree_next_pre (node[0], NULL); TEST_EQ_P (ptr, node[0]); ptr = nih_tree_next_pre (node[0], ptr); TEST_EQ_P (ptr, NULL); nih_free (node[0]); } void test_foreach_pre (void) { NihTree *node[12], *expect[13]; int i; TEST_FUNCTION ("NIH_TREE_FOREACH_PRE"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can in-order iterate a reasonably complex tree, * and that NIH_TREE_FOREACH_PRE sets the iterator to the right nodes * in turn. */ TEST_FEATURE ("with full tree"); expect[0] = node['a' - 97]; expect[1] = node['b' - 97]; expect[2] = node['d' - 97]; expect[3] = node['g' - 97]; expect[4] = node['k' - 97]; expect[5] = node['c' - 97]; expect[6] = node['e' - 97]; expect[7] = node['h' - 97]; expect[8] = node['l' - 97]; expect[9] = node['f' - 97]; expect[10] = node['i' - 97]; expect[11] = node['j' - 97]; expect[12] = NULL; i = 0; NIH_TREE_FOREACH_PRE (node['a' - 97], iter) { if (i > 11) TEST_FAILED ("wrong number of iterations, expected %d got %d", 12, i + 1); if (iter != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], iter); i++; } /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['c' - 97]; expect[1] = node['e' - 97]; expect[2] = node['h' - 97]; expect[3] = node['l' - 97]; expect[4] = node['f' - 97]; expect[5] = node['i' - 97]; expect[6] = node['j' - 97]; expect[7] = NULL; i = 0; NIH_TREE_FOREACH_PRE (node['c' - 97], iter) { if (i > 7) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); if (iter != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], iter); i++; } for (i = 0; i < 12; i++) nih_free (node[i]); } void test_prev_pre (void) { NihTree *node[12], *expect[13], *ptr; int i; TEST_FUNCTION ("nih_tree_prev_pre"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can reverse pre-order iterate a reasonably complex * tree, and that nih_tree_prev_pre returns the right pointer in each * case until it finally returns NULL. */ TEST_FEATURE ("with full tree"); expect[0] = node['j' - 97]; expect[1] = node['i' - 97]; expect[2] = node['f' - 97]; expect[3] = node['l' - 97]; expect[4] = node['h' - 97]; expect[5] = node['e' - 97]; expect[6] = node['c' - 97]; expect[7] = node['k' - 97]; expect[8] = node['g' - 97]; expect[9] = node['d' - 97]; expect[10] = node['b' - 97]; expect[11] = node['a' - 97]; expect[12] = NULL; i = 0; ptr = NULL; do { if (i > 12) TEST_FAILED ("wrong number of iterations, expected %d got %d", 13, i + 1); ptr = nih_tree_prev_pre (node['a' - 97], ptr); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['j' - 97]; expect[1] = node['i' - 97]; expect[2] = node['f' - 97]; expect[3] = node['l' - 97]; expect[4] = node['h' - 97]; expect[5] = node['e' - 97]; expect[6] = node['c' - 97]; expect[7] = NULL; i = 0; ptr = NULL; do { if (i > 7) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); ptr = nih_tree_prev_pre (node['c' - 97], ptr); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); for (i = 0; i < 12; i++) nih_free (node[i]); /* Check that we can iterate a tree with a single node. */ TEST_FEATURE ("with single node"); node[0] = nih_tree_new (NULL); ptr = nih_tree_prev_pre (node[0], NULL); TEST_EQ_P (ptr, node[0]); ptr = nih_tree_prev_pre (node[0], ptr); TEST_EQ_P (ptr, NULL); nih_free (node[0]); } void test_next_post (void) { NihTree *node[12], *expect[13], *ptr; int i; TEST_FUNCTION ("nih_tree_next_post"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can post-order iterate a reasonably complex tree, * and that nih_tree_next_post returns the right pointer in each case * until it finally returns NULL. */ TEST_FEATURE ("with full tree"); expect[0] = node['k' - 97]; expect[1] = node['g' - 97]; expect[2] = node['d' - 97]; expect[3] = node['b' - 97]; expect[4] = node['l' - 97]; expect[5] = node['h' - 97]; expect[6] = node['e' - 97]; expect[7] = node['i' - 97]; expect[8] = node['j' - 97]; expect[9] = node['f' - 97]; expect[10] = node['c' - 97]; expect[11] = node['a' - 97]; expect[12] = NULL; i = 0; ptr = NULL; do { if (i > 12) TEST_FAILED ("wrong number of iterations, expected %d got %d", 13, i + 1); ptr = nih_tree_next_post (node['a' - 97], ptr); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['l' - 97]; expect[1] = node['h' - 97]; expect[2] = node['e' - 97]; expect[3] = node['i' - 97]; expect[4] = node['j' - 97]; expect[5] = node['f' - 97]; expect[6] = node['c' - 97]; expect[7] = NULL; i = 0; ptr = NULL; do { if (i > 7) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); ptr = nih_tree_next_post (node['c' - 97], ptr); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); for (i = 0; i < 12; i++) nih_free (node[i]); /* Check that we can iterate a tree with a single node. */ TEST_FEATURE ("with single node"); node[0] = nih_tree_new (NULL); ptr = nih_tree_next_post (node[0], NULL); TEST_EQ_P (ptr, node[0]); ptr = nih_tree_next_post (node[0], ptr); TEST_EQ_P (ptr, NULL); nih_free (node[0]); } void test_foreach_post (void) { NihTree *node[12], *expect[13]; int i; TEST_FUNCTION ("NIH_TREE_FOREACH_POST"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can post-order iterate a reasonably complex tree, * and that NIH_TREE_FOREACH_POST sets the iterator to the right nodes * in turn. */ TEST_FEATURE ("with full tree"); expect[0] = node['k' - 97]; expect[1] = node['g' - 97]; expect[2] = node['d' - 97]; expect[3] = node['b' - 97]; expect[4] = node['l' - 97]; expect[5] = node['h' - 97]; expect[6] = node['e' - 97]; expect[7] = node['i' - 97]; expect[8] = node['j' - 97]; expect[9] = node['f' - 97]; expect[10] = node['c' - 97]; expect[11] = node['a' - 97]; expect[12] = NULL; i = 0; NIH_TREE_FOREACH_POST (node['a' - 97], iter) { if (i > 11) TEST_FAILED ("wrong number of iterations, expected %d got %d", 12, i + 1); if (iter != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], iter); i++; } /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['l' - 97]; expect[1] = node['h' - 97]; expect[2] = node['e' - 97]; expect[3] = node['i' - 97]; expect[4] = node['j' - 97]; expect[5] = node['f' - 97]; expect[6] = node['c' - 97]; expect[7] = NULL; i = 0; NIH_TREE_FOREACH_POST (node['c' - 97], iter) { if (i > 7) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); if (iter != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], iter); i++; } for (i = 0; i < 12; i++) nih_free (node[i]); } void test_prev_post (void) { NihTree *node[12], *expect[13], *ptr; int i; TEST_FUNCTION ("nih_tree_prev_post"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can reverse post-order iterate a reasonably complex * tree, and that nih_tree_prev_post returns the right pointer in each * case until it finally returns NULL. */ TEST_FEATURE ("with full tree"); expect[0] = node['a' - 97]; expect[1] = node['c' - 97]; expect[2] = node['f' - 97]; expect[3] = node['j' - 97]; expect[4] = node['i' - 97]; expect[5] = node['e' - 97]; expect[6] = node['h' - 97]; expect[7] = node['l' - 97]; expect[8] = node['b' - 97]; expect[9] = node['d' - 97]; expect[10] = node['g' - 97]; expect[11] = node['k' - 97]; expect[12] = NULL; i = 0; ptr = NULL; do { if (i > 12) TEST_FAILED ("wrong number of iterations, expected %d got %d", 13, i + 1); ptr = nih_tree_prev_post (node['a' - 97], ptr); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['c' - 97]; expect[1] = node['f' - 97]; expect[2] = node['j' - 97]; expect[3] = node['i' - 97]; expect[4] = node['e' - 97]; expect[5] = node['h' - 97]; expect[6] = node['l' - 97]; expect[7] = NULL; i = 0; ptr = NULL; do { if (i > 7) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); ptr = nih_tree_prev_post (node['c' - 97], ptr); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); for (i = 0; i < 12; i++) nih_free (node[i]); /* Check that we can iterate a tree with a single node. */ TEST_FEATURE ("with single node"); node[0] = nih_tree_new (NULL); ptr = nih_tree_prev_post (node[0], NULL); TEST_EQ_P (ptr, node[0]); ptr = nih_tree_prev_post (node[0], ptr); TEST_EQ_P (ptr, NULL); nih_free (node[0]); } /* * For the following tests, we use a specific tree as detailed below where * only those nodes marked with *s should be visited. * * *a* * / \ * / \ * *b* *c* * / / \ * *d* *e* f * / \ / \ * g *h* i j * k' l' * * We place each node in order, with node 'a' implicitly placed as the root; * the filter function will return FALSE for 'j' and 'k' as well to test * that they're ignored since they are children. */ static int my_filter (NihTree **nodes, NihTree *node) { /* FALSE means that we DON'T ignore the node */ if (! nodes) return TRUE; if (node == nodes['a' - 97]) return FALSE; if (node == nodes['b' - 97]) return FALSE; if (node == nodes['c' - 97]) return FALSE; if (node == nodes['d' - 97]) return FALSE; if (node == nodes['e' - 97]) return FALSE; if (node == nodes['f' - 97]) return TRUE; if (node == nodes['g' - 97]) return TRUE; if (node == nodes['h' - 97]) return FALSE; if (node == nodes['i' - 97]) return TRUE; if (node == nodes['j' - 97]) return FALSE; if (node == nodes['k' - 97]) return FALSE; if (node == nodes['l' - 97]) return TRUE; assert ("not reached"); return TRUE; } void test_next_full (void) { NihTree *node[12], *expect[13], *ptr; int i; TEST_FUNCTION ("nih_tree_next_full"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can in-order iterate a reasonably complex tree, * and that nih_tree_next returns the right pointer in each case * until it finally returns NULL. */ TEST_FEATURE ("with full tree"); expect[0] = node['d' - 97]; expect[1] = node['b' - 97]; expect[2] = node['a' - 97]; expect[3] = node['e' - 97]; expect[4] = node['h' - 97]; expect[5] = node['c' - 97]; expect[6] = NULL; i = 0; ptr = NULL; do { if (i > 6) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); ptr = nih_tree_next_full (node['a' - 97], ptr, (NihTreeFilter)my_filter, &node); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['e' - 97]; expect[1] = node['h' - 97]; expect[2] = node['c' - 97]; expect[3] = NULL; i = 0; ptr = NULL; do { if (i > 3) TEST_FAILED ("wrong number of iterations, expected %d got %d", 4, i + 1); ptr = nih_tree_next_full (node['c' - 97], ptr, (NihTreeFilter)my_filter, &node); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); for (i = 0; i < 12; i++) nih_free (node[i]); /* Check that a tree with a single node to be ignored is not * iterated. */ TEST_FEATURE ("with single node"); node[0] = nih_tree_new (NULL); ptr = nih_tree_next_full (node[0], NULL, (NihTreeFilter)my_filter, NULL); TEST_EQ_P (ptr, NULL); nih_free (node[0]); } void test_foreach_full (void) { NihTree *node[12], *expect[13]; int i; TEST_FUNCTION ("NIH_TREE_FOREACH_FULL"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can in-order iterate a reasonably complex tree, * and that NIH_TREE_FOREACH sets the iterator to the right nodes * in turn. */ TEST_FEATURE ("with full tree"); expect[0] = node['d' - 97]; expect[1] = node['b' - 97]; expect[2] = node['a' - 97]; expect[3] = node['e' - 97]; expect[4] = node['h' - 97]; expect[5] = node['c' - 97]; expect[6] = NULL; i = 0; NIH_TREE_FOREACH_FULL (node['a' - 97], iter, (NihTreeFilter)my_filter, &node) { if (i > 6) TEST_FAILED ("wrong number of iterations, expected %d got %d", 6, i + 1); if (iter != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], iter); i++; } /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['e' - 97]; expect[1] = node['h' - 97]; expect[2] = node['c' - 97]; expect[3] = NULL; i = 0; NIH_TREE_FOREACH_FULL (node['c' - 97], iter, (NihTreeFilter)my_filter, &node) { if (i > 3) TEST_FAILED ("wrong number of iterations, expected %d got %d", 3, i + 1); if (iter != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], iter); i++; } for (i = 0; i < 12; i++) nih_free (node[i]); } void test_prev_full (void) { NihTree *node[12], *expect[13], *ptr; int i; TEST_FUNCTION ("nih_tree_prev_full"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can reverse in-order iterate a reasonably complex * tree, and that nih_tree_prev returns the right pointer in * each case until it finally returns NULL. */ TEST_FEATURE ("with full tree"); expect[0] = node['c' - 97]; expect[1] = node['h' - 97]; expect[2] = node['e' - 97]; expect[3] = node['a' - 97]; expect[4] = node['b' - 97]; expect[5] = node['d' - 97]; expect[6] = NULL; i = 0; ptr = NULL; do { if (i > 6) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); ptr = nih_tree_prev_full (node['a' - 97], ptr, (NihTreeFilter)my_filter, &node); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['c' - 97]; expect[1] = node['h' - 97]; expect[2] = node['e' - 97]; expect[3] = NULL; i = 0; ptr = NULL; do { if (i > 3) TEST_FAILED ("wrong number of iterations, expected %d got %d", 4, i + 1); ptr = nih_tree_prev_full (node['c' - 97], ptr, (NihTreeFilter)my_filter, &node); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); for (i = 0; i < 12; i++) nih_free (node[i]); /* Check that a tree with a single node to be ignored is not * iterated. */ TEST_FEATURE ("with single node"); node[0] = nih_tree_new (NULL); ptr = nih_tree_prev_full (node[0], NULL, (NihTreeFilter)my_filter, NULL); TEST_EQ_P (ptr, NULL); nih_free (node[0]); } void test_next_pre_full (void) { NihTree *node[12], *expect[13], *ptr; int i; TEST_FUNCTION ("nih_tree_next_pre_full"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can pre-order iterate a reasonably complex tree, * and that nih_tree_next_pre returns the right pointer in each case * until it finally returns NULL. */ TEST_FEATURE ("with full tree"); expect[0] = node['a' - 97]; expect[1] = node['b' - 97]; expect[2] = node['d' - 97]; expect[3] = node['c' - 97]; expect[4] = node['e' - 97]; expect[5] = node['h' - 97]; expect[6] = NULL; i = 0; ptr = NULL; do { if (i > 6) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); ptr = nih_tree_next_pre_full (node['a' - 97], ptr, (NihTreeFilter)my_filter, &node); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['c' - 97]; expect[1] = node['e' - 97]; expect[2] = node['h' - 97]; expect[3] = NULL; i = 0; ptr = NULL; do { if (i > 3) TEST_FAILED ("wrong number of iterations, expected %d got %d", 4, i + 1); ptr = nih_tree_next_pre_full (node['c' - 97], ptr, (NihTreeFilter)my_filter, &node); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); for (i = 0; i < 12; i++) nih_free (node[i]); /* Check that a tree with a single node to be ignored is not * iterated. */ TEST_FEATURE ("with single node"); node[0] = nih_tree_new (NULL); ptr = nih_tree_next_pre_full (node[0], NULL, (NihTreeFilter)my_filter, NULL); TEST_EQ_P (ptr, NULL); nih_free (node[0]); } void test_foreach_pre_full (void) { NihTree *node[12], *expect[13]; int i; TEST_FUNCTION ("NIH_TREE_FOREACH_PRE_FULL"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can in-order iterate a reasonably complex tree, * and that NIH_TREE_FOREACH_PRE sets the iterator to the right nodes * in turn. */ TEST_FEATURE ("with full tree"); expect[0] = node['a' - 97]; expect[1] = node['b' - 97]; expect[2] = node['d' - 97]; expect[3] = node['c' - 97]; expect[4] = node['e' - 97]; expect[5] = node['h' - 97]; expect[6] = NULL; i = 0; NIH_TREE_FOREACH_PRE_FULL (node['a' - 97], iter, (NihTreeFilter)my_filter, &node) { if (i > 6) TEST_FAILED ("wrong number of iterations, expected %d got %d", 6, i + 1); if (iter != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], iter); i++; } /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['c' - 97]; expect[1] = node['e' - 97]; expect[2] = node['h' - 97]; expect[3] = NULL; i = 0; NIH_TREE_FOREACH_PRE_FULL (node['c' - 97], iter, (NihTreeFilter)my_filter, &node) { if (i > 3) TEST_FAILED ("wrong number of iterations, expected %d got %d", 3, i + 1); if (iter != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], iter); i++; } for (i = 0; i < 12; i++) nih_free (node[i]); } void test_prev_pre_full (void) { NihTree *node[12], *expect[13], *ptr; int i; TEST_FUNCTION ("nih_tree_prev_pre_full"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can reverse pre-order iterate a reasonably complex * tree, and that nih_tree_prev_pre returns the right pointer in each * case until it finally returns NULL. */ TEST_FEATURE ("with full tree"); expect[0] = node['h' - 97]; expect[1] = node['e' - 97]; expect[2] = node['c' - 97]; expect[3] = node['d' - 97]; expect[4] = node['b' - 97]; expect[5] = node['a' - 97]; expect[6] = NULL; i = 0; ptr = NULL; do { if (i > 6) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); ptr = nih_tree_prev_pre_full (node['a' - 97], ptr, (NihTreeFilter)my_filter, &node); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['h' - 97]; expect[1] = node['e' - 97]; expect[2] = node['c' - 97]; expect[3] = NULL; i = 0; ptr = NULL; do { if (i > 3) TEST_FAILED ("wrong number of iterations, expected %d got %d", 4, i + 1); ptr = nih_tree_prev_pre_full (node['c' - 97], ptr, (NihTreeFilter)my_filter, &node); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); for (i = 0; i < 12; i++) nih_free (node[i]); /* Check that a tree with a single node to be ignored is not * iterated. */ TEST_FEATURE ("with single node"); node[0] = nih_tree_new (NULL); ptr = nih_tree_prev_pre_full (node[0], NULL, (NihTreeFilter)my_filter, NULL); TEST_EQ_P (ptr, NULL); nih_free (node[0]); } void test_next_post_full (void) { NihTree *node[12], *expect[13], *ptr; int i; TEST_FUNCTION ("nih_tree_next_post_full"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can post-order iterate a reasonably complex tree, * and that nih_tree_next_post returns the right pointer in each case * until it finally returns NULL. */ TEST_FEATURE ("with full tree"); expect[0] = node['d' - 97]; expect[1] = node['b' - 97]; expect[2] = node['h' - 97]; expect[3] = node['e' - 97]; expect[4] = node['c' - 97]; expect[5] = node['a' - 97]; expect[6] = NULL; i = 0; ptr = NULL; do { if (i > 6) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); ptr = nih_tree_next_post_full (node['a' - 97], ptr, (NihTreeFilter)my_filter, &node); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['h' - 97]; expect[1] = node['e' - 97]; expect[2] = node['c' - 97]; expect[3] = NULL; i = 0; ptr = NULL; do { if (i > 3) TEST_FAILED ("wrong number of iterations, expected %d got %d", 4, i + 1); ptr = nih_tree_next_post_full (node['c' - 97], ptr, (NihTreeFilter)my_filter, &node); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); for (i = 0; i < 12; i++) nih_free (node[i]); /* Check that a tree with a single node to be ignored is not * iterated. */ TEST_FEATURE ("with single node"); node[0] = nih_tree_new (NULL); ptr = nih_tree_next_post_full (node[0], NULL, (NihTreeFilter)my_filter, NULL); TEST_EQ_P (ptr, NULL); nih_free (node[0]); } void test_foreach_post_full (void) { NihTree *node[12], *expect[13]; int i; TEST_FUNCTION ("NIH_TREE_FOREACH_POST_FULL"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can post-order iterate a reasonably complex tree, * and that NIH_TREE_FOREACH_POST sets the iterator to the right nodes * in turn. */ TEST_FEATURE ("with full tree"); expect[0] = node['d' - 97]; expect[1] = node['b' - 97]; expect[2] = node['h' - 97]; expect[3] = node['e' - 97]; expect[4] = node['c' - 97]; expect[5] = node['a' - 97]; expect[6] = NULL; i = 0; NIH_TREE_FOREACH_POST_FULL (node['a' - 97], iter, (NihTreeFilter)my_filter, &node) { if (i > 6) TEST_FAILED ("wrong number of iterations, expected %d got %d", 6, i + 1); if (iter != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], iter); i++; } /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['h' - 97]; expect[1] = node['e' - 97]; expect[2] = node['c' - 97]; expect[3] = NULL; i = 0; NIH_TREE_FOREACH_POST_FULL (node['c' - 97], iter, (NihTreeFilter)my_filter, &node) { if (i > 3) TEST_FAILED ("wrong number of iterations, expected %d got %d", 3, i + 1); if (iter != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], iter); i++; } for (i = 0; i < 12; i++) nih_free (node[i]); } void test_prev_post_full (void) { NihTree *node[12], *expect[13], *ptr; int i; TEST_FUNCTION ("nih_tree_prev_post_full"); for (i = 0; i < 12; i++) node[i] = nih_tree_new (NULL); nih_tree_add (node['a' - 97], node['b' - 97], NIH_TREE_LEFT); nih_tree_add (node['a' - 97], node['c' - 97], NIH_TREE_RIGHT); nih_tree_add (node['b' - 97], node['d' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['e' - 97], NIH_TREE_LEFT); nih_tree_add (node['c' - 97], node['f' - 97], NIH_TREE_RIGHT); nih_tree_add (node['d' - 97], node['g' - 97], NIH_TREE_LEFT); nih_tree_add (node['e' - 97], node['h' - 97], NIH_TREE_RIGHT); nih_tree_add (node['f' - 97], node['i' - 97], NIH_TREE_LEFT); nih_tree_add (node['f' - 97], node['j' - 97], NIH_TREE_RIGHT); nih_tree_add (node['g' - 97], node['k' - 97], NIH_TREE_LEFT); nih_tree_add (node['h' - 97], node['l' - 97], NIH_TREE_LEFT); /* Check that we can reverse post-order iterate a reasonably complex * tree, and that nih_tree_prev_post returns the right pointer in each * case until it finally returns NULL. */ TEST_FEATURE ("with full tree"); expect[0] = node['a' - 97]; expect[1] = node['c' - 97]; expect[2] = node['e' - 97]; expect[3] = node['h' - 97]; expect[4] = node['b' - 97]; expect[5] = node['d' - 97]; expect[6] = NULL; i = 0; ptr = NULL; do { if (i > 6) TEST_FAILED ("wrong number of iterations, expected %d got %d", 7, i + 1); ptr = nih_tree_prev_post_full (node['a' - 97], ptr, (NihTreeFilter)my_filter, &node); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); /* Check that we can limit the iteration to a partial tree rooted * at the given tree node. */ TEST_FEATURE ("with partial tree"); expect[0] = node['c' - 97]; expect[1] = node['e' - 97]; expect[2] = node['h' - 97]; expect[3] = NULL; i = 0; ptr = NULL; do { if (i > 3) TEST_FAILED ("wrong number of iterations, expected %d got %d", 4, i + 1); ptr = nih_tree_prev_post_full (node['c' - 97], ptr, (NihTreeFilter)my_filter, &node); if (ptr != expect[i]) TEST_FAILED ("wrong tree node for %d, expected %p got %p", i, expect[i], ptr); i++; } while (ptr); for (i = 0; i < 12; i++) nih_free (node[i]); /* Check that a tree with a single node to be ignored is not * iterated. */ TEST_FEATURE ("with single node"); node[0] = nih_tree_new (NULL); ptr = nih_tree_prev_post_full (node[0], NULL, (NihTreeFilter)my_filter, NULL); TEST_EQ_P (ptr, NULL); nih_free (node[0]); } int main (int argc, char *argv[]) { test_init (); test_new (); test_entry_new (); test_add (); test_remove (); test_unlink (); test_destroy (); test_next (); test_foreach (); test_prev (); test_next_pre (); test_foreach_pre (); test_prev_pre (); test_next_post (); test_foreach_post (); test_prev_post (); test_next_full (); test_foreach_full (); test_prev_full (); test_next_pre_full (); test_foreach_pre_full (); test_prev_pre_full (); test_next_post_full (); test_foreach_post_full (); test_prev_post_full (); return 0; } libnih-1.0.3/nih/tests/test_config.c0000644000175000017500000020032211445765555014311 00000000000000/* libnih * * test_config.c - test suite for nih/config.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include void test_has_token (void) { char buf[1024]; size_t pos; int ret; TEST_FUNCTION ("nih_config_has_token"); strcpy (buf, "this is a test # comment\n"); /* Check that an ordinary token character at the start of the line * causes the function to return TRUE. */ TEST_FEATURE ("with token at start of string"); ret = nih_config_has_token (buf, strlen (buf), NULL, NULL); TEST_TRUE (ret); /* Check that an ordinary token inside the string causes the function * to return TRUE. */ TEST_FEATURE ("with token inside string"); pos = 5; ret = nih_config_has_token (buf, strlen (buf), &pos, NULL); TEST_TRUE (ret); /* Check that a piece of whitespace causes the function to return TRUE. */ TEST_FEATURE ("with whitespace"); pos = 7; ret = nih_config_has_token (buf, strlen (buf), &pos, NULL); TEST_TRUE (ret); /* Check that a comment character causes the function to return FALSE. */ TEST_FEATURE ("with start of comment"); pos = 15; ret = nih_config_has_token (buf, strlen (buf), &pos, NULL); TEST_FALSE (ret); /* Check that a newline character causes the function to return FALSE. */ TEST_FEATURE ("with newline"); pos = 24; ret = nih_config_has_token (buf, strlen (buf), &pos, NULL); TEST_FALSE (ret); /* Check that the end of file causes the function to return FALSE. */ TEST_FEATURE ("at end of file"); pos = 25; ret = nih_config_has_token (buf, strlen (buf), &pos, NULL); TEST_FALSE (ret); } void test_token (void) { char buf[1024], dest[1024]; size_t pos, lineno, len; int ret; NihError *err; TEST_FUNCTION ("nih_config_token"); program_name = "test"; /* Check that we can obtain the length of the first simple token * in a string, and that the position is updated past it. The * length of the token should be returned. */ TEST_FEATURE ("with token at start of string"); strcpy (buf, "this is a test"); pos = 0; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, NULL, NULL, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 4); TEST_EQ (pos, 4); /* Check that we can obtain a length of a token that entirely fills * the remainder of the file. */ TEST_FEATURE ("with token filling string"); strcpy (buf, "wibble"); pos = 0; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, NULL, NULL, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 6); TEST_EQ (pos, 6); /* Check that we can extract a token from the string and have it * copied into our destination buffer. */ TEST_FEATURE ("with token to extract"); strcpy (buf, "this is a test"); ret = nih_config_token (buf, strlen (buf), NULL, NULL, dest, " ", FALSE, NULL); TEST_EQ (ret, 0); TEST_EQ_STR (dest, "this"); /* Check that we can obtain the length of a simple token inside the * string, and the the position is updated past it. */ TEST_FEATURE ("with token inside string"); pos = 5; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, NULL, NULL, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 2); TEST_EQ (pos, 7); /* Check that we can obtain the length of a token that contains * double quotes around the delimeter, the length should include * the quoted part at the quotes. */ TEST_FEATURE ("with double quotes inside token"); strcpy (buf, "\"this is a\" test"); pos = 0; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, NULL, NULL, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 11); TEST_EQ (pos, 11); /* Check that we can extract a token that is surrounded by double * quotes, we should still get those. */ TEST_FEATURE ("with double quotes around token to extract"); len = 0; ret = nih_config_token (buf, strlen (buf), NULL, NULL, dest, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 11); TEST_EQ_STR (dest, "\"this is a\""); /* Check that we can obtain the length of the quoted portion, with * the quotes removed; the position should still point past it. */ TEST_FEATURE ("with double quotes and dequoting"); pos = 0; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, NULL, NULL, " ", TRUE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 9); TEST_EQ (pos, 11); /* Check that we can extract a quoted token and have the quotes * removed. */ TEST_FEATURE ("with double quotes and extract with dequoting"); ret = nih_config_token (buf, strlen (buf), NULL, NULL, dest, " ", TRUE, NULL); TEST_EQ (ret, 0); TEST_EQ_STR (dest, "this is a"); /* Check that we can obtain the length of a token that contains * single quotes around the delimeter, the length should include * the quoted part at the quotes. */ TEST_FEATURE ("with single quotes inside token"); strcpy (buf, "\'this is a\' test"); pos = 0; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, NULL, NULL, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 11); TEST_EQ (pos, 11); /* Check that we can obtain the length of a token that contains * escaped spaces around the delimeter, the length should include * the backslashes. */ TEST_FEATURE ("with escaped spaces inside token"); strcpy (buf, "this\\ is\\ a test"); pos = 0; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, NULL, NULL, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 11); TEST_EQ (pos, 11); /* Check that we can extract a token that contains escaped spaces * around the delimiter. */ TEST_FEATURE ("with escaped spaces within extracted token"); ret = nih_config_token (buf, strlen (buf), NULL, NULL, dest, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 11); TEST_EQ_STR (dest, "this\\ is\\ a"); /* Check that we can obtain the length of a token that contains * escaped spaces around the delimeter, without the blackslashes. */ TEST_FEATURE ("with escaped spaces inside token and dequoting"); pos = 0; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, NULL, NULL, " ", TRUE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 9); TEST_EQ (pos, 11); /* Check that we can extract a token that contains escaped spaces * around the delimiter, while removing them. */ TEST_FEATURE ("with escaped spaces within extracted dequoted token"); len = 0; ret = nih_config_token (buf, strlen (buf), NULL, NULL, dest, " ", TRUE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 9); TEST_EQ_STR (dest, "this is a"); /* Check that a newline inside a quoted string, and surrounding * whitespace, is treated as a single space character. */ TEST_FEATURE ("with newline inside quoted string"); strcpy (buf, "\"this is \n a\" test"); pos = 0; lineno = 1; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, &lineno, NULL, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 11); TEST_EQ (pos, 13); TEST_EQ (lineno, 2); /* Check that extracting a token with a newline inside a quoted * string only returns a single space for the newline. */ TEST_FEATURE ("with newline inside extracted quoted string"); len = 0; ret = nih_config_token (buf, strlen (buf), NULL, NULL, dest, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 11); TEST_EQ_STR (dest, "\"this is a\""); /* Check that lineno is incremented when we encounter a newline * inside a quoted string. */ TEST_FEATURE ("with newline inside quoted string and lineno set"); pos = 0; lineno = 1; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, &lineno, NULL, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 11); TEST_EQ (pos, 13); TEST_EQ (lineno, 2); /* Check that an escaped newline, and surrounding whitespace, is * treated as a single space character. */ TEST_FEATURE ("with escaped newline"); strcpy (buf, "this \\\n is a:test"); pos = 0; lineno = 1; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, &lineno, NULL, ":", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 9); TEST_EQ (pos, 12); TEST_EQ (lineno, 2); /* Check that extracting a token with an escaped newline inside it only * returns a single space for the newline. */ TEST_FEATURE ("with escaped newline inside extracted string"); ret = nih_config_token (buf, strlen (buf), NULL, NULL, dest, ":", FALSE, NULL); TEST_EQ (ret, 0); TEST_EQ_STR (dest, "this is a"); /* Check that lineno is incremented when we encounter an escaped * newline */ TEST_FEATURE ("with escaped newline inside string and lineno set"); pos = 0; lineno = 1; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, &lineno, NULL, ":", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 9); TEST_EQ (pos, 12); TEST_EQ (lineno, 2); /* Check that we can obtain the length of a token that contains * escaped characters, the length should include the backslashes. */ TEST_FEATURE ("with escaped characters inside token"); strcpy (buf, "this\\$FOO"); pos = 0; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, NULL, NULL, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 9); TEST_EQ (pos, 9); /* Check that we can extract a token that contains escaped * characters. */ TEST_FEATURE ("with escaped characters within extracted token"); ret = nih_config_token (buf, strlen (buf), NULL, NULL, dest, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 9); TEST_EQ_STR (dest, "this\\$FOO"); /* Check that we can obtain the length of a token that contains * escaped characters, including the backslashes, even though * we're dequoting. */ TEST_FEATURE ("with escaped characters inside token and dequoting"); pos = 0; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, NULL, NULL, " ", TRUE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 9); TEST_EQ (pos, 9); /* Check that we can extract a token that contains escaped characters, * which should include the backslashes even though we're dequoting. */ TEST_FEATURE ("with escaped characters within extracted dequoted token"); len = 0; ret = nih_config_token (buf, strlen (buf), NULL, NULL, dest, " ", TRUE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 9); TEST_EQ_STR (dest, "this\\$FOO"); /* Check that we can obtain the length of a token that contains * escaped backslashes, the length should include the backslashes. */ TEST_FEATURE ("with escaped backslashes inside token"); strcpy (buf, "this\\\\FOO"); pos = 0; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, NULL, NULL, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 9); TEST_EQ (pos, 9); /* Check that we can extract a token that contains escaped * blackslashes. */ TEST_FEATURE ("with escaped backslashes within extracted token"); ret = nih_config_token (buf, strlen (buf), NULL, NULL, dest, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 9); TEST_EQ_STR (dest, "this\\\\FOO"); /* Check that we can obtain the length of a token that contains * escaped blackslashes, reduced to one since we're dequoting */ TEST_FEATURE ("with escaped backslashes inside token and dequoting"); pos = 0; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, NULL, NULL, " ", TRUE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 8); TEST_EQ (pos, 9); /* Check that we can extract a token that contains escaped backslashes, * which should include only one of the backslashes because * we're dequoting. */ TEST_FEATURE ("with escaped backslashes within extracted dequoted token"); len = 0; ret = nih_config_token (buf, strlen (buf), NULL, NULL, dest, " ", TRUE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 8); TEST_EQ_STR (dest, "this\\FOO"); /* Check that a slash at the end of the file causes a parser error * to be raised with pos and lineno set to the offending location. */ TEST_FEATURE ("with slash at end of string"); strcpy (buf, "wibble\\"); pos = 0; len = 0; lineno = 1; ret = nih_config_token (buf, strlen (buf), &pos, &lineno, NULL, " ", FALSE, NULL); TEST_LT (ret, 0); TEST_EQ (pos, 7); TEST_EQ (lineno, 1); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_TRAILING_SLASH); nih_free (err); /* Ceck that an unterminated quote causes a parser error to be * raised, with pos and lineno set to the offending location. */ TEST_FEATURE ("with unterminated quote"); strcpy (buf, "\"wibble\n"); pos = 0; lineno = 1; ret = nih_config_token (buf, strlen (buf), &pos, &lineno, NULL, " ", FALSE, NULL); TEST_LT (ret, 0); TEST_EQ (pos, 8); TEST_EQ (lineno, 2); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_UNTERMINATED_QUOTE); nih_free (err); /* Check that an empty token results in the position left unchanged * and zero being returned, */ TEST_FEATURE ("with empty token"); strcpy (buf, " wibble"); pos = 0; len = 0; ret = nih_config_token (buf, strlen (buf), &pos, NULL, NULL, " ", FALSE, &len); TEST_EQ (ret, 0); TEST_EQ (len, 0); TEST_EQ (pos, 0); } void test_next_token (void) { char buf[1024]; char *str; size_t pos, lineno; NihError *err; TEST_FUNCTION ("nih_config_next_token"); /* Check that we can extract a token at the start of a string, * and have the position pointing past the whitespace to the next * argument. */ TEST_FEATURE ("with token at start of string"); TEST_ALLOC_FAIL { strcpy (buf, "this is a test"); pos = 0; str = nih_config_next_token (NULL, buf, strlen (buf), &pos, NULL, NIH_CONFIG_CNLWS, FALSE); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 5); TEST_ALLOC_SIZE (str, 5); TEST_EQ_STR (str, "this"); nih_free (str); } /* Check that we can extract an argument inside a string */ TEST_FEATURE ("with token inside string"); TEST_ALLOC_FAIL { strcpy (buf, "this is a test"); pos = 5; str = nih_config_next_token (NULL, buf, strlen (buf), &pos, NULL, NIH_CONFIG_CNLWS, FALSE); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 5); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 8); TEST_ALLOC_SIZE (str, 3); TEST_EQ_STR (str, "is"); nih_free (str); } /* Check that all trailing whitespace is eaten after the token. */ TEST_FEATURE ("with consecutive whitespace after token"); TEST_ALLOC_FAIL { strcpy (buf, "this \t is a test"); pos = 0; str = nih_config_next_token (NULL, buf, strlen (buf), &pos, NULL, NIH_CONFIG_CNLWS, FALSE); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 8); TEST_ALLOC_SIZE (str, 5); TEST_EQ_STR (str, "this"); nih_free (str); } /* Check that any escaped newlines in the whitespace are skipped * over */ TEST_FEATURE ("with escaped newlines in whitespace"); TEST_ALLOC_FAIL { strcpy (buf, "this \\\n is a test"); pos = 0; str = nih_config_next_token (NULL, buf, strlen (buf), &pos, NULL, NIH_CONFIG_CNLWS, FALSE); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 8); TEST_ALLOC_SIZE (str, 5); TEST_EQ_STR (str, "this"); nih_free (str); } /* Check that the line number is incremented for any escaped newlines * in the whitespace. */ TEST_FEATURE ("with line number set"); TEST_ALLOC_FAIL { pos = 0; lineno = 1; str = nih_config_next_token (NULL, buf, strlen (buf), &pos, &lineno, NIH_CONFIG_CNLWS, FALSE); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); TEST_EQ (lineno, 2); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 8); TEST_EQ (lineno, 2); TEST_ALLOC_SIZE (str, 5); TEST_EQ_STR (str, "this"); nih_free (str); } /* Check that the returned token can have the quotes left in it, * but the whitespace around the newline collapsed. */ TEST_FEATURE ("with token containing quotes"); TEST_ALLOC_FAIL { strcpy (buf, "\"this \\\n is\" a test"); pos = 0; str = nih_config_next_token (NULL, buf, strlen (buf), &pos, NULL, NIH_CONFIG_CNLWS, FALSE); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 13); TEST_ALLOC_SIZE (str, 10); TEST_EQ_STR (str, "\"this is\""); nih_free (str); } /* Check that the returned token can be thoroughly dequoted and any * whitespace around an embedded newline collapsed to a single * space. */ TEST_FEATURE ("with quoted whitespace and newline in token"); TEST_ALLOC_FAIL { strcpy (buf, "\"this \\\n is\" a test"); pos = 0; str = nih_config_next_token (NULL, buf, strlen (buf), &pos, NULL, NIH_CONFIG_CNLWS, TRUE); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 13); TEST_ALLOC_SIZE (str, 8); TEST_EQ_STR (str, "this is"); nih_free (str); } /* Check that an error is raised if there is no token at that * position. */ TEST_FEATURE ("with empty line"); TEST_ALLOC_FAIL { strcpy (buf, "\nthis is a test"); pos = 0; lineno = 1; str = nih_config_next_token (NULL, buf, strlen (buf), &pos, &lineno, NIH_CONFIG_CNLWS, FALSE); TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); TEST_EQ (lineno, 1); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN); nih_free (err); } /* Check that a parse error being found with the argument causes an * error to be raised, with pos and lineno at the site of the error. */ TEST_FEATURE ("with parser error"); TEST_ALLOC_FAIL { strcpy (buf, "\"this is a test\nand so is this"); pos = 0; lineno = 1; str = nih_config_next_token (NULL, buf, strlen (buf), &pos, &lineno, NIH_CONFIG_CNLWS, FALSE); TEST_EQ_P (str, NULL); TEST_EQ (pos, 30); TEST_EQ (lineno, 2); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_UNTERMINATED_QUOTE); nih_free (err); } } void test_next_arg (void) { char buf[1024]; char *str; size_t pos, lineno; NihError *err; TEST_FUNCTION ("nih_config_next_arg"); /* Check that we can extract an argument at the start of a string, * and have the position pointing past the whitespace to the next * argument. */ TEST_FEATURE ("with argument at start of string"); TEST_ALLOC_FAIL { strcpy (buf, "this is a test"); pos = 0; str = nih_config_next_arg (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 5); TEST_ALLOC_SIZE (str, 5); TEST_EQ_STR (str, "this"); nih_free (str); } /* Check that we can extract an argument inside a string */ TEST_FEATURE ("with argument inside string"); TEST_ALLOC_FAIL { strcpy (buf, "this is a test"); pos = 5; str = nih_config_next_arg (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 5); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 8); TEST_ALLOC_SIZE (str, 3); TEST_EQ_STR (str, "is"); nih_free (str); } /* Check that all trailing whitespace is eaten after the argument. */ TEST_FEATURE ("with consecutive whitespace after argument"); TEST_ALLOC_FAIL { strcpy (buf, "this \t is a test"); pos = 0; str = nih_config_next_arg (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 8); TEST_ALLOC_SIZE (str, 5); TEST_EQ_STR (str, "this"); nih_free (str); } /* Check that any escaped newlines in the whitespace are skipped * over */ TEST_FEATURE ("with escaped newlines in whitespace"); TEST_ALLOC_FAIL { strcpy (buf, "this \\\n is a test"); pos = 0; str = nih_config_next_arg (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 8); TEST_ALLOC_SIZE (str, 5); TEST_EQ_STR (str, "this"); nih_free (str); } /* Check that the line number is incremented for any escaped newlines * in the whitespace. */ TEST_FEATURE ("with line number set"); TEST_ALLOC_FAIL { pos = 0; lineno = 1; str = nih_config_next_arg (NULL, buf, strlen (buf), &pos, &lineno); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); TEST_EQ (lineno, 2); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 8); TEST_EQ (lineno, 2); TEST_ALLOC_SIZE (str, 5); TEST_EQ_STR (str, "this"); nih_free (str); } /* Check that the returned argument is thoroughly dequoted and any * whitespace around an embedded newline collapsed to a single * space. */ TEST_FEATURE ("with quoted whitespace and newline in arg"); TEST_ALLOC_FAIL { strcpy (buf, "\"this \\\n is\" a test"); pos = 0; str = nih_config_next_arg (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 13); TEST_ALLOC_SIZE (str, 8); TEST_EQ_STR (str, "this is"); nih_free (str); } /* Check that an error is raised if there is no argument at that * position. */ TEST_FEATURE ("with empty line"); TEST_ALLOC_FAIL { strcpy (buf, "\nthis is a test"); pos = 0; lineno = 1; str = nih_config_next_arg (NULL, buf, strlen (buf), &pos, &lineno); TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); TEST_EQ (lineno, 1); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN); nih_free (err); } /* Check that a parse error being found with the argument causes an * error to be raised, with pos and lineno at the site of the error. */ TEST_FEATURE ("with parser error"); TEST_ALLOC_FAIL { strcpy (buf, "\"this is a test\nand so is this"); pos = 0; lineno = 1; str = nih_config_next_arg (NULL, buf, strlen (buf), &pos, &lineno); TEST_EQ_P (str, NULL); TEST_EQ (pos, 30); TEST_EQ (lineno, 2); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_UNTERMINATED_QUOTE); nih_free (err); } } void test_next_line (void) { char buf[1024]; size_t pos, lineno; TEST_FUNCTION ("nih_config_next_line"); /* Check that we can skip a number of characters until the newline, * pointing pos past it. */ TEST_FEATURE ("with simple string"); strcpy (buf, "this is a test\nand so is this\n"); pos = 0; nih_config_next_line (buf, strlen (buf), &pos, NULL); TEST_EQ (pos, 15); /* Check that lineno is incremented when we step over it. */ TEST_FEATURE ("with line number set"); pos = 0; lineno = 1; nih_config_next_line (buf, strlen (buf), &pos, &lineno); TEST_EQ (pos, 15); TEST_EQ (lineno, 2); /* Check that pos is only incremented by a single step if the * character underneath is a newline. */ TEST_FEATURE ("with newline at position"); strcpy (buf, "\nthis is a test"); pos = 0; lineno = 1; nih_config_next_line (buf, strlen (buf), &pos, &lineno); TEST_EQ (pos, 1); TEST_EQ (lineno, 2); /* Check that the end of file can be reached without error. */ TEST_FEATURE ("with no newline before end of file"); strcpy (buf, "this is a test"); pos = 0; nih_config_next_line (buf, strlen (buf), &pos, NULL); TEST_EQ (pos, 14); } void test_skip_whitespace (void) { char buf[1024]; size_t pos, lineno; TEST_FUNCTION ("nih_config_next_whitespace"); /* Check that we can skip an amount of plain whitespace characters * until the next token, pointing pos at is. */ TEST_FEATURE ("with plain whitespace"); strcpy (buf, "a plain string\n"); pos = 1; lineno = 1; nih_config_skip_whitespace (buf, strlen (buf), &pos, &lineno); TEST_EQ (pos, 3); TEST_EQ (lineno, 1); /* Check that we can skip a more complex series of whitespace * characters until the next token. */ TEST_FEATURE ("with complex whitespace"); strcpy (buf, "a more \t \r complex string\n"); pos = 6; lineno = 1; nih_config_skip_whitespace (buf, strlen (buf), &pos, &lineno); TEST_EQ (pos, 15); TEST_EQ (lineno, 1); /* Check that we can skip whitespace characters up until the end * of the line, but that we don't step over it. */ TEST_FEATURE ("with whitespace at end of line"); strcpy (buf, "trailing whitespace \t\r\n"); pos = 19; lineno = 1; nih_config_skip_whitespace (buf, strlen (buf), &pos, &lineno); TEST_EQ (pos, 23); TEST_EQ (lineno, 1); /* Check that we step over an escaped newline embedded in the * whitespace, and increment lineno. */ TEST_FEATURE ("with escaped newline"); strcpy (buf, "this has \\\n a newline"); pos = 8; lineno = 1; nih_config_skip_whitespace (buf, strlen (buf), &pos, &lineno); TEST_EQ (pos, 12); TEST_EQ (lineno, 2); } void test_skip_comment (void) { char buf[1024]; size_t pos, lineno; int ret; NihError *err; TEST_FUNCTION ("nih_config_next_line"); /* Check that we can skip a number of comment characters until the * newline, pointing pos past it. */ TEST_FEATURE ("with simple string"); strcpy (buf, "# this is a test\nand so is this\n"); pos = 0; ret = nih_config_skip_comment (buf, strlen (buf), &pos, NULL); TEST_EQ (ret, 0); TEST_EQ (pos, 17); /* Check that lineno is incremented when we step over it. */ TEST_FEATURE ("with line number set"); pos = 0; lineno = 1; ret = nih_config_skip_comment (buf, strlen (buf), &pos, &lineno); TEST_EQ (ret, 0); TEST_EQ (pos, 17); TEST_EQ (lineno, 2); /* Check that pos is only incremented by a single step if the * character underneath is a newline. */ TEST_FEATURE ("with newline at position"); strcpy (buf, "\nthis is a test"); pos = 0; lineno = 1; ret = nih_config_skip_comment (buf, strlen (buf), &pos, &lineno); TEST_EQ (ret, 0); TEST_EQ (pos, 1); TEST_EQ (lineno, 2); /* Check that the end of file can be reached without error. */ TEST_FEATURE ("with no newline before end of file"); strcpy (buf, "# this is a test"); pos = 0; ret = nih_config_skip_comment (buf, strlen (buf), &pos, NULL); TEST_EQ (ret, 0); TEST_EQ (pos, 16); /* Check that attempting to skip an ordinary argument results in * an error. */ TEST_FEATURE ("with attempt to skip argument"); strcpy (buf, "this is a test\nand so it this\n"); pos = 0; ret = nih_config_skip_comment (buf, strlen (buf), &pos, NULL); TEST_LT (ret, 0); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_UNEXPECTED_TOKEN); nih_free (err); } void test_parse_args (void) { char buf[1024]; char **args; size_t pos, lineno; NihError *err; TEST_FUNCTION ("nih_config_parse_args"); /* Check that we can parse a list of arguments from the start of * a simple string. They should be returned as a NULL-terminated * array of strings, and the position should be updated to point to * the start of the next line. */ TEST_FEATURE ("with args at start of simple string"); TEST_ALLOC_FAIL { strcpy (buf, "this is a test\nand so is this\n"); pos = 0; args = nih_config_parse_args (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (args, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 15); TEST_ALLOC_SIZE (args, sizeof (char *) * 5); TEST_ALLOC_PARENT (args[0], args); TEST_ALLOC_PARENT (args[1], args); TEST_ALLOC_PARENT (args[2], args); TEST_ALLOC_PARENT (args[3], args); TEST_EQ_STR (args[0], "this"); TEST_EQ_STR (args[1], "is"); TEST_EQ_STR (args[2], "a"); TEST_EQ_STR (args[3], "test"); TEST_EQ_P (args[4], NULL); nih_free (args); } /* Check that we can parse a list of arguments from a position * inside an existing string. */ TEST_FEATURE ("with args inside simple string"); TEST_ALLOC_FAIL { pos = 5; args = nih_config_parse_args (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (args, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 15); TEST_ALLOC_SIZE (args, sizeof (char *) * 4); TEST_EQ_STR (args[0], "is"); TEST_EQ_STR (args[1], "a"); TEST_EQ_STR (args[2], "test"); TEST_EQ_P (args[3], NULL); nih_free (args); } /* Check that we can parse a list of arguments up to the end of the * file, which doesn't have a newline. */ TEST_FEATURE ("with args up to end of string"); TEST_ALLOC_FAIL { strcpy (buf, "this is a test"); pos = 0; args = nih_config_parse_args (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (args, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 14); TEST_ALLOC_SIZE (args, sizeof (char *) * 5); TEST_EQ_STR (args[0], "this"); TEST_EQ_STR (args[1], "is"); TEST_EQ_STR (args[2], "a"); TEST_EQ_STR (args[3], "test"); TEST_EQ_P (args[4], NULL); nih_free (args); } /* Check that we can ignore a comment at the end of the line, the * position should be updated past the comment onto the next line. */ TEST_FEATURE ("with args up to comment"); TEST_ALLOC_FAIL { strcpy (buf, "this is a test # comment\nand so is this\n"); pos = 0; args = nih_config_parse_args (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (args, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 25); TEST_ALLOC_SIZE (args, sizeof (char *) * 5); TEST_EQ_STR (args[0], "this"); TEST_EQ_STR (args[1], "is"); TEST_EQ_STR (args[2], "a"); TEST_EQ_STR (args[3], "test"); TEST_EQ_P (args[4], NULL); nih_free (args); } /* Check that we can ignore a comment at the end of the file, the * position should be updated past the end. */ TEST_FEATURE ("with args up to comment at end of file"); TEST_ALLOC_FAIL { strcpy (buf, "this is a test # comment"); pos = 0; args = nih_config_parse_args (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (args, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 24); TEST_ALLOC_SIZE (args, sizeof (char *) * 5); TEST_EQ_STR (args[0], "this"); TEST_EQ_STR (args[1], "is"); TEST_EQ_STR (args[2], "a"); TEST_EQ_STR (args[3], "test"); TEST_EQ_P (args[4], NULL); nih_free (args); } /* Check that the line number is incremented when a new line is * encountered. */ TEST_FEATURE ("with line number given"); TEST_ALLOC_FAIL { strcpy (buf, "this is a test\nand so is this\n"); pos = 0; lineno = 1; args = nih_config_parse_args (NULL, buf, strlen (buf), &pos, &lineno); if (test_alloc_failed) { TEST_EQ_P (args, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 15); TEST_EQ (lineno, 2); nih_free (args); } /* Check that consecutive whitespace, including escaped newlines, * are treated as a single delimeter. The line number should be * incremented for both the embedded one and final one. */ TEST_FEATURE ("with multiple whitespace between arguments"); TEST_ALLOC_FAIL { strcpy (buf, "this is \t a \\\n test\nand so is this\n"); pos = 0; lineno = 1; args = nih_config_parse_args (NULL, buf, strlen (buf), &pos, &lineno); if (test_alloc_failed) { TEST_EQ_P (args, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 24); TEST_EQ (lineno, 3); TEST_ALLOC_SIZE (args, sizeof (char *) * 5); TEST_EQ_STR (args[0], "this"); TEST_EQ_STR (args[1], "is"); TEST_EQ_STR (args[2], "a"); TEST_EQ_STR (args[3], "test"); TEST_EQ_P (args[4], NULL); nih_free (args); } /* Check that each argument can be delimited by quotes, contain * quoted newlines, and each is dequoted before being stored in the * args array, */ TEST_FEATURE ("with whitespace inside arguments"); TEST_ALLOC_FAIL { strcpy (buf, "\"this is\" \"a\ntest\" \\\n and so\nis this\n"); pos = 0; lineno = 1; args = nih_config_parse_args (NULL, buf, strlen (buf), &pos, &lineno); if (test_alloc_failed) { TEST_EQ_P (args, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 29); TEST_EQ (lineno, 4); TEST_ALLOC_SIZE (args, sizeof (char *) * 5); TEST_EQ_STR (args[0], "this is"); TEST_EQ_STR (args[1], "a test"); TEST_EQ_STR (args[2], "and"); TEST_EQ_STR (args[3], "so"); TEST_EQ_P (args[4], NULL); nih_free (args); } /* Check that an empty line results in a one element array being * returned containing only NULL, and the position being incremented * past the empty line. */ TEST_FEATURE ("with empty line"); TEST_ALLOC_FAIL { strcpy (buf, "\nand so is this\n"); pos = 0; args = nih_config_parse_args (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (args, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 1); TEST_ALLOC_SIZE (args, sizeof (char *) * 1); TEST_EQ_P (args[0], NULL); nih_free (args); } /* Check that a line containing only a comment results in a one * element array being returned containing only NULL, and the * position being incremented past the comment and newline. */ TEST_FEATURE ("with only comment in line"); TEST_ALLOC_FAIL { strcpy (buf, "# line with comment\nand so is this\n"); pos = 0; args = nih_config_parse_args (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (args, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 20); TEST_ALLOC_SIZE (args, sizeof (char *) * 1); TEST_EQ_P (args[0], NULL); nih_free (args); } /* Check that an error parsing the arguments results in NULL being * returned and the error raised. */ TEST_FEATURE ("with parser error"); TEST_ALLOC_FAIL { strcpy (buf, "this is a \"test\nand so is this\n"); pos = 0; lineno = 1; args = nih_config_parse_args (NULL, buf, strlen (buf), &pos, &lineno); TEST_EQ_P (args, NULL); if (! test_alloc_failed) { TEST_EQ (pos, 31); TEST_EQ (lineno, 3); } err = nih_error_get (); if (! test_alloc_failed) TEST_EQ (err->number, NIH_CONFIG_UNTERMINATED_QUOTE); nih_free (err); } } void test_parse_command (void) { char buf[1024]; char *str; size_t pos, lineno; NihError *err; TEST_FUNCTION ("nih_config_parse_command"); /* Check that we can parse a command from the start of a simple * string. It should be returned as an allocated string and the * position should be updated to point to the start of the next line. */ TEST_FEATURE ("with command at start of simple string"); TEST_ALLOC_FAIL { strcpy (buf, "this is a test\nand so is this\n"); pos = 0; str = nih_config_parse_command (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 15); TEST_ALLOC_SIZE (str, 15); TEST_EQ_STR (str, "this is a test"); nih_free (str); } /* Check that we can parse a command from inside a string. */ TEST_FEATURE ("with command inside simple string"); TEST_ALLOC_FAIL { strcpy (buf, "this is a test\nand so is this\n"); pos = 5; str = nih_config_parse_command (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 5); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 15); TEST_ALLOC_SIZE (str, 10); TEST_EQ_STR (str, "is a test"); nih_free (str); } /* Check that we can parse a command that ends with the end of file. */ TEST_FEATURE ("with command at end of file"); TEST_ALLOC_FAIL { strcpy (buf, "this is a test"); pos = 0; str = nih_config_parse_command (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 14); TEST_ALLOC_SIZE (str, 15); TEST_EQ_STR (str, "this is a test"); nih_free (str); } /* Check that we can parse a command that ends with a comment, * but the position should be incremented past the end of the comment. */ TEST_FEATURE ("with command up to comment"); TEST_ALLOC_FAIL { strcpy (buf, ("this is a test # this is a comment\n" "and so is this\n")); pos = 0; lineno = 1; str = nih_config_parse_command (NULL, buf, strlen (buf), &pos, &lineno); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); TEST_EQ (lineno, 2); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 35); TEST_EQ (lineno, 2); TEST_ALLOC_SIZE (str, 15); TEST_EQ_STR (str, "this is a test"); nih_free (str); } /* Check that we can parse a command that ends with a comment which * runs up to the end of file. */ TEST_FEATURE ("with command up to comment at end of file"); TEST_ALLOC_FAIL { strcpy (buf, "this is a test # this is a comment"); pos = 0; lineno = 1; str = nih_config_parse_command (NULL, buf, strlen (buf), &pos, &lineno); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); TEST_EQ (lineno, 1); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 34); TEST_EQ (lineno, 1); TEST_ALLOC_SIZE (str, 15); TEST_EQ_STR (str, "this is a test"); nih_free (str); } /* Check that the command is returned including any quotes, * consecutive whitespace, but with any whitespace around a quoted * or escaped newline collapsed to a single space. */ TEST_FEATURE ("with quotes, whitespace and newlines in string"); TEST_ALLOC_FAIL { strcpy (buf, ("\"this is\" a \"test \\\n of\" \\\n " "commands\nfoo\n")); pos = 0; lineno = 1; str = nih_config_parse_command (NULL, buf, strlen (buf), &pos, &lineno); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 39); TEST_EQ (lineno, 4); TEST_ALLOC_SIZE (str, 33); TEST_EQ_STR (str, "\"this is\" a \"test of\" commands"); nih_free (str); } /* Check that we can parse an empty line, and have the empty string * returned. The position should be updated past the newline. */ TEST_FEATURE ("with empty line"); TEST_ALLOC_FAIL { strcpy (buf, "\nthis is a test\n"); pos = 0; str = nih_config_parse_command (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 1); TEST_ALLOC_SIZE (str, 1); TEST_EQ_STR (str, ""); nih_free (str); } /* Check that we can parse a line containing only whitespace, and * have the empty string returned. The position should be updated * past the newline. */ TEST_FEATURE ("with only whitespace in line"); TEST_ALLOC_FAIL { strcpy (buf, " \t \nthis is a test\n"); pos = 0; str = nih_config_parse_command (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 6); TEST_ALLOC_SIZE (str, 1); TEST_EQ_STR (str, ""); nih_free (str); } /* Check that we can parse a line with a comment in it, and have * the empty string returned. The position should be updated past * the newline. */ TEST_FEATURE ("with only comment in line"); TEST_ALLOC_FAIL { strcpy (buf, "# this is a test\nthis is a test\n"); pos = 0; str = nih_config_parse_command (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 17); TEST_ALLOC_SIZE (str, 1); TEST_EQ_STR (str, ""); nih_free (str); } /* Check that we can parse a line with whitespace before a comment, * and have the empty string returned. The position should be updated * past the newline. */ TEST_FEATURE ("with whitespace and comment in line"); TEST_ALLOC_FAIL { strcpy (buf, " # this is a test\nthis is a test\n"); pos = 0; str = nih_config_parse_command (NULL, buf, strlen (buf), &pos, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 19); TEST_ALLOC_SIZE (str, 1); TEST_EQ_STR (str, ""); nih_free (str); } /* Check that a parser error while reading the command results in * NULL being returned and the error raised. */ TEST_FEATURE ("with parser error"); TEST_ALLOC_FAIL { strcpy (buf, "this is a \"test\nand so is this\n"); pos = 0; lineno = 1; str = nih_config_parse_command (NULL, buf, strlen (buf), &pos, &lineno); TEST_EQ_P (str, NULL); TEST_EQ (pos, 31); TEST_EQ (lineno, 3); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_UNTERMINATED_QUOTE); nih_free (err); } } void test_parse_block (void) { char buf[1024]; char *str; size_t pos, lineno; NihError *err; TEST_FUNCTION ("nih_config_parse_block"); program_name = "test"; /* Check that we can parse consecutive lines until we reach one * that ends the block. The block should be returned as an allocated * string with each line in it, except the terminator; the position * should be positioned after the end of the terminator. */ TEST_FEATURE ("with simple block"); TEST_ALLOC_FAIL { strcpy (buf, "this is\na test\nend foo\nblah\n"); pos = 0; str = nih_config_parse_block (NULL, buf, strlen (buf), &pos, NULL, "foo"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 23); TEST_ALLOC_SIZE (str, 16); TEST_EQ_STR (str, "this is\na test\n"); nih_free (str); } /* Check that the line number is incremented for each line that we * discover in the block, including the terminating line. */ TEST_FEATURE ("with line number set"); TEST_ALLOC_FAIL { pos = 0; lineno = 2; str = nih_config_parse_block (NULL, buf, strlen (buf), &pos, &lineno, "foo"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 23); TEST_EQ (lineno, 5); TEST_ALLOC_SIZE (str, 16); TEST_EQ_STR (str, "this is\na test\n"); nih_free (str); } /* Check that the common initial whitespace from each line is stripped, * where common is defined as identical character sequences, not number * of whitespace chars. */ TEST_FEATURE ("with whitespace at start of block"); TEST_ALLOC_FAIL { strcpy (buf, " this is\n \t a test\nend foo\nblah\n"); pos = 0; str = nih_config_parse_block (NULL, buf, strlen (buf), &pos, NULL, "foo"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 31); TEST_ALLOC_SIZE (str, 20); TEST_EQ_STR (str, " this is\n\t a test\n"); nih_free (str); } /* Check that we can parse a block that ends in a terminator with * extraneous whitespace around the words. */ TEST_FEATURE ("with whitespace in terminator"); TEST_ALLOC_FAIL { strcpy (buf, "this is\na test\n end \t foo \nblah\n"); pos = 0; str = nih_config_parse_block (NULL, buf, strlen (buf), &pos, NULL, "foo"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 29); TEST_ALLOC_SIZE (str, 16); TEST_EQ_STR (str, "this is\na test\n"); nih_free (str); } /* Check that we can parse a block that ends in a terminator which * is at the end of the file. */ TEST_FEATURE ("with terminator at end of file"); TEST_ALLOC_FAIL { strcpy (buf, "this is\na test\nend foo"); pos = 0; str = nih_config_parse_block (NULL, buf, strlen (buf), &pos, NULL, "foo"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 22); TEST_ALLOC_SIZE (str, 16); TEST_EQ_STR (str, "this is\na test\n"); nih_free (str); } /* Check that we can parse a block that ends in a terminator which * has a comment following it. */ TEST_FEATURE ("with terminator and comment"); TEST_ALLOC_FAIL { strcpy (buf, "this is\na test\nend foo # comment\ntest\n"); pos = 0; str = nih_config_parse_block (NULL, buf, strlen (buf), &pos, NULL, "foo"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 33); TEST_ALLOC_SIZE (str, 16); TEST_EQ_STR (str, "this is\na test\n"); nih_free (str); } /* Check that we can parse a block that ends in a terminator which * has a comment and then the end of file. */ TEST_FEATURE ("with terminator and comment at end of file"); TEST_ALLOC_FAIL { strcpy (buf, "this is\na test\nend foo # comment"); pos = 0; str = nih_config_parse_block (NULL, buf, strlen (buf), &pos, NULL, "foo"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 32); TEST_ALLOC_SIZE (str, 16); TEST_EQ_STR (str, "this is\na test\n"); nih_free (str); } /* Check that various bogus forms of terminator are ignored. */ TEST_FEATURE ("with various things that aren't terminators"); TEST_ALLOC_FAIL { strcpy (buf, "endfoo\nend a\nend fooish\nend foo\ntest\n"); pos = 0; str = nih_config_parse_block (NULL, buf, strlen (buf), &pos, NULL, "foo"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_EQ (pos, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (pos, 32); TEST_ALLOC_SIZE (str, 25); TEST_EQ_STR (str, "endfoo\nend a\nend fooish\n"); nih_free (str); } /* Check that reaching the end of the file without finding the block * terminator causes an error to be raised and NULL to be returned. */ TEST_FEATURE ("with no terminator before end of file"); TEST_ALLOC_FAIL { strcpy (buf, "this is\na test\n"); pos = 0; lineno = 2; str = nih_config_parse_block (NULL, buf, strlen (buf), &pos, &lineno, "foo"); TEST_EQ_P (str, NULL); TEST_EQ (pos, 15); TEST_EQ (lineno, 4); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_UNTERMINATED_BLOCK); nih_free (err); } } void test_skip_block (void) { char buf[1024]; int ret; size_t pos, lineno, endpos; NihError *err; TEST_FUNCTION ("nih_config_skip_block"); program_name = "test"; /* Check that we can find the end of a simple block. pos should be * updated to point past the block, and the returned endpos should * point at the end of the block itself. */ TEST_FEATURE ("with simple block"); strcpy (buf, "this is\na test\nend foo\nblah\n"); pos = 0; ret = nih_config_skip_block (buf, strlen (buf), &pos, NULL, "foo", &endpos); TEST_EQ (ret, 0); TEST_EQ (pos, 23); TEST_EQ (endpos, 15); /* Check that the line number is incremented for each line that we * discover in the block, including the terminating line. */ TEST_FEATURE ("with line number set"); pos = 0; lineno = 2; ret = nih_config_skip_block (buf, strlen (buf), &pos, &lineno, "foo", &endpos); TEST_EQ (ret, 0); TEST_EQ (pos, 23); TEST_EQ (endpos, 15); TEST_EQ (lineno, 5); /* Check that we can find the end of a block that ends in a terminator * with extraneous whitespace around the words. */ TEST_FEATURE ("with whitespace in terminator"); strcpy (buf, "this is\na test\n end \t foo \nblah\n"); pos = 0; ret = nih_config_skip_block (buf, strlen (buf), &pos, NULL, "foo", &endpos); TEST_EQ (ret, 0); TEST_EQ (pos, 29); TEST_EQ (endpos, 15); /* Check that we can find the end of a block that ends in a * terminator which is at the end of the file. */ TEST_FEATURE ("with terminator at end of file"); strcpy (buf, "this is\na test\nend foo"); pos = 0; ret = nih_config_skip_block (buf, strlen (buf), &pos, NULL, "foo", &endpos); TEST_EQ (ret, 0); TEST_EQ (pos, 22); TEST_EQ (endpos, 15); /* Check that we can find the end of a block that ends in a * terminator which has a comment following it. */ TEST_FEATURE ("with terminator and comment"); strcpy (buf, "this is\na test\nend foo # comment\ntest\n"); pos = 0; ret = nih_config_skip_block (buf, strlen (buf), &pos, NULL, "foo", &endpos); TEST_EQ (ret, 0); TEST_EQ (pos, 33); TEST_EQ (endpos, 15); /* Check that we can find the end of a block that ends in a * terminator which has a comment and then the end of file. */ TEST_FEATURE ("with terminator and comment at end of file"); strcpy (buf, "this is\na test\nend foo # comment"); pos = 0; ret = nih_config_skip_block (buf, strlen (buf), &pos, NULL, "foo", &endpos); TEST_EQ (ret, 0); TEST_EQ (pos, 32); TEST_EQ (endpos, 15); /* Check that various bogus forms of terminator are ignored. */ TEST_FEATURE ("with various things that aren't terminators"); strcpy (buf, "endfoo\nend a\nend fooish\nend foo\ntest\n"); pos = 0; ret = nih_config_skip_block (buf, strlen (buf), &pos, NULL, "foo", &endpos); TEST_EQ (ret, 0); TEST_EQ (pos, 32); TEST_EQ (endpos, 24); /* Check that reaching the end of the file without finding the block * terminator causes an error to be raised and NULL to be returned. */ TEST_FEATURE ("with no terminator before end of file"); strcpy (buf, "this is\na test\n"); pos = 0; lineno = 2; ret = nih_config_skip_block (buf, strlen (buf), &pos, &lineno, "foo", &endpos); TEST_LT (ret, 0); TEST_EQ (pos, 15); TEST_EQ (lineno, 4); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_UNTERMINATED_BLOCK); nih_free (err); } static int handler_called = 0; static void *last_data = NULL; static NihConfigStanza *last_stanza = NULL; static const char *last_file = NULL; static size_t last_len = 0; static size_t last_pos = 0; static size_t last_lineno = 0; static int my_handler (void *data, NihConfigStanza *stanza, const char *file, size_t len, size_t *pos, size_t *lineno) { handler_called++; last_data = data; last_stanza = stanza; last_file = file; last_len = len; last_pos = *pos; if (lineno) { last_lineno = *lineno; } else { last_lineno = -1; } if (strcmp (stanza->name, "foo")) nih_config_next_line (file, len, pos, lineno); return 100; } static NihConfigStanza stanzas[] = { { "foo", my_handler }, { "bar", my_handler }, { "frodo", my_handler }, { "bilbo", my_handler }, NIH_CONFIG_LAST }; static NihConfigStanza any_stanzas[] = { { "", my_handler }, NIH_CONFIG_LAST }; void test_parse_stanza (void) { char buf[1024]; size_t pos, lineno; int ret; NihError *err; TEST_FUNCTION ("nih_config_stanza"); program_name = "test"; /* Check that the handler is called with all of the right arguments * if the stanza is found at the start of the string. The pos should * only be incremented up to the point after the first argument, * leaving it up to the stanza handler to increment it. */ TEST_FEATURE ("with stanza at start of string"); strcpy (buf, "foo this is a test\nwibble\n"); handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; ret = nih_config_parse_stanza (buf, strlen (buf), NULL, NULL, stanzas, &ret); TEST_TRUE (handler_called); TEST_EQ_P (last_data, &ret); TEST_EQ_P (last_file, buf); TEST_EQ (last_len, strlen (buf)); TEST_EQ (last_pos, 4); TEST_EQ (last_lineno, (size_t)-1); TEST_EQ (ret, 100); /* Check that the handler can be called with a position inside the * string. */ TEST_FEATURE ("with stanza inside string"); strcpy (buf, "snarf foo this is a test\nwibble\n"); pos = 6; handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; ret = nih_config_parse_stanza (buf, strlen (buf), &pos, NULL, stanzas, &ret); TEST_TRUE (handler_called); TEST_EQ_P (last_data, &ret); TEST_EQ_P (last_file, buf); TEST_EQ (last_len, strlen (buf)); TEST_EQ (last_pos, 10); TEST_EQ (last_lineno, (size_t)-1); TEST_EQ (ret, 100); TEST_EQ (pos, 10); /* Check that the position can be updated by the handler function * to point wherever it thinks the stanza ends. */ TEST_FEATURE ("with position moved by stanza"); strcpy (buf, "bar this is a test\nwibble\n"); pos = 0; lineno = 1; handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; ret = nih_config_parse_stanza (buf, strlen (buf), &pos, &lineno, stanzas, &ret); TEST_TRUE (handler_called); TEST_EQ_P (last_data, &ret); TEST_EQ_P (last_file, buf); TEST_EQ (last_len, strlen (buf)); TEST_EQ (last_pos, 4); TEST_EQ (last_lineno, 1); TEST_EQ (ret, 100); TEST_EQ (pos, 19); TEST_EQ (lineno, 2); /* Check that finding an unknown stanza results in an error being * raised, and no handler called. */ TEST_FEATURE ("with unknown stanza"); strcpy (buf, "wibble this is a test\nwibble\n"); pos = 0; lineno = 1; handler_called = 0; ret = nih_config_parse_stanza (buf, strlen (buf), &pos, &lineno, stanzas, &ret); TEST_FALSE (handler_called); TEST_LT (ret, 0); TEST_EQ (pos, 0); TEST_EQ (lineno, 1); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_UNKNOWN_STANZA); nih_free (err); /* Check that unknown stanzas can be handled by an entry in the * table with a zero-length name. */ TEST_FEATURE ("with unknown stanza and catch-all"); pos = 0; handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; ret = nih_config_parse_stanza (buf, strlen (buf), NULL, NULL, any_stanzas, &ret); TEST_TRUE (handler_called); TEST_EQ_P (last_data, &ret); TEST_EQ_P (last_file, buf); TEST_EQ (last_len, strlen (buf)); TEST_EQ (last_pos, 7); TEST_EQ (last_lineno, (size_t)-1); TEST_EQ (ret, 100); /* Check that an error is raised if there is no stanza at this * position in the file. */ TEST_FEATURE ("with empty line"); strcpy (buf, "\nfoo this is a test\n"); pos = 0; lineno = 1; handler_called = 0; ret = nih_config_parse_stanza (buf, strlen (buf), &pos, &lineno, stanzas, &ret); TEST_FALSE (handler_called); TEST_LT (ret, 0); TEST_EQ (pos, 0); TEST_EQ (lineno, 1); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN); nih_free (err); } void test_parse_file (void) { char buf[1024]; size_t pos, lineno; int ret; NihError *err; TEST_FUNCTION ("nih_config_parse_file"); /* Check that a simple sequence of stanzas is parsed, with the * handler being called for each. When finished, the position * should be past the end of the file. */ TEST_FEATURE ("with simple lines"); strcpy (buf, "frodo test\nbilbo test\n"); pos = 0; lineno = 1; handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; ret = nih_config_parse_file (buf, strlen (buf), &pos, &lineno, stanzas, &buf); TEST_EQ (ret, 0); TEST_EQ (pos, 22); TEST_EQ (handler_called, 2); TEST_EQ_P (last_data, &buf); TEST_EQ_P (last_file, buf); TEST_EQ (last_len, strlen (buf)); TEST_EQ (last_pos, 17); TEST_EQ (last_lineno, 2); /* Check that a line ending in a comment can be parsed, with the * comment skipped. */ TEST_FEATURE ("with comment at end of line"); strcpy (buf, "frodo test # foo comment\nbilbo test\n"); pos = 0; lineno = 1; handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; ret = nih_config_parse_file (buf, strlen (buf), &pos, &lineno, stanzas, &buf); TEST_EQ (ret, 0); TEST_EQ (pos, 36); TEST_EQ (handler_called, 2); TEST_EQ_P (last_data, &buf); TEST_EQ_P (last_file, buf); TEST_EQ (last_len, strlen (buf)); TEST_EQ (last_pos, 31); TEST_EQ (last_lineno, 2); /* Check that whitespace at the start of a line is skipped. */ TEST_FEATURE ("with whitespace at start of line"); strcpy (buf, " frodo test\n \t \t bilbo test\n"); pos = 0; lineno = 1; handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; ret = nih_config_parse_file (buf, strlen (buf), &pos, &lineno, stanzas, &buf); TEST_EQ (ret, 0); TEST_EQ (pos, 32); TEST_EQ (handler_called, 2); TEST_EQ_P (last_data, &buf); TEST_EQ_P (last_file, buf); TEST_EQ (last_len, strlen (buf)); TEST_EQ (last_pos, 27); TEST_EQ (last_lineno, 2); /* Check that an empty line is skipped over properly. */ TEST_FEATURE ("with empty line"); strcpy (buf, "\nfrodo test\nbilbo test\n"); pos = 0; lineno = 1; handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; ret = nih_config_parse_file (buf, strlen (buf), &pos, &lineno, stanzas, &buf); TEST_EQ (ret, 0); TEST_EQ (pos, 23); TEST_EQ (handler_called, 2); TEST_EQ_P (last_data, &buf); TEST_EQ_P (last_file, buf); TEST_EQ (last_len, strlen (buf)); TEST_EQ (last_pos, 18); TEST_EQ (last_lineno, 3); /* Check that a line containing whitespace is skipped over. */ TEST_FEATURE ("with line containing only whitespace"); strcpy (buf, " \t \nfrodo test\nbilbo test\n"); pos = 0; lineno = 1; handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; ret = nih_config_parse_file (buf, strlen (buf), &pos, &lineno, stanzas, &buf); TEST_EQ (ret, 0); TEST_EQ (pos, 28); TEST_EQ (handler_called, 2); TEST_EQ_P (last_data, &buf); TEST_EQ_P (last_file, buf); TEST_EQ (last_len, strlen (buf)); TEST_EQ (last_pos, 23); TEST_EQ (last_lineno, 3); /* Check that a line containing a comment is skipped over. */ TEST_FEATURE ("with line containing only a comment"); strcpy (buf, "# hello\nfrodo test\nbilbo test\n"); pos = 0; lineno = 1; handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; ret = nih_config_parse_file (buf, strlen (buf), &pos, &lineno, stanzas, &buf); TEST_EQ (ret, 0); TEST_EQ (pos, 30); TEST_EQ (handler_called, 2); TEST_EQ_P (last_data, &buf); TEST_EQ_P (last_file, buf); TEST_EQ (last_len, strlen (buf)); TEST_EQ (last_pos, 25); TEST_EQ (last_lineno, 3); /* Check that a line containing a comment after some whitespace * is skipped over. */ TEST_FEATURE ("with line containing a comment and whitespace"); strcpy (buf, " \t # hello\nfrodo test\nbilbo test\n"); pos = 0; lineno = 1; handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; ret = nih_config_parse_file (buf, strlen (buf), &pos, &lineno, stanzas, &buf); TEST_EQ (ret, 0); TEST_EQ (pos, 35); TEST_EQ (handler_called, 2); TEST_EQ_P (last_data, &buf); TEST_EQ_P (last_file, buf); TEST_EQ (last_len, strlen (buf)); TEST_EQ (last_pos, 30); TEST_EQ (last_lineno, 3); /* Check that a parser error is raised with the position and line * number set to where it was found. Only handlers up to that point * should be called. */ TEST_FEATURE ("with parser error"); strcpy (buf, "frodo test\n\"bilbo test\n"); pos = 0; lineno = 1; handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; ret = nih_config_parse_file (buf, strlen (buf), &pos, &lineno, stanzas, &buf); TEST_LT (ret, 0); TEST_EQ (pos, 23); TEST_EQ (lineno, 3); TEST_EQ (handler_called, 1); TEST_EQ_P (last_data, &buf); TEST_EQ_P (last_file, buf); TEST_EQ (last_len, strlen (buf)); TEST_EQ (last_pos, 6); TEST_EQ (last_lineno, 1); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_UNTERMINATED_QUOTE); nih_free (err); } void test_parse (void) { FILE *fd; char filename[PATH_MAX]; size_t pos, lineno; NihError *err; int ret; TEST_FUNCTION ("nih_config_parse"); /* Check that a file that exists is parsed, with the handlers * called and zero returned. */ TEST_FEATURE ("with existing file"); TEST_FILENAME (filename); fd = fopen (filename, "w"); fprintf (fd, "frodo test\n"); fprintf (fd, "bilbo test\n"); fclose (fd); handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; lineno = 1; ret = nih_config_parse (filename, NULL, &lineno, stanzas, &ret); TEST_EQ (ret, 0); TEST_EQ (handler_called, 2); TEST_EQ_P (last_data, &ret); TEST_NE_P (last_file, NULL); TEST_EQ (last_len, 22); TEST_EQ (last_pos, 17); TEST_EQ (last_lineno, 2); unlink (filename); /* Check that an error is raised if the file doesn't exist. */ TEST_FEATURE ("with non-existant file"); handler_called = 0; ret = nih_config_parse (filename, NULL, NULL, stanzas, &ret); TEST_LT (ret, 0); TEST_FALSE (handler_called); err = nih_error_get (); TEST_EQ (err->number, ENOENT); nih_free (err); /* Check that a parser error is raised with the position and line * number set to where it was found. */ TEST_FEATURE ("with parser error"); fd = fopen (filename, "w"); fprintf (fd, "# first line comment\n"); fprintf (fd, "\n"); fprintf (fd, "frodo test\n"); fprintf (fd, "\"bilbo test\n"); fprintf (fd, "wibble\n"); fclose (fd); pos = 0; lineno = 1; handler_called = 0; last_data = NULL; last_file = NULL; last_len = 0; last_pos = -1; last_lineno = 0; ret = nih_config_parse (filename, &pos, &lineno, stanzas, &ret); TEST_LT (ret, 0); TEST_EQ (handler_called, 1); TEST_EQ_P (last_data, &ret); TEST_NE_P (last_file, NULL); TEST_EQ (last_len, 52); TEST_EQ (last_pos, 28); TEST_EQ (last_lineno, 3); TEST_EQ (pos, 52); TEST_EQ (lineno, 6); err = nih_error_get (); TEST_EQ (err->number, NIH_CONFIG_UNTERMINATED_QUOTE); nih_free (err); unlink (filename); } int main (int argc, char *argv[]) { test_has_token (); test_token (); test_next_token (); test_next_arg (); test_next_line (); test_skip_whitespace (); test_skip_comment (); test_parse_args (); test_parse_command (); test_parse_block (); test_skip_block (); test_parse_stanza (); test_parse_file (); test_parse (); return 0; } libnih-1.0.3/nih/list.c0000644000175000017500000001407711445765555011630 00000000000000/* libnih * * list.c - generic circular doubly-linked list implementation * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include "list.h" /* Prototypes for static functions */ static inline NihList *nih_list_cut (NihList *entry); /** * nih_list_init: * @entry: entry to be initialised. * * Initialise an already allocated list entry, once done it can be used * as the start of a new list or added to an existing list. **/ void nih_list_init (NihList *entry) { nih_assert (entry != NULL); entry->prev = entry->next = entry; } /** * nih_list_new: * @parent: parent object for new list. * * Allocates a new list structure, usually used as the start of a new * list. You may prefer to allocate the NihList structure statically and * use nih_list_init() to initialise it instead. * * The structure is allocated using nih_alloc() so can be used as a context * to other allocations. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned list. When all parents * of the returned list are freed, the returned list will also be * freed. * * Returns: the new list or NULL if the allocation failed. **/ NihList * nih_list_new (const void *parent) { NihList *list; list = nih_new (parent, NihList); if (! list) return NULL; nih_list_init (list); nih_alloc_set_destructor (list, nih_list_destroy); return list; } /** * nih_list_entry_new: * @parent: parent object for new list entry. * * Allocates a new list entry structure, leaving the caller to set the * data of the entry. * * The structure is allocated using nih_alloc() so can be used as a context * to other allocations. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned list entry. When all parents * of the returned list entry are freed, the returned list entry will also be * freed. * * Returns: the new list entry or NULL if the allocation failed. **/ NihListEntry * nih_list_entry_new (const void *parent) { NihListEntry *list; list = nih_new (parent, NihListEntry); if (! list) return NULL; nih_list_init (&list->entry); nih_alloc_set_destructor (list, nih_list_destroy); list->data = NULL; return list; } /** * nih_list_add: * @list: entry in the destination list, * @entry: entry to be added to the list. * * Adds @entry to a new list immediately before the @list entry. If @list * is the pointer you are using to refer to the list itself, this results * in @entry being appended to the list. * * If @entry is already in another list it is removed so there is no need * to call nih_list_remove() before this function. There is also no * requirement that the lists be different, so this can be used to reorder * a list. * * Returns: @entry which is now a member of the same list as @list. **/ NihList * nih_list_add (NihList *list, NihList *entry) { nih_assert (list != NULL); nih_assert (entry != NULL); nih_list_cut (entry); entry->prev = list->prev; list->prev->next = entry; list->prev = entry; entry->next = list; return entry; } /** * nih_list_add_after: * @list: entry in the destination list, * @entry: entry to be added to the list. * * Adds @entry to a new list immediately after the @list entry. If @list * is the pointer you are using to refer to the list itself and that entry * has no data, this results in @entry being pushed onto a stack under it. * * If @entry is already in another list it is removed so there is no need * to call nih_list_remove() before this function. There is also no * requirement that the lists be different, so this can be used to reorder * a list. * * Returns: @entry which is now a member of the same list as @list. **/ NihList * nih_list_add_after (NihList *list, NihList *entry) { nih_assert (list != NULL); nih_assert (entry != NULL); nih_list_cut (entry); entry->next = list->next; list->next->prev = entry; list->next = entry; entry->prev = list; return entry; } /** * nih_list_cut: * @entry: entry to be removed. * * Removes @entry from its containing list, but does not alter @entry * itself; care should be taken to set the pointers immediately after. * * Returns: @entry unmodified. **/ static inline NihList * nih_list_cut (NihList *entry) { nih_assert (entry != NULL); entry->prev->next = entry->next; entry->next->prev = entry->prev; return entry; } /** * nih_list_remove: * @entry: entry to be removed. * * Removes @entry from its containing list. The entry is not freed, but * is instead returned so that it can be added to another list (though * there's no need to call nih_list_remove() first if you wanted to do * that) or used as the start of a new list. * * Returns: @entry as a lone entry. **/ NihList * nih_list_remove (NihList *entry) { nih_assert (entry != NULL); nih_list_cut (entry); nih_list_init (entry); return entry; } /** * nih_list_destroy: * @entry: entry to be removed. * * Removes @entry from its containing list. * * Normally used or called from an nih_alloc() destructor so that the list * item is automatically removed from its containing list when freed. * * Returns: zero. **/ int nih_list_destroy (NihList *entry) { nih_assert (entry != NULL); nih_list_cut (entry); return 0; } libnih-1.0.3/nih/option.c0000644000175000017500000005725611445765555012173 00000000000000/* libnih * * option.c - command-line argument and option parsing * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include /** * NihOptionCtx: * @parent: parent object for returned array, * @argc: number of arguments, * @argv: arguments array, * @options: list of options, * @nargs: number of non-option arguments, * @args: non-option arguments to return, * @arg: current argument index, * @nonopt: index of first non-option argument, * @optend: index of end of options. * * This structure is passed between the various parsing functions to avoid * having to pass a dozen different variables around and to keep us * re-entrant. **/ typedef struct nih_option_ctx { const void *parent; int argc; char **argv; NihOption *options; size_t nargs; char **args; int arg; int nonopt; int optend; } NihOptionCtx; /* Prototypes for static functions */ static NihOption * nih_option_get_short (NihOptionCtx *ctx, int option); static int nih_option_short (NihOptionCtx *ctx); static NihOption * nih_option_get_long (NihOptionCtx *ctx, const char *option, size_t len); static int nih_option_long (NihOptionCtx *ctx); static int nih_option_handle (NihOptionCtx *ctx, NihOption *opt); static int nih_option_handle_arg (NihOptionCtx *ctx, NihOption *opt, const char *arg); static const char *nih_option_next_nonopt (NihOptionCtx *ctx); static void nih_option_help (NihOption *options); static void nih_option_group_help (NihOptionGroup *group, NihOption *options, NihOptionGroup **groups); /** * default_options: * * These default options are appended to those defined by the user * so they can be overriden. **/ static const NihOption default_options[] = { { 'q', "quiet", N_("reduce output to errors only"), NULL, NULL, NULL, nih_option_quiet }, { 'v', "verbose", N_("increase output to include informational messages"), NULL, NULL, NULL, nih_option_verbose }, /* Deliberately hidden, you get told about this when you file * a bug ;-) */ { 0, "debug", NULL, NULL, NULL, NULL, nih_option_debug }, { 0, "help", N_("display this help and exit"), NULL, NULL, NULL, NULL }, { 0, "version", N_("output version information and exit"), NULL, NULL, NULL, NULL }, NIH_OPTION_LAST }; /** * usage_stem: * * This string is prepended to the program's usage line if given. **/ static const char *usage_stem = NULL; /** * usage_string: * * This string is appended to the program's usage line if given. **/ static const char *usage_string = NULL; /** * synopsis_string: * * This string is output after the program's usage string if given. **/ static const char *synopsis_string = NULL; /** * help_string: * * This string is output after the options if given. **/ static const char *help_string = NULL; /** * footer_string: * * This string is output after the options and help if given. **/ static const char *footer_string = NULL; /** * nih_option_parser: * @parent: parent object for returned array, * @argc: number of arguments, * @argv: command-line arguments, * @options: options to look for, * @break_nonopt: stop processing options at first non-option argument. * * Parses the command-line arguments given in @argv looking for options * described in @options, or those built-in. Options are handled according * to common UNIX semantics so that short options may be grouped together * and arguments need not immediately follow the option that requires it. * * Remaining non-option arguments are placed into an array for processing * by the caller. If @break_nonopt is FALSE then the first non-option * argument concludes option processing and all subsequent options are * considered to be ordinary arguments; this is most useful when the * first argument should be a command. * * Both the array itself, and the array items are allocated with nih_alloc(); * the items are children of the array, so it is only necessary to call * nih_free() on the array. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned array. When all parents * of the returned array are freed, the returned array will also be * freed. * * Errors are handled by printing a message to standard error. * * Returns: non-option arguments array or NULL on error. **/ char ** nih_option_parser (const void *parent, int argc, char *argv[], NihOption *options, int break_nonopt) { NihOptionCtx ctx; nih_assert (argc > 0); nih_assert (argv != NULL); nih_assert (options != NULL); ctx.parent = parent; ctx.argc = argc; ctx.argv = argv; ctx.options = nih_option_join (NULL, options, default_options); ctx.nargs = 0; ctx.args = NIH_MUST (nih_str_array_new (parent)); ctx.nonopt = 0; ctx.optend = 0; /* Iterate the arguments looking for options */ for (ctx.arg = 1; ctx.arg < argc; ctx.arg++) { char *arg; arg = ctx.argv[ctx.arg]; if ((arg[0] != '-') || (arg[1] == '\0') || (ctx.optend && ctx.arg > ctx.optend)) { /* Not an option */ if (ctx.arg > ctx.nonopt) { NIH_MUST (nih_str_array_add (&ctx.args, parent, &ctx.nargs, ctx.argv[ctx.arg])); if (break_nonopt) ctx.optend = ctx.arg; } } else if (arg[1] != '-') { /* Short option */ if (nih_option_short (&ctx) < 0) goto error; } else if (arg[2] != '\0') { /* Long option */ if (nih_option_long (&ctx) < 0) goto error; } else { /* End of options */ ctx.optend = ctx.arg; } } nih_free (ctx.options); return ctx.args; error: nih_free (ctx.options); nih_free (ctx.args); return NULL; } /** * nih_option_get_short: * @ctx: parsing context, * @option: option to find. * * Find the option structure with the given short @option. If an option * exists with the short option '-' this is used instead if no specific * option is found. * * Returns; pointer to option, or NULL if not found. **/ static NihOption * nih_option_get_short (NihOptionCtx *ctx, int option) { NihOption *opt, *catch = NULL; for (opt = ctx->options; (opt->option || opt->long_option); opt++) { if (opt->option == '-') catch = opt; if (opt->option == option) return opt; } return catch; } /** * nih_option_short: * @ctx: parsing context. * * Process the current argument as a list of short options, handling * each one individually. * * If the first option in the list expects a value, then the rest of * the argument is taken to be the option argument rather than further * options. * * Returns: zero on success, negative value on invalid option. **/ static int nih_option_short (NihOptionCtx *ctx) { char *ptr; nih_assert (ctx != NULL); nih_assert (program_name != NULL); for (ptr = ctx->argv[ctx->arg] + 1; *ptr != '\0'; ptr++) { NihOption *opt; opt = nih_option_get_short (ctx, *ptr); if (! opt) { fprintf (stderr, _("%s: invalid option: -%c\n"), program_name, *ptr); nih_main_suggest_help (); return -1; } /* If the option takes an argument, this is the first * option in the list and there are further characters; * treat the rest as the argument */ if (opt->arg_name && (ptr[-1] == '-') && (ptr[1] != '\0')) { if (nih_option_handle_arg (ctx, opt, ptr + 1) < 0) return -1; break; } /* Otherwise it's an ordinary option */ if (nih_option_handle (ctx, opt) < 0) return -1; } return 0; } /** * nih_option_get_long: * @ctx: parsing context, * @option: option to find, * @len: length of option. * * Find the option structure with the given long @option, of which only * the first @len characters will be read. If an option named "--" exists * then it is used if no other option could be found. * * Returns; pointer to option, or NULL if not found. **/ static NihOption * nih_option_get_long (NihOptionCtx *ctx, const char *option, size_t len) { NihOption *opt, *catch = NULL; for (opt = ctx->options; (opt->option || opt->long_option); opt++) { if (! opt->long_option) continue; if (! strcmp (opt->long_option, "--")) catch = opt; if (strlen (opt->long_option) > len) continue; if (! strncmp (option, opt->long_option, len)) return opt; } return catch; } /** * nih_option_long: * @ctx: parsing context. * * Process the current argument as a long option to be handled. * * If the option expects a value then it may be separated from the option * name by an '=' sign. * * Returns: zero on success, negative value on invalid option. **/ static int nih_option_long (NihOptionCtx *ctx) { NihOption *opt; char *arg, *ptr; size_t len; nih_assert (ctx != NULL); nih_assert (program_name != NULL); /* Check for an equals sign that separates the option name from * an argument. */ arg = ctx->argv[ctx->arg] + 2; ptr = strchr (arg, '='); len = (ptr ? (size_t)(ptr - arg) : strlen (arg)); /* Find the option */ opt = nih_option_get_long (ctx, arg, len); if (! opt) { fprintf (stderr, _("%s: invalid option: --%s\n"), program_name, arg); nih_main_suggest_help (); return -1; } /* Handle the case where there's an argument; either we need * to process it, or error */ if (ptr != NULL) { if (opt->arg_name) { if (nih_option_handle_arg (ctx, opt, ptr + 1) < 0) return -1; return 0; } else { fprintf (stderr, _("%s: unexpected argument: --%s\n"), program_name, arg); nih_main_suggest_help (); return -1; } } /* Otherwise it's an ordinary option */ if (nih_option_handle (ctx, opt) < 0) return -1; return 0; } /** * nih_option_handle: * @ctx: parsing context, * @opt: option to handle. * * Handle an option which either does not take an argument, or should * take the next non-option argument from the command-line. For options * with arguments, this calls nih_option_handle_arg(); for those without, * this calls the setter function or treats the value member as a pointer * to an int to store TRUE in. * * Returns: zero on success, negative value on invalid option. **/ static int nih_option_handle (NihOptionCtx *ctx, NihOption *opt) { nih_assert (ctx != NULL); nih_assert (opt != NULL); /* Handle the special cased options first */ if (opt->long_option && (! strcmp (opt->long_option, "help"))) { /* --help */ nih_option_help (ctx->options); nih_free (ctx->options); nih_free (ctx->args); exit (0); } else if (opt->long_option && (! strcmp (opt->long_option, "version"))) { /* --version */ nih_main_version (); nih_free (ctx->options); nih_free (ctx->args); exit (0); } if (opt->arg_name) { const char *arg; arg = nih_option_next_nonopt (ctx); if (! arg) { fprintf (stderr, _("%s: missing argument: %s\n"), program_name, ctx->argv[ctx->arg]); nih_main_suggest_help (); return -1; } return nih_option_handle_arg (ctx, opt, arg); } else if (opt->setter) { return opt->setter (opt, NULL); } else if (opt->value) { int *value = (int *)opt->value; *value = TRUE; } return 0; } /** * nih_option_handle_arg: * @ctx: parsing context, * @opt: option to handle, * @arg: argument. * * Handle an option which has the argument specified, either calling * the setter function or treating the value member (if present) as the * address of a char * to store the duplicated argument value in. * * Returns: zero on success, negative value on invalid option. **/ static int nih_option_handle_arg (NihOptionCtx *ctx, NihOption *opt, const char *arg) { nih_assert (ctx != NULL); nih_assert (opt != NULL); nih_assert (opt->arg_name != NULL); nih_assert (arg != NULL); if (opt->setter) { return opt->setter (opt, arg); } else if (opt->value) { char **value = (char **)opt->value; if (*value) nih_free (*value); *value = NIH_MUST (nih_strdup (ctx->parent, arg)); } return 0; } /** * nih_option_next_nonopt: * @ctx: parsing context. * * Iterates the command-line arguments looking for the next argument * that is not an option. Updates the nonopt member of @ctx to point * at the option used. * * Returns: next non-option argument or NULL if none remain. **/ static const char * nih_option_next_nonopt (NihOptionCtx *ctx) { nih_assert (ctx != NULL); if (ctx->nonopt < ctx->arg) ctx->nonopt = ctx->arg; while (++ctx->nonopt < ctx->argc) { char *arg; arg = ctx->argv[ctx->nonopt]; if ((arg[0] != '-') || (ctx->optend && ctx->nonopt > ctx->optend)) { return arg; } else if ((arg[1] == '-') && (arg[2] == '\0')) { /* End of options */ ctx->optend = ctx->nonopt; } } return NULL; } /** * nih_option_join: * @parent: parent object for new array, * @a: first option array, * @b: second option array. * * Joins the two option arrays together to produce a combined array containing * the options from @a followed by the options from @b. * * The new list is allocated with nih_alloc(), but the members are just * copied in from @a and @b including any pointers therein. Freeing the * new array with nih_free() is entirely safe. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned array. When all parents * of the returned array are freed, the returned array will also be * freed. * * Returns: combined option array. **/ NihOption * nih_option_join (const void *parent, const NihOption *a, const NihOption *b) { const NihOption *opt; NihOption *opts; size_t alen = 0, blen = 0; nih_assert (a != NULL); nih_assert (b != NULL); /* Count options in first list */ for (opt = a; (opt->option || opt->long_option); opt++) alen++; /* Count options in second list */ for (opt = b; (opt->option || opt->long_option); opt++) blen++; /* Allocate combined list */ opts = NIH_MUST (nih_alloc (parent, sizeof (NihOption) * (alen + blen + 1))); /* Copy options, making sure to copy the last option from b */ memcpy (opts, a, sizeof (NihOption) * alen); memcpy (opts + alen, b, sizeof (NihOption) * (blen + 1)); return opts; } /** * nih_option_count: * @option: NihOption invoked, * @arg: argument to parse. * * This option setter may be used to create arguments that count the number * of times they are placed on the command line. * * The value member of @option must be a pointer to an integer variable, * the arg_name member must be NULL. * * Returns: always returns zero. **/ int nih_option_count (NihOption *option, const char *arg) { int *value; nih_assert (option != NULL); nih_assert (option->value != NULL); nih_assert (arg == NULL); value = (int *)option->value; (*value)++; return 0; } /** * nih_option_int: * @option: NihOption invoked, * @arg: argument to parse. * * This option setter may be used to parse an integer from the command line * and store it in the value member of @option, which must be a pointer to * an integer variable. * * The arg_name member of @option must not be NULL. * * Returns: zero on success, non-zero on error. **/ int nih_option_int (NihOption *option, const char *arg) { char *endptr; int *value; nih_assert (option != NULL); nih_assert (option->value != NULL); nih_assert (arg != NULL); value = (int *)option->value; *value = strtol (arg, &endptr, 10); if (*endptr) { fprintf (stderr, _("%s: illegal argument: %s\n"), program_name, arg); nih_main_suggest_help (); return -1; } return 0; } /** * nih_option_quiet: * @option: NihOption invoked, * @arg: argument to parse. * * This option setter is used by the built-in -q/--quiet option to set the * default logging level to ERROR. * * Returns: always returns zero. **/ int nih_option_quiet (NihOption *option, const char *arg) { nih_assert (option != NULL); nih_assert (arg == NULL); nih_log_set_priority (NIH_LOG_ERROR); return 0; } /** * nih_option_verbose: * @option: NihOption invoked, * @arg: argument to parse. * * This option setter is used by the built-in -v/--verbose option to set the * default logging level to INFO. * * Returns: always returns zero. **/ int nih_option_verbose (NihOption *option, const char *arg) { nih_assert (option != NULL); nih_assert (arg == NULL); nih_log_set_priority (NIH_LOG_INFO); return 0; } /** * nih_option_debug: * @option: NihOption invoked, * @arg: argument to parse. * * This option setter is used by the built-in --debug option to set the * default logging level to DEBUG. * * Returns: always returns zero. **/ int nih_option_debug (NihOption *option, const char *arg) { nih_assert (option != NULL); nih_assert (arg == NULL); nih_log_set_priority (NIH_LOG_DEBUG); return 0; } /** * nih_option_set_usage_stem: * @usage: usage stem. * * Set the usage stem prepended to the program usage line in the help output, * this should be a static translated string. * * The string should not be terminated with a newline. **/ void nih_option_set_usage_stem (const char *usage) { usage_stem = usage; } /** * nih_option_set_usage: * @usage: usage string. * * Set the usage string appended to the program usage line in the help output, * this should be a static translated string. * * The string should not be terminated with a newline. **/ void nih_option_set_usage (const char *usage) { usage_string = usage; } /** * nih_option_set_synopsis: * @synopsis: synopsis string. * * Set the synopsis string, shown after the program usage line in the help * output. This should be a static translated string. It will be * automatically wrapped to the screen width. * * The string should not be terminated with a newline. **/ void nih_option_set_synopsis (const char *synopsis) { synopsis_string = synopsis; } /** * nih_option_set_help: * @help: help string. * * Set the help string, this is displayed after the options in the help * output. This should be a static translated string. It will be * automatically wrapped to the screen width. * * The string should not be terminated with a newline. **/ void nih_option_set_help (const char *help) { help_string = help; } /** * nih_option_set_footer: * @footer: footer string. * * Set the footer string, this is displayed after the options and help * text in the output. This should be a static translated string. * * The string should not be terminated with a newline. **/ void nih_option_set_footer (const char *footer) { footer_string = footer; } /** * nih_option_help: * @options: program options list. * * Output a description of the program's options to standard output * grouped by the group member of the option. **/ static void nih_option_help (NihOption *options) { NihOption *opt; nih_local NihOptionGroup **groups = NULL; size_t group, ngroups; int other = FALSE; nih_assert (program_name != NULL); /* Count the number of option groups */ ngroups = 0; for (opt = options; (opt->option || opt->long_option); opt++) { if (! opt->group) { other = TRUE; continue; } for (group = 0; group < ngroups; group++) { if (groups[group] == opt->group) break; } if (group < ngroups) continue; groups = NIH_MUST (nih_realloc (groups, NULL, (sizeof (NihOptionGroup *) * (ngroups + 1)))); groups[ngroups++] = opt->group; } printf ("%s: %s", _("Usage"), program_name); if (usage_stem) { printf (" %s", usage_stem); } else { printf (" %s", _("[OPTION]...")); } if (usage_string) printf (" %s", usage_string); printf ("\n"); /* Wrap the synopsis to the screen width */ if (synopsis_string) { nih_local char *str; str = NIH_MUST (nih_str_screen_wrap (NULL, synopsis_string, 0, 0)); printf ("%s\n", str); } printf ("\n"); /* Iterate the option groups we found in order, and display * only their options */ for (group = 0; group < ngroups; group++) nih_option_group_help (groups[group], options, groups); /* Display the other group */ if (other) nih_option_group_help (NULL, options, groups); /* Wrap the help to the screen width */ if (help_string) { nih_local char *str; str = NIH_MUST (nih_str_screen_wrap (NULL, help_string, 0, 0)); printf ("%s\n", str); if (package_bugreport || footer_string) printf ("\n"); } /* Append the footer */ if (footer_string) { printf ("%s\n", footer_string); if (package_bugreport) printf ("\n"); } /* Append the bug report address */ if (package_bugreport) { if (strchr (package_bugreport, '@')) { printf (_("Report bugs to <%s>\n"), package_bugreport); } else { printf (_("Report bugs at <%s>\n"), package_bugreport); } } } /** * nih_option_group_help: * @group: group to display, * @options: program options list, * @groups: all groups. * * Output a list of the program's options in the given option group to * standard output. **/ static void nih_option_group_help (NihOptionGroup *group, NihOption *options, NihOptionGroup **groups) { NihOption *opt; size_t width; nih_assert (options != NULL); if (group) { printf (_("%s options:\n"), _(group->title)); } else if (groups) { printf (_("Other options:\n")); } else { printf (_("Options:\n")); } width = nih_max (nih_str_screen_width (), 50U) - 31; for (opt = options; (opt->option || opt->long_option); opt++) { nih_local char *str = NULL; char *ptr; size_t len = 0; if (opt->group != group) continue; if (! opt->help) continue; /* Indent by two spaces */ printf (" "); len += 2; /* Display the short option */ if (opt->option) { printf ("-%c", opt->option); len += 2; /* Seperate short and long option, or * give the argument name */ if (opt->long_option) { printf (", "); len += 2; } else if (opt->arg_name) { printf (" %s", opt->arg_name); len += strlen (opt->arg_name) + 1; } } else { /* Make all long options the same indent * whether or not there's a short one */ printf (" "); len += 4; } /* Display the long option */ if (opt->long_option) { printf ("--%s", opt->long_option); len += strlen (opt->long_option) + 2; /* With the argument name */ if (opt->arg_name) { printf ("=%s", opt->arg_name); len += strlen (opt->arg_name) + 1; } } /* Format the help string to fit in the latter * half of the screen */ str = NIH_MUST (nih_str_wrap (NULL, opt->help, width, 0, 2)); /* Write the description to the screen */ ptr = str; while (ptr && *ptr) { size_t linelen; /* Not enough room on this line */ if (len > 28) { printf ("\n"); len = 0; } /* Pad line up to the right column */ while (len < 30) { printf (" "); len++; } /* Output the line up until the next line */ linelen = strcspn (ptr, "\n"); printf ("%.*s\n", (int)linelen, ptr); len = 0; /* Skip to the next line */ ptr += linelen; if (*ptr == '\n') ptr++; } } printf ("\n"); } libnih-1.0.3/nih/libnih.h0000644000175000017500000000240211445765555012114 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_LIBNIH_H #define NIH_LIBNIH_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif /* NIH_LIBNIH_H */ libnih-1.0.3/nih/string.c0000644000175000017500000006243711445765555012166 00000000000000/* libnih * * string.c - useful string utility functions * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include "string.h" /** * nih_sprintf: * @parent: parent object for new string, * @format: format string. * * Writes a new string according to @format as sprintf(), except that the * string is allocated using nih_alloc(). * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * nih_sprintf (const void *parent, const char *format, ...) { char *str; va_list args; nih_assert (format != NULL); va_start (args, format); str = nih_vsprintf (parent, format, args); va_end (args); return str; } /** * nih_vsprintf: * @parent: parent object for new string, * @format: format string, * @args: arguments to format string. * * Writes a new string according to @format as vsprintf(), except that the * string is allocated using nih_alloc(). * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * nih_vsprintf (const void *parent, const char *format, va_list args) { ssize_t len; va_list args_copy; char *str; nih_assert (format != NULL); va_copy (args_copy, args); len = vsnprintf (NULL, 0, format, args_copy); va_end (args_copy); nih_assert (len >= 0); str = nih_alloc (parent, len + 1); if (! str) return NULL; va_copy (args_copy, args); vsnprintf (str, len + 1, format, args_copy); va_end (args_copy); return str; } /** * nih_strdup: * @parent: parent object for new string, * @str: string to duplicate. * * Allocates enough memory to store a duplicate of @str and writes a * copy of the string to it. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: duplicated string or NULL if insufficient memory. **/ char * nih_strdup (const void *parent, const char *str) { size_t len; nih_assert (str != NULL); len = strlen (str); return nih_strndup (parent, str, len); } /** * nih_strndup: * @parent: parent object for new string, * @str: string to duplicate, * @len: length of string to duplicate. * * Allocates enough memory to store up to @len bytes of @str, or if @str * is shorter, @len bytes. A copy of the string is written to this * block with a NUL byte appended. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: duplicated string or NULL if insufficient memory. **/ char * nih_strndup (const void *parent, const char *str, size_t len) { char *dup; nih_assert (str != NULL); dup = nih_alloc (parent, len + 1); if (! dup) return NULL; memset (dup, '\0', len + 1); strncpy (dup, str, len); return dup; } /** * nih_strcat: * @str: pointer to string to modify, * @parent: parent object of new string, * @src: string to append to @str. * * Modifies @str, concatenating the contents of @src to it. The new string * is allocated using nih_alloc(), and @str will be updated to point to the * new pointer; use the return value simply to check for success. * * If the string pointed to by @str is NULL, this is equivalent to * nih_strdup() and if @parent is not NULL, it should be a pointer to another * object which will be used as a parent for the returned string. When all * parents of the returned string are freed, the returned string will also be * freed. * * When the string pointed to by @str is not NULL, @parent is ignored; * though it usual to pass a parent of @str for style reasons. * * Returns: new string pointer or NULL if insufficient memory. **/ char * nih_strcat (char **str, const void *parent, const char *src) { nih_assert (str != NULL); nih_assert (src != NULL); return nih_strncat (str, parent, src, strlen (src)); } /** * nih_strncat: * @str: pointer to string to modify, * @parent: parent object of new string, * @src: string to append to @str, * @len: length of @src. * * Modifies @str, concatenating up to @len characters of the contents of @src * to it. The new string is allocated using nih_alloc(), and @str will be * updated to point to the new pointer; use the return value simply to check * for success. * * If the string pointed to by @str is NULL, this is equivalent to * nih_strdup() and if @parent is not NULL, it should be a pointer to another * object which will be used as a parent for the returned string. When all * parents of the returned string are freed, the returned string will also be * freed. * * When the string pointed to by @str is not NULL, @parent is ignored; * though it usual to pass a parent of @str for style reasons. * * Returns: new string pointer or NULL if insufficient memory. **/ char * nih_strncat (char **str, const void *parent, const char *src, size_t len) { char *ret; nih_assert (str != NULL); nih_assert (src != NULL); if (! *str) { *str = nih_strndup (parent, src, len); return *str; } ret = nih_realloc (*str, parent, strlen (*str) + len + 1); if (! ret) return NULL; *str = ret; strncat (*str, src, len); return ret; } /** * nih_strcat_sprintf: * @str: pointer to string to modify, * @parent: parent object of new string, * @format: format string to append to @str. * * Modifies @str, concatenating according to @format as sprintf(). The new * string is allocated using nih_alloc(), and @str will be updated to point * to the new pointer; use the return value simply to check for success. * * If the string pointed to by @str is NULL, this is equivalent to * nih_sprintf() and if @parent is not NULL, it should be a pointer to another * object which will be used as a parent for the returned string. When all * parents of the returned string are freed, the returned string will also be * freed. * * When the string pointed to by @str is not NULL, @parent is ignored; * though it usual to pass a parent of @str for style reasons. * * Returns: new string pointer or NULL if insufficient memory. **/ char * nih_strcat_sprintf (char **str, const void *parent, const char *format, ...) { char *ret; va_list args; nih_assert (str != NULL); nih_assert (format != NULL); va_start (args, format); ret = nih_strcat_vsprintf (str, parent, format, args); va_end (args); return ret; } /** * nih_strcat_vsprintf: * @str: pointer to string to modify, * @parent: parent object of new string, * @format: format string to append to @str, * @args: arguments to format string. * * Modifies @str, concatenating according to @format as vsprintf(). The new * string is allocated using nih_alloc(), and @str will be updated to point * to the new pointer; use the return value simply to check for success. * * If the string pointed to by @str is NULL, this is equivalent to * nih_vsprintf() and if @parent is not NULL, it should be a pointer to another * object which will be used as a parent for the returned string. When all * parents of the returned string are freed, the returned string will also be * freed. * * When the string pointed to by @str is not NULL, @parent is ignored; * though it usual to pass a parent of @str for style reasons. * * Returns: new string pointer or NULL if insufficient memory. **/ char * nih_strcat_vsprintf (char **str, const void *parent, const char *format, va_list args) { ssize_t len, str_len; va_list args_copy; char *ret; nih_assert (str != NULL); nih_assert (format != NULL); str_len = *str ? strlen (*str) : 0; va_copy (args_copy, args); len = vsnprintf (NULL, 0, format, args_copy); va_end (args_copy); nih_assert (len >= 0); ret = nih_realloc (*str, parent, str_len + len + 1); if (! ret) return NULL; *str = ret; va_copy (args_copy, args); vsnprintf (*str + str_len, len + 1, format, args_copy); va_end (args_copy); return ret; } /** * nih_str_split: * @parent: parent object of new array, * @str: string to split, * @delim: characters to split on, * @repeat: allow repeated characters. * * Splits @str into an array of strings by separating on any character in * @delim; if @repeat is true then sequences of @delim are ignored, otherwise * they result in empty strings in the returned array. * * The last element in the array is always NULL. * * The individual strings are allocated using nih_alloc() so you may just use * nih_free() on the returned array. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned array. When all parents * of the returned string are freed, the returned array will also be * freed. * * Returns: allocated array or NULL if insufficient memory. **/ char ** nih_str_split (const void *parent, const char *str, const char *delim, int repeat) { char **array; size_t len; nih_assert (str != NULL); nih_assert (delim != NULL); len = 0; array = nih_str_array_new (parent); if (! array) return NULL; while (*str) { const char *ptr; /* Skip initial delimiters */ while (repeat && strchr (delim, *str)) str++; /* Find the end of the token */ ptr = str; while (*str && (! strchr (delim, *str))) str++; if (! nih_str_array_addn (&array, parent, &len, ptr, str - ptr)) { nih_free (array); return NULL; } /* Skip over the delimiter */ if (*str) str++; } return array; } /** * nih_str_array_new: * @parent: parent object of new array. * * Allocates a new NULL-terminated array of strings with zero elements; * use nih_str_array_add() to append new strings to the array. Because * each array element will be allocated using nih_alloc() as a child of * the array itself, the entire array can be freed with nih_free(). * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned array. When all parents * of the returned object are freed, the returned array will also be * freed. * * Returns: newly allocated array or NULL if insufficient memory. **/ char ** nih_str_array_new (const void *parent) { char **array; array = nih_alloc (parent, sizeof (char *)); if (! array) return NULL; array[0] = NULL; return array; } /** * nih_str_array_add: * @array: array of strings, * @parent: parent object of new array, * @len: length of @array, * @str: string to add. * * Extend the NULL-terminated string @array (which has @len elements, * excluding the final NULL element), appending a copy of @str to it. * Both the array and the new string are allocated using nih_alloc(), * * @len will be updated to contain the new array length and @array will * be updated to point to the new array pointer; use the return value * simply to check for success. * * If you don't know or care about the length, @len may be set to NULL; * this is less efficient as it necessates counting the length on each * invocation. * * If the array pointed to by @array is NULL, the array will be allocated * and @ptr the first element, and if @parent is not NULL, it should be a * pointer to another object which will be used as a parent for the returned * array. When all parents of the returned array are freed, the returned * array will also be freed. * * When the array pointed to by @array is not NULL, @parent is ignored; * though it usual to pass a parent of @array for style reasons. * * Returns: new array pointer or NULL if insufficient memory. **/ char ** nih_str_array_add (char ***array, const void *parent, size_t *len, const char *str) { nih_local char *new_str; nih_assert (array != NULL); nih_assert (str != NULL); new_str = nih_strdup (NULL, str); if (! new_str) return NULL; return nih_str_array_addp (array, parent, len, new_str); } /** * nih_str_array_addn: * @array: array of strings, * @parent: parent object of new array, * @len: length of @array, * @str: string to add, * @strlen: length of @str. * * Extend the NULL-terminated string @array (which has @len elements, * excluding the final NULL element), appending a copy of the first * @strlen bytes of @str to it. * * Both the array and the new string are allocated using nih_alloc(), * * @len will be updated to contain the new array length and @array will * be updated to point to the new array pointer; use the return value * simply to check for success. * * If you don't know or care about the length, @len may be set to NULL; * this is less efficient as it necessates counting the length on each * invocation. * * If the array pointed to by @array is NULL, the array will be allocated * and @ptr the first element, and if @parent is not NULL, it should be a * pointer to another object which will be used as a parent for the returned * array. When all parents of the returned array are freed, the returned * array will also be freed. * * When the array pointed to by @array is not NULL, @parent is ignored; * though it usual to pass a parent of @array for style reasons. * * Returns: new array pointer or NULL if insufficient memory. **/ char ** nih_str_array_addn (char ***array, const void *parent, size_t *len, const char *str, size_t strlen) { nih_local char *new_str; nih_assert (array != NULL); nih_assert (str != NULL); new_str = nih_strndup (NULL, str, strlen); if (! new_str) return NULL; return nih_str_array_addp (array, parent, len, new_str); } /** * nih_str_array_addp: * @array: array of strings, * @parent: parent object of new array, * @len: length of @array, * @ptr: pointer to add. * * Extend the NULL-terminated string @array (which has @len elements, * excluding the final NULL element), appending the nih_alloc() allocated * object @ptr to it. * * The array is allocated using nih_alloc(), and @ptr will be referenced * by the new array. After calling this function, you should never use * nih_free() to free @ptr and instead use nih_unref() or nih_discard() * if you no longer need to use it. * * @len will be updated to contain the new array length and @array will * be updated to point to the new array pointer; use the return value * simply to check for success. * * If you don't know or care about the length, @len may be set to NULL; * this is less efficient as it necessates counting the length on each * invocation. * * If the array pointed to by @array is NULL, the array will be allocated * and @ptr the first element, and if @parent is not NULL, it should be a * pointer to another object which will be used as a parent for the returned * array. When all parents of the returned array are freed, the returned * array will also be freed. * * When the array pointed to by @array is not NULL, @parent is ignored; * though it usual to pass a parent of @array for style reasons. * * Returns: new array pointer or NULL if insufficient memory. **/ char ** nih_str_array_addp (char ***array, const void *parent, size_t *len, void *ptr) { char **new_array; size_t c_len; nih_assert (array != NULL); nih_assert (ptr != NULL); if (! len) { len = &c_len; c_len = 0; for (new_array = *array; new_array && *new_array; new_array++) c_len++; } new_array = nih_realloc (*array, parent, sizeof (char *) * (*len + 2)); if (! new_array) return NULL; *array = new_array; nih_ref (ptr, *array); (*array)[(*len)++] = ptr; (*array)[*len] = NULL; return *array; } /** * nih_str_array_copy: * @parent: parent object of new array. * @len: length of new array, * @array: array of strings to copy. * * Allocates a new NULL-terminated array of strings with elements copied * from the existing @array given. * * Because each array element will be allocated using nih_alloc() as a child * of the array itself, the entire array can be freed with nih_free(). * This will not affect the array copied. * * @len will be updated to contain the new array length. If you don't care * about the length, @len may be set to NULL; this is less efficient as it * necessates counting the length on each future add operation. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned array. When all parents * of the returned array are freed, the returned array will also be * freed. * * Returns: newly allocated array or NULL if insufficient memory. **/ char ** nih_str_array_copy (const void *parent, size_t *len, char * const *array) { char **new_array; nih_assert (array != NULL); new_array = nih_str_array_new (parent); if (! new_array) return NULL; if (! nih_str_array_append (&new_array, parent, len, array)) { nih_free (new_array); return NULL; } return new_array; } /** * nih_str_array_append: * @array: array of strings, * @parent: parent object of new array, * @len: length of @array, * @args: array of strings to add. * * Extend the NULL-terminated string @array (which has @len elements, * excluding the final NULL element), appending a copy of each element in * the additional NULL-terminated string array @args to it. * Both the array and the new strings are allocated using nih_alloc(), * * @len will be updated to contain the new array length and @array will * be updated to point to the new array pointer; use the return value * simply to check for success. * * If you don't know or care about the length, @len may be set to NULL; * this is less efficient as it necessates counting the length on each * operation. * * If the array pointed to by @array is NULL, this is equivalent to * nih_str_array_copy() and if @parent is not NULL, it should be a pointer to * another object which will be used as a parent for the returned array. * When all parents of the returned array are freed, the returned array will * also be freed. * * When the array pointed to by @array is not NULL, @parent is ignored; * though it usual to pass a parent of @array for style reasons. * * Returns: new array pointer or NULL if insufficient memory. **/ char ** nih_str_array_append (char ***array, const void *parent, size_t *len, char * const *args) { size_t c_len, o_len; int free_on_error = FALSE; char * const *arg; nih_assert (array != NULL); nih_assert (args != NULL); if (! *array) free_on_error = TRUE; if (! len) { c_len = 0; for (arg = *array; arg && *arg; arg++) c_len++; } else { c_len = *len; } o_len = c_len; for (arg = args; *arg; arg++) { if (! nih_str_array_add (array, parent, &c_len, *arg)) { if (*array) { for (; c_len > o_len; c_len--) nih_free ((*array)[c_len - 1]); (*array)[o_len] = NULL; if (free_on_error) { nih_free (*array); *array = NULL; } } return NULL; } } if (len) *len = c_len; return *array; } /** * nih_str_wrap: * @parent: parent object of new string, * @str: string to be wrapped, * @len: length of line to fit into, * @first_indent: indent for first line, * @indent: indent for subsequent lines. * * Returns a newly allocated copy of @str with newlines inserted so no * line is longer than @len characters (not including the newline). Where * possible, newlines replace existing whitespace characters so that words * are not broken. * * The first line may be indented by an extra @first_indent characters, and * subsequent lines may be intended by an extra @indent characters. These * are added to the string as whitespace characters. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * nih_str_wrap (const void *parent, const char *str, size_t len, size_t first_indent, size_t indent) { char *txt; size_t txtlen, col, ls, i; nih_assert (str != NULL); nih_assert (len > 0); txtlen = first_indent + strlen (str); txt = nih_alloc (parent, txtlen + 1); if (! txt) return NULL; memset (txt, ' ', first_indent); memcpy (txt + first_indent, str, strlen (str) + 1); col = ls = 0; for (i = 0; i < txtlen; i++) { int nl = 0; if (strchr (" \t\r", txt[i])) { /* Character is whitespace; convert to an ordinary * space and remember the position for next time. */ txt[i] = ' '; ls = i; /* If this doesn't go over the line length, * continue to the next character */ if (++col <= len) continue; } else if (txt[i] != '\n') { /* Character is part of a word. If this doesn't go * over the line length, continue to the next * character */ if (++col <= len) continue; /* Filled a line; if we marked a whitespace character * on this line, go back to that, otherwise we'll * need to add a newline to the string after this * character */ if (ls) { i = ls; } else { nl = 1; } } /* We need to insert a line break at this position, and * any indent that goes along with it */ if (indent | nl) { char *new_txt; /* Need to increase the size of the string in memory */ new_txt = nih_realloc (txt, parent, txtlen + indent + nl + 1); if (! new_txt) { nih_free (txt); return NULL; } txt = new_txt; /* Move up the existing characters, then replace * the gap with the indent */ memmove (txt + i + indent + 1, txt + i + 1 - nl, txtlen - i + nl); memset (txt + i + 1, ' ', indent); txtlen += indent + nl; } /* Replace the current character with a newline */ txt[i] = '\n'; /* Reset the current column and last seen whitespace index; * make sure we skip any indent as it's whitespace that doesn't * count */ i += indent; col = indent; ls = 0; } return txt; } /** * nih_str_screen_width: * * Checks the COLUMNS environment variable, standard output if it is a * terminal or defaults to 80 characters. * * Returns: the width of the screen. **/ size_t nih_str_screen_width (void) { char *columns; size_t len = 0; /* Look at the columns environment variable */ columns = getenv ("COLUMNS"); if ((! len) && columns) { char *endptr; len = strtoul (columns, &endptr, 10); if (*endptr) len = 0; } /* Check whether standard output is a tty */ if ((! len) && isatty (STDOUT_FILENO)) { struct winsize winsize; if (ioctl (STDOUT_FILENO, TIOCGWINSZ, &winsize) == 0) len = winsize.ws_col; } /* Fallback to 80 columns */ if (! len) len = 80; return len; } /** * nih_str_screen_wrap: * @parent: parent object of new string, * @str: string to be wrapped, * @first_indent: indent for first line, * @indent: indent for subsequent lines. * * Returns a newly allocated copy of @str with newlines inserted so no * line is wider than the screen (not including the newline). Where * possible, newlines replace existing whitespace characters so that words * are not broken. * * If standard output is not a terminal, then 80 characters is assumed. * The width can be overriden with the COLUMNS environment variable. * * The first line may be indented by an extra @first_indent characters, and * subsequent lines may be intended by an extra @indent characters. These * are added to the string as whitespace characters. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * nih_str_screen_wrap (const void *parent, const char *str, size_t first_indent, size_t indent) { size_t len; nih_assert (str != NULL); len = nih_str_screen_width () - 1; return nih_str_wrap (parent, str, len, first_indent, indent); } libnih-1.0.3/nih/logging.h0000644000175000017500000001215711445765555012305 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_LOGGING_H #define NIH_LOGGING_H /** * These functions provide a logging interface for outputting messages * at different priorities, and filtering based on them. * * The output for the logger can be selected using nih_log_set_logger(), * where nih_logger_printf() is the default and nih_logger_syslog() another * popular alternative. * * Log messages are output with different macros. **/ #include #include /** * NihLogLevel: * * Severity of log messages, used both to influence formatting of the * message and to filter messages below a particular severity. **/ typedef enum { NIH_LOG_UNKNOWN, NIH_LOG_DEBUG, NIH_LOG_INFO, NIH_LOG_MESSAGE, NIH_LOG_WARN, NIH_LOG_ERROR, NIH_LOG_FATAL } NihLogLevel; /** * NihLogger: * @priority: priority of message, * @message: message to log. * * A logger is a function that receives a formatted message to be logged * in whatever manner is appropriate. The priority of the message is given * so that the logger may direct it appropriately, however the function * should not discard any messages and instead nih_log_set_priority() used * to decide the treshold of logged messages. * * Returns: zero on success, negative value if the logger was not able * to output the message. **/ typedef int (*NihLogger) (NihLogLevel priority, const char *message); /** * nih_debug: * @format: printf-style format string. * * Outputs a debugging message, including the name of the function that * generated it. Almost never shown, except when debugging information is * required. **/ #define nih_debug(format, ...) \ nih_log_message (NIH_LOG_DEBUG, "%s: " format, \ __FUNCTION__, ##__VA_ARGS__) /** * nih_info: * @format: printf-style format string. * * Outputs a message that is purely informational, usually not shown unless * the user wants verbose operation. **/ #define nih_info(format, ...) \ nih_log_message (NIH_LOG_INFO, format, ##__VA_ARGS__) /** * nih_message: * @format: printf-style format string. * * Outputs a message from a non-daemon process that is normally shown unless * the user wants quiet operation. The difference between this and nih_warn() * is that this is usually send to standard output, instead of standard * error, and it is not prefixed. **/ #define nih_message(format, ...) \ nih_log_message (NIH_LOG_MESSAGE, format, ##__VA_ARGS__) /** * nih_warn: * @format: printf-style format string. * * Outputs a warning message, one that indicates a potential problem that * has been ignored; these are shown by default unless the user wants quiet * operation. **/ #define nih_warn(format, ...) \ nih_log_message (NIH_LOG_WARN, format, ##__VA_ARGS__) /** * nih_error: * @format: printf-style format string. * * Outputs an error message, one that the software may be able to recover * from but that has caused an operation to fail. These are shown in all * but the most quiet of operation modes. **/ #define nih_error(format, ...) \ nih_log_message (NIH_LOG_ERROR, format, ##__VA_ARGS__) /** * nih_fatal: * @format: printf-style format string. * * Outputs a fatal error message that caused the software to cease * functioning. Always shown. **/ #define nih_fatal(format, ...) \ nih_log_message (NIH_LOG_FATAL, format, ##__VA_ARGS__) /** * nih_assert: * @expr: expression to check. * * Outputs a fatal error message and terminates the process if @expr is * false. **/ #define nih_assert(expr) \ if (! NIH_LIKELY(expr)) { \ nih_fatal ("%s:%d: Assertion failed in %s: %s", \ __FILE__, __LINE__, __FUNCTION__, #expr); \ abort (); \ } /** * nih_assert_not_reached: * * Outputs a fatal error message and terminates the process if this * line of code is reached. **/ #define nih_assert_not_reached() \ do { \ nih_fatal ("%s:%d: Not reached assertion failed in %s", \ __FILE__, __LINE__, __FUNCTION__); \ abort (); \ } while (0) NIH_BEGIN_EXTERN extern NihLogLevel nih_log_priority; void nih_log_init (void); void nih_log_set_logger (NihLogger new_logger); void nih_log_set_priority (NihLogLevel new_priority); int nih_log_message (NihLogLevel priority, const char *format, ...) __attribute__ ((format (printf, 2, 3))); int nih_logger_printf (NihLogLevel priority, const char *message); int nih_logger_syslog (NihLogLevel priority, const char *message); NIH_END_EXTERN #endif /* NIH_LOGGING_H */ libnih-1.0.3/nih/hash.h0000644000175000017500000001775711445765555011615 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_HASH_H #define NIH_HASH_H /** * Provides a generic hash table implementation using NihList for the bins, * which means that entries may be freely moved between lists and hash * tables. * * Members are identified by a constant key, which is used for both hashing * and comparison. The key function takes a given member (referenced by * its list head) and returns a pointer, this pointer is passed to the * hash function for hashing and the comparison function for comparison. * * The key, hash and comparison function are given when creating the hash * table with nih_hash_new(). * * The most common use of this pointer is a string, generally a constant * one found as the first member in the structure after the list head. * For this case, you may use nih_hash_string_new() instead. * * Entries may be added to a hash table using nih_hash_add(), no assumption * is made about whether duplicate entries are permitted or not. To add * and fail if the entry already exists use nih_hash_add_unique(), to add * and replace an existing entry use nih_hash_replace(). * * The hash table may be iterated with nih_hash_search(), passing the return * value to subsequent calls iterates all values with the given key. * * To lookup the first value nih_hash_lookup() is a convenient simpler * function. **/ #include #include /** * NihKeyFunction: * @entry: entry to key. * * This function is used to obtain a constant key for a given table entry. * * Returns: constant key from entry. **/ typedef const void *(*NihKeyFunction) (NihList *entry); /** * NihHashFunction: * @key: key to hash. * * This function is used to generate a 32-bit hash for a given constant * key, this will be bounded by the hash size automatically. * * Returns: 32-bit hash. **/ typedef uint32_t (*NihHashFunction) (const void *key); /** * NihCmpFunction: * @key1: key to compare, * @key2: key to compare against. * * This function is used to compare constant keys from two given table * entries. * * Returns: integer less than, equal to or greater than zero if @key1 is * respectively less then, equal to or greater than @key2. **/ typedef int (*NihCmpFunction) (const void *key1, const void *key2); /** * NihHash: * @bins: array of bins, * @size: size of bins array, * @key_function: function used to obtain keys for entries, * @hash_function: function used to obtain hash of keys, * @cmp_function: function used to compare keys. * * This structure represents a hash table which is more efficient for * looking up members than an ordinary list. * * Individual members of the hash table are NihList members as are the * bins themselves, so to remove an entry from the table you can just * use nih_list_remove(). **/ typedef struct nih_hash { NihList *bins; size_t size; NihKeyFunction key_function; NihHashFunction hash_function; NihCmpFunction cmp_function; } NihHash; /** * NIH_HASH_FOREACH: * @hash: hash table to iterate, * @iter: name of iterator variable. * * Expands to nested for statements that iterate over each entry in each * bin of @hash, except the bin head pointer, setting @iter to each entry * for the block within the loop. A variable named _@iter_i is used to * iterate the hash bins. * * This is the cheapest form of iteration, however it is not safe to perform * various modifications to the hash; most importantly, you must not change * the member being iterated in any way, including removing it from the hash * or freeing it. If you need to do that, use NIH_HASH_FOREACH_SAFE() instead. * * However since it doesn't modify the hash being iterated in any way, it * is safe to traverse or iterate the hash again while iterating. **/ #define NIH_HASH_FOREACH(hash, iter) \ for (size_t _##iter##_i = 0; _##iter##_i < (hash)->size; \ _##iter##_i++) \ NIH_LIST_FOREACH (&(hash)->bins[_##iter##_i], iter) /** * NIH_HASH_FOREACH_SAFE: * @hash: hash table to iterate, * @iter: name of iterator variable. * * Expans to nested for statements that iterate over each entry in each * bin of @hash, except for the bin head pointer, setting @iter to each * entry for the block within the loop. A variable named _@iter_i is used * to iterate the hash bins. * * The iteration is performed safely by placing a cursor node after @iter; * this means that any node including @iter can be removed from the hash, * added to a different hash or list, or entries added before or after it. * * Note that if you add an entry directly after @iter and wish it to be * visited, you would need to use NIH_HASH_FOREACH() instead, as this * would be placed before the cursor and thus skipped. * * Also since the hash has an extra node during iteration of a different * type, it is expressly not safe to traverse or iterate the hash while * iterating - including performing lookups. If you need to perform * multiple iterations, lookups, or reference the next or previous pointers * of a node, you must use NIH_HASH_FOREACH(). **/ #define NIH_HASH_FOREACH_SAFE(hash, iter) \ for (size_t _##iter##_i = 0; _##iter##_i < (hash)->size; \ _##iter##_i++) \ NIH_LIST_FOREACH_SAFE (&(hash)->bins[_##iter##_i], iter) /** * nih_hash_string_new: * @parent: parent of new hash, * @entries: rough number of entries expected, * * Allocates a new hash table, the number of buckets selected is a prime * number that is no larger than @entries; this should be set to a rough * number of expected entries to ensure optimum distribution. * * Individual members of the hash table are NihList member which have * a constant string as the first member that can be used as the hash key, * these will be compared case sensitively. * * The structure is allocated using nih_alloc() so it can be used as a * context to other allocations; there is no non-allocated version of this * function because the hash must be usable as a parent context to its bins. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned hash table. When all parents * of the returned hash table are freed, the returned hash table will also be * freed. * * Returns: the new hash table or NULL if the allocation failed. **/ #define nih_hash_string_new(parent, entries) \ nih_hash_new (parent, entries, \ (NihKeyFunction)nih_hash_string_key, \ (NihHashFunction)nih_hash_string_hash, \ (NihCmpFunction)nih_hash_string_cmp) NIH_BEGIN_EXTERN NihHash * nih_hash_new (const void *parent, size_t entries, NihKeyFunction key_function, NihHashFunction hash_function, NihCmpFunction cmp_function) __attribute__ ((warn_unused_result, malloc)); NihList * nih_hash_add (NihHash *hash, NihList *entry); NihList * nih_hash_add_unique (NihHash *hash, NihList *entry); NihList * nih_hash_replace (NihHash *hash, NihList *entry); NihList * nih_hash_search (NihHash *hash, const void *key, NihList *entry); NihList * nih_hash_lookup (NihHash *hash, const void *key); const char *nih_hash_string_key (NihList *entry); uint32_t nih_hash_string_hash (const char *key); int nih_hash_string_cmp (const char *key1, const char *key2); NIH_END_EXTERN #endif /* NIH_HASH_H */ libnih-1.0.3/AUTHORS0000644000175000017500000000026111445765555010771 00000000000000libnih was written by Scott James Remnant . A complete list of contributors to the code can be obtained from the ChangeLog file. Many thanks to them all. libnih-1.0.3/TODO0000644000175000017500000001476711445765555010431 000000000000001.1/2.0 ------- alloc: - malloc() returning NULL doesn't usually mean that we're temporarily out of memory these days, but out of address space or some other fault; looping on it is probably not the right thing to do. - Maybe have some reserved sump pages that we use for temporary allocations that must succeed, and have an nih_must_alloc() function - Some are because we can't easily deal with failure, we should try harder or free memory first macros: - audit uses of NIH_MUST and try and remove them where possible. - NIH_ZERO is probably never right, syscalls need their errnos checked and action taken on just about everything except EINTR and EAGAIN - assert on conditions we don't know how to handle misc: - try and make sure each basic object type has an _init() function, this shall take a const void *parent which it uses for any internal allocations. The _new() function calls it with parent and the object set to the same value. - except when we need to separately manage the life cycle of the objects (e.g. current main loop code) - and except when references will be taken (since otherwise we'd have to stash the parent somewhere) - destructors should be mentioned in _init() documentation and chained in _destroy() functions - generally start moving to function pointers being Handlers rather than clever names error: - final audit that we always push an error context before calling a handler function - use nih_error_steal() and nih_error_raise_error() to raise it in the parent context - final audit that raised error is included in a new context for error handler functions and context popped afterwards without freeing the error (we expect the function to do that to indicate it actually handled it) poll: - new epoll/eventfd based loop that replaces the old main loop code (there's copies of this floating around that I need to merge together) event: - uses new poll code to wrap an eventfd() for the simplest kind of event handling buffer: - separate out buffer code into NihBuffer, it's probably useful for other things too; I can think of a few places where we grow strings and I could just use this io: - separate out the NihIoWatch code, this should largely go away with the new poll code - separate out the NihIoMessage code into NihMessage, it behaves sufficiently differently that it should be separate - the remaining code is pure buffered stream I/O - there's a couple of tricky tests left to do: - nih_io_message_recv() with socket types other than PF_UNIX - nih_io_message_recv() when recv() fails - nih_io_watcher() with write error and free called timers: - rewrite based on new poll code and timerfd() - clock selection and sub-second resolution - calendar scheduled timers signal: - rewrite based on new poll code and signalfd() - the API will probably change massively since you'll just add a signal watch, with one or more signals, rather than the set/add handler stuff child: - update to new signal API - call wait() for each child signal file: - nih_dir_walk() is buggy and doesn't work in some situations (probably) - should use openat() to save string copying - avoid stat() where possible - depth-first and depth-last modes - parent directory fd - add the allocating fgets() code that's floating around, rebased onto NihBuffer - probably a bug in nih_file_map/unmap watch: - nih_watch_new() is buggy when subdirs is FALSE - should use openat() to save string copying - inotify already has an IN_ISDIR flag to let us know that we got an event for a directory, so we don't really need to stat() it or pass a statbuf around; except maybe for compatibility with the walk code. - handle IN_Q_OVERFLOW in some sane manner, at least log it. - ideally we could rework this based off something like fanotify(), since it's expensive to walk large files with this - see the Upstart conf file for the fact that this API doesn't actually work in practice for watching files - easier nih_watch_file() API? dbus: - property naming isn't consistent with D-Bus recommendations, which says we should use TitleCase for them, see recent D-Bus thread - need to ignore standard/built-in D-Bus interfaces such as Peer, Properties and Introspectable when parsing introspection data - ideally have pre-canned code that would work on any proxy, would mean we need to generate code and link with it again - allow structures to be named and re-used by multiple interface members - structure name hints come from annotations on arguments and properties - this means only marshal() and demarshal() need to the extra name list argument - (de)marshal_array() just passes it on - (de)marshal_struct() uses the first item in the name list, then passes on the next (need returnable pointer so we know where we got to) - never destroy the original list or pointer, we probably use it several times (each property function) - use annotations on annotations for the member names: com.netsplit.Nih.Struct foo com.netsplit.Nih.StructMember jazz com.netsplit.Nih.StructMember ratchett - check whether the struct is already in the list, if not add it using the member names here, if it use the names there and warn/error on names here - NihDBusProxy always tracks the remote name, which is expensive and annoying since you need one for every object and have to recreate them in every reply function and signal function - passing NULL for the name to the _new() function and setting the name by hand later is one solution - allowing no tracking is another - but required for signals, so maybe only activated if a lost handler is created or a signal attached? - create a proxy from another, could share the same name tracking code (in which case make it an object) - then find a way of getting those to reply and signal functions - we're not using the no_reply annotation - object implementation probably shouldn't - the client is free to ignore the annotation so might be waiting for a reply, so we should send one anyway - proxy implementation is interesting, because we need to wait for a reply to get an error return; we wouldn't want a sync function or even a notify function or even a pending call :-/ - doc strings for methods, signals, arguments, etc. - annotation would be used to set them - auto-generate doc strings for output functions - what if we want both proxy and object code in one source? - right now, the method names would conflict - arrays would need to be generated for both libnih-1.0.3/Makefile.am0000644000175000017500000000024411503251216011731 00000000000000## Process this file with automake to produce Makefile.in SUBDIRS = m4 intl nih nih-dbus nih-dbus-tool po EXTRA_DIST = HACKING ACLOCAL_AMFLAGS = --install -I m4 libnih-1.0.3/config.guess0000755000175000017500000012763711461165276012252 00000000000000#! /bin/sh # Attempt to guess a canonical system name. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 # Free Software Foundation, Inc. timestamp='2009-12-30' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA # 02110-1301, USA. # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # Originally written by Per Bothner. Please send patches (context # diff format) to and include a ChangeLog # entry. # # This script attempts to guess a canonical system name similar to # config.sub. If it succeeds, it prints the system name on stdout, and # exits with 0. Otherwise, it exits with 1. # # You can get the latest version of this script from: # http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] Output the configuration name of the system \`$me' is run on. Operation modes: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try \`$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" >&2 exit 1 ;; * ) break ;; esac done if test $# != 0; then echo "$me: too many arguments$help" >&2 exit 1 fi trap 'exit 1' 1 2 15 # CC_FOR_BUILD -- compiler used by this script. Note that the use of a # compiler to aid in system detection is discouraged as it requires # temporary files to be created and, as you can see below, it is a # headache to deal with in a portable fashion. # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still # use `HOST_CC' if defined, but it is deprecated. # Portable tmp directory creation inspired by the Autoconf team. set_cc_for_build=' trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; : ${TMPDIR=/tmp} ; { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; dummy=$tmp/dummy ; tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; case $CC_FOR_BUILD,$HOST_CC,$CC in ,,) echo "int x;" > $dummy.c ; for c in cc gcc c89 c99 ; do if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then CC_FOR_BUILD="$c"; break ; fi ; done ; if test x"$CC_FOR_BUILD" = x ; then CC_FOR_BUILD=no_compiler_found ; fi ;; ,,*) CC_FOR_BUILD=$CC ;; ,*,*) CC_FOR_BUILD=$HOST_CC ;; esac ; set_cc_for_build= ;' # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) if (test -f /.attbin/uname) >/dev/null 2>&1 ; then PATH=$PATH:/.attbin ; export PATH fi UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in *:NetBSD:*:*) # NetBSD (nbsd) targets should (where applicable) match one or # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently # switched to ELF, *-*-netbsd* would select the old # object file format. This provides both forward # compatibility and a consistent mechanism for selecting the # object file format. # # Note: NetBSD doesn't particularly care about the vendor # portion of the name. We always set it to "unknown". sysctl="sysctl -n hw.machine_arch" UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ /usr/sbin/$sysctl 2>/dev/null || echo unknown)` case "${UNAME_MACHINE_ARCH}" in armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; *) machine=${UNAME_MACHINE_ARCH}-unknown ;; esac # The Operating System including object format, if it has switched # to ELF recently, or will in the future. case "${UNAME_MACHINE_ARCH}" in arm*|i386|m68k|ns32k|sh3*|sparc|vax) eval $set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ELF__ then # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). # Return netbsd for either. FIX? os=netbsd else os=netbsdelf fi ;; *) os=netbsd ;; esac # The OS release # Debian GNU/NetBSD machines have a different userland, and # thus, need a distinct triplet. However, they do not need # kernel version information, so it can be replaced with a # suitable tag, in the style of linux-gnu. case "${UNAME_VERSION}" in Debian*) release='-gnu' ;; *) release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` ;; esac # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. echo "${machine}-${os}${release}" exit ;; *:OpenBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} exit ;; *:ekkoBSD:*:*) echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} exit ;; *:SolidBSD:*:*) echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} exit ;; macppc:MirBSD:*:*) echo powerpc-unknown-mirbsd${UNAME_RELEASE} exit ;; *:MirBSD:*:*) echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} exit ;; alpha:OSF1:*:*) case $UNAME_RELEASE in *4.0) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` ;; *5.*) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` ;; esac # According to Compaq, /usr/sbin/psrinfo has been available on # OSF/1 and Tru64 systems produced since 1995. I hope that # covers most systems running today. This code pipes the CPU # types through head -n 1, so we only detect the type of CPU 0. ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` case "$ALPHA_CPU_TYPE" in "EV4 (21064)") UNAME_MACHINE="alpha" ;; "EV4.5 (21064)") UNAME_MACHINE="alpha" ;; "LCA4 (21066/21068)") UNAME_MACHINE="alpha" ;; "EV5 (21164)") UNAME_MACHINE="alphaev5" ;; "EV5.6 (21164A)") UNAME_MACHINE="alphaev56" ;; "EV5.6 (21164PC)") UNAME_MACHINE="alphapca56" ;; "EV5.7 (21164PC)") UNAME_MACHINE="alphapca57" ;; "EV6 (21264)") UNAME_MACHINE="alphaev6" ;; "EV6.7 (21264A)") UNAME_MACHINE="alphaev67" ;; "EV6.8CB (21264C)") UNAME_MACHINE="alphaev68" ;; "EV6.8AL (21264B)") UNAME_MACHINE="alphaev68" ;; "EV6.8CX (21264D)") UNAME_MACHINE="alphaev68" ;; "EV6.9A (21264/EV69A)") UNAME_MACHINE="alphaev69" ;; "EV7 (21364)") UNAME_MACHINE="alphaev7" ;; "EV7.9 (21364A)") UNAME_MACHINE="alphaev79" ;; esac # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` exit ;; Alpha\ *:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # Should we change UNAME_MACHINE based on the output of uname instead # of the specific Alpha model? echo alpha-pc-interix exit ;; 21064:Windows_NT:50:3) echo alpha-dec-winnt3.5 exit ;; Amiga*:UNIX_System_V:4.0:*) echo m68k-unknown-sysv4 exit ;; *:[Aa]miga[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-amigaos exit ;; *:[Mm]orph[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-morphos exit ;; *:OS/390:*:*) echo i370-ibm-openedition exit ;; *:z/VM:*:*) echo s390-ibm-zvmoe exit ;; *:OS400:*:*) echo powerpc-ibm-os400 exit ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} exit ;; arm:riscos:*:*|arm:RISCOS:*:*) echo arm-unknown-riscos exit ;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) echo hppa1.1-hitachi-hiuxmpp exit ;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. if test "`(/bin/universe) 2>/dev/null`" = att ; then echo pyramid-pyramid-sysv3 else echo pyramid-pyramid-bsd fi exit ;; NILE*:*:*:dcosx) echo pyramid-pyramid-svr4 exit ;; DRS?6000:unix:4.0:6*) echo sparc-icl-nx6 exit ;; DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) case `/usr/bin/uname -p` in sparc) echo sparc-icl-nx7; exit ;; esac ;; s390x:SunOS:*:*) echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4H:SunOS:5.*:*) echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) echo i386-pc-auroraux${UNAME_RELEASE} exit ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) eval $set_cc_for_build SUN_ARCH="i386" # If there is a compiler, see if it is configured for 64-bit objects. # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. # This test works for both compilers. if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then SUN_ARCH="x86_64" fi fi echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:*:*) case "`/usr/bin/arch -k`" in Series*|S4*) UNAME_RELEASE=`uname -v` ;; esac # Japanese Language versions have a version number like `4.1.3-JL'. echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` exit ;; sun3*:SunOS:*:*) echo m68k-sun-sunos${UNAME_RELEASE} exit ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 case "`/bin/arch`" in sun3) echo m68k-sun-sunos${UNAME_RELEASE} ;; sun4) echo sparc-sun-sunos${UNAME_RELEASE} ;; esac exit ;; aushp:SunOS:*:*) echo sparc-auspex-sunos${UNAME_RELEASE} exit ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not # "atarist" or "atariste" at least should have a processor # > m68000). The system name ranges from "MiNT" over "FreeMiNT" # to the lowercase version "mint" (or "freemint"). Finally # the system name "TOS" denotes a system which is actually not # MiNT. But MiNT is downward compatible to TOS, so this should # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} exit ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} exit ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} exit ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) echo m68k-milan-mint${UNAME_RELEASE} exit ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) echo m68k-hades-mint${UNAME_RELEASE} exit ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) echo m68k-unknown-mint${UNAME_RELEASE} exit ;; m68k:machten:*:*) echo m68k-apple-machten${UNAME_RELEASE} exit ;; powerpc:machten:*:*) echo powerpc-apple-machten${UNAME_RELEASE} exit ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 exit ;; RISC*:ULTRIX:*:*) echo mips-dec-ultrix${UNAME_RELEASE} exit ;; VAX*:ULTRIX*:*:*) echo vax-dec-ultrix${UNAME_RELEASE} exit ;; 2020:CLIX:*:* | 2430:CLIX:*:*) echo clipper-intergraph-clix${UNAME_RELEASE} exit ;; mips:*:*:UMIPS | mips:*:*:RISCos) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #ifdef __cplusplus #include /* for printf() prototype */ int main (int argc, char *argv[]) { #else int main (argc, argv) int argc; char *argv[]; { #endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_SVR4) printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); #endif #endif exit (-1); } EOF $CC_FOR_BUILD -o $dummy $dummy.c && dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && SYSTEM_NAME=`$dummy $dummyarg` && { echo "$SYSTEM_NAME"; exit; } echo mips-mips-riscos${UNAME_RELEASE} exit ;; Motorola:PowerMAX_OS:*:*) echo powerpc-motorola-powermax exit ;; Motorola:*:4.3:PL8-*) echo powerpc-harris-powermax exit ;; Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) echo powerpc-harris-powermax exit ;; Night_Hawk:Power_UNIX:*:*) echo powerpc-harris-powerunix exit ;; m88k:CX/UX:7*:*) echo m88k-harris-cxux7 exit ;; m88k:*:4*:R4*) echo m88k-motorola-sysv4 exit ;; m88k:*:3*:R3*) echo m88k-motorola-sysv3 exit ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] then if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ [ ${TARGET_BINARY_INTERFACE}x = x ] then echo m88k-dg-dgux${UNAME_RELEASE} else echo m88k-dg-dguxbcs${UNAME_RELEASE} fi else echo i586-dg-dgux${UNAME_RELEASE} fi exit ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 exit ;; M88*:*:R3*:*) # Delta 88k system running SVR3 echo m88k-motorola-sysv3 exit ;; XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) echo m88k-tektronix-sysv3 exit ;; Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) echo m68k-tektronix-bsd exit ;; *:IRIX*:*:*) echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` exit ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' i*86:AIX:*:*) echo i386-ibm-aix exit ;; ia64:AIX:*:*) if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` else IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} exit ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #include main() { if (!__power_pc()) exit(1); puts("powerpc-ibm-aix3.2.5"); exit(0); } EOF if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` then echo "$SYSTEM_NAME" else echo rs6000-ibm-aix3.2.5 fi elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then echo rs6000-ibm-aix3.2.4 else echo rs6000-ibm-aix3.2 fi exit ;; *:AIX:*:[456]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc fi if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` else IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${IBM_ARCH}-ibm-aix${IBM_REV} exit ;; *:AIX:*:*) echo rs6000-ibm-aix exit ;; ibmrt:4.4BSD:*|romp-ibm:BSD:*) echo romp-ibm-bsd4.4 exit ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to exit ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) echo rs6000-bull-bosx exit ;; DPX/2?00:B.O.S.:*:*) echo m68k-bull-sysv3 exit ;; 9000/[34]??:4.3bsd:1.*:*) echo m68k-hp-bsd exit ;; hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) echo m68k-hp-bsd4.4 exit ;; 9000/[34678]??:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` case "${UNAME_MACHINE}" in 9000/31? ) HP_ARCH=m68000 ;; 9000/[34]?? ) HP_ARCH=m68k ;; 9000/[678][0-9][0-9]) if [ -x /usr/bin/getconf ]; then sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` case "${sc_cpu_version}" in 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 532) # CPU_PA_RISC2_0 case "${sc_kernel_bits}" in 32) HP_ARCH="hppa2.0n" ;; 64) HP_ARCH="hppa2.0w" ;; '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 esac ;; esac fi if [ "${HP_ARCH}" = "" ]; then eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #define _HPUX_SOURCE #include #include int main () { #if defined(_SC_KERNEL_BITS) long bits = sysconf(_SC_KERNEL_BITS); #endif long cpu = sysconf (_SC_CPU_VERSION); switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0"); break; case CPU_PA_RISC1_1: puts ("hppa1.1"); break; case CPU_PA_RISC2_0: #if defined(_SC_KERNEL_BITS) switch (bits) { case 64: puts ("hppa2.0w"); break; case 32: puts ("hppa2.0n"); break; default: puts ("hppa2.0"); break; } break; #else /* !defined(_SC_KERNEL_BITS) */ puts ("hppa2.0"); break; #endif default: puts ("hppa1.0"); break; } exit (0); } EOF (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac if [ ${HP_ARCH} = "hppa2.0w" ] then eval $set_cc_for_build # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler # generating 64-bit code. GNU and HP use different nomenclature: # # $ CC_FOR_BUILD=cc ./config.guess # => hppa2.0w-hp-hpux11.23 # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess # => hppa64-hp-hpux11.23 if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | grep -q __LP64__ then HP_ARCH="hppa2.0w" else HP_ARCH="hppa64" fi fi echo ${HP_ARCH}-hp-hpux${HPUX_REV} exit ;; ia64:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` echo ia64-hp-hpux${HPUX_REV} exit ;; 3050*:HI-UX:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #include int main () { long cpu = sysconf (_SC_CPU_VERSION); /* The order matters, because CPU_IS_HP_MC68K erroneously returns true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct results, however. */ if (CPU_IS_PA_RISC (cpu)) { switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; default: puts ("hppa-hitachi-hiuxwe2"); break; } } else if (CPU_IS_HP_MC68K (cpu)) puts ("m68k-hitachi-hiuxwe2"); else puts ("unknown-hitachi-hiuxwe2"); exit (0); } EOF $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && { echo "$SYSTEM_NAME"; exit; } echo unknown-hitachi-hiuxwe2 exit ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) echo hppa1.1-hp-bsd exit ;; 9000/8??:4.3bsd:*:*) echo hppa1.0-hp-bsd exit ;; *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) echo hppa1.0-hp-mpeix exit ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) echo hppa1.1-hp-osf exit ;; hp8??:OSF1:*:*) echo hppa1.0-hp-osf exit ;; i*86:OSF1:*:*) if [ -x /usr/sbin/sysversion ] ; then echo ${UNAME_MACHINE}-unknown-osf1mk else echo ${UNAME_MACHINE}-unknown-osf1 fi exit ;; parisc*:Lites*:*:*) echo hppa1.1-hp-lites exit ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) echo c1-convex-bsd exit ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi exit ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) echo c34-convex-bsd exit ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) echo c38-convex-bsd exit ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) echo c4-convex-bsd exit ;; CRAY*Y-MP:*:*:*) echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*[A-Z]90:*:*:*) echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' exit ;; CRAY*TS:*:*:*) echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*T3E:*:*:*) echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*SV1:*:*:*) echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; *:UNICOS/mp:*:*) echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; 5000:UNIX_System_V:4.*:*) FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} exit ;; sparc*:BSD/OS:*:*) echo sparc-unknown-bsdi${UNAME_RELEASE} exit ;; *:BSD/OS:*:*) echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} exit ;; *:FreeBSD:*:*) case ${UNAME_MACHINE} in pc98) echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; amd64) echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; *) echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; esac exit ;; i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin exit ;; *:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 exit ;; i*:windows32*:*) # uname -m includes "-pc" on this system. echo ${UNAME_MACHINE}-mingw32 exit ;; i*:PW*:*) echo ${UNAME_MACHINE}-pc-pw32 exit ;; *:Interix*:*) case ${UNAME_MACHINE} in x86) echo i586-pc-interix${UNAME_RELEASE} exit ;; authenticamd | genuineintel | EM64T) echo x86_64-unknown-interix${UNAME_RELEASE} exit ;; IA64) echo ia64-unknown-interix${UNAME_RELEASE} exit ;; esac ;; [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) echo i${UNAME_MACHINE}-pc-mks exit ;; 8664:Windows_NT:*) echo x86_64-pc-mks exit ;; i*:Windows_NT*:* | Pentium*:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we # UNAME_MACHINE based on the output of uname instead of i386? echo i586-pc-interix exit ;; i*:UWIN*:*) echo ${UNAME_MACHINE}-pc-uwin exit ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) echo x86_64-unknown-cygwin exit ;; p*:CYGWIN*:*) echo powerpcle-unknown-cygwin exit ;; prep*:SunOS:5.*:*) echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; *:GNU:*:*) # the GNU system echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` exit ;; *:GNU/*:*:*) # other systems with GNU libc and userland echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu exit ;; i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix exit ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; PCA57) UNAME_MACHINE=alphapca56 ;; EV6) UNAME_MACHINE=alphaev6 ;; EV67) UNAME_MACHINE=alphaev67 ;; EV68*) UNAME_MACHINE=alphaev68 ;; esac objdump --private-headers /bin/sh | grep -q ld.so.1 if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} exit ;; arm*:Linux:*:*) eval $set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then echo ${UNAME_MACHINE}-unknown-linux-gnu else echo ${UNAME_MACHINE}-unknown-linux-gnueabi fi exit ;; avr32*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; cris:Linux:*:*) echo cris-axis-linux-gnu exit ;; crisv32:Linux:*:*) echo crisv32-axis-linux-gnu exit ;; frv:Linux:*:*) echo frv-unknown-linux-gnu exit ;; i*86:Linux:*:*) LIBC=gnu eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #ifdef __dietlibc__ LIBC=dietlibc #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'` echo "${UNAME_MACHINE}-pc-linux-${LIBC}" exit ;; ia64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; m32r*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; m68*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; mips:Linux:*:* | mips64:Linux:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #undef CPU #undef ${UNAME_MACHINE} #undef ${UNAME_MACHINE}el #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) CPU=${UNAME_MACHINE}el #else #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) CPU=${UNAME_MACHINE} #else CPU= #endif #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } ;; or32:Linux:*:*) echo or32-unknown-linux-gnu exit ;; padre:Linux:*:*) echo sparc-unknown-linux-gnu exit ;; parisc64:Linux:*:* | hppa64:Linux:*:*) echo hppa64-unknown-linux-gnu exit ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in PA7*) echo hppa1.1-unknown-linux-gnu ;; PA8*) echo hppa2.0-unknown-linux-gnu ;; *) echo hppa-unknown-linux-gnu ;; esac exit ;; ppc64:Linux:*:*) echo powerpc64-unknown-linux-gnu exit ;; ppc:Linux:*:*) echo powerpc-unknown-linux-gnu exit ;; s390:Linux:*:* | s390x:Linux:*:*) echo ${UNAME_MACHINE}-ibm-linux exit ;; sh64*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; sh*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; sparc:Linux:*:* | sparc64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; vax:Linux:*:*) echo ${UNAME_MACHINE}-dec-linux-gnu exit ;; x86_64:Linux:*:*) echo x86_64-unknown-linux-gnu exit ;; xtensa*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both # sysname and nodename. echo i386-sequent-sysv4 exit ;; i*86:UNIX_SV:4.2MP:2.*) # Unixware is an offshoot of SVR4, but it has its own version # number series starting with 2... # I am not positive that other SVR4 systems won't match this, # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} exit ;; i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. echo ${UNAME_MACHINE}-pc-os2-emx exit ;; i*86:XTS-300:*:STOP) echo ${UNAME_MACHINE}-unknown-stop exit ;; i*86:atheos:*:*) echo ${UNAME_MACHINE}-unknown-atheos exit ;; i*86:syllable:*:*) echo ${UNAME_MACHINE}-pc-syllable exit ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) echo i386-unknown-lynxos${UNAME_RELEASE} exit ;; i*86:*DOS:*:*) echo ${UNAME_MACHINE}-pc-msdosdjgpp exit ;; i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} else echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} fi exit ;; i*86:*:5:[678]*) # UnixWare 7.x, OpenUNIX and OpenServer 6. case `/bin/uname -X | grep "^Machine"` in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} exit ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ && UNAME_MACHINE=i586 (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ && UNAME_MACHINE=i686 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ && UNAME_MACHINE=i686 echo ${UNAME_MACHINE}-pc-sco$UNAME_REL else echo ${UNAME_MACHINE}-pc-sysv32 fi exit ;; pc:*:*:*) # Left here for compatibility: # uname -m prints for DJGPP always 'pc', but it prints nothing about # the processor, so we play safe by assuming i586. # Note: whatever this is, it MUST be the same as what config.sub # prints for the "djgpp" host, or else GDB configury will decide that # this is a cross-build. echo i586-pc-msdosdjgpp exit ;; Intel:Mach:3*:*) echo i386-pc-mach3 exit ;; paragon:*:*:*) echo i860-intel-osf1 exit ;; i860:*:4.*:*) # i860-SVR4 if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 fi exit ;; mini*:CTIX:SYS*5:*) # "miniframe" echo m68010-convergent-sysv exit ;; mc68k:UNIX:SYSTEM5:3.51m) echo m68k-convergent-sysv exit ;; M680?0:D-NIX:5.3:*) echo m68k-diab-dnix exit ;; M68*:*:R3V[5678]*:*) test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4; exit; } ;; NCR*:*:4.2:* | MPRAS*:*:4.2:*) OS_REL='.3' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) echo m68k-unknown-lynxos${UNAME_RELEASE} exit ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 exit ;; TSUNAMI:LynxOS:2.*:*) echo sparc-unknown-lynxos${UNAME_RELEASE} exit ;; rs6000:LynxOS:2.*:*) echo rs6000-unknown-lynxos${UNAME_RELEASE} exit ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) echo powerpc-unknown-lynxos${UNAME_RELEASE} exit ;; SM[BE]S:UNIX_SV:*:*) echo mips-dde-sysv${UNAME_RELEASE} exit ;; RM*:ReliantUNIX-*:*:*) echo mips-sni-sysv4 exit ;; RM*:SINIX-*:*:*) echo mips-sni-sysv4 exit ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=`(uname -p) 2>/dev/null` echo ${UNAME_MACHINE}-sni-sysv4 else echo ns32k-sni-sysv fi exit ;; PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort # says echo i586-unisys-sysv4 exit ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm echo hppa1.1-stratus-sysv4 exit ;; *:*:*:FTX*) # From seanf@swdc.stratus.com. echo i860-stratus-sysv4 exit ;; i*86:VOS:*:*) # From Paul.Green@stratus.com. echo ${UNAME_MACHINE}-stratus-vos exit ;; *:VOS:*:*) # From Paul.Green@stratus.com. echo hppa1.1-stratus-vos exit ;; mc68*:A/UX:*:*) echo m68k-apple-aux${UNAME_RELEASE} exit ;; news*:NEWS-OS:6*:*) echo mips-sony-newsos6 exit ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if [ -d /usr/nec ]; then echo mips-nec-sysv${UNAME_RELEASE} else echo mips-unknown-sysv${UNAME_RELEASE} fi exit ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. echo powerpc-be-beos exit ;; BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. echo powerpc-apple-beos exit ;; BePC:BeOS:*:*) # BeOS running on Intel PC compatible. echo i586-pc-beos exit ;; BePC:Haiku:*:*) # Haiku running on Intel PC compatible. echo i586-pc-haiku exit ;; SX-4:SUPER-UX:*:*) echo sx4-nec-superux${UNAME_RELEASE} exit ;; SX-5:SUPER-UX:*:*) echo sx5-nec-superux${UNAME_RELEASE} exit ;; SX-6:SUPER-UX:*:*) echo sx6-nec-superux${UNAME_RELEASE} exit ;; SX-7:SUPER-UX:*:*) echo sx7-nec-superux${UNAME_RELEASE} exit ;; SX-8:SUPER-UX:*:*) echo sx8-nec-superux${UNAME_RELEASE} exit ;; SX-8R:SUPER-UX:*:*) echo sx8r-nec-superux${UNAME_RELEASE} exit ;; Power*:Rhapsody:*:*) echo powerpc-apple-rhapsody${UNAME_RELEASE} exit ;; *:Rhapsody:*:*) echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} exit ;; *:Darwin:*:*) UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown case $UNAME_PROCESSOR in i386) eval $set_cc_for_build if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then UNAME_PROCESSOR="x86_64" fi fi ;; unknown) UNAME_PROCESSOR=powerpc ;; esac echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` if test "$UNAME_PROCESSOR" = "x86"; then UNAME_PROCESSOR=i386 UNAME_MACHINE=pc fi echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} exit ;; *:QNX:*:4*) echo i386-pc-qnx exit ;; NSE-?:NONSTOP_KERNEL:*:*) echo nse-tandem-nsk${UNAME_RELEASE} exit ;; NSR-?:NONSTOP_KERNEL:*:*) echo nsr-tandem-nsk${UNAME_RELEASE} exit ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux exit ;; BS2000:POSIX*:*:*) echo bs2000-siemens-sysv exit ;; DS/*:UNIX_System_V:*:*) echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} exit ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 # operating systems. if test "$cputype" = "386"; then UNAME_MACHINE=i386 else UNAME_MACHINE="$cputype" fi echo ${UNAME_MACHINE}-unknown-plan9 exit ;; *:TOPS-10:*:*) echo pdp10-unknown-tops10 exit ;; *:TENEX:*:*) echo pdp10-unknown-tenex exit ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) echo pdp10-dec-tops20 exit ;; XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) echo pdp10-xkl-tops20 exit ;; *:TOPS-20:*:*) echo pdp10-unknown-tops20 exit ;; *:ITS:*:*) echo pdp10-unknown-its exit ;; SEI:*:*:SEIUX) echo mips-sei-seiux${UNAME_RELEASE} exit ;; *:DragonFly:*:*) echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` exit ;; *:*VMS:*:*) UNAME_MACHINE=`(uname -p) 2>/dev/null` case "${UNAME_MACHINE}" in A*) echo alpha-dec-vms ; exit ;; I*) echo ia64-dec-vms ; exit ;; V*) echo vax-dec-vms ; exit ;; esac ;; *:XENIX:*:SysV) echo i386-pc-xenix exit ;; i*86:skyos:*:*) echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' exit ;; i*86:rdos:*:*) echo ${UNAME_MACHINE}-pc-rdos exit ;; i*86:AROS:*:*) echo ${UNAME_MACHINE}-pc-aros exit ;; esac #echo '(No uname command or uname output not recognized.)' 1>&2 #echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 eval $set_cc_for_build cat >$dummy.c < # include #endif main () { #if defined (sony) #if defined (MIPSEB) /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, I don't know.... */ printf ("mips-sony-bsd\n"); exit (0); #else #include printf ("m68k-sony-newsos%s\n", #ifdef NEWSOS4 "4" #else "" #endif ); exit (0); #endif #endif #if defined (__arm) && defined (__acorn) && defined (__unix) printf ("arm-acorn-riscix\n"); exit (0); #endif #if defined (hp300) && !defined (hpux) printf ("m68k-hp-bsd\n"); exit (0); #endif #if defined (NeXT) #if !defined (__ARCHITECTURE__) #define __ARCHITECTURE__ "m68k" #endif int version; version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; if (version < 4) printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); else printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); exit (0); #endif #if defined (MULTIMAX) || defined (n16) #if defined (UMAXV) printf ("ns32k-encore-sysv\n"); exit (0); #else #if defined (CMU) printf ("ns32k-encore-mach\n"); exit (0); #else printf ("ns32k-encore-bsd\n"); exit (0); #endif #endif #endif #if defined (__386BSD__) printf ("i386-pc-bsd\n"); exit (0); #endif #if defined (sequent) #if defined (i386) printf ("i386-sequent-dynix\n"); exit (0); #endif #if defined (ns32000) printf ("ns32k-sequent-dynix\n"); exit (0); #endif #endif #if defined (_SEQUENT_) struct utsname un; uname(&un); if (strncmp(un.version, "V2", 2) == 0) { printf ("i386-sequent-ptx2\n"); exit (0); } if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ printf ("i386-sequent-ptx1\n"); exit (0); } printf ("i386-sequent-ptx\n"); exit (0); #endif #if defined (vax) # if !defined (ultrix) # include # if defined (BSD) # if BSD == 43 printf ("vax-dec-bsd4.3\n"); exit (0); # else # if BSD == 199006 printf ("vax-dec-bsd4.3reno\n"); exit (0); # else printf ("vax-dec-bsd\n"); exit (0); # endif # endif # else printf ("vax-dec-bsd\n"); exit (0); # endif # else printf ("vax-dec-ultrix\n"); exit (0); # endif #endif #if defined (alliant) && defined (i860) printf ("i860-alliant-bsd\n"); exit (0); #endif exit (1); } EOF $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && { echo "$SYSTEM_NAME"; exit; } # Apollos put the system type in the environment. test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } # Convex versions that predate uname can use getsysinfo(1) if [ -x /usr/convex/getsysinfo ] then case `getsysinfo -f cpu_type` in c1*) echo c1-convex-bsd exit ;; c2*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi exit ;; c34*) echo c34-convex-bsd exit ;; c38*) echo c38-convex-bsd exit ;; c4*) echo c4-convex-bsd exit ;; esac fi cat >&2 < in order to provide the needed information to handle your system. config.guess timestamp = $timestamp uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` /bin/uname -X = `(/bin/uname -X) 2>/dev/null` hostinfo = `(hostinfo) 2>/dev/null` /bin/universe = `(/bin/universe) 2>/dev/null` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` /bin/arch = `(/bin/arch) 2>/dev/null` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` UNAME_MACHINE = ${UNAME_MACHINE} UNAME_RELEASE = ${UNAME_RELEASE} UNAME_SYSTEM = ${UNAME_SYSTEM} UNAME_VERSION = ${UNAME_VERSION} EOF exit 1 # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: libnih-1.0.3/nih-dbus-tool/0000755000175000017500000000000011504742363012452 500000000000000libnih-1.0.3/nih-dbus-tool/demarshal.c0000644000175000017500000010772711445765555014530 00000000000000/* nih-dbus-tool * * demarshal.c - type demarshalling * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include "indent.h" #include "symbol.h" #include "type.h" #include "demarshal.h" /* Prototypes for static functions */ static char *demarshal_basic (const void *parent, DBusSignatureIter *iter, const char *parent_name, const char *iter_name, const char *name, const char *oom_error_code, const char *type_error_code, NihList *outputs, NihList *locals, const char *prefix, const char *interface_symbol, const char *member_symbol, const char *symbol, NihList *structs) __attribute__ ((warn_unused_result, malloc)); static char *demarshal_array (const void *parent, DBusSignatureIter *iter, const char *parent_name, const char *iter_name, const char *name, const char *oom_error_code, const char *type_error_code, NihList *outputs, NihList *locals, const char *prefix, const char *interface_symbol, const char *member_symbol, const char *symbol, NihList *structs) __attribute__ ((warn_unused_result, malloc)); static char *demarshal_struct (const void *parent, DBusSignatureIter *iter, const char *parent_name, const char *iter_name, const char *name, const char *oom_error_code, const char *type_error_code, NihList *outputs, NihList *locals, const char *prefix, const char *interface_symbol, const char *member_symbol, const char *symbol, NihList *structs) __attribute__ ((warn_unused_result, malloc)); /** * demarshal: * @parent: parent object for new string, * @signature: signature of type, * @parent_name: name of parent variable, * @iter_name: name of iterator variable, * @name: name of variable, * @oom_error_code: code to execute on OOM Error, * @type_error_code: code to exectute on type error, * @outputs: list to append output variables to, * @locals: list to append local variables to, * @interface_symbol: symbol of interface for structure names, * @member_symbol: symbol of interface member for structure names, * @symbol: symbol of argument or variable for structure names, * @structs: list to append structure definitions to. * * Generates C code to demarshal any D-Bus type from the D-Bus iterator * variable named @iter_name into an appropriately typed variable named * @name. * * The type should be the current element of the signature iterator @iter. * This then simply calls demarshal_fixed(), demarshal_string(), * demarshal_fixed_array(), demarshal_flexible_array() or demarshal_struct() * as appropriate. * * The generated code detects out-of-memory conditions but does not know * how to handle them, therefore you need to pass the appropriate handling * code in @oom_error_code. This code will be inserted wherever an OOM * condition is detected. * * Likewise the code detects an invalid type in the iterator, but requires * that you pass the appropriate handling code in @type_error_code. * * The expected output variable types and names are given as TypeVar objects * appended to the @outputs list, each name is guaranteed to begin with @name * and the first member will always be @name itself. Should the C code * require local variables, similar TypeVar objects will be appended to * the @locals list. * * If the variable requires a structure to be defined, the definition is * returned as a TypeStruct object appended to the @structs list. The name * is generated from @prefix, @interface_symbol, @member_symbol and @symbol. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Demarshalling may require that memory is allocated, the parent object * is the variable named in @parent_name which may of course be "NULL". * * Returns: newly allocated string or NULL if insufficient memory. **/ char * demarshal (const void * parent, DBusSignatureIter *iter, const char * parent_name, const char * iter_name, const char * name, const char * oom_error_code, const char * type_error_code, NihList * outputs, NihList * locals, const char * prefix, const char * interface_symbol, const char * member_symbol, const char * symbol, NihList * structs) { int dbus_type; nih_assert (iter != NULL); nih_assert (parent_name != NULL); nih_assert (iter_name != NULL); nih_assert (name != NULL); nih_assert (oom_error_code != NULL); nih_assert (type_error_code != NULL); nih_assert (outputs != NULL); nih_assert (locals != NULL); nih_assert (prefix != NULL); nih_assert (member_symbol != NULL); nih_assert (structs != NULL); dbus_type = dbus_signature_iter_get_current_type (iter); if (dbus_type_is_basic (dbus_type)) { return demarshal_basic (parent, iter, parent_name, iter_name, name, oom_error_code, type_error_code, outputs, locals, prefix, interface_symbol, member_symbol, symbol, structs); } else if (dbus_type == DBUS_TYPE_ARRAY) { return demarshal_array (parent, iter, parent_name, iter_name, name, oom_error_code, type_error_code, outputs, locals, prefix, interface_symbol, member_symbol, symbol, structs); } else if ((dbus_type == DBUS_TYPE_STRUCT) || (dbus_type == DBUS_TYPE_DICT_ENTRY)) { return demarshal_struct (parent, iter, parent_name, iter_name, name, oom_error_code, type_error_code, outputs, locals, prefix, interface_symbol, member_symbol, symbol, structs); } else { nih_assert_not_reached (); } } /** * demarshal_basic: * @parent: parent object for new string, * @iter: D-Bus signature iterator, * @parent_name: name of parent variable, * @name: name of variable, * @oom_error_code: code to execute on OOM Error, * @type_error_code: code to exectute on type error, * @outputs: list to append output variables to, * @locals: list to append local variables to, * @interface_symbol: symbol of interface for structure names, * @member_symbol: symbol of interface member for structure names, * @symbol: symbol of argument or variable for structure names, * @structs: list to append structure definitions to. * * Generates C code to demarshal a D-Bus basic type (ie. numerics and * strings) from the D-Bus iterator variable named @iter_name into an * appropriately typed variable pointer named @name. * * The type should be the current element of the signature iterator @iter. * * The generated code detects out-of-memory conditions but does not know * how to handle them, therefore you need to pass the appropriate handling * code in @oom_error_code. This code will be inserted wherever an OOM * condition is detected. * * Likewise the code detects an invalid type in the iterator, but requires * that you pass the appropriate handling code in @type_error_code. * * The expected output variable types and names are given as TypeVar objects * appended to the @outputs list, each name is guaranteed to begin with @name * and the first member will always be @name itself. Should the C code * require local variables, similar TypeVar objects will be appended to * the @locals list. * * If the variable requires a structure to be defined, the definition is * returned as a TypeStruct object appended to the @structs list. The name * is generated from @prefix, @interface_symbol, @member_symbol and @symbol. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Demarshalling may require that memory is allocated, the parent object * is the variable named in @parent_name which may of course be "NULL". * * Returns: newly allocated string or NULL if insufficient memory. **/ static char * demarshal_basic (const void * parent, DBusSignatureIter *iter, const char * parent_name, const char * iter_name, const char * name, const char * oom_error_code, const char * type_error_code, NihList * outputs, NihList * locals, const char * prefix, const char * interface_symbol, const char * member_symbol, const char * symbol, NihList * structs) { int dbus_type; const char * dbus_const; nih_local char *oom_error_block = NULL; nih_local char *type_error_block = NULL; nih_local char *c_type = NULL; char * code = NULL; TypeVar * var; nih_assert (iter != NULL); nih_assert (parent_name != NULL); nih_assert (iter_name != NULL); nih_assert (name != NULL); nih_assert (oom_error_code != NULL); nih_assert (type_error_code != NULL); nih_assert (outputs != NULL); nih_assert (locals != NULL); nih_assert (prefix != NULL); nih_assert (member_symbol != NULL); nih_assert (structs != NULL); dbus_type = dbus_signature_iter_get_current_type (iter); dbus_const = type_const (dbus_type); oom_error_block = nih_strdup (NULL, oom_error_code); if (! oom_error_block) return NULL; if (! indent (&oom_error_block, NULL, 1)) return NULL; type_error_block = nih_strdup (NULL, type_error_code); if (! type_error_block) return NULL; if (! indent (&type_error_block, NULL, 1)) return NULL; c_type = type_of (NULL, iter); if (! c_type) return NULL; if (! nih_strcat_sprintf (&code, parent, "/* Demarshal a %s from the message */\n" "if (dbus_message_iter_get_arg_type (&%s) != %s) {\n" "%s" "}\n" "\n", c_type, iter_name, dbus_const, type_error_block)) return NULL; if (dbus_type_is_fixed (dbus_type)) { if (! nih_strcat_sprintf (&code, parent, "dbus_message_iter_get_basic (&%s, &%s);\n" "\n", iter_name, name)) { nih_free (code); return NULL; } } else { nih_local char *local_name = NULL; nih_local char *local_type = NULL; /* We need a local variable to store the const value we get * from D-Bus before we allocate the copy that we return. */ local_name = nih_sprintf (NULL, "%s_dbus", name); if (! local_name) { nih_free (code); return NULL; } local_type = nih_strdup (NULL, c_type); if (! local_type) { nih_free (code); return NULL; } if (! type_to_const (&local_type, NULL)) { nih_free (code); return NULL; } if (! nih_strcat_sprintf (&code, parent, "dbus_message_iter_get_basic (&%s, &%s);\n" "\n" "%s = nih_strdup (%s, %s);\n" "if (! %s) {\n" "%s" "}\n" "\n", iter_name, local_name, name, parent_name, local_name, name, oom_error_block)) { nih_free (code); return NULL; } var = type_var_new (code, local_type, local_name); if (! var) { nih_free (code); return NULL; } nih_list_add (locals, &var->entry); } if (! nih_strcat_sprintf (&code, parent, "dbus_message_iter_next (&%s);\n", iter_name)) { nih_free (code); return NULL; } /* Append our required output variable */ var = type_var_new (code, c_type, name); if (! var) { nih_free (code); return NULL; } nih_list_add (outputs, &var->entry); return code; } /** * demarshal_array: * @parent: parent object for new string, * @iter: D-Bus signature iterator, * @parent_name: name of parent variable, * @name: name of variable, * @oom_error_code: code to execute on OOM Error, * @type_error_code: code to exectute on type error, * @outputs: list to append output variables to, * @locals: list to append local variables to, * @interface_symbol: symbol of interface for structure names, * @member_symbol: symbol of interface member for structure names, * @symbol: symbol of argument or variable for structure names, * @structs: list to append structure definitions to. * * Generates C code to demarshal a D-Bus array type from the D-Bus * iterator variable named @iter_name into an appropriately typed, * NULL-terminated, array variable pointer named @name. In the case * of arrays (of any number of levels) ultimately to a fixed type, an * additional input named "@name"_len is required of size_t type or an * appropriate number of pointers to it. * * The type should be the current element of the signature iterator @iter. * * The generated code detects out-of-memory conditions but does not know * how to handle them, therefore you need to pass the appropriate handling * code in @oom_error_code. This code will be inserted wherever an OOM * condition is detected. * * Likewise the code detects an invalid type in the iterator, but requires * that you pass the appropriate handling code in @type_error_code. * * The expected output variable types and names are given as TypeVar objects * appended to the @outputs list, each name is guaranteed to begin with @name * and the first member will always be @name itself. Should the C code * require local variables, similar TypeVar objects will be appended to * the @locals list. * * If the variable requires a structure to be defined, the definition is * returned as a TypeStruct object appended to the @structs list. The name * is generated from @prefix, @interface_symbol, @member_symbol and @symbol. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Demarshalling may require that memory is allocated, the parent object * is the variable named in @parent_name which may of course be "NULL". * * Returns: newly allocated string or NULL if insufficient memory. **/ static char * demarshal_array (const void * parent, DBusSignatureIter *iter, const char * parent_name, const char * iter_name, const char * name, const char * oom_error_code, const char * type_error_code, NihList * outputs, NihList * locals, const char * prefix, const char * interface_symbol, const char * member_symbol, const char * symbol, NihList * structs) { nih_local char * array_iter_name = NULL; nih_local char * element_name = NULL; nih_local char * element_symbol = NULL; nih_local char * size_name = NULL; nih_local char * oom_error_block = NULL; nih_local char * child_oom_error_code = NULL; nih_local char * child_oom_error_block = NULL; nih_local char * type_error_block = NULL; nih_local char * child_type_error_code = NULL; nih_local char * child_type_error_block = NULL; DBusSignatureIter subiter; int element_type; char * code = NULL; TypeVar * array_iter_var; TypeVar * size_var; NihList element_outputs; NihList element_locals; NihList element_structs; nih_local char * element_block = NULL; nih_local char * alloc_block = NULL; nih_local char * block = NULL; nih_local char * vars_block = NULL; nih_assert (iter != NULL); nih_assert (parent_name != NULL); nih_assert (iter_name != NULL); nih_assert (name != NULL); nih_assert (oom_error_code != NULL); nih_assert (outputs != NULL); nih_assert (locals != NULL); nih_assert (prefix != NULL); nih_assert (member_symbol != NULL); nih_assert (structs != NULL); dbus_signature_iter_recurse (iter, &subiter); element_type = dbus_signature_iter_get_current_type (&subiter); array_iter_name = nih_sprintf (NULL, "%s_iter", name); if (! array_iter_name) return NULL; element_name = nih_sprintf (NULL, "%s_element", name); if (! element_name) return NULL; element_symbol = (symbol ? nih_sprintf (NULL, "%s_element", symbol) : nih_strdup (NULL, "element")); if (! element_symbol) return NULL; if (dbus_type_is_fixed (element_type)) { size_name = nih_sprintf (NULL, "%s_len", name); if (! size_name) return NULL; } else { size_name = nih_sprintf (NULL, "%s_size", name); if (! size_name) return NULL; } oom_error_block = nih_strdup (NULL, oom_error_code); if (! oom_error_block) return NULL; if (! indent (&oom_error_block, NULL, 1)) return NULL; child_oom_error_code = nih_sprintf (NULL, ("if (%s)\n" "\tnih_free (%s);\n" "%s"), name, name, oom_error_code); if (! child_oom_error_code) return NULL; child_oom_error_block = nih_strdup (NULL, child_oom_error_code); if (! child_oom_error_block) return NULL; if (! indent (&child_oom_error_block, NULL, 1)) return NULL; type_error_block = nih_strdup (NULL, type_error_code); if (! type_error_block) return NULL; if (! indent (&type_error_block, NULL, 1)) return NULL; child_type_error_code = nih_sprintf (NULL, ("if (%s)\n" "\tnih_free (%s);\n" "%s"), name, name, type_error_code); if (! child_type_error_code) return NULL; child_type_error_block = nih_strdup (NULL, child_type_error_code); if (! child_type_error_block) return NULL; if (! indent (&child_type_error_block, NULL, 1)) return NULL; /* Recurse into the array */ if (! nih_strcat_sprintf (&code, parent, "/* Demarshal an array from the message */\n" "if (dbus_message_iter_get_arg_type (&%s) != DBUS_TYPE_ARRAY) {\n" "%s" "}\n" "\n" "dbus_message_iter_recurse (&%s, &%s);\n" "\n", iter_name, type_error_block, iter_name, array_iter_name)) return NULL; array_iter_var = type_var_new (code, "DBusMessageIter", array_iter_name); if (! array_iter_var) { nih_free (code); return NULL; } nih_list_add (locals, &array_iter_var->entry); /* We need a variable to keep track of the array sizes for * allocation; for fixed types, this is an output but for non-fixed * types it's a local. */ size_var = type_var_new (code, "size_t", size_name); if (! size_var) { nih_free (code); return NULL; } if (! dbus_type_is_fixed (element_type)) nih_list_add (locals, &size_var->entry); if (! nih_strcat_sprintf (&code, parent, "%s = 0;\n", size_name)) { nih_free (code); return NULL; } /* Get the code that will demarshal the individual elements, and * any output and local variables it needs. */ nih_list_init (&element_outputs); nih_list_init (&element_locals); nih_list_init (&element_structs); element_block = demarshal (NULL, &subiter, name, array_iter_name, element_name, child_oom_error_code, child_type_error_code, &element_outputs, &element_locals, prefix, interface_symbol, member_symbol, element_symbol, &element_structs); if (! element_block) { nih_free (code); return NULL; } /* Each of the outputs of the demarshalling code equates to one * of our own outputs, except that we add another level of pointers * for the array; at the same time, we keep the suffix and append * it to our own name. * * Since the outputs are all arrays, they need to be initialised * or allocated before demarshalling begins. Those of fixed types * simply need to be set to NULL, those of pointer types need * to be allocated with a single element containing the terminating * NULL pointer. * * Instead of mucking around with pointers and structure members, * we also append the outputs onto the local lists and fill in our * variable from this. */ NIH_LIST_FOREACH_SAFE (&element_outputs, iter) { TypeVar * output_var = (TypeVar *)iter; char * ptr; nih_local char *var_type = NULL; const char * suffix; nih_local char *var_name = NULL; TypeVar * var; nih_local char *tmp_name = NULL; const char * var_parent; /* Output variable */ var_type = nih_strdup (NULL, output_var->type); if (! var_type) { nih_free (code); return NULL; } if (! type_to_pointer (&var_type, NULL)) { nih_free (code); return NULL; } nih_assert (! strncmp (output_var->name, element_name, strlen (element_name))); suffix = output_var->name + strlen (element_name); var_name = nih_sprintf (NULL, "%s%s", name, suffix); if (! var_name) { nih_free (code); return NULL; } var = type_var_new (code, var_type, var_name); if (! var) { nih_free (code); return NULL; } nih_list_add (outputs, &var->entry); /* For array reallocation we need yet another variable to * capture the output and make sure it didn't fail, we could * just cheat and use void * but instead we use the proper * type which is the same as the output variable. */ tmp_name = nih_sprintf (NULL, "%s_tmp", var_name); if (! tmp_name) { nih_free (code); return NULL; } var = type_var_new (element_block, var_type, tmp_name); if (! var) { nih_free (code); return NULL; } nih_list_add (&element_locals, &var->entry); /* Code to allocate and reallocate */ var_parent = (*suffix ? name : parent_name); if (! nih_strcat_sprintf (&code, parent, "%s = NULL;\n", var_name)) { nih_free (code); return NULL; } ptr = output_var->type + strlen (output_var->type) - 1; if (*ptr != '*') { if (! nih_strcat_sprintf (&block, NULL, "if (%s + 1 > SIZE_MAX / sizeof (%s)) {\n" "%s" "}\n" "\n" "%s = nih_realloc (%s, %s, sizeof (%s) * (%s + 1));\n" "if (! %s) {\n" "%s" "}\n" "\n" "%s = %s;\n" "%s[%s] = %s;\n" "\n", size_name, output_var->type, child_type_error_block, tmp_name, var_name, var_parent, output_var->type, size_name, tmp_name, child_oom_error_block, var_name, tmp_name, var_name, size_name, output_var->name)) { nih_free (code); return NULL; } } else { if (! nih_strcat_sprintf (&alloc_block, NULL, "%s = nih_alloc (%s, sizeof (%s));\n" "if (! %s) {\n" "%s" "}\n" "\n" "%s[%s] = NULL;\n" "\n", var_name, var_parent, output_var->type, var_name, (*suffix ? child_oom_error_block : oom_error_block), var_name, size_name)) { nih_free (code); return NULL; } if (! nih_strcat_sprintf (&block, NULL, "if (%s + 2 > SIZE_MAX / sizeof (%s)) {\n" "%s" "}\n" "\n" "%s = nih_realloc (%s, %s, sizeof (%s) * (%s + 2));\n" "if (! %s) {\n" "%s" "}\n" "\n" "%s = %s;\n" "%s[%s] = %s;\n" "%s[%s + 1] = NULL;\n" "\n", size_name, output_var->type, child_type_error_block, tmp_name, var_name, var_parent, output_var->type, size_name, tmp_name, child_oom_error_block, var_name, tmp_name, var_name, size_name, output_var->name, var_name, size_name)) { nih_free (code); return NULL; } } nih_list_add (&element_locals, &output_var->entry); } if (! nih_strcat_sprintf (&code, parent, "\n" "%s", alloc_block ?: "")) { nih_free (code); return NULL; } if (! nih_strcat_sprintf (&block, parent, "%s++;\n", size_name)) { nih_free (code); return NULL; } vars_block = type_var_layout (NULL, &element_locals); if (! vars_block) { nih_free (code); return NULL; } NIH_LIST_FOREACH_SAFE (&element_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } /* Iterate over the incoming message */ if (! nih_strcat_sprintf (&code, parent, "while (dbus_message_iter_get_arg_type (&%s) != DBUS_TYPE_INVALID) {\n", array_iter_name)) { nih_free (code); return NULL; } /* Lay all that out in an indented block inside the while loop. * Make sure that we increase the size of the array as we go, * which varies depending on whether we are using a fixed type or * not. */ if (! indent (&vars_block, NULL, 1)) { nih_free (code); return NULL; } if (! indent (&element_block, NULL, 1)) { nih_free (code); return NULL; } if (! indent (&block, NULL, 1)) { nih_free (code); return NULL; } if (! nih_strcat_sprintf (&code, parent, "%s" "\n" "%s" "\n" "%s", vars_block, element_block, block)) { nih_free (code); return NULL; } /* Finish off the iteration and move onto the next message item */ if (! nih_strcat_sprintf (&code, parent, "}\n" "\n" "dbus_message_iter_next (&%s);\n", iter_name)) { nih_free (code); return NULL; } if (dbus_type_is_fixed (element_type)) nih_list_add (outputs, &size_var->entry); return code; } /** * demarshal_struct: * @parent: parent object for new string, * @iter: D-Bus signature iterator, * @parent_name: name of parent variable, * @name: name of variable, * @oom_error_code: code to execute on OOM Error, * @type_error_code: code to exectute on type error, * @outputs: list to append output variables to, * @locals: list to append local variables to, * @interface_symbol: symbol of interface for structure names, * @member_symbol: symbol of interface member for structure names, * @symbol: symbol of argument or variable for structure names, * @structs: list to append structure definitions to. * * Generates C code to demarshal a D-Bus structure type, and its members, * from the D-Bus iterator variable named @iter_name into an appropriately * typed variable pointer named @name. * * The type should be the current element of the signature iterator @iter. * * The generated code detects out-of-memory conditions but does not know * how to handle them, therefore you need to pass the appropriate handling * code in @oom_error_code. This code will be inserted wherever an OOM * condition is detected. * * Likewise the code detects an invalid type in the iterator, but requires * that you pass the appropriate handling code in @type_error_code. * * The expected output variable types and names are given as TypeVar objects * appended to the @outputs list, each name is guaranteed to begin with @name * and the first member will always be @name itself. Should the C code * require local variables, similar TypeVar objects will be appended to * the @locals list. * * If the variable requires a structure to be defined, the definition is * returned as a TypeStruct object appended to the @structs list. The name * is generated from @prefix, @interface_symbol, @member_symbol and @symbol. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Demarshalling may require that memory is allocated, the parent object * is the variable named in @parent_name which may of course be "NULL". * * Returns: newly allocated string or NULL if insufficient memory. **/ static char * demarshal_struct (const void * parent, DBusSignatureIter *iter, const char * parent_name, const char * iter_name, const char * name, const char * oom_error_code, const char * type_error_code, NihList * outputs, NihList * locals, const char * prefix, const char * interface_symbol, const char * member_symbol, const char * symbol, NihList * structs) { nih_local char * struct_iter_name = NULL; nih_local char * oom_error_block = NULL; nih_local char * child_oom_error_code = NULL; nih_local char * child_oom_error_block = NULL; nih_local char * type_error_block = NULL; nih_local char * child_type_error_code = NULL; nih_local char * child_type_error_block = NULL; int dbus_type; const char * dbus_const; DBusSignatureIter subiter; char * code = NULL; TypeVar * struct_iter_var; nih_local char * c_type = NULL; nih_local char * alloc_type = NULL; TypeStruct * structure; size_t count = 0; TypeVar * var; nih_assert (iter != NULL); nih_assert (parent_name != NULL); nih_assert (iter_name != NULL); nih_assert (name != NULL); nih_assert (oom_error_code != NULL); nih_assert (type_error_code != NULL); nih_assert (outputs != NULL); nih_assert (locals != NULL); nih_assert (prefix != NULL); nih_assert (member_symbol != NULL); nih_assert (structs != NULL); struct_iter_name = nih_sprintf (NULL, "%s_iter", name); if (! struct_iter_name) return NULL; oom_error_block = nih_strdup (NULL, oom_error_code); if (! oom_error_block) return NULL; if (! indent (&oom_error_block, NULL, 1)) return NULL; child_oom_error_code = nih_sprintf (NULL, ("nih_free (%s);\n" "%s"), name, oom_error_code); if (! child_oom_error_code) return NULL; child_oom_error_block = nih_strdup (NULL, child_oom_error_code); if (! child_oom_error_block) return NULL; if (! indent (&child_oom_error_block, NULL, 1)) return NULL; type_error_block = nih_strdup (NULL, type_error_code); if (! type_error_block) return NULL; if (! indent (&type_error_block, NULL, 1)) return NULL; child_type_error_code = nih_sprintf (NULL, ("nih_free (%s);\n" "%s"), name, type_error_code); if (! child_type_error_code) return NULL; child_type_error_block = nih_strdup (NULL, child_type_error_code); if (! child_type_error_block) return NULL; if (! indent (&child_type_error_block, NULL, 1)) return NULL; /* Open the struct container, for that we need to know whether this * is a struct or a dictionary entry even through we handled the two * identically. We'll obviously need a local variable for the * recursed iterator. */ dbus_type = dbus_signature_iter_get_current_type (iter); dbus_const = type_const (dbus_type); dbus_signature_iter_recurse (iter, &subiter); if (! nih_strcat_sprintf (&code, parent, "/* Demarshal a structure from the message */\n" "if (dbus_message_iter_get_arg_type (&%s) != %s) {\n" "%s" "}\n" "\n" "dbus_message_iter_recurse (&%s, &%s);\n" "\n", iter_name, dbus_const, type_error_block, iter_name, struct_iter_name)) return NULL; struct_iter_var = type_var_new (code, "DBusMessageIter", struct_iter_name); if (! struct_iter_var) { nih_free (code); return NULL; } nih_list_add (locals, &struct_iter_var->entry); /* FIXME there should be a way to override this to a different type * name by annotation. */ alloc_type = symbol_typedef (NULL, prefix, interface_symbol, NULL, member_symbol, symbol); if (! alloc_type) { nih_free (code); return NULL; } c_type = nih_strdup (NULL, alloc_type); if (! c_type) { nih_free (code); return NULL; } structure = type_struct_new (code, c_type); if (! structure) { nih_free (code); return NULL; } nih_list_add (structs, &structure->entry); if (! type_to_pointer (&c_type, NULL)) { nih_free (code); return NULL; } /* Allocate the new structure */ if (! nih_strcat_sprintf (&code, parent, "%s = nih_new (%s, %s);\n" "if (! %s) {\n" "%s" "}\n" "\n", name, parent_name, alloc_type, name, oom_error_block)) { nih_free (code); return NULL; } /* Deal with each structure element individually, however we have * to end up with just one set of locals and one block so we * append directly onto our locals. */ do { nih_local char *item_member = NULL; nih_local char *item_name = NULL; nih_local char *item_symbol = NULL; NihList item_outputs; NihList item_locals; NihList item_structs; nih_local char *item_code = NULL; /* FIXME there should be a way to override the item names * via an annotation, which would also show up in the * structure definition itself. */ item_member = nih_sprintf (NULL, "item%zu", count); if (! item_member) { nih_free (code); return NULL; } item_name = nih_sprintf (NULL, "%s_%s", name, item_member); if (! item_name) { nih_free (code); return NULL; } item_symbol = (symbol ? nih_sprintf (NULL, "%s_%s", symbol, item_member) : nih_strdup (NULL, item_member)); if (! item_symbol) { nih_free (code); return NULL; } /* Get the code to do the demarshalling of this item */ nih_list_init (&item_outputs); nih_list_init (&item_locals); nih_list_init (&item_structs); item_code = demarshal (NULL, &subiter, name, struct_iter_name, item_name, child_oom_error_code, child_type_error_code, &item_outputs, &item_locals, prefix, interface_symbol, member_symbol, item_symbol, &item_structs); if (! item_code) { nih_free (code); return NULL; } /* Append the item locals onto our locals list, we have * to reference these as we go. */ NIH_LIST_FOREACH_SAFE (&item_locals, iter) { TypeVar *item_local_var = (TypeVar *)iter; nih_list_add (locals, &item_local_var->entry); nih_ref (item_local_var, code); } /* Append item demarshalling code block */ if (! nih_strcat_sprintf (&code, parent, "%s" "\n", item_code)) { nih_free (code); return NULL; } /* Instead of mucking around with pointers and structure * members, each of the marshalling code outputs is appended * onto the local list and we copy from the local into * our output variable. */ NIH_LIST_FOREACH_SAFE (&item_outputs, iter) { TypeVar * output_var = (TypeVar *)iter; char * suffix; nih_local char *member_name = NULL; TypeVar * member_var; nih_assert (! strncmp (output_var->name, item_name, strlen (item_name))); suffix = output_var->name + strlen (item_name); /* Create the structure member entry */ member_name = nih_sprintf (NULL, "%s%s", item_member, suffix); if (! member_name) { nih_free (code); return NULL; } member_var = type_var_new (structure, output_var->type, member_name); if (! member_var) { nih_free (code); return NULL; } nih_list_add (&structure->members, &member_var->entry); /* Add code to copy from local variable */ if (! nih_strcat_sprintf (&code, parent, "%s->%s = %s;\n", name, member_name, output_var->name)) { nih_free (code); return NULL; } /* Add to locals */ nih_list_add (locals, &output_var->entry); nih_ref (output_var, code); } NIH_LIST_FOREACH_SAFE (&item_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } if (! nih_strcat (&code, parent, "\n")) { nih_free (code); return NULL; } nih_assert (++count > 0); } while (dbus_signature_iter_next (&subiter)); /* Close the container again */ if (! nih_strcat_sprintf (&code, parent, "if (dbus_message_iter_get_arg_type (&%s) != DBUS_TYPE_INVALID) {\n" "%s" "}\n" "\n" "dbus_message_iter_next (&%s);\n", struct_iter_name, child_type_error_block, iter_name)) { nih_free (code); return NULL; } /* Append our required output variable */ var = type_var_new (code, c_type, name); if (! var) { nih_free (code); return NULL; } nih_list_add (outputs, &var->entry); return code; } libnih-1.0.3/nih-dbus-tool/parse.h0000644000175000017500000000551011445765555013672 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_PARSE_H #define NIH_DBUS_TOOL_PARSE_H #include #include #include "node.h" #include "interface.h" #include "method.h" #include "signal.h" #include "property.h" #include "argument.h" /** * ParseStackType: * * Type of parsed object on the stack. **/ typedef enum parse_stack_type { PARSE_IGNORED, PARSE_NODE, PARSE_INTERFACE, PARSE_METHOD, PARSE_SIGNAL, PARSE_PROPERTY, PARSE_ARGUMENT, PARSE_ANNOTATION, } ParseStackType; /** * ParseStack: * @entry: list header, * @type: type of object parsed, * @data: object pointer. * * This structure represents an object parsed from the XML file and is used * as a stack. @type indicates which type of object is being parsed, and * the @data pointer is part of a union of the different types of pointer. **/ typedef struct parse_stack { NihList entry; ParseStackType type; union { void * data; Node * node; Interface *interface; Method * method; Signal * signal; Property * property; Argument * argument; }; } ParseStack; /** * ParseContext: * @parent: parent for node, * @stack: parse stack, * @filename: filename being parsed, * @node: top-level node. * * This structure is used as the user data for the XML parser, it tracks the * stack of objects being parsed and returns the top-level node object which * has all of the interfaces, etc. **/ typedef struct parse_context { const void *parent; NihList stack; const char *filename; Node * node; } ParseContext; NIH_BEGIN_EXTERN ParseStack *parse_stack_push (const void *parent, NihList *stack, ParseStackType type, void *data) __attribute__ ((warn_unused_result, malloc)); ParseStack *parse_stack_top (NihList *stack); void parse_start_tag (XML_Parser xmlp, const char *tag, char * const *attr); void parse_end_tag (XML_Parser xmlp, const char *tag); Node * parse_xml (const void *parent, int fd, const char *filename) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_PARSE_H */ libnih-1.0.3/nih-dbus-tool/interface.c0000644000175000017500000022672011445765555014523 00000000000000/* nih-dbus-tool * * interface.c - interface parsing and handling * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include "symbol.h" #include "indent.h" #include "type.h" #include "demarshal.h" #include "node.h" #include "interface.h" #include "method.h" #include "property.h" #include "parse.h" #include "errors.h" /** * interface_name_valid: * @name: Interface name to verify. * * Verifies whether @name matches the specification for D-Bus interface * names. * * Returns: TRUE if valid, FALSE if not. **/ int interface_name_valid (const char *name) { size_t parts = 1; nih_assert (name != NULL); /* Name must not begin with a '.' */ if (name[0] == '.') return FALSE; /* We can get away with just using strlen() here even through name * is in UTF-8 because all the valid characters are ASCII. */ for (size_t i = 0; i < strlen (name); i++) { /* Name components may be separated by single '.' characters, * multiple ones are not allowed. Keep a count of how many * parts we have, since there's a defined minimum. */ if (name[i] == '.') { if (name[i-1] == '.') return FALSE; parts++; continue; } /* Names may contain digits, but not at the beginning of the * name or any part of it. */ if ((name[i] >= '0') && (name[i] <= '9')) { if (i == 0) return FALSE; if (name[i-1] == '.') return FALSE; continue; } /* Valid characters anywhere are [A-Za-z_] */ if ( ((name[i] < 'A') || (name[i] > 'Z')) && ((name[i] < 'a') || (name[i] > 'z')) && (name[i] != '_')) return FALSE; } /* Name must consist of at least two parts */ if (parts < 2) return FALSE; /* Final character may not be '.' */ if (name[strlen (name) - 1] == '.') return FALSE; /* Name must be no more than 255 characters */ if (strlen (name) > 255) return FALSE; return TRUE; } /** * interface_new: * @parent: parent object for new interface, * @name: D-Bus name of interface. * * Allocates a new D-Bus object Interface data structure, with the D-Bus * name set to @name. The returned structure is not placed into any list. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned interface. When all parents * of the returned interface are freed, the returned interface will also be * freed. * * Returns: the new interface or NULL if the allocation failed. **/ Interface * interface_new (const void *parent, const char *name) { Interface *interface; nih_assert (name != NULL); interface = nih_new (parent, Interface); if (! interface) return NULL; nih_list_init (&interface->entry); nih_alloc_set_destructor (interface, nih_list_destroy); interface->name = nih_strdup (interface, name); if (! interface->name) { nih_free (interface); return NULL; } interface->symbol = NULL; interface->deprecated = FALSE; nih_list_init (&interface->methods); nih_list_init (&interface->signals); nih_list_init (&interface->properties); return interface; } /** * interface_start_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed, * @attr: NULL-terminated array of attribute name and value pairs. * * This function is called by parse_start_tag() for an "interface" * start tag, a child of the "node" tag that defines a D-Bus interface * implemented by that object. * * If the interface does not appear within a node tag a warning is emitted * and the tag will be ignored. * * Interfaces must have a "name" attribute containing the D-Bus name * of the interface. * * Any unknown attributes result in a warning and will be ignored. * * An Interface object will be allocated and pushed onto the stack, this is * not added to the node until the end tag is found. * * Returns: zero on success, negative value on raised error. **/ int interface_start_tag (XML_Parser xmlp, const char * tag, char * const *attr) { ParseContext * context; ParseStack * parent; nih_local Interface *interface = NULL; char * const * key; char * const * value; const char * name = NULL; nih_assert (xmlp != NULL); nih_assert (tag != NULL); nih_assert (attr != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); /* Interfaces should only appear inside nodes. */ parent = parse_stack_top (&context->stack); if ((! parent) || (parent->type != PARSE_NODE)) { nih_warn ("%s:%zu:%zu: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unexpected tag")); if (! parse_stack_push (NULL, &context->stack, PARSE_IGNORED, NULL)) nih_return_system_error (-1); return 0; } /* Retrieve the name from the attributes */ for (key = attr; key && *key; key += 2) { value = key + 1; nih_assert (value && *value); if (! strcmp (*key, "name")) { name = *value; } else { nih_warn ("%s:%zu:%zu: %s: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unknown attribute"), *key); } } /* Check we have a name and that it's valid */ if (! name) nih_return_error (-1, INTERFACE_MISSING_NAME, _(INTERFACE_MISSING_NAME_STR)); if (! interface_name_valid (name)) nih_return_error (-1, INTERFACE_INVALID_NAME, _(INTERFACE_INVALID_NAME_STR)); /* Allocate an Interface object and push onto the stack */ interface = interface_new (NULL, name); if (! interface) nih_return_system_error (-1); if (! parse_stack_push (NULL, &context->stack, PARSE_INTERFACE, interface)) { nih_error_raise_system (); return -1; } return 0; } /** * interface_end_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed. * * This function is called by parse_end_tag() for an "interface" end * tag, and matches a call to interface_start_tag() made at the same * parsing level. * * The interface is added to the list of interfaces defined by its parent * node. * * Returns: zero on success, negative value on raised error. **/ int interface_end_tag (XML_Parser xmlp, const char *tag) { ParseContext *context; ParseStack * entry; ParseStack * parent; Interface * interface; Interface * conflict; Node * node; nih_assert (xmlp != NULL); nih_assert (tag != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); entry = parse_stack_top (&context->stack); nih_assert (entry != NULL); nih_assert (entry->type == PARSE_INTERFACE); interface = entry->interface; /* Generate a symbol from the trailing part of the name */ if (! interface->symbol) { char *trail; trail = strrchr (interface->name, '.'); nih_assert (trail != NULL); trail++; interface->symbol = symbol_from_name (interface, trail); if (! interface->symbol) nih_return_no_memory_error (-1); } nih_list_remove (&entry->entry); parent = parse_stack_top (&context->stack); nih_assert (parent != NULL); nih_assert (parent->type == PARSE_NODE); node = parent->node; /* Make sure there's not a conflict before adding the interface */ conflict = node_lookup_interface (node, interface->symbol); if (conflict) { nih_error_raise_printf (INTERFACE_DUPLICATE_SYMBOL, _(INTERFACE_DUPLICATE_SYMBOL_STR), interface->symbol, conflict->name); return -1; } nih_debug ("Add %s interface to %s node", interface->name, node->path ?: "(unknown)"); nih_ref (interface, node); nih_list_add (&node->interfaces, &interface->entry); nih_free (entry); return 0; } /** * interface_annotation: * @interface: interface object annotation applies to, * @name: annotation name, * @value: annotation value. * * Handles applying the annotation @name with value @value to the interface * @interface. Interfaces may be annotated as deprecated or may have an * alternate symbol name specified. * * Unknown annotations or illegal values to the known annotations result * in an error being raised. * * Returns: zero on success, negative value on raised error. **/ int interface_annotation (Interface * interface, const char *name, const char *value) { nih_assert (interface != NULL); nih_assert (name != NULL); nih_assert (value != NULL); if (! strcmp (name, "org.freedesktop.DBus.Deprecated")) { if (! strcmp (value, "true")) { nih_debug ("Marked %s interface as deprecated", interface->name); interface->deprecated = TRUE; } else if (! strcmp (value, "false")) { nih_debug ("Marked %s interface as not deprecated", interface->name); interface->deprecated = FALSE; } else { nih_return_error (-1, INTERFACE_ILLEGAL_DEPRECATED, _(INTERFACE_ILLEGAL_DEPRECATED_STR)); } } else if (! strcmp (name, "com.netsplit.Nih.Symbol")) { if (symbol_valid (value)) { if (interface->symbol) nih_unref (interface->symbol, interface); interface->symbol = nih_strdup (interface, value); if (! interface->symbol) nih_return_no_memory_error (-1); nih_debug ("Set %s interface symbol to %s", interface->name, interface->symbol); } else { nih_return_error (-1, INTERFACE_INVALID_SYMBOL, _(INTERFACE_INVALID_SYMBOL_STR)); } } else { nih_error_raise_printf (INTERFACE_UNKNOWN_ANNOTATION, "%s: %s: %s", _(INTERFACE_UNKNOWN_ANNOTATION_STR), interface->name, name); return -1; } return 0; } /** * interface_methods_array: * @parent: parent object for new string, * @prefix: prefix for array name, * @interface: interface to generate array for, * @with_handlers: whether to include handler pointers, * @prototypes: list to append prototype to. * * Generates C code to declare an array of NihDBusMethod variables * containing information about the methods of the interface @interface; * this will also include array definitions for the arguments of each * method, since these are referred to by the returned array. * * If @with_handlers is TRUE the returned array will contain pointers to * handler functions that should be already defined (or at least prototyped); * when FALSE this member will be NULL. * * The prototype of the returned variable declaration is returned as a * TypeVar object appended to the @prototypes list. The arguments array * prototypes are not returned since they are made static. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * interface_methods_array (const void *parent, const char *prefix, Interface * interface, int with_handlers, NihList * prototypes) { nih_local char *name = NULL; NihList vars; size_t max_name = 0; size_t max_args = 0; size_t max_handler = 0; nih_local char *args = NULL; TypeVar * var; nih_local char *block = NULL; char * code; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (prototypes != NULL); name = symbol_impl (NULL, prefix, interface->name, NULL, "methods"); if (! name) return NULL; nih_list_init (&vars); /* Figure out the longest method name, arguments array variable name * and handler function name. */ NIH_LIST_FOREACH (&interface->methods, iter) { Method * method = (Method *)iter; NihList args_prototypes; nih_local char *args_array = NULL; nih_local char *handler_name = NULL; /* Obtain the arguments array for the method, giving us the * name of the array. Append it as a static to the block * we prepend to our code. */ nih_list_init (&args_prototypes); args_array = method_args_array (NULL, prefix, interface, method, &args_prototypes); if (! args_array) return NULL; if (! nih_strcat_sprintf (&args, NULL, "static %s" "\n", args_array)) return NULL; nih_assert (! NIH_LIST_EMPTY (&args_prototypes)); var = (TypeVar *)args_prototypes.next; nih_list_add (&vars, &var->entry); nih_ref (var, args); /* Calculate size of method name and args var name */ if (strlen (method->name) > max_name) max_name = strlen (method->name); if (strlen (var->name) > max_args) max_args = strlen (var->name); /* Work out name of handler or leave space for "NULL" */ if (with_handlers) { handler_name = symbol_impl (NULL, prefix, interface->name, method->name, "method"); if (! handler_name) return NULL; if (strlen (handler_name) > max_handler) max_handler = strlen (handler_name); } else { if (max_handler < 4) max_handler = 4; } } /* Append each method such that the names, args variable names and * handler function names are all lined up with each other. */ var = (TypeVar *)vars.next; NIH_LIST_FOREACH (&interface->methods, iter) { Method * method = (Method *)iter; nih_local char *line = NULL; char * dest; nih_local char *handler_name = NULL; nih_assert (&var->entry != &vars); /* Allocate the line and fill in the values, padding out * where necessary. */ line = nih_alloc (NULL, max_name + max_args + max_handler + 13); if (! line) return NULL; dest = line; memcpy (dest, "{ \"", 3); dest += 3; memcpy (dest, method->name, strlen (method->name)); dest += strlen (method->name); memcpy (dest, "\", ", 3); dest += 3; memset (dest, ' ', max_name - strlen (method->name)); dest += max_name - strlen (method->name); memcpy (dest, var->name, strlen (var->name)); dest += strlen (var->name); memcpy (dest, ", ", 2); dest += 2; memset (dest, ' ', max_args - strlen (var->name)); dest += max_args - strlen (var->name); if (with_handlers) { handler_name = symbol_impl (NULL, prefix, interface->name, method->name, "method"); if (! handler_name) return NULL; memcpy (dest, handler_name, strlen (handler_name)); dest += strlen (handler_name); memset (dest, ' ', max_handler - strlen (handler_name)); dest += max_handler - strlen (handler_name); } else { memcpy (dest, "NULL", 4); dest += 4; memset (dest, ' ', max_handler - 4); dest += max_handler - 4; } memcpy (dest, " },\n", 4); dest += 4; *dest = '\0'; if (! nih_strcat (&block, NULL, line)) return NULL; var = (TypeVar *)var->entry.next; } /* Append the final element to the block of elements, indent and * surround with the structure definition. */ if (! nih_strcat (&block, NULL, "{ NULL }\n")) return NULL; if (! indent (&block, NULL, 1)) return NULL; code = nih_sprintf (parent, "%s" "const NihDBusMethod %s[] = {\n" "%s" "};\n", args ?: "", name, block); if (! code) return NULL; /* Append the prototype to the list */ var = type_var_new (code, "const NihDBusMethod", name); if (! var) { nih_free (code); return NULL; } var->array = TRUE; nih_list_add (prototypes, &var->entry); return code; } /** * interface_signals_array: * @parent: parent object for new string, * @prefix: prefix for array name, * @interface: interface to generate array for, * @with_filter: whether to include filter function pointers, * @prototypes: list to append prototype to. * * Generates C code to declare an array of NihDBusSignal variables * containing information about the signals of the interface @interface; * this will also include array definitions for the arguments of each * signals, since these are referred to by the returned array. * * If @with_filters is TRUE the returned array will contain pointers to * filter functions that should be already defined (or at least prototyped); * when FALSE this member will be NULL. * * The prototype of the returned variable declaration is returned as a * TypeVar object appended to the @prototypes list. The arguments array * prototypes are not returned since they are made static. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * interface_signals_array (const void *parent, const char *prefix, Interface * interface, int with_filters, NihList * prototypes) { nih_local char *name = NULL; NihList vars; size_t max_name = 0; size_t max_args = 0; size_t max_filter = 0; nih_local char *args = NULL; TypeVar * var; nih_local char *block = NULL; char * code; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (prototypes != NULL); name = symbol_impl (NULL, prefix, interface->name, NULL, "signals"); if (! name) return NULL; nih_list_init (&vars); /* Figure out the longest signal name, arguments array variable name * and filter function name. */ NIH_LIST_FOREACH (&interface->signals, iter) { Signal * signal = (Signal *)iter; NihList args_prototypes; nih_local char *args_array = NULL; nih_local char *filter_name = NULL; /* Obtain the arguments array for the signal, giving us the * name of the array. Append it as a static to the block * we prepend to our code. */ nih_list_init (&args_prototypes); args_array = signal_args_array (NULL, prefix, interface, signal, &args_prototypes); if (! args_array) return NULL; if (! nih_strcat_sprintf (&args, NULL, "static %s" "\n", args_array)) return NULL; nih_assert (! NIH_LIST_EMPTY (&args_prototypes)); var = (TypeVar *)args_prototypes.next; nih_list_add (&vars, &var->entry); nih_ref (var, args); /* Calculate size of signal name and args var name */ if (strlen (signal->name) > max_name) max_name = strlen (signal->name); if (strlen (var->name) > max_args) max_args = strlen (var->name); /* Work out name of filter or leave space for "NULL" */ if (with_filters) { filter_name = symbol_impl (NULL, prefix, interface->name, signal->name, "signal"); if (! filter_name) return NULL; if (strlen (filter_name) > max_filter) max_filter = strlen (filter_name); } else { if (max_filter < 4) max_filter = 4; } } /* Append each signal such that the names, args variable names and * filter function names are all lined up with each other. */ var = (TypeVar *)vars.next; NIH_LIST_FOREACH (&interface->signals, iter) { Signal * signal = (Signal *)iter; nih_local char *line = NULL; char * dest; nih_local char *filter_name = NULL; nih_assert (&var->entry != &vars); /* Allocate the line and fill in the values, padding out * where necessary. */ line = nih_alloc (NULL, max_name + max_args + max_filter + 13); if (! line) return NULL; dest = line; memcpy (dest, "{ \"", 3); dest += 3; memcpy (dest, signal->name, strlen (signal->name)); dest += strlen (signal->name); memcpy (dest, "\", ", 3); dest += 3; memset (dest, ' ', max_name - strlen (signal->name)); dest += max_name - strlen (signal->name); memcpy (dest, var->name, strlen (var->name)); dest += strlen (var->name); memcpy (dest, ", ", 2); dest += 2; memset (dest, ' ', max_args - strlen (var->name)); dest += max_args - strlen (var->name); if (with_filters) { filter_name = symbol_impl (NULL, prefix, interface->name, signal->name, "signal"); if (! filter_name) return NULL; memcpy (dest, filter_name, strlen (filter_name)); dest += strlen (filter_name); memset (dest, ' ', max_filter - strlen (filter_name)); dest += max_filter - strlen (filter_name); } else { memcpy (dest, "NULL", 4); dest += 4; memset (dest, ' ', max_filter - 4); dest += max_filter - 4; } memcpy (dest, " },\n", 4); dest += 4; *dest = '\0'; if (! nih_strcat (&block, NULL, line)) return NULL; var = (TypeVar *)var->entry.next; } /* Append the final element to the block of elements, indent and * surround with the structure definition. */ if (! nih_strcat (&block, NULL, "{ NULL }\n")) return NULL; if (! indent (&block, NULL, 1)) return NULL; code = nih_sprintf (parent, "%s" "const NihDBusSignal %s[] = {\n" "%s" "};\n", args ?: "", name, block); if (! code) return NULL; /* Append the prototype to the list */ var = type_var_new (code, "const NihDBusSignal", name); if (! var) { nih_free (code); return NULL; } var->array = TRUE; nih_list_add (prototypes, &var->entry); return code; } /** * interface_properties_array: * @parent: parent object for new string, * @prefix: prefix for array name, * @interface: interface to generate array for, * @with_handlers: whether to include handler pointers, * @prototypes: list to append prototype to. * * Generates C code to declare an array of NihDBusProperty variables * containing information about the properties of the interface @interface. * * If @with_handlers is TRUE the returned array will contain pointers to * getter and setter functions that should be already defined (or at least * prototyped); when FALSE these members will be NULL. * * The prototype of the returned variable declaration is returned as a * TypeVar object appended to the @prototypes list. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * interface_properties_array (const void *parent, const char *prefix, Interface * interface, int with_handlers, NihList * prototypes) { nih_local char *name = NULL; size_t max_name = 0; size_t max_type = 0; size_t max_access = 0; size_t max_getter = 0; size_t max_setter = 0; nih_local char *block = NULL; char * code; TypeVar * var; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (prototypes != NULL); name = symbol_impl (NULL, prefix, interface->name, NULL, "properties"); if (! name) return NULL; /* Figure out the longest property name, type, access variable, * getter and setter function names. */ NIH_LIST_FOREACH (&interface->properties, iter) { Property * property = (Property *)iter; nih_local char *getter_name = NULL; nih_local char *setter_name = NULL; if (strlen (property->name) > max_name) max_name = strlen (property->name); if (strlen (property->type) > max_type) max_type = strlen (property->type); switch (property->access) { case NIH_DBUS_READ: if (max_access < 13) max_access = 13; break; case NIH_DBUS_WRITE: if (max_access < 14) max_access = 14; break; case NIH_DBUS_READWRITE: if (max_access < 18) max_access = 18; break; default: nih_assert_not_reached (); } if (with_handlers && (property->access != NIH_DBUS_WRITE)) { getter_name = symbol_impl (NULL, prefix, interface->name, property->name, "get"); if (! getter_name) return NULL; if (strlen (getter_name) > max_getter) max_getter = strlen (getter_name); } else { if (max_getter < 4) max_getter = 4; } if (with_handlers && (property->access != NIH_DBUS_READ)) { setter_name = symbol_impl (NULL, prefix, interface->name, property->name, "set"); if (! setter_name) return NULL; if (strlen (setter_name) > max_setter) max_setter = strlen (setter_name); } else { if (max_setter < 4) max_setter = 4; } } /* Append each property such that the names, types, access enum, * getter and setter function names are all lined up with each other. */ NIH_LIST_FOREACH (&interface->properties, iter) { Property * property = (Property *)iter; nih_local char *line = NULL; char * dest; nih_local char *getter_name = NULL; nih_local char *setter_name = NULL; line = nih_alloc (NULL, (max_name + max_type + max_access + max_getter + max_setter + 19)); if (! line) return NULL; dest = line; memcpy (dest, "{ \"", 3); dest += 3; memcpy (dest, property->name, strlen (property->name)); dest += strlen (property->name); memcpy (dest, "\", ", 3); dest += 3; memset (dest, ' ', max_name - strlen (property->name)); dest += max_name - strlen (property->name); memcpy (dest, "\"", 1); dest += 1; memcpy (dest, property->type, strlen (property->type)); dest += strlen (property->type); memcpy (dest, "\", ", 3); dest += 3; memset (dest, ' ', max_type - strlen (property->type)); dest += max_type - strlen (property->type); switch (property->access) { case NIH_DBUS_READ: memcpy (dest, "NIH_DBUS_READ, ", 15); dest += 15; memset (dest, ' ', max_access - 13); dest += max_access - 13; break; case NIH_DBUS_WRITE: memcpy (dest, "NIH_DBUS_WRITE, ", 16); dest += 16; memset (dest, ' ', max_access - 14); dest += max_access - 14; break; case NIH_DBUS_READWRITE: memcpy (dest, "NIH_DBUS_READWRITE, ", 20); dest += 20; memset (dest, ' ', max_access - 18); dest += max_access - 18; break; default: nih_assert_not_reached (); } if (with_handlers && (property->access != NIH_DBUS_WRITE)) { getter_name = symbol_impl (NULL, prefix, interface->name, property->name, "get"); if (! getter_name) return NULL; memcpy (dest, getter_name, strlen (getter_name)); dest += strlen (getter_name); memcpy (dest, ", ", 2); dest += 2; memset (dest, ' ', max_getter - strlen (getter_name)); dest += max_getter - strlen (getter_name); } else { memcpy (dest, "NULL, ", 6); dest += 6; memset (dest, ' ', max_getter - 4); dest += max_getter - 4; } if (with_handlers && (property->access != NIH_DBUS_READ)) { setter_name = symbol_impl (NULL, prefix, interface->name, property->name, "set"); if (! setter_name) return NULL; memcpy (dest, setter_name, strlen (setter_name)); dest += strlen (setter_name); memset (dest, ' ', max_setter - strlen (setter_name)); dest += max_setter - strlen (setter_name); } else { memcpy (dest, "NULL", 4); dest += 4; memset (dest, ' ', max_setter - 4); dest += max_setter - 4; } memcpy (dest, " },\n", 4); dest += 4; *dest = '\0'; if (! nih_strcat (&block, NULL, line)) return NULL; } /* Append the final element to the block of elements, indent and * surround with the structure definition. */ if (! nih_strcat (&block, NULL, "{ NULL }\n")) return NULL; if (! indent (&block, NULL, 1)) return NULL; code = nih_sprintf (parent, "const NihDBusProperty %s[] = {\n" "%s" "};\n", name, block); if (! code) return NULL; /* Append the prototype to the list */ var = type_var_new (code, "const NihDBusProperty", name); if (! var) { nih_free (code); return NULL; } var->array = TRUE; nih_list_add (prototypes, &var->entry); return code; } /** * interface_struct: * @parent: parent object for new string, * @prefix: prefix for struct name, * @interface: interface to generate struct for, * @object: whether struct is for an object or proxy, * @prototypes: list to append prototype to. * * Generates C code to declare an NihDBusInterface structure variable for * the given interface @interface, the code includes the array definitions * for methods, signals, properties and their arguments. * * If @object is TRUE, the struct will be for an object definition so method * handler function and property getter and setter function pointers will * be filled in. If @object is FALSE, the struct will be for a proxy * definition so the signal filter function pointers will be filled in. * * The prototype of the returned variable declaration is returned as a * TypeVar object appended to the @prototypes list. The methods, signals * and properties array prototypes are not returned since they are made * static. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * interface_struct (const void *parent, const char *prefix, Interface * interface, int object, NihList * prototypes) { nih_local char *name = NULL; nih_local char *block = NULL; nih_local char *arrays = NULL; TypeVar * var; char * ptr; NihList methods_prototypes; nih_local char *methods_array = NULL; NihList signals_prototypes; nih_local char *signals_array = NULL; NihList properties_prototypes; nih_local char *properties_array = NULL; char * code; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (prototypes != NULL); /* Work out the structure name, and append the interface name to the * definition. */ name = symbol_impl (NULL, prefix, interface->name, NULL, NULL); if (! name) return NULL; if (! nih_strcat_sprintf (&block, NULL, "\"%s\",\n", interface->name)) return NULL; /* Append the methods array to the arrays block, making it static * in the process. */ nih_list_init (&methods_prototypes); methods_array = interface_methods_array (NULL, prefix, interface, object ? TRUE : FALSE, &methods_prototypes); if (! methods_array) return NULL; nih_assert (! NIH_LIST_EMPTY (&methods_prototypes)); var = (TypeVar *)methods_prototypes.next; ptr = strstr (methods_array, var->type); nih_assert (ptr != NULL); if (! nih_strncat (&arrays, NULL, methods_array, ptr - methods_array)) return NULL; if (! nih_strcat_sprintf (&arrays, NULL, "static %s\n", ptr)) return NULL; if (! nih_strcat_sprintf (&block, NULL, "%s,\n", var->name)) return NULL; /* Append the signals array to the arrays block, making it static * in the process. */ nih_list_init (&signals_prototypes); signals_array = interface_signals_array (NULL, prefix, interface, object ? FALSE : TRUE, &signals_prototypes); if (! signals_array) return NULL; nih_assert (! NIH_LIST_EMPTY (&signals_prototypes)); var = (TypeVar *)signals_prototypes.next; ptr = strstr (signals_array, var->type); nih_assert (ptr != NULL); if (! nih_strncat (&arrays, NULL, signals_array, ptr - signals_array)) return NULL; if (! nih_strcat_sprintf (&arrays, NULL, "static %s\n", ptr)) return NULL; if (! nih_strcat_sprintf (&block, NULL, "%s,\n", var->name)) return NULL; /* Append the properties array to the arrays block, making it static * in the process. */ nih_list_init (&properties_prototypes); properties_array = interface_properties_array (NULL, prefix, interface, object ? TRUE : FALSE, &properties_prototypes); if (! properties_array) return NULL; nih_assert (! NIH_LIST_EMPTY (&properties_prototypes)); var = (TypeVar *)properties_prototypes.next; if (! nih_strcat_sprintf (&arrays, NULL, "static %s\n", properties_array)) return NULL; if (! nih_strcat_sprintf (&block, NULL, "%s\n", var->name)) return NULL; /* Output the code */ if (! indent (&block, NULL, 1)) return NULL; code = nih_sprintf (parent, "%s" "const NihDBusInterface %s = {\n" "%s" "};\n", arrays, name, block); if (! code) return NULL; /* Append the prototype to the list */ var = type_var_new (code, "const NihDBusInterface", name); if (! var) { nih_free (code); return NULL; } nih_list_add (prototypes, &var->entry); return code; } /** * interface_proxy_get_all_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface to generate function for, * @prototypes: list to append function prototypes to, * @structs: list to append structure definitions to. * * Generates C code for a function that will make an asynchronous method * call to obtain the value of all of the properties on @interface, * calling a notify function when the method call completes. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * If any of the arguments require a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and the * property. * * The names of both the returned function and notify function prototype * will be generated using information in @interface, prefixed with @prefix. * * The notify function will call a handler function passed in if the * reply is valid. The name and type for this can be obtained from * interface_proxy_get_all_notify_function(). * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * interface_proxy_get_all_function (const void *parent, const char *prefix, Interface * interface, NihList * prototypes, NihList * structs) { NihList locals; NihList all_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; NihListEntry * attrib; nih_local char * assert_block = NULL; nih_local char * handler_type = NULL; nih_local TypeVar * message_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * pending_var = NULL; nih_local TypeVar * data_var = NULL; nih_local TypeVar * interface_var = NULL; nih_local char * call_block = NULL; nih_local char * notify_name = NULL; nih_local char * block = NULL; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (prototypes != NULL); nih_assert (structs != NULL); nih_list_init (&locals); nih_list_init (&all_structs); /* The function returns a pending call, and takes the proxy object * as the only argument. The pending call also indicates whether * an error occurred, so we want warning if the result isn't used. * We don't have a malloc attribute, since we can't guarantee that * D-Bus doesn't cache them. */ name = symbol_extern (NULL, prefix, interface->symbol, NULL, "get_all", NULL); if (! name) return NULL; func = type_func_new (NULL, "DBusPendingCall *", name); if (! func) return NULL; attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "warn_unused_result"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); arg = type_var_new (func, "NihDBusProxy *", "proxy"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (proxy != NULL);\n")) return NULL; /* We also require a handler (which receives the property value), * error handler (in case of error) and data arguments to pass to * both as well as a timeout for the method call. Unlike the * method call case, we don't allow for no-reply calls since * they're nonsensical. */ handler_type = symbol_typedef (NULL, prefix, interface->symbol, NULL, "GetAll", "Reply"); if (! handler_type) return NULL; arg = type_var_new (func, handler_type, "handler"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "NihDBusErrorHandler", "error_handler"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "void *", "data"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert ((handler != NULL) && (error_handler != NULL));\n")) return NULL; arg = type_var_new (func, "int", "timeout"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); /* The function requires a message pointer, which we allocate, * and an iterator for it to append the arguments. We also need * a return pending call pointer and data structure as well. * Rather than deal with these by hand, it's far easier to put them * on the locals list and deal with them along with the rest. */ message_var = type_var_new (NULL, "DBusMessage *", "method_call"); if (! message_var) return NULL; nih_list_add (&locals, &message_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); pending_var = type_var_new (NULL, "DBusPendingCall *", "pending_call"); if (! pending_var) return NULL; nih_list_add (&locals, &pending_var->entry); data_var = type_var_new (NULL, "NihDBusPendingData *", "pending_data"); if (! data_var) return NULL; nih_list_add (&locals, &data_var->entry); /* Annoyingly we also need a variable for the interface name, * since D-Bus wants its address and can't just take a constant * string. */ interface_var = type_var_new (NULL, "const char *", "interface"); if (! interface_var) return NULL; nih_list_add (&locals, &interface_var->entry); /* Create the method call to get the property, the property * interface gets specified as an argument - the method call * interface is the D-Bus properties one. */ if (! nih_strcat_sprintf (&call_block, NULL, "/* Construct the method call message. */\n" "method_call = dbus_message_new_method_call (proxy->name, proxy->path, \"%s\", \"GetAll\");\n" "if (! method_call)\n" "\tnih_return_no_memory_error (NULL);\n" "\n" "dbus_message_set_auto_start (method_call, proxy->auto_start);\n" "\n" "dbus_message_iter_init_append (method_call, &iter);\n" "\n" "interface = \"%s\";\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n", DBUS_INTERFACE_PROPERTIES, interface->name)) return NULL; /* FIXME autostart? */ /* Complete the marshalling block by sending the message and checking * for error replies. */ notify_name = symbol_impl (NULL, prefix, interface->name, "get_all", "notify"); if (! notify_name) return NULL; if (! nih_strcat_sprintf (&call_block, NULL, "/* Send the message and set up the reply notification. */\n" "pending_data = nih_dbus_pending_data_new (NULL, proxy->connection,\n" " (NihDBusReplyHandler)handler,\n" " error_handler, data);\n" "if (! pending_data) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n" "pending_call = NULL;\n" "if (! dbus_connection_send_with_reply (proxy->connection, method_call,\n" " &pending_call, timeout)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_free (pending_data);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n" "dbus_message_unref (method_call);\n" "\n" "if (! pending_call) {\n" "\tnih_dbus_error_raise (DBUS_ERROR_DISCONNECTED,\n" "\t \"Connection is closed\");\n" "\tnih_free (pending_data);\n" "\treturn NULL;\n" "}\n" "\n" "NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)%s,\n" " pending_data, (DBusFreeFunction)nih_discard));\n", notify_name)) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "\n" "return pending_call;\n", vars_block, assert_block, call_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the function to the prototypes list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); return code; } /** * interface_proxy_get_all_notify_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface to generate function for, * @prototypes: list to append function prototypes to, * @typedefs: list to append function pointer typedef definitions to, * @structs: list to append structure definitions to. * * Generates C code for a function to handle the notification of * a complete pending call to obtain the value of all of the properties * of @interface by calling either the handler function on success or * error function on failure. * * The notify function will call a handler function passed in if the * reply is valid, the typedef name for this handler must be passed as * @handler_type. The actual type for this can be obtained from the * entry added to @typedefs. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * The typedef for the handler function is returned as a TypeFunc object * added to the @typedefs list. * * If any of the arguments require a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and the * property. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * interface_proxy_get_all_notify_function (const void *parent, const char *prefix, Interface * interface, NihList * prototypes, NihList * typedefs, NihList * structs) { nih_local char * c_type = NULL; nih_local TypeStruct *structure = NULL; NihList locals; NihList all_structs; nih_local char * name = NULL; nih_local TypeFunc * func = NULL; TypeVar * arg; nih_local char * assert_block = NULL; nih_local TypeVar * reply_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * arrayiter_var = NULL; nih_local TypeVar * dictiter_var = NULL; nih_local TypeVar * variter_var = NULL; nih_local TypeVar * error_var = NULL; nih_local TypeVar * property_var = NULL; nih_local TypeVar * parent_var = NULL; nih_local TypeVar * structure_var = NULL; nih_local TypeVar * count_var = NULL; nih_local char * steal_block = NULL; nih_local char * demarshal_block = NULL; nih_local char * property_block = NULL; size_t property_count; nih_local char * oom_error_code = NULL; nih_local char * type_error_code = NULL; nih_local char * call_block = NULL; nih_local char * handler_type = NULL; nih_local char * handler_name = NULL; nih_local TypeFunc * handler_func = NULL; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (prototypes != NULL); nih_assert (typedefs != NULL); nih_assert (structs != NULL); nih_list_init (&locals); nih_list_init (&all_structs); /* The function takes the pending call being notified and the * associated data structure. We don't mark the function deprecated * since it's used internally, it's enough to mark the method * call function deprecated. */ name = symbol_impl (NULL, prefix, interface->name, "get_all", "notify"); if (! name) return NULL; func = type_func_new (NULL, "void", name); if (! func) return NULL; arg = type_var_new (func, "DBusPendingCall *", "pending_call"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (pending_call != NULL);\n")) return NULL; arg = type_var_new (func, "NihDBusPendingData *", "pending_data"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (pending_data != NULL);\n")) return NULL; /* The function requires a message pointer, stolen from the * pending call and iterators for the message and variant. We * also need a parent message context for any allocations we make, * as well as an error object. */ reply_var = type_var_new (NULL, "DBusMessage *", "reply"); if (! reply_var) return NULL; nih_list_add (&locals, &reply_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); arrayiter_var = type_var_new (NULL, "DBusMessageIter", "arrayiter"); if (! arrayiter_var) return NULL; nih_list_add (&locals, &arrayiter_var->entry); dictiter_var = type_var_new (NULL, "DBusMessageIter", "dictiter"); if (! dictiter_var) return NULL; nih_list_add (&locals, &dictiter_var->entry); variter_var = type_var_new (NULL, "DBusMessageIter", "variter"); if (! variter_var) return NULL; nih_list_add (&locals, &variter_var->entry); parent_var = type_var_new (NULL, "NihDBusMessage *", "message"); if (! parent_var) return NULL; nih_list_add (&locals, &parent_var->entry); error_var = type_var_new (NULL, "DBusError", "error"); if (! error_var) return NULL; nih_list_add (&locals, &error_var->entry); /* Need a variable to hold the property name */ property_var = type_var_new (NULL, "const char *", "property"); if (! property_var) return NULL; nih_list_add (&locals, &property_var->entry); /* We also need a local for the structure we pass to the handler */ c_type = symbol_typedef (NULL, prefix, interface->symbol, NULL, "properties", NULL); if (! c_type) return NULL; structure = type_struct_new (NULL, c_type); if (! structure) return NULL; if (! type_to_pointer (&c_type, NULL)) return NULL; structure_var = type_var_new (NULL, c_type, "properties"); if (! structure_var) return NULL; nih_list_add (&locals, &structure_var->entry); count_var = type_var_new (NULL, "size_t", "property_count"); if (! count_var) return NULL; nih_list_add (&locals, &count_var->entry); /* Assert that the pending call is, in fact, complete then * steal the message from it; handling it immediately if it's an * error. */ if (! nih_strcat (&steal_block, NULL, "nih_assert (dbus_pending_call_get_completed (pending_call));\n" "\n" "/* Steal the reply from the pending call. */\n" "reply = dbus_pending_call_steal_reply (pending_call);\n" "nih_assert (reply != NULL);\n" "\n" "/* Handle error replies */\n" "if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {\n" "\tmessage = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply));\n" "\n" "\tdbus_error_init (&error);\n" "\tdbus_set_error_from_message (&error, message->message);\n" "\n" "\tnih_error_push_context ();\n" "\tnih_dbus_error_raise (error.name, error.message);\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tdbus_error_free (&error);\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n" "nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN);\n" "\n")) return NULL; /* Begin the demarshalling block, making sure that the first * argument is an array and recursing into it and looping over * the values. */ if (! nih_strcat_sprintf (&demarshal_block, NULL, "/* Create a message context for the reply, and iterate\n" " * over and recurse into the arguments.\n" " */\n" "message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply));\n" "\n" "/* Iterate the method arguments, recursing into the array */\n" "dbus_message_iter_init (reply, &iter);\n" "\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) {\n" "\tnih_error_push_context ();\n" "\tnih_error_raise (NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n" "properties = NIH_MUST (nih_new (message, %s));\n" "property_count = 0;\n" "\n" "dbus_message_iter_recurse (&iter, &arrayiter);\n" "\n" "while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) {\n" "\t__label__ enomem;\n" "\n", structure->name)) return NULL; /* Begin the property checking block, each array item should be * a dictionary entry which we recurse into; the first value of * which should be a string containing the property name. */ if (! nih_strcat_sprintf (&property_block, NULL, "if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) {\n" "\tnih_error_push_context ();\n" "\tnih_error_raise (NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n" "dbus_message_iter_recurse (&arrayiter, &dictiter);\n" "\n" "if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) {\n" "\tnih_error_push_context ();\n" "\tnih_error_raise (NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n" "dbus_message_iter_get_basic (&dictiter, &property);\n" "\n" "dbus_message_iter_next (&dictiter);\n" "\n" "if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) {\n" "\tnih_error_push_context ();\n" "\tnih_error_raise (NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n" "dbus_message_iter_recurse (&dictiter, &variter);\n")) return NULL; /* In case of out of memory, we can't just return because we've * already made the method call so we loop over the code instead. * But in case of type error in the returned arguments, all we * can do is return an error. */ oom_error_code = nih_strdup (NULL, "goto enomem;\n"); if (! oom_error_code) return NULL; type_error_code = nih_strdup (NULL, "nih_error_push_context ();\n" "nih_error_raise (NIH_DBUS_INVALID_ARGS,\n" " _(NIH_DBUS_INVALID_ARGS_STR));\n" "pending_data->error_handler (pending_data->data, message);\n" "nih_error_pop_context ();\n" "\n" "nih_free (message);\n" "dbus_message_unref (reply);\n" "return;\n"); if (! type_error_code) return NULL; property_count = 0; NIH_LIST_FOREACH (&interface->properties, iter) { Property * property = (Property *)iter; DBusSignatureIter iter; NihList property_outputs; NihList property_locals; NihList property_structs; nih_local char * block = NULL; if (property->access == NIH_DBUS_WRITE) continue; dbus_signature_iter_init (&iter, property->type); nih_list_init (&property_outputs); nih_list_init (&property_locals); nih_list_init (&property_structs); block = demarshal (NULL, &iter, "properties", "variter", property->symbol, oom_error_code, type_error_code, &property_outputs, &property_locals, prefix, interface->symbol, property->symbol, NULL, &property_structs); if (! block) return NULL; if (! nih_strcat (&block, NULL, "\n")) return NULL; /* Each of the outputs from the demarshalling code becomes a * local variable to our function that we store the value in, * and that we copy into the structure. */ NIH_LIST_FOREACH_SAFE (&property_outputs, iter) { TypeVar *var = (TypeVar *)iter; TypeVar *member_var; /* Create the structure member entry */ member_var = type_var_new (structure, var->type, var->name); if (! member_var) return NULL; nih_list_add (&structure->members, &member_var->entry); /* Add code to copy from local variable */ if (! nih_strcat_sprintf (&block, NULL, "properties->%s = %s;\n", var->name, var->name)) return NULL; /* Add to locals */ nih_list_add (&locals, &var->entry); nih_ref (var, demarshal_block); } NIH_LIST_FOREACH_SAFE (&property_locals, iter) { TypeVar *var = (TypeVar *)iter; nih_list_add (&locals, &var->entry); nih_ref (var, demarshal_block); } NIH_LIST_FOREACH_SAFE (&property_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_list_add (&all_structs, &structure->entry); nih_ref (structure, demarshal_block); } if (! nih_strcat (&block, NULL, "\n" "nih_assert (++property_count);\n")) return NULL; /* Wrap the code in a test for the property by name */ if (! indent (&block, NULL, 1)) return NULL; if (! nih_strcat_sprintf (&property_block, NULL, "\n" "if (! strcmp (property, \"%s\")) {\n" "%s" "}\n", property->name, block)) return NULL; property_count++; } /* Finish the property checking block, making sure that there are * no further items in the dictionary entry before moving on to the * next array item. */ if (! nih_strcat_sprintf (&property_block, NULL, "\n" "dbus_message_iter_next (&dictiter);\n" "\n" "if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) {\n" "\tnih_error_push_context ();\n" "\tnih_error_raise (NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n" "dbus_message_iter_next (&arrayiter);\n")) return NULL; /* Indent the property block and append to the demarshal block */ if (! indent (&property_block, NULL, 1)) return NULL; if (! nih_strcat (&demarshal_block, NULL, property_block)) return NULL; /* Finish off the demarshalling block by ending the loop and * making sure that there are no further arguments in the reply. */ if (! nih_strcat_sprintf (&demarshal_block, NULL, "enomem: __attribute__ ((unused));\n" "}\n" "\n" "dbus_message_iter_next (&iter);\n" "\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {\n" "\tnih_error_push_context ();\n" "\tnih_error_raise (NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n" "if (property_count < %zu) {\n" "\tnih_error_push_context ();\n" "\tnih_error_raise (NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n", property_count)) return NULL; /* Create the handler calling block, the handler is not permitted * to reply. */ handler_type = symbol_typedef (NULL, prefix, interface->symbol, NULL, "GetAll", "Reply"); if (! handler_type) return NULL; if (! nih_strcat_sprintf (&call_block, NULL, "/* Call the handler function */\n" "nih_error_push_context ();\n" "((%s)pending_data->handler) (pending_data->data, message, properties);\n" "nih_error_pop_context ();\n" "\n" "nih_free (message);\n" "dbus_message_unref (reply);\n", handler_type)) return NULL; handler_name = nih_sprintf (NULL, "(*%s)", handler_type); if (! handler_name) return NULL; handler_func = type_func_new (NULL, "typedef void", handler_name); if (! handler_func) return NULL; arg = type_var_new (handler_func, "void *", "data"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); arg = type_var_new (handler_func, "NihDBusMessage *", "message"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); arg = type_var_new (handler_func, c_type, "properties"); if (! arg) return NULL; if (! type_to_const (&arg->type, arg)) return NULL; nih_list_add (&handler_func->args, &arg->entry); /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "%s" "\n" "%s", vars_block, assert_block, steal_block, demarshal_block, call_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the functions to the prototypes and typedefs list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); nih_list_add (typedefs, &handler_func->entry); nih_ref (handler_func, code); NIH_LIST_FOREACH_SAFE (&all_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } nih_ref (structure, code); nih_list_add (structs, &structure->entry); return code; } /** * interface_proxy_get_all_sync_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface to generate function for, * @prototypes: list to append function prototypes to, * @structs: list to append structure definitions to. * * Generates C code for a function that will make a synchronous method * call to obtain the value of all of the properties of @interface. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list, with the name as @name itself. * * If any of the arguments require a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and the * property. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * interface_proxy_get_all_sync_function (const void *parent, const char *prefix, Interface * interface, NihList * prototypes, NihList * structs) { nih_local char * c_type = NULL; nih_local TypeStruct *structure = NULL; NihList locals; NihList all_structs; nih_local char * name = NULL; nih_local TypeFunc * func = NULL; TypeVar * arg; NihListEntry * attrib; nih_local char * assert_block = NULL; nih_local TypeVar * message_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * arrayiter_var = NULL; nih_local TypeVar * dictiter_var = NULL; nih_local TypeVar * variter_var = NULL; nih_local TypeVar * error_var = NULL; nih_local TypeVar * reply_var = NULL; nih_local TypeVar * count_var = NULL; nih_local TypeVar * interface_var = NULL; nih_local TypeVar * property_var = NULL; nih_local char * call_block = NULL; nih_local char * demarshal_block = NULL; nih_local char * property_block = NULL; nih_local char * oom_error_code = NULL; nih_local char * type_error_code = NULL; size_t property_count; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (prototypes != NULL); nih_assert (structs != NULL); nih_list_init (&locals); nih_list_init (&all_structs); /* The function returns an integer, and takes a parent object and * the proxy object as the argument along with an output structure * argument for the property values. The integer is negative if a * raised error occurred, so we want warning if the result isn't * used. */ name = symbol_extern (NULL, prefix, interface->symbol, NULL, "get_all", "sync"); if (! name) return NULL; func = type_func_new (NULL, "int", name); if (! func) return NULL; attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "warn_unused_result"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); arg = type_var_new (func, "const void *", "parent"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "NihDBusProxy *", "proxy"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (proxy != NULL);\n")) return NULL; c_type = symbol_typedef (NULL, prefix, interface->symbol, NULL, "properties", NULL); if (! c_type) return NULL; structure = type_struct_new (NULL, c_type); if (! structure) return NULL; if (! type_to_pointer (&c_type, NULL)) return NULL; if (! type_to_pointer (&c_type, NULL)) return NULL; arg = type_var_new (func, c_type, "properties"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (properties != NULL);\n")) return NULL; /* The function requires a message pointer, which we allocate, * and an iterator for it to append the arguments. We also need * a reply message pointer as well and an error object. * Rather than deal with these by hand, it's far easier to put them * on the locals list and deal with them along with the rest. */ message_var = type_var_new (NULL, "DBusMessage *", "method_call"); if (! message_var) return NULL; nih_list_add (&locals, &message_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); arrayiter_var = type_var_new (NULL, "DBusMessageIter", "arrayiter"); if (! arrayiter_var) return NULL; nih_list_add (&locals, &arrayiter_var->entry); dictiter_var = type_var_new (NULL, "DBusMessageIter", "dictiter"); if (! dictiter_var) return NULL; nih_list_add (&locals, &dictiter_var->entry); variter_var = type_var_new (NULL, "DBusMessageIter", "variter"); if (! variter_var) return NULL; nih_list_add (&locals, &variter_var->entry); error_var = type_var_new (NULL, "DBusError", "error"); if (! error_var) return NULL; nih_list_add (&locals, &error_var->entry); reply_var = type_var_new (NULL, "DBusMessage *", "reply"); if (! reply_var) return NULL; nih_list_add (&locals, &reply_var->entry); count_var = type_var_new (NULL, "size_t", "property_count"); if (! count_var) return NULL; nih_list_add (&locals, &count_var->entry); /* Annoyingly we need a variable for the interface name, since * D-Bus wants its address and can't just take a constant string. * We also need a variable in which to store the property names * we find. */ interface_var = type_var_new (NULL, "const char *", "interface"); if (! interface_var) return NULL; nih_list_add (&locals, &interface_var->entry); property_var = type_var_new (NULL, "const char *", "property"); if (! property_var) return NULL; nih_list_add (&locals, &property_var->entry); /* Create the method call to get the properties, the property * interface gets specified as an argument - the method call * interface is the D-Bus properties one. */ if (! nih_strcat_sprintf (&call_block, NULL, "/* Construct the method call message. */\n" "method_call = dbus_message_new_method_call (proxy->name, proxy->path, \"%s\", \"GetAll\");\n" "if (! method_call)\n" "\tnih_return_no_memory_error (-1);\n" "\n" "dbus_message_set_auto_start (method_call, proxy->auto_start);\n" "\n" "dbus_message_iter_init_append (method_call, &iter);\n" "\n" "interface = \"%s\";\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (-1);\n" "}\n" "\n", DBUS_INTERFACE_PROPERTIES, interface->name)) return NULL; /* FIXME autostart? */ /* Complete the marshalling block by sending the message and checking * for error replies. */ if (! nih_strcat_sprintf (&call_block, NULL, "/* Send the message, and wait for the reply. */\n" "dbus_error_init (&error);\n" "\n" "reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error);\n" "if (! reply) {\n" "\tdbus_message_unref (method_call);\n" "\n" "\tif (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) {\n" "\t\tnih_error_raise_no_memory ();\n" "\t} else {\n" "\t\tnih_dbus_error_raise (error.name, error.message);\n" "\t}\n" "\n" "\tdbus_error_free (&error);\n" "\treturn -1;\n" "}\n" "\n")) return NULL; /* Begin the demarshalling block, making sure that the first * argument is an array and recursing into it and looping over * the values. */ if (! nih_strcat_sprintf (&demarshal_block, NULL, "dbus_message_unref (method_call);\n" "\n" "/* Iterate the method arguments, recursing into the array */\n" "dbus_message_iter_init (reply, &iter);\n" "\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) {\n" "\tdbus_message_unref (reply);\n" "\tnih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "}\n" "\n" "*properties = NIH_MUST (nih_new (parent, %s));\n" "property_count = 0;\n" "\n" "dbus_message_iter_recurse (&iter, &arrayiter);\n" "\n" "while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) {\n" "\t__label__ enomem;\n" "\n", structure->name)) return NULL; /* Begin the property checking block, each array item should be * a dictionary entry which we recurse into; the first value of * which should be a string containing the property name. */ if (! nih_strcat_sprintf (&property_block, NULL, "if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) {\n" "\tnih_free (*properties);\n" "\t*properties = NULL;\n" "\tdbus_message_unref (reply);\n" "\tnih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "}\n" "\n" "dbus_message_iter_recurse (&arrayiter, &dictiter);\n" "\n" "if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) {\n" "\tnih_free (*properties);\n" "\t*properties = NULL;\n" "\tdbus_message_unref (reply);\n" "\tnih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "}\n" "\n" "dbus_message_iter_get_basic (&dictiter, &property);\n" "\n" "dbus_message_iter_next (&dictiter);\n" "\n" "if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) {\n" "\tnih_free (*properties);\n" "\t*properties = NULL;\n" "\tdbus_message_unref (reply);\n" "\tnih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "}\n" "\n" "dbus_message_iter_recurse (&dictiter, &variter);\n")) return NULL; /* In case of out of memory, we can't just return because we've * already made the method call so we loop over the code instead. * But in case of type error in the returned arguments, all we * can do is return an error. */ oom_error_code = nih_strdup (NULL, "goto enomem;\n"); if (! oom_error_code) return NULL; type_error_code = nih_strdup (NULL, "nih_free (*properties);\n" "*properties = NULL;\n" "dbus_message_unref (reply);\n" "nih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" " _(NIH_DBUS_INVALID_ARGS_STR));\n"); if (! type_error_code) return NULL; property_count = 0; NIH_LIST_FOREACH (&interface->properties, iter) { Property * property = (Property *)iter; DBusSignatureIter iter; NihList property_outputs; NihList property_locals; NihList property_structs; nih_local char * block = NULL; if (property->access == NIH_DBUS_WRITE) continue; dbus_signature_iter_init (&iter, property->type); nih_list_init (&property_outputs); nih_list_init (&property_locals); nih_list_init (&property_structs); block = demarshal (NULL, &iter, "*properties", "variter", property->symbol, oom_error_code, type_error_code, &property_outputs, &property_locals, prefix, interface->symbol, property->symbol, NULL, &property_structs); if (! block) return NULL; if (! nih_strcat (&block, NULL, "\n")) return NULL; /* Each of the outputs from the demarshalling code becomes a * local variable to our function that we store the value in, * and that we copy into the structure. */ NIH_LIST_FOREACH_SAFE (&property_outputs, iter) { TypeVar *var = (TypeVar *)iter; TypeVar *member_var; /* Create the structure member entry */ member_var = type_var_new (structure, var->type, var->name); if (! member_var) return NULL; nih_list_add (&structure->members, &member_var->entry); /* Add code to copy from local variable */ if (! nih_strcat_sprintf (&block, NULL, "(*properties)->%s = %s;\n", var->name, var->name)) return NULL; /* Add to locals */ nih_list_add (&locals, &var->entry); nih_ref (var, demarshal_block); } NIH_LIST_FOREACH_SAFE (&property_locals, iter) { TypeVar *var = (TypeVar *)iter; nih_list_add (&locals, &var->entry); nih_ref (var, demarshal_block); } NIH_LIST_FOREACH_SAFE (&property_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_list_add (&all_structs, &structure->entry); nih_ref (structure, demarshal_block); } if (! nih_strcat (&block, NULL, "\n" "nih_assert (++property_count);\n")) return NULL; /* Wrap the code in a test for the property by name */ if (! indent (&block, NULL, 1)) return NULL; if (! nih_strcat_sprintf (&property_block, NULL, "\n" "if (! strcmp (property, \"%s\")) {\n" "%s" "}\n", property->name, block)) return NULL; property_count++; } /* Finish the property checking block, making sure that there are * no further items in the dictionary entry before moving on to the * next array item. */ if (! nih_strcat_sprintf (&property_block, NULL, "\n" "dbus_message_iter_next (&dictiter);\n" "\n" "if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) {\n" "\tnih_free (*properties);\n" "\t*properties = NULL;\n" "\tdbus_message_unref (reply);\n" "\tnih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "}\n" "\n" "dbus_message_iter_next (&arrayiter);\n")) return NULL; /* Indent the property block and append to the demarshal block */ if (! indent (&property_block, NULL, 1)) return NULL; if (! nih_strcat (&demarshal_block, NULL, property_block)) return NULL; /* Finish off the demarshalling block by ending the loop and * making sure that there are no further arguments in the reply. */ if (! nih_strcat_sprintf (&demarshal_block, NULL, "enomem: __attribute__ ((unused));\n" "}\n" "\n" "dbus_message_iter_next (&iter);\n" "\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {\n" "\tnih_free (*properties);\n" "\t*properties = NULL;\n" "\tdbus_message_unref (reply);\n" "\tnih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "}\n" "\n" "if (property_count < %zu) {\n" "\tnih_free (*properties);\n" "\t*properties = NULL;\n" "\tdbus_message_unref (reply);\n" "\tnih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "}\n" "\n" "dbus_message_unref (reply);\n", property_count)) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "%s" "\n" "return 0;\n", vars_block, assert_block, call_block, demarshal_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the function to the prototypes list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); NIH_LIST_FOREACH_SAFE (&all_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } nih_ref (structure, code); nih_list_add (structs, &structure->entry); return code; } libnih-1.0.3/nih-dbus-tool/method.c0000644000175000017500000023000411445765555014031 00000000000000/* nih-dbus-tool * * method.c - method parsing and generation * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include "symbol.h" #include "interface.h" #include "method.h" #include "argument.h" #include "parse.h" #include "indent.h" #include "type.h" #include "marshal.h" #include "demarshal.h" #include "errors.h" /** * method_name_valid: * @name: Member name to verify. * * Verifies whether @name matches the specification for a D-Bus interface * member name, and thus is valid for a method. * * Returns: TRUE if valid, FALSE if not. **/ int method_name_valid (const char *name) { nih_assert (name != NULL); /* We can get away with just using strlen() here even through name * is in UTF-8 because all the valid characters are ASCII. */ for (size_t i = 0; i < strlen (name); i++) { /* Names may contain digits, but not at the beginning. */ if ((name[i] >= '0') && (name[i] <= '9')) { if (i == 0) return FALSE; continue; } /* Valid characters anywhere are [A-Za-z_] */ if ( ((name[i] < 'A') || (name[i] > 'Z')) && ((name[i] < 'a') || (name[i] > 'z')) && (name[i] != '_')) return FALSE; } /* Name must be at least 1 character and no more than 255 characters */ if ((strlen (name) < 1) || (strlen (name) > 255)) return FALSE; return TRUE; } /** * method_new: * @parent: parent object for new method, * @name: D-Bus name of method. * * Allocates a new D-Bus object Method data structure, with the D-Bus name * set to @name. The returned structure is not placed into any list and * has no arguments. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned method. When all parents * of the returned method are freed, the returned method will also be * freed. * * Returns: the new method or NULL if the allocation failed. **/ Method * method_new (const void *parent, const char *name) { Method *method; nih_assert (name != NULL); method = nih_new (parent, Method); if (! method) return NULL; nih_list_init (&method->entry); nih_alloc_set_destructor (method, nih_list_destroy); method->name = nih_strdup (method, name); if (! method->name) { nih_free (method); return NULL; } method->symbol = NULL; method->async = FALSE; method->no_reply = FALSE; method->deprecated = FALSE; nih_list_init (&method->arguments); return method; } /** * method_start_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed, * @attr: NULL-terminated array of attribute name and value pairs. * * This function is called by parse_start_tag() for a "method" * start tag, a child of the "interface" tag that defines a method the * D-Bus interface specifies. * * If the method does not appear within an interface tag a warning is * emitted and the tag will be ignored. * * Methods must have a "name" attribute containing the D-Bus name of the * method. * * Any unknown attributes result in a warning and will be ignored. * * A Method object will be allocated and pushed onto the stack, this is * not added to the interface until the end tag is found. * * Returns: zero on success, negative value on raised error. **/ int method_start_tag (XML_Parser xmlp, const char * tag, char * const *attr) { ParseContext * context; ParseStack * parent; nih_local Method *method = NULL; char * const * key; char * const * value; const char * name = NULL; nih_assert (xmlp != NULL); nih_assert (tag != NULL); nih_assert (attr != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); /* Methods should only appear inside interfaces. */ parent = parse_stack_top (&context->stack); if ((! parent) || (parent->type != PARSE_INTERFACE)) { nih_warn ("%s:%zu:%zu: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unexpected tag")); if (! parse_stack_push (NULL, &context->stack, PARSE_IGNORED, NULL)) nih_return_system_error (-1); return 0; } /* Retrieve the name from the attributes */ for (key = attr; key && *key; key += 2) { value = key + 1; nih_assert (value && *value); if (! strcmp (*key, "name")) { name = *value; } else { nih_warn ("%s:%zu:%zu: %s: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unknown attribute"), *key); } } /* Check we have a name and that it's valid */ if (! name) nih_return_error (-1, METHOD_MISSING_NAME, _(METHOD_MISSING_NAME_STR)); if (! method_name_valid (name)) nih_return_error (-1, METHOD_INVALID_NAME, _(METHOD_INVALID_NAME_STR)); /* Allocate a Method object and push onto the stack */ method = method_new (NULL, name); if (! method) nih_return_system_error (-1); if (! parse_stack_push (NULL, &context->stack, PARSE_METHOD, method)) { nih_error_raise_system (); return -1; } return 0; } /** * method_end_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed. * * This function is called by parse_end_tag() for a "method" end * tag, and matches a call to method_start_tag() made at the same parsing * level. * * The method is added to the list of methods defined by the parent * interface. * * Returns: zero on success, negative value on raised error. **/ int method_end_tag (XML_Parser xmlp, const char *tag) { ParseContext *context; ParseStack * entry; ParseStack * parent; Method * method; Method * conflict; Interface * interface; nih_assert (xmlp != NULL); nih_assert (tag != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); entry = parse_stack_top (&context->stack); nih_assert (entry != NULL); nih_assert (entry->type == PARSE_METHOD); method = entry->method; /* Generate a symbol from the name */ if (! method->symbol) { method->symbol = symbol_from_name (method, method->name); if (! method->symbol) nih_return_no_memory_error (-1); } nih_list_remove (&entry->entry); parent = parse_stack_top (&context->stack); nih_assert (parent != NULL); nih_assert (parent->type == PARSE_INTERFACE); interface = parent->interface; /* Make sure there's not a conflict before adding the method */ conflict = method_lookup (interface, method->symbol); if (conflict) { nih_error_raise_printf (METHOD_DUPLICATE_SYMBOL, _(METHOD_DUPLICATE_SYMBOL_STR), method->symbol, conflict->name); return -1; } /* Ignore the no_reply annoitation is the method has output * arguments. */ NIH_LIST_FOREACH (&method->arguments, iter) { Argument *argument = (Argument *)iter; if ((argument->direction == NIH_DBUS_ARG_OUT) && method->no_reply) { method->no_reply = FALSE; nih_warn ("%s:%zu:%zu: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored NoReply annotation for method with output arguments")); break; } } /* Ignore the async annotation if the method is no_reply */ if (method->no_reply && method->async) { method->async = FALSE; nih_warn ("%s:%zu:%zu: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored Async annotation for NoReply method")); } nih_debug ("Add %s method to %s interface", method->name, interface->name); nih_list_add (&interface->methods, &method->entry); nih_ref (method, interface); nih_free (entry); return 0; } /** * method_annotation: * @method: method object annotation applies to, * @name: annotation name, * @value: annotation value. * * Handles applying the annotation @name with value @value to the method * @method. Methods may be annotated as deprecated, that a client should * expect no reply, an alternate symbol name may be specified or that the * object implementation will be asynchronous. * * Unknown annotations or illegal values to the known annotations result * in an error being raised. * * Returns: zero on success, negative value on raised error. **/ int method_annotation (Method * method, const char *name, const char *value) { nih_assert (method != NULL); nih_assert (name != NULL); nih_assert (value != NULL); if (! strcmp (name, "org.freedesktop.DBus.Deprecated")) { if (! strcmp (value, "true")) { nih_debug ("Marked %s method as deprecated", method->name); method->deprecated = TRUE; } else if (! strcmp (value, "false")) { nih_debug ("Marked %s method as not deprecated", method->name); method->deprecated = FALSE; } else { nih_return_error (-1, METHOD_ILLEGAL_DEPRECATED, _(METHOD_ILLEGAL_DEPRECATED_STR)); } } else if (! strcmp (name, "org.freedesktop.DBus.Method.NoReply")) { if (! strcmp (value, "true")) { nih_debug ("Marked %s method to expect no reply", method->name); method->no_reply = TRUE; } else if (! strcmp (value, "false")) { nih_debug ("Marked %s method to expect a reply", method->name); method->no_reply = FALSE; } else { nih_return_error (-1, METHOD_ILLEGAL_NO_REPLY, _(METHOD_ILLEGAL_NO_REPLY_STR)); } } else if (! strcmp (name, "com.netsplit.Nih.Symbol")) { if (symbol_valid (value)) { if (method->symbol) nih_unref (method->symbol, method); method->symbol = nih_strdup (method, value); if (! method->symbol) nih_return_no_memory_error (-1); nih_debug ("Set %s method symbol to %s", method->name, method->symbol); } else { nih_return_error (-1, METHOD_INVALID_SYMBOL, _(METHOD_INVALID_SYMBOL_STR)); } } else if (! strcmp (name, "com.netsplit.Nih.Method.Async")) { if (! strcmp (value, "true")) { nih_debug ("Marked %s method as async", method->name); method->async = TRUE; } else if (! strcmp (value, "false")) { nih_debug ("Marked %s method as non-async", method->name); method->async = FALSE; } else { nih_return_error (-1, METHOD_ILLEGAL_ASYNC, _(METHOD_ILLEGAL_ASYNC_STR)); } } else { nih_error_raise_printf (METHOD_UNKNOWN_ANNOTATION, "%s: %s: %s", _(METHOD_UNKNOWN_ANNOTATION_STR), method->name, name); return -1; } return 0; } /** * method_lookup: * @interface: interface to search, * @symbol: method symbol to find. * * Finds a method in @interface's methods list which has the generated * or supplied C symbol @symbol. * * Returns: method found or NULL if no method matches. **/ Method * method_lookup (Interface * interface, const char *symbol) { nih_assert (interface != NULL); nih_assert (symbol != NULL); NIH_LIST_FOREACH (&interface->methods, iter) { Method *method = (Method *)iter; if (method->symbol && (! strcmp (method->symbol, symbol))) return method; } return NULL; } /** * method_lookup_argument: * @method: method to search, * @symbol: argument symbol to find. * * Finds a argument in @method's arguments list which has the generated * or supplied C symbol @symbol. * * Returns: argument found or NULL if no argument matches. **/ Argument * method_lookup_argument (Method * method, const char *symbol) { nih_assert (method != NULL); nih_assert (symbol != NULL); NIH_LIST_FOREACH (&method->arguments, iter) { Argument *argument = (Argument *)iter; if (argument->symbol && (! strcmp (argument->symbol, symbol))) return argument; } return NULL; } /** * method_object_function: * @parent: parent object for new string, * @prefix: prefix for function name, * @interface: interface of @method, * @method: method to generate function for, * @prototypes: list to append function prototypes to, * @handlers: list to append definitions of required handlers to, * @structs: list to append structure definitions to. * * Generates C code for a function to handle the method @method on @interface, * demarshalling the incoming arguments, calling a handler function * and marshalling the output arguments into a reply or responding with an * error. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * The prototype for the handler function is returned as a TypeFunc object * added to the @handlers list. * * The names of both the returned function and handled function prototype * will be generated using information in @interface and @method, prefixed * with @prefix. * * If any of the arguments require a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @method. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * method_object_function (const void *parent, const char *prefix, Interface * interface, Method * method, NihList * prototypes, NihList * handlers, NihList * structs) { NihList locals; NihList method_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; nih_local char * assert_block = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * reply_var = NULL; nih_local char * demarshal_block = NULL; nih_local char * call_block = NULL; nih_local char * handler_name = NULL; nih_local TypeFunc *handler_func = NULL; NihListEntry * attrib; nih_local char * marshal_block = NULL; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (method != NULL); nih_assert (prototypes != NULL); nih_assert (handlers != NULL); nih_assert (structs != NULL); nih_list_init (&locals); nih_list_init (&method_structs); /* The function returns a DBusHandlerResult since it's a handling * function, and accepts arguments for the object and message. * We don't have any attributes, not even "deprecated" for a * deprecated method since we always want to implement it without * error. */ name = symbol_impl (NULL, prefix, interface->name, method->name, "method"); if (! name) return NULL; func = type_func_new (NULL, "DBusHandlerResult", name); if (! func) return NULL; arg = type_var_new (func, "NihDBusObject *", "object"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (object != NULL);\n")) return NULL; arg = type_var_new (func, "NihDBusMessage *", "message"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (message != NULL);\n")) return NULL; /* The function requires a local iterator for the message, and a * reply message pointer. Rather than deal with these by hand, * it's far easier to put them on the locals list and deal with * them along with the rest. */ iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); reply_var = type_var_new (NULL, "DBusMessage *", "reply"); if (! reply_var) return NULL; nih_list_add (&locals, &reply_var->entry); /* Begin the pre-handler demarshalling block with the iterator */ if (! nih_strcat_sprintf (&demarshal_block, NULL, "/* Iterate the arguments to the message and demarshal into arguments\n" " * for our own function call.\n" " */\n" "dbus_message_iter_init (message->message, &iter);\n" "\n")) return NULL; /* Begin the handler calling block. The handler function always * has a warn_unusued_result attribute, just for completeness. */ handler_name = symbol_extern (NULL, prefix, interface->symbol, NULL, method->symbol, NULL); if (! handler_name) return NULL; if (! nih_strcat_sprintf (&call_block, NULL, "/* Call the handler function */\n" "nih_error_push_context ();\n" "if (%s (object->data, message", handler_name)) return NULL; handler_func = type_func_new (NULL, "int", handler_name); if (! handler_func) return NULL; attrib = nih_list_entry_new (handler_func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "warn_unused_result"); if (! attrib->str) return NULL; nih_list_add (&handler_func->attribs, &attrib->entry); arg = type_var_new (handler_func, "void *", "data"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); arg = type_var_new (handler_func, "NihDBusMessage *", "message"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); /* Begin the post-handler marshalling block with the creation of * the return message and re-using the iterator to marshal it. */ if (! method->async) if (! nih_strcat_sprintf (&marshal_block, NULL, "/* Construct the reply message. */\n" "reply = dbus_message_new_method_return (message->message);\n" "if (! reply)\n" "\tgoto enomem;\n" "\n" "dbus_message_iter_init_append (reply, &iter);\n")) return NULL; /* Iterate over the method arguments, for each input argument we * append the code to the pre-handler demarshalling code and for * each output argument we append the code to the post-handler * marshalling code. At the same time, we build up the handler * call itself and transfer the actual arguments to the locals * list. */ NIH_LIST_FOREACH (&method->arguments, iter) { Argument * argument = (Argument *)iter; NihList arg_vars; NihList arg_locals; NihList arg_structs; DBusSignatureIter iter; nih_local char * oom_error_code = NULL; nih_local char * type_error_code = NULL; nih_local char * block = NULL; nih_list_init (&arg_vars); nih_list_init (&arg_locals); nih_list_init (&arg_structs); dbus_signature_iter_init (&iter, argument->type); switch (argument->direction) { case NIH_DBUS_ARG_IN: /* In case of out of memory, let D-Bus decide what to * do. In case of type error, we return an error to * D-Bus. */ oom_error_code = nih_strdup (NULL, "return DBUS_HANDLER_RESULT_NEED_MEMORY;\n"); if (! oom_error_code) return NULL; type_error_code = nih_sprintf (NULL, "reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,\n" " \"Invalid arguments to %s method\");\n" "if (! reply)\n" "\treturn DBUS_HANDLER_RESULT_NEED_MEMORY;\n" "\n" "if (! dbus_connection_send (message->connection, reply, NULL)) {\n" "\tdbus_message_unref (reply);\n" "\treturn DBUS_HANDLER_RESULT_NEED_MEMORY;\n" "}\n" "\n" "dbus_message_unref (reply);\n" "return DBUS_HANDLER_RESULT_HANDLED;\n", method->name); if (! type_error_code) return NULL; block = demarshal (NULL, &iter, "message", "iter", argument->symbol, oom_error_code, type_error_code, &arg_vars, &arg_locals, prefix, interface->symbol, method->symbol, argument->symbol, &arg_structs); if (! block) return NULL; if (! nih_strcat_sprintf (&demarshal_block, NULL, "%s" "\n", block)) return NULL; NIH_LIST_FOREACH_SAFE (&arg_vars, iter) { TypeVar *var = (TypeVar *)iter; if (! nih_strcat_sprintf (&call_block, NULL, ", %s", var->name)) return NULL; nih_list_add (&locals, &var->entry); nih_ref (var, call_block); /* Handler argument is const */ arg = type_var_new (handler_func, var->type, var->name); if (! arg) return NULL; if (! type_to_const (&arg->type, arg)) return NULL; nih_list_add (&handler_func->args, &arg->entry); } NIH_LIST_FOREACH_SAFE (&arg_locals, iter) { TypeVar *var = (TypeVar *)iter; nih_list_add (&locals, &var->entry); nih_ref (var, call_block); } NIH_LIST_FOREACH_SAFE (&arg_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_list_add (&method_structs, &structure->entry); nih_ref (structure, call_block); } break; case NIH_DBUS_ARG_OUT: /* Asynchronous methods don't have output arguments */ if (method->async) continue; /* In case of out of memory, we can't just return * beacuse handler side-effects have already happened. * Discard the message and loop again to try and * reconstruct it. */ oom_error_code = nih_strdup (NULL, "dbus_message_unref (reply);\n" "reply = NULL;\n" "goto enomem;\n"); if (! oom_error_code) return NULL; block = marshal (NULL, &iter, "iter", argument->symbol, oom_error_code, &arg_vars, &arg_locals, prefix, interface->symbol, method->symbol, argument->symbol, &arg_structs); if (! block) return NULL; if (! nih_strcat_sprintf (&marshal_block, NULL, "\n" "%s", block)) return NULL; /* Need to pass the address of the return variable */ NIH_LIST_FOREACH_SAFE (&arg_vars, iter) { TypeVar *var = (TypeVar *)iter; if (! nih_strcat_sprintf (&call_block, NULL, ", &%s", var->name)) return NULL; nih_list_add (&locals, &var->entry); nih_ref (var, call_block); /* Handler argument is a pointer */ arg = type_var_new (handler_func, var->type, var->name); if (! arg) return NULL; if (! type_to_pointer (&arg->type, arg)) return NULL; nih_list_add (&handler_func->args, &arg->entry); } NIH_LIST_FOREACH_SAFE (&arg_locals, iter) { TypeVar *var = (TypeVar *)iter; nih_list_add (&locals, &var->entry); nih_ref (var, call_block); } NIH_LIST_FOREACH_SAFE (&arg_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_list_add (&method_structs, &structure->entry); nih_ref (structure, call_block); } break; default: nih_assert_not_reached (); } } /* Complete the demarshalling block, checking for any unexpected * arguments which we also want to error on. */ if (! nih_strcat_sprintf (&demarshal_block, NULL, "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {\n" "\treply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS,\n" "\t \"Invalid arguments to %s method\");\n" "\tif (! reply)\n" "\t\treturn DBUS_HANDLER_RESULT_NEED_MEMORY;\n" "\n" "\tif (! dbus_connection_send (message->connection, reply, NULL)) {\n" "\t\tdbus_message_unref (reply);\n" "\t\treturn DBUS_HANDLER_RESULT_NEED_MEMORY;\n" "\t}\n" "\n" "\tdbus_message_unref (reply);\n" "\treturn DBUS_HANDLER_RESULT_HANDLED;\n" "}\n" "\n", method->name)) return NULL; /* Complete the call block, handling errors from the called function; * out of memory is easy, we return that to D-Bus and let that decide * what to do. Other errors must be returned, even if we run out of * memory while trying to return them because side-effects of the * handler function may have already happened. */ if (! nih_strcat_sprintf (&call_block, NULL, ") < 0) {\n" "\tNihError *err;\n" "\n" "\terr = nih_error_get ();\n" "\tif (err->number == ENOMEM) {\n" "\t\tnih_free (err);\n" "\t\tnih_error_pop_context ();\n" "\n" "\t\treturn DBUS_HANDLER_RESULT_NEED_MEMORY;\n" "\t} else if (err->number == NIH_DBUS_ERROR) {\n" "\t\tNihDBusError *dbus_err = (NihDBusError *)err;\n" "\n" "\t\treply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message));\n" "\t\tnih_free (err);\n" "\t\tnih_error_pop_context ();\n" "\n" "\t\tNIH_MUST (dbus_connection_send (message->connection, reply, NULL));\n" "\n" "\t\tdbus_message_unref (reply);\n" "\t\treturn DBUS_HANDLER_RESULT_HANDLED;\n" "\t} else {\n" "\t\treply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message));\n" "\t\tnih_free (err);\n" "\t\tnih_error_pop_context ();\n" "\n" "\t\tNIH_MUST (dbus_connection_send (message->connection, reply, NULL));\n" "\n" "\t\tdbus_message_unref (reply);\n" "\t\treturn DBUS_HANDLER_RESULT_HANDLED;\n" "\t}\n" "}\n" "nih_error_pop_context ();\n" "\n")) return NULL; if (! method->async) if (! nih_strcat_sprintf (&call_block, NULL, "/* If the sender doesn't care about a reply, don't bother wasting\n" " * effort constructing and sending one.\n" " */\n" "if (dbus_message_get_no_reply (message->message))\n" "\treturn DBUS_HANDLER_RESULT_HANDLED;\n" "\n")) return NULL; /* Indent the marshalling block, it goes inside a while loop */ if (! method->async) if (! indent (&marshal_block, NULL, 1)) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "%s", vars_block, assert_block, demarshal_block, call_block)) return NULL; if (! method->async) { if (! nih_strcat_sprintf (&body, NULL, "do {\n" "\t__label__ enomem;\n" "\n" "%s" "enomem: __attribute__ ((unused));\n" "} while (! reply);\n" "\n" "/* Send the reply, appending it to the outgoing queue. */\n" "NIH_MUST (dbus_connection_send (message->connection, reply, NULL));\n" "\n" "dbus_message_unref (reply);\n" "\n", marshal_block)) return NULL; } if (! nih_strcat_sprintf (&body, NULL, "return DBUS_HANDLER_RESULT_HANDLED;\n")) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the functions to the prototypes and handlers lists */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); nih_list_add (handlers, &handler_func->entry); nih_ref (handler_func, code); NIH_LIST_FOREACH_SAFE (&method_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_list_add (structs, &structure->entry); nih_ref (structure, code); } return code; } /** * method_reply_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface of @method, * @method: method to generate function for, * @prototypes: list to append function prototypes to, * @structs: list to append structure definitions to. * * Generates C code for a function to send a reply for the method @method * on @interface by marshalling the arguments. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * The name of the returned function will be generated using information * in @interface and @method, prefixed with @prefix. * * If any of the arguments require a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @method. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * method_reply_function (const void *parent, const char *prefix, Interface * interface, Method * method, NihList * prototypes, NihList * structs) { NihList locals; NihList method_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; NihListEntry * attrib; nih_local char * assert_block = NULL; nih_local TypeVar * reply_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local char * marshal_block = NULL; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (method != NULL); nih_assert (prototypes != NULL); nih_assert (structs != NULL); nih_list_init (&locals); nih_list_init (&method_structs); /* The function returns an integer, and accepts an argument for * the original message. The integer indicates whether an error * occurred, so we want if the result isn't used; but like the * method handler, we don't care about marshalling. */ name = symbol_extern (NULL, prefix, interface->symbol, NULL, method->symbol, "reply"); if (! name) return NULL; func = type_func_new (NULL, "int", name); if (! func) return NULL; arg = type_var_new (func, "NihDBusMessage *", "message"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (message != NULL);\n")) return NULL; attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "warn_unused_result"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); /* The function requires a reply message pointer, which we allocate, * and an iterator for it to append the arguments. Rather than * deal with these by hand, it's far easier to put them on the * locals list and deal with them along with the rest. */ reply_var = type_var_new (NULL, "DBusMessage *", "reply"); if (! reply_var) return NULL; nih_list_add (&locals, &reply_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); /* Create the reply and set up the iterator to append to it. */ if (! nih_strcat_sprintf (&marshal_block, NULL, "/* If the sender doesn't care about a reply, don't bother wasting\n" " * effort constructing and sending one.\n" " */\n" "if (dbus_message_get_no_reply (message->message))\n" "\treturn 0;\n" "\n" "/* Construct the reply message. */\n" "reply = dbus_message_new_method_return (message->message);\n" "if (! reply)\n" "\treturn -1;\n" "\n" "dbus_message_iter_init_append (reply, &iter);\n" "\n")) return NULL; /* Iterate over the method's output arguments, for each one we * append the code to the marshalling code and at the same time * build up our own expected arguments themselves. */ NIH_LIST_FOREACH (&method->arguments, iter) { Argument * argument = (Argument *)iter; NihList arg_vars; NihList arg_locals; NihList arg_structs; DBusSignatureIter iter; nih_local char * oom_error_code = NULL; nih_local char * type_error_code = NULL; nih_local char * block = NULL; if (argument->direction != NIH_DBUS_ARG_OUT) continue; nih_list_init (&arg_vars); nih_list_init (&arg_locals); nih_list_init (&arg_structs); dbus_signature_iter_init (&iter, argument->type); /* In case of out of memory, simply return; the caller * can try again. */ oom_error_code = nih_strdup (NULL, "dbus_message_unref (reply);\n" "return -1;\n"); if (! oom_error_code) return NULL; block = marshal (NULL, &iter, "iter", argument->symbol, oom_error_code, &arg_vars, &arg_locals, prefix, interface->symbol, method->symbol, argument->symbol, &arg_structs); if (! block) return NULL; if (! nih_strcat_sprintf (&marshal_block, NULL, "%s" "\n", block)) return NULL; /* We take a parameter of the expected type and name of * the marshal input variable; if it's a pointer, we * make sure it's const. */ NIH_LIST_FOREACH_SAFE (&arg_vars, iter) { TypeVar *var = (TypeVar *)iter; if (! type_to_const (&var->type, var)) return NULL; if (! type_strcat_assert (&assert_block, NULL, var, func->args.prev != &func->args ? (TypeVar *)func->args.prev : NULL, _iter.next != &arg_vars ? (TypeVar *)_iter.next : NULL)) return NULL; nih_list_add (&func->args, &var->entry); nih_ref (var, func); } NIH_LIST_FOREACH_SAFE (&arg_locals, iter) { TypeVar *var = (TypeVar *)iter; nih_list_add (&locals, &var->entry); nih_ref (var, marshal_block); } NIH_LIST_FOREACH_SAFE (&arg_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_list_add (&method_structs, &structure->entry); nih_ref (structure, marshal_block); } } /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "/* Send the reply, appending it to the outgoing queue. */\n" "if (! dbus_connection_send (message->connection, reply, NULL)) {\n" "\tdbus_message_unref (reply);\n" "\treturn -1;\n" "}\n" "\n" "dbus_message_unref (reply);\n" "\n" "return 0;\n", vars_block, assert_block, marshal_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the function to the prototypes list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); NIH_LIST_FOREACH_SAFE (&method_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } return code; } /** * method_proxy_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface of @method, * @method: method to generate function for, * @prototypes: list to append function prototypes to, * @structs: list to append structure definitions to. * * Generates C code for a function to make an asynchronous method call for * the method @method on interface @interface by marshalling the arguments, * calling a notify function when the method call completes. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * The prototype for the notify function is returned as a TypeFunc object * added to the @handlers list. * * The names of both the returned function and notify function prototype * will be generated using information in @interface and @method, prefixed * with @prefix. * * The notify function will call a handler function passed in if the * reply is valid. The name and type for this can be obtained from * method_proxy_notify_function(). * * If any of the arguments require a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @method. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * method_proxy_function (const void *parent, const char *prefix, Interface * interface, Method * method, NihList * prototypes, NihList * structs) { NihList locals; NihList method_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; NihListEntry * attrib; nih_local char * assert_block = NULL; nih_local TypeVar * message_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * pending_var = NULL; nih_local TypeVar * data_var = NULL; nih_local char * marshal_block = NULL; nih_local char * vars_block = NULL; nih_local char * handler_type = NULL; nih_local char * notify_name = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (method != NULL); nih_assert (prototypes != NULL); nih_assert (structs != NULL); nih_list_init (&locals); nih_list_init (&method_structs); /* The function returns a pending call, and takes the proxy object * as the argument along with the input arguments of the method call. * The pending call also indicates whether an error occurred, so we * want warning if the result isn't used. We don't have a malloc * attribute, since we can't guarantee that D-Bus doesn't cache them. * Since this is used by the client, we also add a deprecated * attribute if the method is deprecated. */ name = symbol_extern (NULL, prefix, interface->symbol, NULL, method->symbol, NULL); if (! name) return NULL; func = type_func_new (NULL, "DBusPendingCall *", name); if (! func) return NULL; attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "warn_unused_result"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); if (method->deprecated) { attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "deprecated"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); } arg = type_var_new (func, "NihDBusProxy *", "proxy"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (proxy != NULL);\n")) return NULL; /* The function requires a message pointer, which we allocate, * and an iterator for it to append the arguments. We also need * a pending call pointer as well, which is what we return after * sending the message call. Rather than deal with these by hand, * it's far easier to put them on the locals list and deal with them * along with the rest. */ message_var = type_var_new (NULL, "DBusMessage *", "method_call"); if (! message_var) return NULL; nih_list_add (&locals, &message_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); pending_var = type_var_new (NULL, "DBusPendingCall *", "pending_call"); if (! pending_var) return NULL; nih_list_add (&locals, &pending_var->entry); data_var = type_var_new (NULL, "NihDBusPendingData *", "pending_data"); if (! data_var) return NULL; nih_list_add (&locals, &data_var->entry); /* Create the message and set up the iterator to append to it. */ if (! nih_strcat_sprintf (&marshal_block, NULL, "/* Construct the method call message. */\n" "method_call = dbus_message_new_method_call (proxy->name, proxy->path, \"%s\", \"%s\");\n" "if (! method_call)\n" "\tnih_return_no_memory_error (NULL);\n" "\n" "dbus_message_set_auto_start (method_call, proxy->auto_start);\n" "\n" "dbus_message_iter_init_append (method_call, &iter);\n" "\n", interface->name, method->name)) return NULL; /* FIXME autostart? */ /* Iterate over the method's arguments, for each input argument we * append the code to the pre-call marshalling code. */ NIH_LIST_FOREACH (&method->arguments, iter) { Argument * argument = (Argument *)iter; NihList arg_vars; NihList arg_locals; NihList arg_structs; DBusSignatureIter iter; nih_local char * local_name = NULL; nih_local char * oom_error_code = NULL; nih_local char * type_error_code = NULL; nih_local char * block = NULL; if (argument->direction != NIH_DBUS_ARG_IN) continue; nih_list_init (&arg_vars); nih_list_init (&arg_locals); nih_list_init (&arg_structs); dbus_signature_iter_init (&iter, argument->type); /* In case of out of memory, simply return; the caller * can try again. */ oom_error_code = nih_strdup (NULL, "dbus_message_unref (method_call);\n" "nih_return_no_memory_error (NULL);\n"); if (! oom_error_code) return NULL; block = marshal (NULL, &iter, "iter", argument->symbol, oom_error_code, &arg_vars, &arg_locals, prefix, interface->symbol, method->symbol, argument->symbol, &arg_structs); if (! block) return NULL; if (! nih_strcat_sprintf (&marshal_block, NULL, "%s" "\n", block)) return NULL; /* We take a parameter of the expected type and name of * the marshal input variable; if it's a pointer, we * assert that it's not NULL and make sure it's const. */ NIH_LIST_FOREACH_SAFE (&arg_vars, iter) { TypeVar *var = (TypeVar *)iter; if (! type_to_const (&var->type, var)) return NULL; if (! type_strcat_assert (&assert_block, NULL, var, func->args.prev != &func->args ? (TypeVar *)func->args.prev : NULL, _iter.next != &arg_vars ? (TypeVar *)_iter.next : NULL)) return NULL; nih_list_add (&func->args, &var->entry); nih_ref (var, func); } NIH_LIST_FOREACH_SAFE (&arg_locals, iter) { TypeVar *var = (TypeVar *)iter; nih_list_add (&locals, &var->entry); nih_ref (var, marshal_block); } NIH_LIST_FOREACH_SAFE (&arg_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_list_add (&method_structs, &structure->entry); nih_ref (structure, marshal_block); } } /* After the input arguments, the function also takes the reply * handler, error handler, data and timeout arguments. We allow * the reply handler and error handler to be both NULL, otherwise * both must be given - if you make a method call, you have to * deal with the reply or not expect one at all. */ handler_type = symbol_typedef (NULL, prefix, interface->symbol, NULL, method->symbol, "Reply"); if (! handler_type) return NULL; arg = type_var_new (func, handler_type, "handler"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "NihDBusErrorHandler", "error_handler"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "void *", "data"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert ((handler == NULL) || (error_handler != NULL));\n")) return NULL; arg = type_var_new (func, "int", "timeout"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); /* Complete the marshalling block by sending the message and * establishing the pending call. */ notify_name = symbol_impl (NULL, prefix, interface->name, method->name, "notify"); if (! notify_name) return NULL; if (! nih_strcat_sprintf (&marshal_block, NULL, "/* Handle a fire-and-forget message */\n" "if (! error_handler) {\n" "\tdbus_message_set_no_reply (method_call, TRUE);\n" "\tif (! dbus_connection_send (proxy->connection, method_call, NULL)) {\n" "\t\tdbus_message_unref (method_call);\n" "\t\tnih_return_no_memory_error (NULL);\n" "\t}\n" "\n" "\tdbus_message_unref (method_call);\n" "\treturn (DBusPendingCall *)TRUE;\n" "}\n" "\n" "/* Send the message and set up the reply notification. */\n" "pending_data = nih_dbus_pending_data_new (NULL, proxy->connection,\n" " (NihDBusReplyHandler)handler,\n" " error_handler, data);\n" "if (! pending_data) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n" "pending_call = NULL;\n" "if (! dbus_connection_send_with_reply (proxy->connection, method_call,\n" " &pending_call, timeout)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_free (pending_data);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n" "dbus_message_unref (method_call);\n" "\n" "if (! pending_call) {\n" "\tnih_dbus_error_raise (DBUS_ERROR_DISCONNECTED,\n" "\t \"Connection is closed\");\n" "\tnih_free (pending_data);\n" "\treturn NULL;\n" "}\n" "\n" "NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)%s,\n" " pending_data, (DBusFreeFunction)nih_discard));\n", notify_name)) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "\n" "return pending_call;\n", vars_block, assert_block, marshal_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the function to the prototypes list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); NIH_LIST_FOREACH_SAFE (&method_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } return code; } /** * method_proxy_notify_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface of @method, * @method: method to generate function for, * @prototypes: list to append function prototypes to, * @typedefs: list to append function pointer typedef definitions to, * @structs: list to append structure definitions to. * * Generates C code for a function to handle the notification of a * complete pending call for the method @method on @interface by * demarshalling the arguments of the attached reply and calling either * the handler function or error function. * * The notify function will call a handler function passed in if the * reply is valid, the typedef name for this handler must be passed as * @handler_type. The actual type for this can be obtained from the * entry added to @typedefs. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * The typedef for the handler function is returned as a TypeFunc object * added to the @typedefs list. * * If any of the arguments require a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @method. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * method_proxy_notify_function (const void *parent, const char *prefix, Interface * interface, Method * method, NihList * prototypes, NihList * typedefs, NihList * structs) { NihList locals; NihList method_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; nih_local char * assert_block = NULL; nih_local TypeVar * reply_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * parent_var = NULL; nih_local TypeVar * error_var = NULL; nih_local char * steal_block = NULL; nih_local char * demarshal_block = NULL; nih_local char * call_block = NULL; nih_local char * handler_name = NULL; nih_local char * handler_type = NULL; nih_local TypeFunc *handler_func = NULL; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (method != NULL); nih_assert (prototypes != NULL); nih_assert (typedefs != NULL); nih_assert (structs != NULL); nih_list_init (&locals); nih_list_init (&method_structs); /* The function takes the pending call being notified and the * associated data structure. We don't mark the function deprecated * since it's used internally, it's enough to mark the method * call function deprecated. */ name = symbol_impl (NULL, prefix, interface->name, method->name, "notify"); if (! name) return NULL; func = type_func_new (NULL, "void", name); if (! func) return NULL; arg = type_var_new (func, "DBusPendingCall *", "pending_call"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (pending_call != NULL);\n")) return NULL; arg = type_var_new (func, "NihDBusPendingData *", "pending_data"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (pending_data != NULL);\n")) return NULL; /* The function requires a message pointer, stolen from the * pending call, and an iterator for it; we allocate an * encapsulating (parent) object to attach arguments to while * we call the handler. Also for the case of errors we need an * error object. */ reply_var = type_var_new (NULL, "DBusMessage *", "reply"); if (! reply_var) return NULL; nih_list_add (&locals, &reply_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); parent_var = type_var_new (NULL, "NihDBusMessage *", "message"); if (! parent_var) return NULL; nih_list_add (&locals, &parent_var->entry); error_var = type_var_new (NULL, "DBusError", "error"); if (! error_var) return NULL; nih_list_add (&locals, &error_var->entry); /* Assert that the pending call is, in fact, complete then * steal the message from it; handling it immediately if it's an * error. */ if (! nih_strcat (&steal_block, NULL, "nih_assert (dbus_pending_call_get_completed (pending_call));\n" "\n" "/* Steal the reply from the pending call. */\n" "reply = dbus_pending_call_steal_reply (pending_call);\n" "nih_assert (reply != NULL);\n" "\n" "/* Handle error replies */\n" "if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {\n" "\tmessage = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply));\n" "\n" "\tdbus_error_init (&error);\n" "\tdbus_set_error_from_message (&error, message->message);\n" "\n" "\tnih_error_push_context ();\n" "\tnih_dbus_error_raise (error.name, error.message);\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tdbus_error_free (&error);\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n" "nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN);\n" "\n")) return NULL; /* To deal with out-of-memory situations, we have to loop until we've * extracted all of the arguments, so this now happens in a different * code block. Create a message context and initialise the iterator. */ if (! nih_strcat (&demarshal_block, NULL, "/* Create a message context for the reply, and iterate\n" " * over its arguments.\n" " */\n" "message = nih_dbus_message_new (pending_data, pending_data->connection, reply);\n" "if (! message)\n" "\tgoto enomem;\n" "\n" "dbus_message_iter_init (message->message, &iter);\n" "\n")) return NULL; /* Begin the handler calling block, the handler is not permitted * to reply. */ handler_type = symbol_typedef (NULL, prefix, interface->symbol, NULL, method->symbol, "Reply"); if (! handler_type) return NULL; if (! nih_strcat_sprintf (&call_block, NULL, "/* Call the handler function */\n" "if (pending_data->handler) {\n" "\tnih_error_push_context ();\n" "\t((%s)pending_data->handler) (pending_data->data, message", handler_type)) return NULL; handler_name = nih_sprintf (NULL, "(*%s)", handler_type); if (! handler_name) return NULL; handler_func = type_func_new (NULL, "typedef void", handler_name); if (! handler_func) return NULL; arg = type_var_new (handler_func, "void *", "data"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); arg = type_var_new (handler_func, "NihDBusMessage *", "message"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); /* Iterate over the method arguments, for each output argument * each output argument we append the code to the the pre-call * demarshalling code. At the same time, we build up the handler * call itself and transfer the actual arguments to the locals * list. */ NIH_LIST_FOREACH (&method->arguments, iter) { Argument * argument = (Argument *)iter; NihList arg_vars; NihList arg_locals; NihList arg_structs; DBusSignatureIter iter; nih_local char * local_name = NULL; nih_local char * oom_error_code = NULL; nih_local char * type_error_code = NULL; nih_local char * block = NULL; if (argument->direction != NIH_DBUS_ARG_OUT) continue; nih_list_init (&arg_vars); nih_list_init (&arg_locals); nih_list_init (&arg_structs); dbus_signature_iter_init (&iter, argument->type); /* In case of out of memory, we can't just return because * we've already made the method call so we loop over the * code instead. But in case of type error in the returned * arguments, all we can do is treat it as an error reply. */ oom_error_code = nih_sprintf (NULL, "nih_free (message);\n" "message = NULL;\n" "goto enomem;\n"); if (! oom_error_code) return NULL; type_error_code = nih_strdup (NULL, "nih_error_push_context ();\n" "nih_error_raise (NIH_DBUS_INVALID_ARGS,\n" " _(NIH_DBUS_INVALID_ARGS_STR));\n" "pending_data->error_handler (pending_data->data, message);\n" "nih_error_pop_context ();\n" "\n" "nih_free (message);\n" "dbus_message_unref (reply);\n" "return;\n"); if (! type_error_code) return NULL; block = demarshal (NULL, &iter, "message", "iter", argument->symbol, oom_error_code, type_error_code, &arg_vars, &arg_locals, prefix, interface->symbol, method->symbol, argument->symbol, &arg_structs); if (! block) return NULL; if (! nih_strcat (&block, NULL, "\n")) return NULL; NIH_LIST_FOREACH_SAFE (&arg_vars, iter) { TypeVar *var = (TypeVar *)iter; TypeVar *arg; if (! nih_strcat_sprintf (&call_block, NULL, ", %s", var->name)) return NULL; nih_list_add (&locals, &var->entry); nih_ref (var, call_block); /* Handler argument is const */ arg = type_var_new (handler_func, var->type, var->name); if (! arg) return NULL; if (! type_to_const (&arg->type, arg)) return NULL; nih_list_add (&handler_func->args, &arg->entry); } NIH_LIST_FOREACH_SAFE (&arg_locals, iter) { TypeVar *var = (TypeVar *)iter; nih_list_add (&locals, &var->entry); nih_ref (var, demarshal_block); } NIH_LIST_FOREACH_SAFE (&arg_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_list_add (&method_structs, &structure->entry); nih_ref (structure, demarshal_block); } if (! nih_strcat (&demarshal_block, NULL, block)) return NULL; } /* Complete the demarshalling block, checking for any unexpected * reply arguments which we also want to error on. */ if (! nih_strcat_sprintf (&demarshal_block, NULL, "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {\n" "\tnih_error_push_context ();\n" "\tnih_error_raise (NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n")) return NULL; /* Complete the call block. */ if (! nih_strcat (&call_block, NULL, ");\n" "\tnih_error_pop_context ();\n" "}\n" "\n" "nih_free (message);\n" "dbus_message_unref (reply);\n")) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! indent (&demarshal_block, NULL, 1)) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "do {\n" "\t__label__ enomem;\n" "\n" "%s" "enomem: __attribute__ ((unused));\n" "} while (! message);\n" "\n" "%s", vars_block, assert_block, steal_block, demarshal_block, call_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the functions to the prototypes and typedefs list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); nih_list_add (typedefs, &handler_func->entry); nih_ref (handler_func, code); NIH_LIST_FOREACH_SAFE (&method_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } return code; } /** * method_proxy_sync_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface of @method, * @method: method to generate function for, * @prototypes: list to append function prototypes to, * @structs: list to append structure definitions to. * * Generates C code for a function to make a synchronous method call for * the method @method on @interface by marshalling the arguments, wiating * for the reply, then demarshalling the reply arguments. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * If any of the arguments require a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @method. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * method_proxy_sync_function (const void *parent, const char *prefix, Interface * interface, Method * method, NihList * prototypes, NihList * structs) { NihList locals; NihList method_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; NihListEntry * attrib; nih_local char * assert_block = NULL; nih_local TypeVar * message_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * error_var = NULL; nih_local TypeVar * reply_var = NULL; nih_local char * marshal_block = NULL; nih_local char * free_block = NULL; nih_local char * demarshal_block = NULL; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (method != NULL); nih_assert (prototypes != NULL); nih_assert (structs != NULL); nih_list_init (&locals); nih_list_init (&method_structs); /* The function returns an integer, and takes a parent object and * the proxy object as the arguments along with the input and * output arguments of the method call. The integer indicates * whether an error occurred, so we want warning if the result * isn't used. Since this is used by the client, we also add a * deprecated attribute if the method is deprecated. */ name = symbol_extern (NULL, prefix, interface->symbol, NULL, method->symbol, "sync"); if (! name) return NULL; func = type_func_new (NULL, "int", name); if (! func) return NULL; attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "warn_unused_result"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); if (method->deprecated) { attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "deprecated"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); } arg = type_var_new (func, "const void *", "parent"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "NihDBusProxy *", "proxy"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (proxy != NULL);\n")) return NULL; /* The function requires a message pointer, which we allocate, * and an iterator for it to append the arguments. We also need * a reply message pointer as well and an error object. */ message_var = type_var_new (NULL, "DBusMessage *", "method_call"); if (! message_var) return NULL; nih_list_add (&locals, &message_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); error_var = type_var_new (NULL, "DBusError", "error"); if (! error_var) return NULL; nih_list_add (&locals, &error_var->entry); reply_var = type_var_new (NULL, "DBusMessage *", "reply"); if (! reply_var) return NULL; nih_list_add (&locals, &reply_var->entry); /* Create the message and set up the iterator to append to it. * When demarshalling we set up the iterator to go over the reply. */ if (! nih_strcat_sprintf (&marshal_block, NULL, "/* Construct the method call message. */\n" "method_call = dbus_message_new_method_call (proxy->name, proxy->path, \"%s\", \"%s\");\n" "if (! method_call)\n" "\tnih_return_no_memory_error (-1);\n" "\n" "dbus_message_set_auto_start (method_call, proxy->auto_start);\n" "\n" "dbus_message_iter_init_append (method_call, &iter);\n" "\n", interface->name, method->name)) return NULL; /* FIXME autostart? */ if (! nih_strcat_sprintf (&demarshal_block, NULL, "dbus_message_unref (method_call);\n" "\n" "/* Iterate the arguments of the reply */\n" "dbus_message_iter_init (reply, &iter);\n" "\n")) return NULL; /* Iterate over the method arguments, for each input argument we * append the code to the pre-call marshalling code and for * each output argument we append the code to the post-call * demarshalling code. */ NIH_LIST_FOREACH (&method->arguments, iter) { Argument * argument = (Argument *)iter; NihList arg_vars; NihList arg_locals; NihList arg_structs; DBusSignatureIter iter; nih_local char * local_name = NULL; nih_local char * oom_error_code = NULL; nih_local char * type_error_code = NULL; nih_local char * block = NULL; nih_list_init (&arg_vars); nih_list_init (&arg_locals); nih_list_init (&arg_structs); dbus_signature_iter_init (&iter, argument->type); switch (argument->direction) { case NIH_DBUS_ARG_IN: /* In case of out of memory, simply return; the caller * can try again. */ oom_error_code = nih_strdup (NULL, "dbus_message_unref (method_call);\n" "nih_return_no_memory_error (-1);\n"); if (! oom_error_code) return NULL; block = marshal (NULL, &iter, "iter", argument->symbol, oom_error_code, &arg_vars, &arg_locals, prefix, interface->symbol, method->symbol, argument->symbol, &arg_structs); if (! block) return NULL; if (! nih_strcat_sprintf (&marshal_block, NULL, "%s" "\n", block)) return NULL; /* We take a parameter of the expected type and name of * the marshal input variable; if it's a pointer, we * assert that it's not NULL and make sure it's const. */ NIH_LIST_FOREACH_SAFE (&arg_vars, iter) { TypeVar *var = (TypeVar *)iter; if (! type_to_const (&var->type, var)) return NULL; if (! type_strcat_assert (&assert_block, NULL, var, func->args.prev != &func->args ? (TypeVar *)func->args.prev : NULL, _iter.next != &arg_vars ? (TypeVar *)_iter.next : NULL)) return NULL; nih_list_add (&func->args, &var->entry); nih_ref (var, func); } NIH_LIST_FOREACH_SAFE (&arg_locals, iter) { TypeVar *var = (TypeVar *)iter; nih_list_add (&locals, &var->entry); nih_ref (var, marshal_block); } NIH_LIST_FOREACH_SAFE (&arg_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_list_add (&method_structs, &structure->entry); nih_ref (structure, marshal_block); } break; case NIH_DBUS_ARG_OUT: /* We can't write directly to the pointer argument * we were given, instead we use a local variable * and write out later. */ local_name = nih_sprintf (NULL, "%s_local", argument->symbol); if (! local_name) return NULL; /* In case of out of memory, we can't just return * because we've already made the method call so * we loop over the code instead. But in case of * type error in the returned arguments, all we * can do is return an error. */ oom_error_code = nih_sprintf (NULL, "*%s = NULL;\n" "goto enomem;\n", argument->symbol); if (! oom_error_code) return NULL; type_error_code = nih_sprintf (NULL, "%s" "dbus_message_unref (reply);\n" "nih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" " _(NIH_DBUS_INVALID_ARGS_STR));\n", free_block ?: ""); if (! type_error_code) return NULL; block = demarshal (NULL, &iter, "parent", "iter", local_name, oom_error_code, type_error_code, &arg_vars, &arg_locals, prefix, interface->symbol, method->symbol, argument->symbol, &arg_structs); if (! block) return NULL; if (! nih_strcat (&block, NULL, "\n")) return NULL; /* We take a parameter as a pointer to the expected * type and name of the demarshal output variable, * asserting that it's not NULL. We actually * demarshal to a local variable though, to avoid * dealing with that extra level of pointers. */ NIH_LIST_FOREACH_SAFE (&arg_vars, iter) { TypeVar * var = (TypeVar *)iter; nih_local char *arg_type = NULL; const char * suffix; nih_local char *arg_name = NULL; TypeVar * arg; /* Output variable */ arg_type = nih_strdup (NULL, var->type); if (! arg_type) return NULL; if (! type_to_pointer (&arg_type, NULL)) return NULL; nih_assert (! strncmp (var->name, local_name, strlen (local_name))); suffix = var->name + strlen (local_name); arg_name = nih_sprintf (NULL, "%s%s", argument->symbol, suffix); if (! arg_name) return NULL; arg = type_var_new (func, arg_type, arg_name); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat_sprintf (&assert_block, NULL, "nih_assert (%s != NULL);\n", arg->name)) return NULL; /* Copy from local variable to output */ if (! nih_strcat_sprintf (&block, NULL, "*%s = %s;\n", arg->name, var->name)) return NULL; nih_list_add (&locals, &var->entry); nih_ref (var, demarshal_block); /* Build up the code to free the output * arguments on error as we go. */ if (strchr (var->type, '*')) { free_block = nih_sprintf (NULL, "nih_free (%s);\n" "*%s = NULL;\n" "%s", var->name, arg->name, free_block ?: ""); if (! free_block) return NULL; } } NIH_LIST_FOREACH_SAFE (&arg_locals, iter) { TypeVar *var = (TypeVar *)iter; nih_list_add (&locals, &var->entry); nih_ref (var, demarshal_block); } NIH_LIST_FOREACH_SAFE (&arg_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_list_add (&method_structs, &structure->entry); nih_ref (structure, demarshal_block); } if (! indent (&block, NULL, 1)) return NULL; if (! nih_strcat_sprintf (&demarshal_block, NULL, "do {\n" "\t__label__ enomem;\n" "\n" "%s" "enomem: __attribute__ ((unused));\n" "} while (! *%s);\n" "\n", block, argument->symbol)) return NULL; break; default: nih_assert_not_reached (); } } /* Complete the marshalling block by sending the message and checking * for error replies. */ if (! nih_strcat_sprintf (&marshal_block, NULL, "/* Send the message, and wait for the reply. */\n" "dbus_error_init (&error);\n" "\n" "reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error);\n" "if (! reply) {\n" "\tdbus_message_unref (method_call);\n" "\n" "\tif (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) {\n" "\t\tnih_error_raise_no_memory ();\n" "\t} else {\n" "\t\tnih_dbus_error_raise (error.name, error.message);\n" "\t}\n" "\n" "\tdbus_error_free (&error);\n" "\treturn -1;\n" "}\n" "\n")) return NULL; /* Complete the demarshalling block, checking for any unexpected * reply arguments which we also want to error on. */ if (free_block) if (! indent (&free_block, NULL, 1)) return NULL; if (! nih_strcat_sprintf (&demarshal_block, NULL, "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {\n" "%s" "\tdbus_message_unref (reply);\n" "\tnih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "}\n" "\n" "dbus_message_unref (reply);\n", free_block ?: "")) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "%s" "\n" "return 0;\n", vars_block, assert_block, marshal_block, demarshal_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the function to the prototypes list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); NIH_LIST_FOREACH_SAFE (&method_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_list_add (structs, &structure->entry); nih_ref (structure, code); } return code; } /** * method_args_array: * @parent: parent object for new string, * @prefix: prefix for array name, * @interface: interface of @method, * @method: method to generate array for, * @prototypes: list to append prototype to. * * Generates C code to declare an array of NihDBusArg variables containing * information about the arguments of the method @method on @interface. * * The prototype of the returned variable declaration is returned as a * TypeVar object appended to the @prototypes list. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * method_args_array (const void *parent, const char *prefix, Interface * interface, Method * method, NihList * prototypes) { nih_local char *name = NULL; size_t max_name = 0; size_t max_type = 0; nih_local char *block = NULL; char * code; TypeVar * var; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (method != NULL); nih_assert (prototypes != NULL); name = symbol_impl (NULL, prefix, interface->name, method->name, "method_args"); if (! name) return NULL; /* Figure out the longest argument name and signature */ NIH_LIST_FOREACH (&method->arguments, iter) { Argument *argument = (Argument *)iter; if (argument->name) { if (strlen (argument->name) > max_name) max_name = strlen (argument->name); } else { if (max_name < 4) max_name = 4; } if (strlen (argument->type) > max_type) max_type = strlen (argument->type); } /* Append each argument such that the names, types and directions * are all lined up with each other. */ NIH_LIST_FOREACH (&method->arguments, iter) { Argument * argument = (Argument *)iter; nih_local char *line = NULL; char * dest; line = nih_alloc (NULL, max_name + max_type + 31); if (! line) return NULL; dest = line; memcpy (dest, "{ ", 2); dest += 2; if (argument->name) { memcpy (dest, "\"", 1); dest += 1; memcpy (dest, argument->name, strlen (argument->name)); dest += strlen (argument->name); memcpy (dest, "\", ", 3); dest += 3; memset (dest, ' ', max_name - strlen (argument->name)); dest += max_name - strlen (argument->name); } else { memcpy (dest, "NULL, ", 6); dest += 6; memset (dest, ' ', max_name - 2); dest += max_name - 2; } memcpy (dest, "\"", 1); dest += 1; memcpy (dest, argument->type, strlen (argument->type)); dest += strlen (argument->type); memcpy (dest, "\", ", 3); dest += 3; memset (dest, ' ', max_type - strlen (argument->type)); dest += max_type - strlen (argument->type); switch (argument->direction) { case NIH_DBUS_ARG_IN: memcpy (dest, "NIH_DBUS_ARG_IN ", 16); dest += 16; break; case NIH_DBUS_ARG_OUT: memcpy (dest, "NIH_DBUS_ARG_OUT", 16); dest += 16; break; default: nih_assert_not_reached (); } memcpy (dest, " },\n", 4); dest += 4; *dest = '\0'; if (! nih_strcat (&block, NULL, line)) return NULL; } /* Append the final element to the block of elements, indent and * surround with the structure definition. */ if (! nih_strcat (&block, NULL, "{ NULL }\n")) return NULL; if (! indent (&block, NULL, 1)) return NULL; code = nih_sprintf (parent, "const NihDBusArg %s[] = {\n" "%s" "};\n", name, block); if (! code) return NULL; /* Append the prototype to the list */ var = type_var_new (code, "const NihDBusArg", name); if (! var) { nih_free (code); return NULL; } var->array = TRUE; nih_list_add (prototypes, &var->entry); return code; } libnih-1.0.3/nih-dbus-tool/output.c0000644000175000017500000003322611445765555014120 00000000000000/* nih-dbus-tool * * output.c - source and header file output * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include #include "type.h" #include "node.h" #include "interface.h" #include "method.h" #include "signal.h" #include "property.h" #include "output.h" /* Prototypes for static functions */ static int output_write (int fd, const char *str) __attribute__ ((warn_unused_result)); /** * output_package: * * Package name to use when generating header and source file comments * and header file sentinel macro. Defaults to libnih when not set. **/ char *output_package = NULL; /** * output: * @source_path: path of source file to write, * @source_fd: file descriptor open to write to @source_path, * @header_path: path of header file to write, * @header_fd: file descriptor open to write to @header_path, * @prefix: prefix to prepend to symbols, * @node: node to output, * @object: whether to output for an object or proxy. * * Writes a valid C source file to @source_fd and its accompanying header * file to @header_fd; which should file descriptors open to writing to * @source_path and @header_path respectively. * * If @object is TRUE, the output code provides D-Bus bindings that wrap * externally defined C functions providing an implementation of @node. * When @object is FALSE, the output code instead provides API functions * that access a remote D-Bus object @node. * * Externally available symbols will all be prefixed with @prefix. * * Returns: zero on success, negative value on raised error. **/ int output (const char *source_path, int source_fd, const char *header_path, int header_fd, const char *prefix, Node * node, int object) { NihList prototypes; NihList handlers; NihList structs; NihList typedefs; NihList vars; NihList externs; nih_local char *array = NULL; nih_local char *code = NULL; nih_local char *source = NULL; nih_local char *header = NULL; nih_local char *sentinel = NULL; nih_assert (source_path != NULL); nih_assert (source_fd >= 0); nih_assert (header_path != NULL); nih_assert (header_fd >= 0); nih_assert (prefix != NULL); nih_assert (node != NULL); nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); nih_list_init (&typedefs); nih_list_init (&vars); nih_list_init (&externs); /* Start off the text of the source file with the copyright preamble * and the list of includes. */ source = output_preamble (NULL, source_path); if (! source) { nih_error_raise_no_memory (); return -1; } if (! nih_strcat (&source, NULL, "#ifdef HAVE_CONFIG_H\n" "# include \n" "#endif /* HAVE_CONFIG_H */\n" "\n" "\n" "#include \n" "\n" "#include \n" "#include \n" "\n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "\n" "#include \n" "#include \n")) { nih_error_raise_no_memory (); return -1; } /* Start off the text of the header file with the copyright preamble, * sentinel and list of includes. */ header = output_preamble (NULL, NULL); if (! header) { nih_error_raise_no_memory (); return -1; } sentinel = output_sentinel (NULL, header_path); if (! sentinel) { nih_error_raise_no_memory (); return -1; } if (! nih_strcat_sprintf (&header, NULL, "#ifndef %s\n" "#define %s\n" "\n", sentinel, sentinel)) { nih_error_raise_no_memory (); return -1; } if (! nih_strcat (&header, NULL, "#include \n" "\n" "#include \n" "\n" "#include \n" "\n" "#include \n" "#include \n")) { nih_error_raise_no_memory (); return -1; } /* Obtain the interfaces array for the source file */ array = node_interfaces_array (NULL, prefix, node, object, &vars); if (! array) { nih_error_raise_no_memory (); return -1; } /* Add any object/proxy-specific headers, and obtain the code * for the functions, as well as the prototypes, typedefs, handler * prototypes, extern prototypes, etc. */ if (object) { if (! nih_strcat (&source, NULL, "#include \n")) { nih_error_raise_no_memory (); return -1; } code = node_object_functions (NULL, prefix, node, &prototypes, &handlers, &structs, &externs); if (! code) { nih_error_raise_no_memory (); return -1; } } else { if (! nih_strcat (&source, NULL, "#include \n" "#include \n")) { nih_error_raise_no_memory (); return -1; } if (! nih_strcat (&header, NULL, "#include \n" "#include \n")) { nih_error_raise_no_memory (); return -1; } code = node_proxy_functions (NULL, prefix, node, &prototypes, &structs, &typedefs, &externs); if (! code) { nih_error_raise_no_memory (); return -1; } } /* errors.h is always the last header by style, followed by the * header itself. */ if (! nih_strcat_sprintf (&source, NULL, "#include \n" "\n" "#include \"%s\"\n" "\n" "\n", header_path)) { nih_error_raise_no_memory (); return -1; } if (! nih_strcat (&header, NULL, "\n" "\n")) { nih_error_raise_no_memory (); return -1; } /* Declare the prototypes of static functions defined here in the * source file. These are the handler and getter/setter functions * referred to in the array structures. */ if (! NIH_LIST_EMPTY (&prototypes)) { nih_local char *block = NULL; block = type_func_layout (NULL, &prototypes); if (! block) { nih_error_raise_no_memory (); return -1; } if (! nih_strcat_sprintf (&source, NULL, "/* Prototypes for static functions */\n" "%s" "\n" "\n", block)) { nih_error_raise_no_memory (); return -1; } } /* Declare the prototypes of external handler functions that we * expect other source files to implement. */ if (! NIH_LIST_EMPTY (&handlers)) { nih_local char *block = NULL; block = type_func_layout (NULL, &handlers); if (! block) { nih_error_raise_no_memory (); return -1; } if (! nih_strcat_sprintf (&source, NULL, "/* Prototypes for externally implemented handler functions */\n" "%s" "\n" "\n", block)) { nih_error_raise_no_memory (); return -1; } } /* Define the arrays of methods and signals and their arguments, * prototypes, interfaces, etc. for the node. These refer to the * above prototypes. */ if (! nih_strcat_sprintf (&source, NULL, "%s" "\n" "\n", array)) { nih_error_raise_no_memory (); return -1; } /* Finally append all of the function code. */ if (! nih_strcat (&source, NULL, code)) { nih_error_raise_no_memory (); return -1; } /* Write it */ if (output_write (source_fd, source) < 0) return -1; /* Define each of the structures in the header file, each is * a typdef so gets its own line. */ if (! NIH_LIST_EMPTY (&structs)) { NIH_LIST_FOREACH (&structs, iter) { TypeStruct * structure = (TypeStruct *)iter; nih_local char *block = NULL; block = type_struct_to_string (NULL, structure); if (! block) { nih_error_raise_no_memory (); return -1; } if (! nih_strcat_sprintf (&header, NULL, "%s" "\n", block)) { nih_error_raise_no_memory (); return -1; } } if (! nih_strcat (&header, NULL, "\n")) { nih_error_raise_no_memory (); return -1; } } /* Define each of the typedefs in the header file, some of these * are actually required in the prototypes while others serve as * documentation for what to pass to nih_dbus_proxy_connect() */ if (! NIH_LIST_EMPTY (&typedefs)) { NIH_LIST_FOREACH (&typedefs, iter) { TypeFunc * func = (TypeFunc *)iter; nih_local char *block = NULL; block = type_func_to_typedef (NULL, func); if (! block) { nih_error_raise_no_memory (); return -1; } if (! nih_strcat_sprintf (&header, NULL, "%s" "\n", block)) { nih_error_raise_no_memory (); return -1; } } if (! nih_strcat (&header, NULL, "\n")) { nih_error_raise_no_memory (); return -1; } } if (! nih_strcat (&header, NULL, "NIH_BEGIN_EXTERN\n")) { nih_error_raise_no_memory (); return -1; } /* Declare global variables defined in the source file, these are * the interface structures and the array of them for the node. */ if (! NIH_LIST_EMPTY (&vars)) { nih_local char *block = NULL; block = type_var_layout (NULL, &vars); if (! block) { nih_error_raise_no_memory (); return -1; } if (! nih_strcat_sprintf (&header, NULL, "\n" "%s" "\n", block)) { nih_error_raise_no_memory (); return -1; } } /* Declare the prototypes of the functions defined in the source * file. */ if (! NIH_LIST_EMPTY (&externs)) { nih_local char *block = NULL; block = type_func_layout (NULL, &externs); if (! block) { nih_error_raise_no_memory (); return -1; } if (! nih_strcat_sprintf (&header, NULL, "\n" "%s" "\n", block)) { nih_error_raise_no_memory (); return -1; } } if (! nih_strcat_sprintf (&header, NULL, "NIH_END_EXTERN\n" "\n" "#endif /* %s */\n", sentinel)) { nih_error_raise_no_memory (); return -1; } /* Write it */ if (output_write (header_fd, header) < 0) return -1; return 0; } /** * output_preamble: * @parent: parent object for new string, * @path: path of source file. * * Generates the preamble header of a source or header file, containing the * package name of the software being built, @path if specified, the author's * copyright and a statement to see the source for copying conditions. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if allocation failed. **/ char * output_preamble (const void *parent, const char *path) { char *code; code = nih_sprintf (parent, "/* %s\n *\n", output_package ?: package_name); if (! code) return NULL; if (path) { if (! nih_strcat_sprintf (&code, parent, " * %s - auto-generated D-Bus bindings\n" " *\n", path)) { nih_free (code); return NULL; } } if (! nih_strcat_sprintf (&code, parent, " * %s\n" " *\n" " * This file was automatically generated; see the source for copying\n" " * conditions.\n" " */\n" "\n", package_copyright)) { nih_free (code); return NULL; } return code; } /** * output_sentinel: * @parent: parent object for new string, * @path: path of header file. * * Generates the name of header sentinel macro, used to ensure that a header * is not accidentally included twice (thus making out-of-order includes * possible). * * The name is the path, prefixed with the package name of the software being * built, uppercased and unrecognised characters replaced by underscores. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if allocation failed. **/ char * output_sentinel (const void *parent, const char *path) { char *sentinel, *s; nih_assert (path != NULL); sentinel = nih_sprintf (parent, "%s_%s", output_package ?: package_name, path); if (! sentinel) return NULL; for (s = sentinel; *s; s++) { if (((*s < 'A') || (*s > 'Z')) && ((*s < 'a') || (*s > 'z')) && ((*s < '0') || (*s > '9'))) { *s = '_'; } else { *s = toupper (*s); } } return sentinel; } /** * output_write: * @fd: file descriptor to write to, * @str: string to write. * * Wraps the write() syscall to ensure that the entire string @str is written * to @fd, since write() may perform short writes. * * Returns: zero on success, negative value on raised error. **/ static int output_write (int fd, const char *str) { ssize_t len; size_t count; nih_assert (fd >= 0); nih_assert (str != NULL); count = strlen (str); while (count) { len = write (fd, str, count); if (len < 0) { nih_error_raise_system (); return -1; } count -= len; str += len; } return 0; } libnih-1.0.3/nih-dbus-tool/main.c0000644000175000017500000002554411445765555013510 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "node.h" #include "interface.h" #include "parse.h" #include "output.h" /* Prototypes for option functions */ int mode_option (NihOption *option, const char *arg); /* Prototypes for local functions */ char *source_file_path (const void *parent, const char *output_path, const char *filename) __attribute__ ((warn_unused_result, malloc)); char *header_file_path (const void *parent, const char *output_path, const char *filename) __attribute__ ((warn_unused_result, malloc)); /** * mode_option: * @option: NihOption invoked, * @arg: argument to parse. * * This option setter parses the output mode argument @arg and sets * the value member of @option, which must be a pointer to an integer. * * The arg_name member of @option must not be NULL. **/ int mode_option (NihOption * option, const char *arg) { int *value; nih_assert (option != NULL); nih_assert (option->value != NULL); nih_assert (arg != NULL); value = (int *)option->value; if (! strcmp (arg, "proxy")) { *value = FALSE; } else if (! strcmp (arg, "object")) { *value = TRUE; } else { fprintf (stderr, _("%s: illegal output mode: %s\n"), program_name, arg); nih_main_suggest_help (); return -1; } return 0; } /** * source_file_path: * @parent: parent object for new string, * @output_path: output path, * @filename: input filename. * * Generates a path to the output source (.c) file from either the output * path given in @output_path or the input filename given in @filename, * depending on which one is not NULL. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * source_file_path (const void *parent, const char *output_path, const char *filename) { char *path; if (output_path) { char *ptr; /* When the output path is given, return it; but allow for * the output path being the header to make Makefile rules * easier, and replace extension with .c when given one. */ ptr = strrchr (output_path, '.'); if (ptr && (! strcmp (ptr, ".h"))) { path = nih_strndup (parent, output_path, ptr - output_path); if (! path) return NULL; if (! nih_strcat (&path, parent, ".c")) { nih_free (path); return NULL; } } else { path = nih_strdup (parent, output_path); } } else if (filename) { char *ptr; /* Always output to the current directory */ ptr = strrchr (filename, '/'); if (ptr) filename = ptr + 1; /* When the input filename is given, strip the extension off * and replace with .c unless the extension is .c or .h in * which case we append the .c extension instead */ ptr = strrchr (filename, '.'); if (ptr && strcmp (ptr, ".c") && strcmp (ptr, ".h")) { path = nih_strndup (parent, filename, ptr - filename); if (! path) return NULL; } else { path = nih_strdup (parent, filename); if (! path) return NULL; } if (! nih_strcat (&path, parent, ".c")) { nih_free (path); return NULL; } } else { nih_assert_not_reached (); } return path; } /** * header_file_path: * @parent: parent object for new string, * @output_path: output path, * @filename: input filename. * * Generates a path to the output header (.h) file from either the output * path given in @output_path or the input filename given in @filename, * depending on which one is not NULL. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * header_file_path (const void *parent, const char *output_path, const char *filename) { char *path; if (output_path) { char *ptr; /* When the output path is given, and is the header file, * return it; otherwise replace the extension with .h or * append it if there was no extension */ ptr = strrchr (output_path, '.'); if (ptr && (! strcmp (ptr, ".h"))) { path = nih_strdup (parent, output_path); } else if (ptr) { path = nih_strndup (parent, output_path, ptr - output_path); if (! path) return NULL; if (! nih_strcat (&path, parent, ".h")) { nih_free (path); return NULL; } } else { path = nih_strdup (parent, output_path); if (! path) return NULL; if (! nih_strcat (&path, parent, ".h")) { nih_free (path); return NULL; } } } else if (filename) { char *ptr; /* Always output to the current directory */ ptr = strrchr (filename, '/'); if (ptr) filename = ptr + 1; /* When the input filename is given, strip the extension off * and replace with .h unless the extension is .c or .h in * which case we append the .h extension instead */ ptr = strrchr (filename, '.'); if (ptr && strcmp (ptr, ".c") && strcmp (ptr, ".h")) { path = nih_strndup (parent, filename, ptr - filename); if (! path) return NULL; } else { path = nih_strdup (parent, filename); if (! path) return NULL; } if (! nih_strcat (&path, parent, ".h")) { nih_free (path); return NULL; } } else { nih_assert_not_reached (); } return path; } #ifndef TEST /** * object: * * Set to TRUE to output code for a remote object with C access methods or * FALSE for a local object implementation wrapping existing C functions. **/ static int object = FALSE; /** * prefix: * * Prefix of expected and generated functions. **/ static const char *prefix = NULL; /** * default_interface: * * Interface which should not have the last component of its name included * in generated symbol names. **/ static const char *default_interface = NULL; /** * output_path: * * Path to output C code to, header is automatically placed alongside. **/ static const char *output_path = NULL; /** * options: * * Command-line options accepted by this tool. **/ static NihOption options[] = { { 0, "mode", N_("output mode: object, or proxy [default: proxy]"), NULL, "MODE", &object, mode_option }, { 0, "prefix", N_("prefix for C functions [default: dbus]"), NULL, "PREFIX", &prefix, NULL }, { 0, "default-interface", N_("interface name not included in symbols"), NULL, "INTERFACE", &default_interface, NULL }, { 'o', "output", N_("write C source to FILENAME, header alongside"), NULL, "FILENAME", &output_path, NULL }, { 0, "package", N_("name of software source being created for"), NULL, "PACKAGE", &output_package, NULL }, NIH_OPTION_LAST }; int main (int argc, char *argv[]) { char ** args; char * filename; nih_local char *source_path = NULL; nih_local char *header_path = NULL; int source_fd; int header_fd; Node * node; nih_main_init (argv[0]); nih_option_set_usage (_("[XMLFILE]")); nih_option_set_synopsis (_("Generate C bindings for D-Bus objects")); nih_option_set_help (_("Fill this in later")); args = nih_option_parser (NULL, argc, argv, options, FALSE); if (! args) exit (1); /* Filename defaults to standard input when not specified, or when * specified as "-". */ filename = args[0]; if (filename && (! strcmp (filename, "-"))) filename = NULL; /* Output path must be specified when we're using standard input */ if ((! filename) && (! output_path)) { fprintf (stderr, _("%s: --output must be specified when using standard input\n"), program_name); nih_main_suggest_help (); exit (1); } /* Calculate output paths */ source_path = source_file_path (NULL, output_path, filename); if (! source_path) { nih_error ("%s", strerror (ENOMEM)); exit (1); } header_path = header_file_path (NULL, output_path, filename); if (! header_path) { nih_error ("%s", strerror (ENOMEM)); exit (1); } /* Set default prefix if not set */ if (! prefix) prefix = "dbus"; /* Parse the input file, which may be standard input */ if (filename) { int fd; fd = open (filename, O_RDONLY); if (fd < 0) { nih_error ("%s: %s", filename, strerror (errno)); exit (1); } node = parse_xml (NULL, fd, filename); if (! node) exit (1); if (close (fd) < 0) { nih_error ("%s: %s", filename, strerror (errno)); exit (1); } } else { node = parse_xml (NULL, STDIN_FILENO, "(standard input)"); if (! node) exit (1); } /* Remove the symbol from the default interface */ if (default_interface) { int found = FALSE; NIH_LIST_FOREACH (&node->interfaces, iter) { Interface *interface = (Interface *)iter; if (! strcmp (interface->name, default_interface)) { nih_unref (interface->symbol, interface); interface->symbol = NULL; found = TRUE; } } if (! found) { nih_error ("%s: %s", _("No such interface"), default_interface); exit (1); } } /* Write the output files */ source_fd = open (source_path, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (source_fd < 0) { nih_error ("%s: %s", source_path, strerror (errno)); exit (1); } header_fd = open (header_path, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (header_fd < 0) { nih_error ("%s: %s", header_path, strerror (errno)); exit (1); } if (output (source_path, source_fd, header_path, header_fd, prefix, node, object) < 0) { NihError *err; err = nih_error_get (); nih_error ("%s", err->message); nih_free (err); exit (1); } if ((fsync (source_fd) < 0) || (close (source_fd) < 0)) { nih_error ("%s: %s", source_path, strerror (errno)); exit (1); } if ((fsync (header_fd) < 0) || (close (header_fd) < 0)) { nih_error ("%s: %s", header_path, strerror (errno)); exit (1); } return 0; } #endif libnih-1.0.3/nih-dbus-tool/annotation.c0000644000175000017500000001551311445765555014731 00000000000000/* nih-dbus-tool * * annotation.c - annotation parsing and handling * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include "annotation.h" #include "parse.h" #include "errors.h" /** * annotation_start_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed, * @attr: NULL-terminated array of attribute name and value pairs. * * This function is called by parse_start_tag() for an "annotation" * start tag, this may be a child of the "interface", "method", "signal", * "property" or (nih extension) "argument" tags and specifies a further * property not defined by the Introspection specification. * * If the annotation does not appear within one of the permitted tags a * warning is emitted and the tag will be ignored. * * Annotations must have a "name" attribute containing the well-known * annotation name and a "value" attribute contianing the value. * * Any unknown attributes result in a warning and will be ignored. * * The appropriate *_annotation() function is called to handle * identifying the annotation and applying it to the parent object. This * may result in a warning being emitted if the annotation is unknown or * an error if the value is not permitted. * * Returns: zero on success, negative value on raised error. **/ int annotation_start_tag (XML_Parser xmlp, const char * tag, char * const *attr) { ParseContext *context; ParseStack * parent; char * const *key; char * const *value; const char * name = NULL; const char * val = NULL; int ret; nih_assert (xmlp != NULL); nih_assert (tag != NULL); nih_assert (attr != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); /* Annotations apply to their parent tag */ parent = parse_stack_top (&context->stack); if ((! parent) || ( (parent->type != PARSE_INTERFACE) && (parent->type != PARSE_METHOD) && (parent->type != PARSE_SIGNAL) && (parent->type != PARSE_PROPERTY) && (parent->type != PARSE_ARGUMENT))) { nih_warn ("%s:%zu:%zu: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unexpected tag")); if (! parse_stack_push (NULL, &context->stack, PARSE_IGNORED, NULL)) nih_return_system_error (-1); return 0; } /* Retrieve the name and value from the attributes */ for (key = attr; key && *key; key += 2) { value = key + 1; nih_assert (value && *value); if (! strcmp (*key, "name")) { name = *value; } else if (! strcmp (*key, "value")) { val = *value; } else { nih_warn ("%s:%zu:%zu: %s: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unknown attribute"), *key); } } /* Check we have a name and value */ if (! name) nih_return_error (-1, ANNOTATION_MISSING_NAME, _(ANNOTATION_MISSING_NAME_STR)); if (! val) nih_return_error (-1, ANNOTATION_MISSING_VALUE, _(ANNOTATION_MISSING_VALUE_STR)); /* Meaning of the annotation depends on the parent */ switch (parent->type) { case PARSE_INTERFACE: ret = interface_annotation (parent->interface, name, val); break; case PARSE_METHOD: ret = method_annotation (parent->method, name, val); break; case PARSE_SIGNAL: ret = signal_annotation (parent->signal, name, val); break; case PARSE_PROPERTY: ret = property_annotation (parent->property, name, val); break; case PARSE_ARGUMENT: ret = argument_annotation (parent->argument, name, val); break; default: nih_assert_not_reached (); } if (ret < 0) { NihError *err; err = nih_error_get (); switch (err->number) { case INTERFACE_UNKNOWN_ANNOTATION: nih_warn ("%s:%zu:%zu: %s: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unknown interface annotation"), name); break; case METHOD_UNKNOWN_ANNOTATION: nih_warn ("%s:%zu:%zu: %s: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unknown method annotation"), name); break; case SIGNAL_UNKNOWN_ANNOTATION: nih_warn ("%s:%zu:%zu: %s: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unknown signal annotation"), name); break; case PROPERTY_UNKNOWN_ANNOTATION: nih_warn ("%s:%zu:%zu: %s: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unknown property annotation"), name); break; case ARGUMENT_UNKNOWN_ANNOTATION: nih_warn ("%s:%zu:%zu: %s: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unknown argument annotation"), name); break; default: return -1; } nih_free (err); if (! parse_stack_push (NULL, &context->stack, PARSE_IGNORED, NULL)) { nih_error_raise_system (); return -1; } } else { if (! parse_stack_push (NULL, &context->stack, PARSE_ANNOTATION, NULL)) { nih_error_raise_system (); return -1; } } return 0; } /** * annotation_end_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed. * * This function is called by parse_end_tag() for an "annotation" end * tag, and matches a call to annotation_start_tag() made at the same * parsing level. * * The object on the stack is always discarded. * * Returns: zero on success, negative value on raised error. **/ int annotation_end_tag (XML_Parser xmlp, const char *tag) { ParseContext *context; ParseStack * entry; nih_assert (xmlp != NULL); nih_assert (tag != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); entry = parse_stack_top (&context->stack); nih_assert (entry != NULL); nih_assert (entry->type == PARSE_ANNOTATION); nih_free (entry); return 0; } libnih-1.0.3/nih-dbus-tool/man/0000755000175000017500000000000011504742363013225 500000000000000libnih-1.0.3/nih-dbus-tool/man/nih-dbus-tool.10000644000175000017500000000424511445765555015734 00000000000000.TH nih-dbus-tool 1 2009-04-11 libnih-dus .\" .SH NAME nih-dbus-tool \- D-Bus binding code generator .\" .SH SYNOPSIS .B nih-dbus-tool .RI [ OPTIONS ]... .RB [ \-o .IR FILE ] .RI [ XMLFILE ] .br .B nih-dbus-tool .RI [ OPTIONS ]... .B \-o .I FILE .BR \-\-system | \-\-session .BI \-\-dest\fR= NAME .I OBJECT-PATH .\" .SH DESCRIPTION .\" .SH OVERVIEW The D-Bus introspection format is an XML document describing the interfaces implemented by a particular object, including the methods and signals of that interface along with their arguments and the properties of that interface. A single document describes a single object, represented by the root .B tag. Interfaces implemented by that object are specified by .B tags within it. Methods, signals and properties defined by the interface are described by .BR ", " " and " tags within the interface. Arguments to methods and signals are defined by .B tags within them. Names and other values are specified as attributes to the tag. Additional properties for external tools or software may be given in .B tags. These may appear within interfaces, methods, signals, properties and arguments. .B nih-dbus-tool makes use of many of these. .I Note that argument annotations are an nih-dbus-tool extension to .I the format. .BR nih-dbus-tool 's parser is reasonably liberal, to allow for future expansion of the D-Bus introspection format. Any unknown tag, attribute or annotation, or any tag not in an expected location, will be ignored with a warning. However a missing root node tag, missing attributes, illegal or invalid format values for defined attributes or non well-formed XML will result in an error. Character data and comments are not considered part of description, and are not parsed. .\" .SH OPTIONS .\" .SH AUTHOR Written by Scott James Remnant .RB < scott@netsplit.com > .\" .SH BUGS Report bugs at .RB < https://launchpad.net/libnih/+bugs > .\" .SH COPYRIGHT Copyright \(co 2009 Scott James Remnant . .PP This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. libnih-1.0.3/nih-dbus-tool/indent.h0000644000175000017500000000216311445765555014042 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_INDENT_H #define NIH_DBUS_TOOL_INDENT_H #include NIH_BEGIN_EXTERN char *indent (char **str, const void *parent, int level) __attribute__ ((warn_unused_result, malloc)); char *comment (char **str, const void *parent) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_INDENT_H */ libnih-1.0.3/nih-dbus-tool/Makefile.am0000644000175000017500000003620511445765555014450 00000000000000## Process this file with automake to produce Makefile.in AM_CFLAGS = \ $(DBUS_CFLAGS) AM_CPPFLAGS = \ -DLOCALEDIR="\"$(localedir)\"" \ -I$(top_builddir) -I$(top_srcdir) -iquote$(builddir) -iquote$(srcdir) \ -I$(top_srcdir)/intl dist_man_MANS = \ man/nih-dbus-tool.1 bin_PROGRAMS = \ nih-dbus-tool nih_dbus_tool_SOURCES = \ main.c \ symbol.c symbol.h \ indent.c indent.h \ type.c type.h \ marshal.c marshal.h \ demarshal.c demarshal.h \ node.c node.h \ interface.c interface.h \ method.c method.h \ signal.c signal.h \ property.c property.h \ argument.c argument.h \ annotation.c annotation.h \ parse.c parse.h \ output.c output.h \ errors.h nih_dbus_tool_LDADD = \ ../nih/libnih.la \ $(LTLIBINTL) \ $(EXPAT_LIBS) \ $(DBUS_LIBS) TESTS = \ test_main \ test_symbol \ test_indent \ test_type \ test_marshal \ test_demarshal \ test_node \ test_interface \ test_method \ test_signal \ test_property \ test_argument \ test_annotation \ test_parse \ test_output \ test_com.netsplit.Nih.Test_object \ test_com.netsplit.Nih.Test_proxy check_PROGRAMS = \ $(TESTS) \ marshal_factory \ demarshal_factory \ interface_factory \ method_factory \ signal_factory \ property_factory test_main_SOURCES = tests/test_main.c main.c test_main_CFLAGS = $(AM_CFLAGS) -DTEST test_main_LDFLAGS = -static test_main_LDADD = ../nih/libnih.la test_symbol_SOURCES = tests/test_symbol.c test_symbol_LDFLAGS = -static test_symbol_LDADD = \ symbol.o \ ../nih/libnih.la test_indent_SOURCES = tests/test_indent.c test_indent_LDFLAGS = -static test_indent_LDADD = \ indent.o \ ../nih/libnih.la test_type_SOURCES = tests/test_type.c test_type_LDFLAGS = -static test_type_LDADD = \ type.o indent.o symbol.o \ ../nih/libnih.la \ $(DBUS_LIBS) test_marshal_SOURCES = \ tests/test_marshal.c tests/marshal_code.h nodist_test_marshal_SOURCES = \ tests/marshal_code.c test_marshal_LDFLAGS = -static test_marshal_LDADD = \ marshal.o type.o indent.o symbol.o \ ../nih/libnih.la \ $(DBUS_LIBS) test_demarshal_SOURCES = \ tests/test_demarshal.c tests/demarshal_code.h nodist_test_demarshal_SOURCES = \ tests/demarshal_code.c test_demarshal_LDFLAGS = -static test_demarshal_LDADD = \ demarshal.o type.o indent.o symbol.o \ ../nih/libnih.la \ $(DBUS_LIBS) test_node_SOURCES = tests/test_node.c test_node_LDFLAGS = -static test_node_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_interface_SOURCES = \ tests/test_interface.c tests/interface_code.h nodist_test_interface_SOURCES = \ tests/interface_code.c test_interface_LDFLAGS = -static test_interface_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih-dbus/libnih-dbus.la \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_method_SOURCES = \ tests/test_method.c tests/method_code.h nodist_test_method_SOURCES = \ tests/method_code.c test_method_LDFLAGS = -static test_method_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih-dbus/libnih-dbus.la \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_signal_SOURCES = \ tests/test_signal.c tests/signal_code.h nodist_test_signal_SOURCES = \ tests/signal_code.c test_signal_LDFLAGS = -static test_signal_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih-dbus/libnih-dbus.la \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_property_SOURCES = \ tests/test_property.c tests/property_code.h nodist_test_property_SOURCES = \ tests/property_code.c test_property_LDFLAGS = -static test_property_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih-dbus/libnih-dbus.la \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_argument_SOURCES = tests/test_argument.c test_argument_LDFLAGS = -static test_argument_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_annotation_SOURCES = tests/test_annotation.c test_annotation_LDFLAGS = -static test_annotation_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_parse_SOURCES = tests/test_parse.c test_parse_LDFLAGS = -static test_parse_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_output_SOURCES = tests/test_output.c test_output_LDFLAGS = -static test_output_LDADD = \ demarshal.o marshal.o type.o indent.o \ output.o parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_com_netsplit_Nih_Test_object_SOURCES = \ tests/test_com.netsplit.Nih.Test_object.c \ tests/com.netsplit.Nih.Test_impl.c tests/com.netsplit.Nih.Test_impl.h nodist_test_com_netsplit_Nih_Test_object_SOURCES = \ $(com_netsplit_Nih_Test_object_OUTPUTS) test_com_netsplit_Nih_Test_object_LDFLAGS = -static test_com_netsplit_Nih_Test_object_LDADD = ../nih-dbus/libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_com_netsplit_Nih_Test_proxy_SOURCES = \ tests/test_com.netsplit.Nih.Test_proxy.c \ tests/com.netsplit.Nih.Test_impl.c tests/com.netsplit.Nih.Test_impl.h nodist_test_com_netsplit_Nih_Test_proxy_SOURCES = \ $(com_netsplit_Nih_Test_object_OUTPUTS) \ $(com_netsplit_Nih_Test_proxy_OUTPUTS) test_com_netsplit_Nih_Test_proxy_LDFLAGS = -static test_com_netsplit_Nih_Test_proxy_LDADD = ../nih-dbus/libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) com_netsplit_Nih_Test_object_OUTPUTS = \ tests/com.netsplit.Nih.Test_object.c \ tests/com.netsplit.Nih.Test_object.h com_netsplit_Nih_Test_object_XML = \ tests/com.netsplit.Nih.Test.xml $(com_netsplit_Nih_Test_object_OUTPUTS): $(com_netsplit_Nih_Test_object_XML) $(builddir)/nih-dbus-tool $(AM_V_GEN)$(MKDIR_P) `echo "$@" | \ sed '/\//!d;s,/[^/]*$$,,' | \ sort -u` && \ $(NIH_DBUS_TOOL) --mode=object --prefix=my --output=$@ $< com_netsplit_Nih_Test_proxy_OUTPUTS = \ tests/com.netsplit.Nih.Test_proxy.c \ tests/com.netsplit.Nih.Test_proxy.h com_netsplit_Nih_Test_proxy_XML = \ tests/com.netsplit.Nih.Test.xml $(com_netsplit_Nih_Test_proxy_OUTPUTS): $(com_netsplit_Nih_Test_proxy_XML) $(builddir)/nih-dbus-tool $(AM_V_GEN)$(MKDIR_P) `echo "$@" | \ sed '/\//!d;s,/[^/]*$$,,' | \ sort -u` && \ $(NIH_DBUS_TOOL) --mode=proxy --prefix=proxy --output=$@ $< # These have to be built sources because we can't compile test_*.o without # the header file existing first. BUILT_SOURCES = \ $(com_netsplit_Nih_Test_object_OUTPUTS) \ $(com_netsplit_Nih_Test_proxy_OUTPUTS) EXTRA_DIST = \ $(com_netsplit_Nih_Test_object_XML) \ $(com_netsplit_Nih_Test_proxy_XML) marshal_factory_SOURCES = tests/marshal_factory.c marshal_factory_LDFLAGS = -static marshal_factory_LDADD = \ marshal.o type.o indent.o symbol.o \ ../nih/libnih.la \ $(DBUS_LIBS) tests/marshal_code.c: $(builddir)/marshal_factory $(AM_V_GEN)$(builddir)/marshal_factory > $@ demarshal_factory_SOURCES = tests/demarshal_factory.c demarshal_factory_LDFLAGS = -static demarshal_factory_LDADD = \ demarshal.o type.o indent.o symbol.o \ ../nih/libnih.la \ $(DBUS_LIBS) tests/demarshal_code.c: $(builddir)/demarshal_factory $(AM_V_GEN)$(builddir)/demarshal_factory > $@ interface_factory_SOURCES = tests/interface_factory.c interface_factory_LDFLAGS = -static interface_factory_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) tests/interface_code.c: $(builddir)/interface_factory $(AM_V_GEN)$(builddir)/interface_factory > $@ method_factory_SOURCES = tests/method_factory.c method_factory_LDFLAGS = -static method_factory_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) tests/method_code.c: $(builddir)/method_factory $(AM_V_GEN)$(builddir)/method_factory > $@ signal_factory_SOURCES = tests/signal_factory.c signal_factory_LDFLAGS = -static signal_factory_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) tests/signal_code.c: $(builddir)/signal_factory $(AM_V_GEN)$(builddir)/signal_factory > $@ property_factory_SOURCES = tests/property_factory.c property_factory_LDFLAGS = -static property_factory_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) tests/property_code.c: $(builddir)/property_factory $(AM_V_GEN)$(builddir)/property_factory > $@ CLEANFILES = \ $(com_netsplit_Nih_Test_object_OUTPUTS) \ $(com_netsplit_Nih_Test_proxy_OUTPUTS) \ $(nodist_test_marshal_SOURCES) \ $(nodist_test_demarshal_SOURCES) \ $(nodist_test_interface_SOURCES) \ $(nodist_test_method_SOURCES) \ $(nodist_test_signal_SOURCES) \ $(nodist_test_property_SOURCES) EXTRA_DIST += \ tests/expected/test_interface_proxy_get_all_function_standard.c \ tests/expected/test_interface_proxy_get_all_notify_function_standard.c \ tests/expected/test_interface_proxy_get_all_notify_function_structure.c \ tests/expected/test_interface_proxy_get_all_sync_function_standard.c \ tests/expected/test_interface_proxy_get_all_sync_function_structure.c \ tests/expected/test_method_object_function_standard.c \ tests/expected/test_method_object_function_no_input.c \ tests/expected/test_method_object_function_no_output.c \ tests/expected/test_method_object_function_structure_input.c \ tests/expected/test_method_object_function_structure_output.c \ tests/expected/test_method_object_function_no_args.c \ tests/expected/test_method_object_function_async.c \ tests/expected/test_method_object_function_deprecated.c \ tests/expected/test_method_reply_function_standard.c \ tests/expected/test_method_reply_function_no_args.c \ tests/expected/test_method_reply_function_structure.c \ tests/expected/test_method_reply_function_array.c \ tests/expected/test_method_reply_function_deprecated.c \ tests/expected/test_method_proxy_function_standard.c \ tests/expected/test_method_proxy_function_no_args.c \ tests/expected/test_method_proxy_function_structure.c \ tests/expected/test_method_proxy_function_array.c \ tests/expected/test_method_proxy_function_deprecated.c \ tests/expected/test_method_proxy_notify_function_standard.c \ tests/expected/test_method_proxy_notify_function_no_args.c \ tests/expected/test_method_proxy_notify_function_structure.c \ tests/expected/test_method_proxy_notify_function_array.c \ tests/expected/test_method_proxy_sync_function_standard.c \ tests/expected/test_method_proxy_sync_function_no_input.c \ tests/expected/test_method_proxy_sync_function_no_output.c \ tests/expected/test_method_proxy_sync_function_no_args.c \ tests/expected/test_method_proxy_sync_function_structure_input.c \ tests/expected/test_method_proxy_sync_function_structure_output.c \ tests/expected/test_method_proxy_sync_function_array_input.c \ tests/expected/test_method_proxy_sync_function_deprecated.c \ tests/expected/test_signal_object_function_standard.c \ tests/expected/test_signal_object_function_no_args.c \ tests/expected/test_signal_object_function_structure.c \ tests/expected/test_signal_object_function_array.c \ tests/expected/test_signal_object_function_deprecated.c \ tests/expected/test_signal_proxy_function_standard.c \ tests/expected/test_signal_proxy_function_no_args.c \ tests/expected/test_signal_proxy_function_structure.c \ tests/expected/test_signal_proxy_function_deprecated.c \ tests/expected/test_property_object_get_function_standard.c \ tests/expected/test_property_object_get_function_structure.c \ tests/expected/test_property_object_get_function_deprecated.c \ tests/expected/test_property_object_set_function_standard.c \ tests/expected/test_property_object_set_function_structure.c \ tests/expected/test_property_object_set_function_deprecated.c \ tests/expected/test_property_proxy_get_function_standard.c \ tests/expected/test_property_proxy_get_function_deprecated.c \ tests/expected/test_property_proxy_get_notify_function_standard.c \ tests/expected/test_property_proxy_get_notify_function_structure.c \ tests/expected/test_property_proxy_get_notify_function_deprecated.c \ tests/expected/test_property_proxy_set_function_standard.c \ tests/expected/test_property_proxy_set_function_structure.c \ tests/expected/test_property_proxy_set_function_array.c \ tests/expected/test_property_proxy_set_function_deprecated.c \ tests/expected/test_property_proxy_set_notify_function_standard.c \ tests/expected/test_property_proxy_set_notify_function_deprecated.c \ tests/expected/test_property_proxy_get_sync_function_standard.c \ tests/expected/test_property_proxy_get_sync_function_structure.c \ tests/expected/test_property_proxy_get_sync_function_deprecated.c \ tests/expected/test_property_proxy_set_sync_function_standard.c \ tests/expected/test_property_proxy_set_sync_function_structure.c \ tests/expected/test_property_proxy_set_sync_function_array.c \ tests/expected/test_property_proxy_set_sync_function_deprecated.c \ tests/expected/test_node_interfaces_array_object.c \ tests/expected/test_node_interfaces_array_proxy.c \ tests/expected/test_node_interfaces_array_none.c \ tests/expected/test_node_object_functions_standard.c \ tests/expected/test_node_object_functions_no_methods.c \ tests/expected/test_node_object_functions_no_signals.c \ tests/expected/test_node_object_functions_no_properties.c \ tests/expected/test_node_object_functions_only_properties.c \ tests/expected/test_node_object_functions_structure.c \ tests/expected/test_node_proxy_functions_standard.c \ tests/expected/test_node_proxy_functions_no_methods.c \ tests/expected/test_node_proxy_functions_no_signals.c \ tests/expected/test_node_proxy_functions_no_properties.c \ tests/expected/test_node_proxy_functions_only_properties.c \ tests/expected/test_node_proxy_functions_structure.c \ tests/expected/test_output_proxy_standard.c \ tests/expected/test_output_proxy_standard.h \ tests/expected/test_output_proxy_no_interfaces.c \ tests/expected/test_output_proxy_no_interfaces.h \ tests/expected/test_output_object_standard.c \ tests/expected/test_output_object_standard.h \ tests/expected/test_output_object_no_interfaces.c \ tests/expected/test_output_object_no_interfaces.h .PHONY: tests tests: $(BUILT_SOURCES) $(check_PROGRAMS) clean-local: rm -f *.gcno *.gcda maintainer-clean-local: rm -f *.gcov libnih-1.0.3/nih-dbus-tool/interface.h0000644000175000017500000001026611445765555014524 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_INTERFACE_H #define NIH_DBUS_TOOL_INTERFACE_H #include #include #include /** * Interface: * @entry: list header, * @name: D-Bus name of interface, * @symbol: name used when constructing C name, * @deprecated: whether this interface is deprecated, * @methods: methods defined by the interface, * @signals: signals defined by the interface, * @properties: properties defined by the interface. * * D-Bus objects implement zero or more interfaces defining the @methods, * @signals and @properties available. Interfaces are selected by @name * over the bus. * * When generating the C symbol names @symbol will be used. If @symbol * is NULL, and the interface is not the first for the object, as many * final components of @name required to ensure uniqueness will be used. **/ typedef struct interface { NihList entry; char * name; char * symbol; int deprecated; NihList methods; NihList signals; NihList properties; } Interface; NIH_BEGIN_EXTERN int interface_name_valid (const char *name); Interface *interface_new (const void *parent, const char *name) __attribute__ ((warn_unused_result, malloc)); int interface_start_tag (XML_Parser xmlp, const char *tag, char * const *attr) __attribute__ ((warn_unused_result)); int interface_end_tag (XML_Parser xmlp, const char *tag) __attribute__ ((warn_unused_result)); int interface_annotation (Interface *interface, const char *name, const char *value) __attribute__ ((warn_unused_result)); char * interface_methods_array (const void *parent, const char *prefix, Interface *interface, int with_handlers, NihList *prototypes) __attribute__ ((warn_unused_result, malloc)); char * interface_signals_array (const void *parent, const char *prefix, Interface *interface, int with_filters, NihList *prototypes) __attribute__ ((warn_unused_result, malloc)); char * interface_properties_array (const void *parent, const char *prefix, Interface *interface, int with_handlers, NihList *prototypes) __attribute__ ((warn_unused_result, malloc)); char * interface_struct (const void *parent, const char *prefix, Interface *interface, int object, NihList *prototypes) __attribute__ ((warn_unused_result, malloc)); char * interface_proxy_get_all_function (const void *parent, const char *prefix, Interface *interface, NihList *prototypes, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * interface_proxy_get_all_notify_function (const void *parent, const char *prefix, Interface *interface, NihList *prototypes, NihList *typedefs, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * interface_proxy_get_all_sync_function (const void *parent, const char *prefix, Interface *interface, NihList *prototypes, NihList *structs) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_INTERFACE_H */ libnih-1.0.3/nih-dbus-tool/signal.h0000644000175000017500000000572611445765555014046 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_SIGNAL_H #define NIH_DBUS_TOOL_SIGNAL_H #include #include #include #include "interface.h" #include "argument.h" /** * Signal: * @entry: list header, * @name: D-Bus name of signal, * @symbol: name used when constructing C name, * @deprecated: whether this signal is deprecated, * @arguments: arguments provided by the signal. * * D-Bus interfaces specify zero or more signals, which are identified by * @name over the bus and may have zero or more @arguments. * * When generating the C symbol names @symbol will be used. If @symbol * is NULL, @name will be converted into the usual C lowercase and underscore * style and used instead. **/ typedef struct signal { NihList entry; char * name; char * symbol; int deprecated; NihList arguments; } Signal; NIH_BEGIN_EXTERN int signal_name_valid (const char *name); Signal * signal_new (const void *parent, const char *name) __attribute__ ((warn_unused_result, malloc)); int signal_start_tag (XML_Parser xmlp, const char *tag, char * const *attr) __attribute__ ((warn_unused_result)); int signal_end_tag (XML_Parser xmlp, const char *tag) __attribute__ ((warn_unused_result)); int signal_annotation (Signal *signal, const char *name, const char *value) __attribute__ ((warn_unused_result)); Signal * signal_lookup (Interface *interface, const char *symbol); Argument *signal_lookup_argument (Signal *signal, const char *symbol); char * signal_object_function (const void *parent, const char *prefix, Interface *interface, Signal *signal, NihList *prototypes, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * signal_proxy_function (const void *parent, const char *prefix, Interface *interface, Signal *signal, NihList *prototypes, NihList *typedefs, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * signal_args_array (const void *parent, const char *prefix, Interface *interface, Signal *signal, NihList *prototypes) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_SIGNAL_H */ libnih-1.0.3/nih-dbus-tool/argument.h0000644000175000017500000000464111445765555014406 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_ARGUMENT_H #define NIH_DBUS_TOOL_ARGUMENT_H #include #include #include #include /** * Argument: * @entry: list header, * @name: D-Bus name of argument, * @symbol: name used when constructing C name, * @type: type signature of argument, * @direction: direction of argument. * * D-Bus methods and signals specify zero or more arguments, which are * identified by an optional @name over the bus and have the type signature * @type. Arguments may be either input to the method or output from it * depending on @direction. * * When generating the C symbol names @symbol will be used. If @symbol * is NULL, @name will be converted into the usual C lowercase and underscore * style and used instead. If @name is NULL, then a simple "arg1" form is * used. **/ typedef struct argument { NihList entry; char * name; char * symbol; char * type; NihDBusArgDir direction; } Argument; NIH_BEGIN_EXTERN int argument_name_valid (const char *name); Argument *argument_new (const void *parent, const char *name, const char *type, NihDBusArgDir direction) __attribute__ ((warn_unused_result, malloc)); int argument_start_tag (XML_Parser xmlp, const char *tag, char * const *attr) __attribute__ ((warn_unused_result)); int argument_end_tag (XML_Parser xmlp, const char *tag) __attribute__ ((warn_unused_result)); int argument_annotation (Argument *argument, const char *name, const char *value) __attribute__ ((warn_unused_result)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_ARGUMENT_H */ libnih-1.0.3/nih-dbus-tool/errors.h0000644000175000017500000001451311445765555014077 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_ERRORS_H #define NIH_DBUS_TOOL_ERRORS_H #include #include /* Allocated error numbers */ enum { NIH_DBUS_TOOL_ERROR_START = NIH_ERROR_APPLICATION_START, NODE_INVALID_PATH, INTERFACE_MISSING_NAME, INTERFACE_INVALID_NAME, INTERFACE_ILLEGAL_DEPRECATED, INTERFACE_UNKNOWN_ANNOTATION, INTERFACE_INVALID_SYMBOL, INTERFACE_DUPLICATE_SYMBOL, METHOD_MISSING_NAME, METHOD_INVALID_NAME, METHOD_ILLEGAL_DEPRECATED, METHOD_INVALID_SYMBOL, METHOD_ILLEGAL_NO_REPLY, METHOD_ILLEGAL_ASYNC, METHOD_UNKNOWN_ANNOTATION, METHOD_DUPLICATE_SYMBOL, SIGNAL_MISSING_NAME, SIGNAL_INVALID_NAME, SIGNAL_ILLEGAL_DEPRECATED, SIGNAL_INVALID_SYMBOL, SIGNAL_UNKNOWN_ANNOTATION, SIGNAL_DUPLICATE_SYMBOL, PROPERTY_MISSING_NAME, PROPERTY_INVALID_NAME, PROPERTY_MISSING_TYPE, PROPERTY_INVALID_TYPE, PROPERTY_MISSING_ACCESS, PROPERTY_ILLEGAL_ACCESS, PROPERTY_ILLEGAL_DEPRECATED, PROPERTY_INVALID_SYMBOL, PROPERTY_UNKNOWN_ANNOTATION, PROPERTY_DUPLICATE_SYMBOL, ARGUMENT_INVALID_NAME, ARGUMENT_MISSING_TYPE, ARGUMENT_INVALID_TYPE, ARGUMENT_ILLEGAL_METHOD_DIRECTION, ARGUMENT_ILLEGAL_SIGNAL_DIRECTION, ARGUMENT_INVALID_SYMBOL, ARGUMENT_UNKNOWN_ANNOTATION, ARGUMENT_DUPLICATE_SYMBOL, ANNOTATION_MISSING_NAME, ANNOTATION_MISSING_VALUE, }; /* Error strings for defined messages */ #define SYMBOLS_UNIQUE_OVERFLOW_STR N_("Unable to generate unique name for symbol") #define NODE_INVALID_PATH_STR N_("Invalid object path in name attribute") #define INTERFACE_MISSING_NAME_STR N_(" missing required name attribute") #define INTERFACE_INVALID_NAME_STR N_("Invalid interface name in name attribute") #define INTERFACE_ILLEGAL_DEPRECATED_STR N_("Illegal value for org.freedesktop.DBus.Deprecated interface annotation, expected 'true' or 'false'") #define INTERFACE_INVALID_SYMBOL_STR N_("Invalid C symbol for interface") #define INTERFACE_UNKNOWN_ANNOTATION_STR N_("Unknown annotation for interface") #define INTERFACE_DUPLICATE_SYMBOL_STR N_("Symbol '%s' already assigned to %s interface") #define METHOD_MISSING_NAME_STR N_(" missing required name attribute") #define METHOD_INVALID_NAME_STR N_("Invalid method name in name attribute") #define METHOD_ILLEGAL_DEPRECATED_STR N_("Illegal value for org.freedesktop.DBus.Deprecated method annotation, expected 'true' or 'false'") #define METHOD_ILLEGAL_NO_REPLY_STR N_("Illegal value for org.freedesktop.DBus.Method.NoReply method annotation, expected 'true' or 'false'") #define METHOD_INVALID_SYMBOL_STR N_("Invalid C symbol for method") #define METHOD_ILLEGAL_ASYNC_STR N_("Illegal value for com.netsplit.Nih.Method.Async method annotation, expected 'true' or 'false'") #define METHOD_UNKNOWN_ANNOTATION_STR N_("Unknown annotation for method") #define METHOD_DUPLICATE_SYMBOL_STR N_("Symbol '%s' already assigned to %s method") #define SIGNAL_MISSING_NAME_STR N_(" missing required name attribute") #define SIGNAL_INVALID_NAME_STR N_("Invalid signal name in name attribute") #define SIGNAL_ILLEGAL_DEPRECATED_STR N_("Illegal value for org.freedesktop.DBus.Deprecated signal annotation, expected 'true' or 'false'") #define SIGNAL_INVALID_SYMBOL_STR N_("Invalid C symbol for signal") #define SIGNAL_UNKNOWN_ANNOTATION_STR N_("Unknown annotation for signal") #define SIGNAL_DUPLICATE_SYMBOL_STR N_("Symbol '%s' already assigned to %s signal") #define PROPERTY_MISSING_NAME_STR N_(" missing required name attribute") #define PROPERTY_INVALID_NAME_STR N_("Invalid property name in name attribute") #define PROPERTY_MISSING_TYPE_STR N_(" missing required type attribute") #define PROPERTY_INVALID_TYPE_STR N_("Invalid D-Bus type in type attribute") #define PROPERTY_MISSING_ACCESS_STR N_(" missing required access attribute") #define PROPERTY_ILLEGAL_ACCESS_STR N_("Illegal value for access attribute, expected 'read', 'write' or 'readwrite'") #define PROPERTY_ILLEGAL_DEPRECATED_STR N_("Illegal value for org.freedesktop.DBus.Deprecated property annotation, expected 'true' or 'false'") #define PROPERTY_INVALID_SYMBOL_STR N_("Invalid C symbol for property") #define PROPERTY_UNKNOWN_ANNOTATION_STR N_("Unknown annotation for property") #define PROPERTY_DUPLICATE_SYMBOL_STR N_("Symbol '%s' already assigned to %s property") #define ARGUMENT_INVALID_SYMBOL_STR N_("Invalid C symbol for argument") #define ARGUMENT_UNKNOWN_ANNOTATION_STR N_("Unknown annotation for argument") #define ARGUMENT_INVALID_NAME_STR N_("Invalid argument name in name attribute") #define ARGUMENT_MISSING_TYPE_STR N_(" missing required type attribute") #define ARGUMENT_INVALID_TYPE_STR N_("Invalid D-Bus type in type attribute") #define ARGUMENT_ILLEGAL_METHOD_DIRECTION_STR N_("Illegal value for direction attribute, expected 'in' or 'out'") #define ARGUMENT_ILLEGAL_SIGNAL_DIRECTION_STR N_("Illegal value for direction attribute, expected 'out'") #define ARGUMENT_DUPLICATE_SYMBOL_STR N_("Symbol '%s' already assigned to %s argument") #define ANNOTATION_MISSING_NAME_STR N_(" missing required name attribute") #define ANNOTATION_MISSING_VALUE_STR N_(" missing required value attribute") #endif /* NIH_DBUS_TOOL_ERRORS_H */ libnih-1.0.3/nih-dbus-tool/marshal.h0000644000175000017500000000252211445765555014207 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_MARSHAL_H #define NIH_DBUS_TOOL_MARSHAL_H #include #include #include NIH_BEGIN_EXTERN char *marshal (const void *parent, DBusSignatureIter *iter, const char *iter_name, const char *name, const char *oom_error_code, NihList *inputs, NihList *locals, const char *prefix, const char *interface_symbol, const char *member_symbol, const char *symbol, NihList *structs) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_MARSHAL_H */ libnih-1.0.3/nih-dbus-tool/symbol.c0000644000175000017500000003041411445765555014061 00000000000000/* nih-dbus-tool * * symbol.c - C symbol generation and validation * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include "symbol.h" /* Prototypes for static functions */ static char *symbol_strcat_interface (char **str, const void *parent, const char *format, ...) __attribute__ ((format (printf, 3, 4), warn_unused_result, malloc)); static char *symbol_strcat_title (char **str, const void *parent, const char *format, ...) __attribute__ ((format (printf, 3, 4), warn_unused_result, malloc)); /** * symbol_valid: * @symbol: Symbol to verify. * * Verifies whether @symbol matches the rules for C symbol names. To make * things easier for ourselves, we only support a subset of what C99 can * really support. ie. no universal character names. * * Returns: TRUE if valid, FALSE if not. **/ int symbol_valid (const char *symbol) { nih_assert (symbol != NULL); /* We can get away with just using strlen() here even through symbol * is in UTF-8 because all the valid characters are ASCII. */ for (size_t i = 0; i < strlen (symbol); i++) { /* Symbols may contain digits, but not at the beginning. */ if ((symbol[i] >= '0') && (symbol[i] <= '9')) { if (i == 0) return FALSE; continue; } /* Valid characters anywhere are [A-Za-z_] */ if ( ((symbol[i] < 'A') || (symbol[i] > 'Z')) && ((symbol[i] < 'a') || (symbol[i] > 'z')) && (symbol[i] != '_')) return FALSE; } /* Symbol must be at least 1 character */ if (strlen (symbol) < 1) return FALSE; return TRUE; } /** * symbol_from_name: * @parent: parent object of new string, * @name: name to convert. * * Converts the D-Bus style name @name to C style; basically the name * is lower-cased, and underscores inserted between CamelCase words. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if allocation fails. **/ char * symbol_from_name (const void *parent, const char *name) { char * symbol; char * ptr; size_t len = 0; nih_assert (name != NULL); /* Figure out how long the symbol will need to be by counting * how many places we need to add underscores and adding them * to the length. */ len = strlen (name); for (size_t i = 0; i < strlen (name); i++) if ((i > 0) && (name[i] >= 'A') && (name[i] <= 'Z') && (name[i-1] != '_') && ((name[i-1] < 'A') || (name[i-1] > 'Z'))) len++; /* Allocate the new string */ symbol = nih_alloc (parent, len + 1); if (! symbol) return NULL; /* Copy the characters across, lowercasing as we go and inserting * underscores before any capital unless it follows an underscore. */ ptr = symbol; for (size_t i = 0; i < strlen (name); i++) { if ((i > 0) && (name[i] >= 'A') && (name[i] <= 'Z') && (name[i-1] != '_') && ((name[i-1] < 'A') || (name[i-1] > 'Z'))) *(ptr++) = '_'; *(ptr++) = tolower (name[i]); } *ptr = '\0'; return symbol; } /** * symbol_strcat_interface: * @str: pointer to string to modify, * @parent: parent object of new string, * @format: format to append to @str. * * Replaces periods in the string expanded from @format with underscores * and concatenates it onto @str. The new string is allocated using * nih_alloc() and @str will be updated to point to the new string; use * the return value simply to check for success. * * @parent is ignored; though it is usual to pass a parent of @str for * style reasons. * * Returns: newly allocated string or NULL if allocation fails. **/ static char * symbol_strcat_interface (char ** str, const void *parent, const char *format, ...) { nih_local char *name = NULL; va_list args; size_t len; char * ret; nih_assert (str != NULL); nih_assert (*str != NULL); nih_assert (format != NULL); va_start (args, format); name = nih_vsprintf (NULL, format, args); if (! name) return NULL; va_end (args); len = strlen (*str); ret = nih_realloc (*str, parent, len + strlen (name) + 1); if (! ret) return NULL; *str = ret; /* Copy the characters across, replacing the periods between * interface components with underscores. */ for (char *s = name; *s; s++) (*str)[len++] = (*s == '.' ? '_' : *s); (*str)[len] = '\0'; return *str; } /** * symbol_strcat_title: * @str: pointer to string to modify, * @parent: parent object of new string, * @format: format to append to @str. * * Expands the @format string and modifies it so that each underscore- * separated word has the underscores removed and the initial character * uppercased. The new string is allocated using nih_alloc() and @str * will be updated to point to the new string; use the return value * simply to check for success. * * If the string pointed to by @str is NULL, a new string will be * allocated and if @parent is not NULL, it should be a pointer to another * object which will be used as a parent for the returned string. When all * parents of the returned string are freed, the returned string will also * be freed. * * When the string pointed to by @str is not NULL, @parent is ignored; * though it is usual to pass a parent of @str for style reasons. * * Returns: newly allocated string or NULL if allocation fails. **/ static char * symbol_strcat_title (char ** str, const void *parent, const char *format, ...) { va_list args; nih_local char *symbol = NULL; size_t str_len; size_t len; char * ret; int first = TRUE; nih_assert (str != NULL); nih_assert (format != NULL); va_start (args, format); symbol = nih_vsprintf (NULL, format, args); if (! symbol) return NULL; va_end (args); str_len = *str ? strlen (*str) : 0; len = str_len; /* Figure out how long the new string will be by counting how many * characters that aren't underscores we'll end up adding. */ for (char *s = symbol; *s; s++) if (*s != '_') len++; ret = nih_realloc (*str, parent, len + 1); if (! ret) return NULL; *str = ret; len = str_len; /* Copy the characters across, uppercasing the first character of * each word and stripping underscores. */ for (char *s = symbol; *s; s++) { if (*s == '_') { first = TRUE; } else { (*str)[len++] = (first ? toupper (*s) : *s); first = FALSE; } } (*str)[len] = '\0'; return *str; } /** * symbol_impl: * @parent: parent object of new string, * @prefix: prefix for returned symbol, * @interface_name: name of D-Bus interface, * @name: name of interface member, * @postfix: postfix for returned symbol. * * Generates a C symbol for an implementation function, one that is hidden * from the API and thus uniqueness and verboseness is more desirable than * readability. The @prefix is prepended to the @interface_name and * member @name, with the @postfix appended. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if allocation fails. **/ char * symbol_impl (const void *parent, const char *prefix, const char *interface_name, const char *name, const char *postfix) { char *str; nih_assert (prefix != NULL); nih_assert (interface_name != NULL); nih_assert ((postfix != NULL) || (name == NULL)); str = nih_sprintf (parent, "%s_", prefix); if (! str) return NULL; if (! symbol_strcat_interface (&str, parent, (name ? "%s_" : "%s"), interface_name)) { nih_free (str); return NULL; } if (name) { if (! nih_strcat (&str, parent, name)) { nih_free (str); return NULL; } } if (postfix) { if (! nih_strcat_sprintf (&str, parent, "_%s", postfix)) { nih_free (str); return NULL; } } return str; } /** * symbol_extern: * @parent: parent object of new string, * @prefix: prefix for returned symbol, * @interface_symbol: symbol for D-Bus interface, * @midfix: midfix for returned symbol, * @symbol: symbol of interface member, * @postfix: postfix for returned symbol. * * Generates a C symbol for an external function, one that is either part of * the API or intended to be supplied externally, thus where readability * is more desirable than uniqueness or verboseness. The @prefix is * prepended to the @interface_symbol (if supplied), @midfix (if supplied), * member @symbol, with the @postfix (if supplied) appended. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if allocation fails. **/ char * symbol_extern (const void *parent, const char *prefix, const char *interface_symbol, const char *midfix, const char *symbol, const char *postfix) { char *str; nih_assert (prefix != NULL); nih_assert (symbol != NULL); str = nih_sprintf (parent, "%s_", prefix); if (! str) return NULL; if (interface_symbol) { if (! nih_strcat_sprintf (&str, parent, "%s_", interface_symbol)) { nih_free (str); return NULL; } } if (midfix) { if (! nih_strcat_sprintf (&str, parent, "%s_", midfix)) { nih_free (str); return NULL; } } if (! nih_strcat (&str, parent, symbol)) { nih_free (str); return NULL; } if (postfix) { if (! nih_strcat_sprintf (&str, parent, "_%s", postfix)) { nih_free (str); return NULL; } } return str; } /** * symbol_typedef: * @parent: parent object of new string, * @prefix: prefix for returned symbol, * @interface_symbol: symbol for D-Bus interface, * @midfix: midfix for returned symbol, * @symbol: symbol of interface member, * @postfix: postfix for returned symbol. * * Generates a C typedef name for a function that is expected to be * supplied, this has the same basic form as an external symbol except that * underscores are removed and the first letter of each part is uppercased. * The @prefix is prepended to the @interface_symbol (if supplied), @midfix * (if supplied), member @symbol, with the @postfix appended. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if allocation fails. **/ char * symbol_typedef (const void *parent, const char *prefix, const char *interface_symbol, const char *midfix, const char *symbol, const char *postfix) { char *str; nih_assert (prefix != NULL); nih_assert (symbol != NULL); str = NULL; if (! symbol_strcat_title (&str, parent, "%s_", prefix)) return NULL; if (interface_symbol) { if (! symbol_strcat_title (&str, parent, "%s_", interface_symbol)) { nih_free (str); return NULL; } } if (midfix) { if (! symbol_strcat_title (&str, parent, "%s_", midfix)) { nih_free (str); return NULL; } } if (! symbol_strcat_title (&str, parent, "%s", symbol)) { nih_free (str); return NULL; } if (postfix) { if (! symbol_strcat_title (&str, parent, "_%s", postfix)) { nih_free (str); return NULL; } } return str; } libnih-1.0.3/nih-dbus-tool/symbol.h0000644000175000017500000000324211445765555014065 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_SYMBOL_H #define NIH_DBUS_TOOL_SYMBOL_H #include NIH_BEGIN_EXTERN int symbol_valid (const char *symbol); char *symbol_from_name (const void *parent, const char *name) __attribute__ ((warn_unused_result, malloc)); char *symbol_impl (const void *parent, const char *prefix, const char *interface_name, const char *name, const char *postfix) __attribute__ ((warn_unused_result, malloc)); char *symbol_extern (const void *parent, const char *prefix, const char *interface_symbol, const char *midfix, const char *symbol, const char *postfix) __attribute__ ((warn_unused_result, malloc)); char *symbol_typedef (const void *parent, const char *prefix, const char *interface_symbol, const char *midfix, const char *symbol, const char *postfix) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_SYMBOL_H */ libnih-1.0.3/nih-dbus-tool/property.c0000644000175000017500000027100411445765555014442 00000000000000/* nih-dbus-tool * * property.c - property parsing and generation * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include "symbol.h" #include "indent.h" #include "type.h" #include "marshal.h" #include "demarshal.h" #include "property.h" #include "interface.h" #include "property.h" #include "parse.h" #include "errors.h" /** * property_name_valid: * @name: Member name to verify. * * Verifies whether @name matches the specification for a D-Bus interface * member name, and thus is valid for a property. * * Returns: TRUE if valid, FALSE if not. **/ int property_name_valid (const char *name) { nih_assert (name != NULL); /* We can get away with just using strlen() here even through name * is in UTF-8 because all the valid characters are ASCII. */ for (size_t i = 0; i < strlen (name); i++) { /* Names may contain digits, but not at the beginning. */ if ((name[i] >= '0') && (name[i] <= '9')) { if (i == 0) return FALSE; continue; } /* Valid characters anywhere are [A-Za-z_] */ if ( ((name[i] < 'A') || (name[i] > 'Z')) && ((name[i] < 'a') || (name[i] > 'z')) && (name[i] != '_')) return FALSE; } /* Name must be at least 1 character and no more than 255 characters */ if ((strlen (name) < 1) || (strlen (name) > 255)) return FALSE; return TRUE; } /** * property_new: * @parent: parent object for new property, * @name: D-Bus name of property, * @type: D-Bus type signature, * @access: access to property. * * Allocates a new D-Bus object Property data structure, with the D-Bus name * set to @name and the D-Bus type signature set to @type. The returned * structure is not placed into any list. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned property. When all parents * of the returned property are freed, the returned property will also be * freed. * * Returns: the new property or NULL if the allocation failed. **/ Property * property_new (const void * parent, const char * name, const char * type, NihDBusAccess access) { Property *property; nih_assert (name != NULL); property = nih_new (parent, Property); if (! property) return NULL; nih_list_init (&property->entry); nih_alloc_set_destructor (property, nih_list_destroy); property->name = nih_strdup (property, name); if (! property->name) { nih_free (property); return NULL; } property->symbol = NULL; property->type = nih_strdup (property, type); if (! property->type) { nih_free (property); return NULL; } property->access = access; property->deprecated = FALSE; return property; } /** * property_start_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed, * @attr: NULL-terminated array of attribute name and value pairs. * * This function is called by parse_start_tag() for a "property" * start tag, a child of the "interface" tag that defines a property the * D-Bus interface specifies. * * If the property does not appear within an interface tag a warning is * emitted and the tag will be ignored. * * Properties must have a "name" attribute containing the D-Bus name * of the interface, a "type" attribute containing the D-Bus type * signature and an "access" attribute specifying whether the property * is read-only, write-only or read/write. * * Any unknown attributes result in a warning and will be ignored; an * unknown value for the "access" attribute results in an error. * * A Property object will be allocated and pushed onto the stack, this is * not added to the interface until the end tag is found. * * Returns: zero on success, negative value on raised error. **/ int property_start_tag (XML_Parser xmlp, const char * tag, char * const *attr) { ParseContext * context; ParseStack * parent; nih_local Property *property = NULL; char * const * key; char * const * value; const char * name = NULL; const char * type = NULL; const char * access_str = NULL; NihDBusAccess access; DBusError error; nih_assert (xmlp != NULL); nih_assert (tag != NULL); nih_assert (attr != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); /* Properties should only appear inside interfaces. */ parent = parse_stack_top (&context->stack); if ((! parent) || (parent->type != PARSE_INTERFACE)) { nih_warn ("%s:%zu:%zu: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unexpected tag")); if (! parse_stack_push (NULL, &context->stack, PARSE_IGNORED, NULL)) nih_return_system_error (-1); return 0; } /* Retrieve the name, type and access from the attributes */ for (key = attr; key && *key; key += 2) { value = key + 1; nih_assert (value && *value); if (! strcmp (*key, "name")) { name = *value; } else if (! strcmp (*key, "type")) { type = *value; } else if (! strcmp (*key, "access")) { access_str = *value; } else { nih_warn ("%s:%zu:%zu: %s: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unknown attribute"), *key); } } /* Check we have a name, type and access and that they are valid */ if (! name) nih_return_error (-1, PROPERTY_MISSING_NAME, _(PROPERTY_MISSING_NAME_STR)); if (! property_name_valid (name)) nih_return_error (-1, PROPERTY_INVALID_NAME, _(PROPERTY_INVALID_NAME_STR)); if (! type) nih_return_error (-1, PROPERTY_MISSING_TYPE, _(PROPERTY_MISSING_TYPE_STR)); dbus_error_init (&error); if (! dbus_signature_validate_single (type, &error)) { nih_error_raise_printf (PROPERTY_INVALID_TYPE, "%s: %s", _(PROPERTY_INVALID_TYPE_STR), error.message); dbus_error_free (&error); return -1; } if (! access_str) nih_return_error (-1, PROPERTY_MISSING_ACCESS, _(PROPERTY_MISSING_ACCESS_STR)); if (! strcmp (access_str, "read")) { access = NIH_DBUS_READ; } else if (! strcmp (access_str, "write")) { access = NIH_DBUS_WRITE; } else if (! strcmp (access_str, "readwrite")) { access = NIH_DBUS_READWRITE; } else { nih_return_error (-1, PROPERTY_ILLEGAL_ACCESS, _(PROPERTY_ILLEGAL_ACCESS_STR)); } /* Allocate a Property object and push onto the stack */ property = property_new (NULL, name, type, access); if (! property) nih_return_system_error (-1); if (! parse_stack_push (NULL, &context->stack, PARSE_PROPERTY, property)) { nih_error_raise_system (); return -1; } return 0; } /** * property_end: * @xmlp: XML parser, * @tag: name of XML tag being parsed. * * This function is called by parse_end_tag() for a "property" end * tag, and matches a call to property_start_tag() made at the same * parsing level. * * The property is added to the list of properties defined by the parent * interface. * * Returns: zero on success, negative value on raised error. **/ int property_end_tag (XML_Parser xmlp, const char *tag) { ParseContext *context; ParseStack * entry; ParseStack * parent; Property * property; Property * conflict; Interface * interface; nih_assert (xmlp != NULL); nih_assert (tag != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); entry = parse_stack_top (&context->stack); nih_assert (entry != NULL); nih_assert (entry->type == PARSE_PROPERTY); property = entry->property; /* Generate a symbol from the name */ if (! property->symbol) { property->symbol = symbol_from_name (property, property->name); if (! property->symbol) nih_return_no_memory_error (-1); } nih_list_remove (&entry->entry); parent = parse_stack_top (&context->stack); nih_assert (parent != NULL); nih_assert (parent->type == PARSE_INTERFACE); interface = parent->interface; /* Make sure there's not a conflict before adding the property */ conflict = property_lookup (interface, property->symbol); if (conflict) { nih_error_raise_printf (PROPERTY_DUPLICATE_SYMBOL, _(PROPERTY_DUPLICATE_SYMBOL_STR), property->symbol, conflict->name); return -1; } nih_debug ("Add %s property to %s interface", property->name, interface->name); nih_list_add (&interface->properties, &property->entry); nih_ref (property, interface); nih_free (entry); return 0; } /** * property_annotation: * @property: property object annotation applies to, * @name: annotation name, * @value: annotation value. * * Handles applying the annotation @name with value @value to the property * @property. Properties may be annotated as deprecated or may have an * alternate symbol name specified. * * Unknown annotations or illegal values to the known annotations result * in an error being raised. * * Returns: zero on success, negative value on raised error. **/ int property_annotation (Property * property, const char *name, const char *value) { nih_assert (property != NULL); nih_assert (name != NULL); nih_assert (value != NULL); if (! strcmp (name, "org.freedesktop.DBus.Deprecated")) { if (! strcmp (value, "true")) { nih_debug ("Marked %s property as deprecated", property->name); property->deprecated = TRUE; } else if (! strcmp (value, "false")) { nih_debug ("Marked %s property as not deprecated", property->name); property->deprecated = FALSE; } else { nih_return_error (-1, PROPERTY_ILLEGAL_DEPRECATED, _(PROPERTY_ILLEGAL_DEPRECATED_STR)); } } else if (! strcmp (name, "com.netsplit.Nih.Symbol")) { if (symbol_valid (value)) { if (property->symbol) nih_unref (property->symbol, property); property->symbol = nih_strdup (property, value); if (! property->symbol) nih_return_no_memory_error (-1); nih_debug ("Set %s property symbol to %s", property->name, property->symbol); } else { nih_return_error (-1, PROPERTY_INVALID_SYMBOL, _(PROPERTY_INVALID_SYMBOL_STR)); } } else { nih_error_raise_printf (PROPERTY_UNKNOWN_ANNOTATION, "%s: %s: %s", _(PROPERTY_UNKNOWN_ANNOTATION_STR), property->name, name); return -1; } return 0; } /** * property_lookup: * @interface: interface to search, * @symbol: property symbol to find. * * Finds a property in @interface's properties list which has the generated * or supplied C symbol @symbol. * * Returns: property found or NULL if no property matches. **/ Property * property_lookup (Interface * interface, const char *symbol) { nih_assert (interface != NULL); nih_assert (symbol != NULL); NIH_LIST_FOREACH (&interface->properties, iter) { Property *property = (Property *)iter; if (property->symbol && (! strcmp (property->symbol, symbol))) return property; } return NULL; } /** * property_object_get_function: * @parent: parent object for new string, * @prefix: prefix for function name, * @interface: interface of @property, * @property: property to generate function for, * @prototypes: list to append function prototypes to, * @handlers: list to append definitions of required handlers to, * @structs: list to append structure definitions to. * * Generates C code for a function that will append a variant containing * the value of property @property on @interface to a D-Bus message iterator, * the value being obtained from a handler function. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * The prototype for the handler function is returned as a TypeFunc object * added to the @handlers list. * * The names of both the returned function and handled function prototype * will be generated using information in @interface and @property, prefixed * with @prefix. * * If the property type requires a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @property. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * property_object_get_function (const void *parent, const char *prefix, Interface * interface, Property * property, NihList * prototypes, NihList * handlers, NihList * structs) { DBusSignatureIter iter; NihList inputs; NihList locals; NihList property_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; nih_local TypeVar * iter_var = NULL; nih_local char * code_block = NULL; nih_local char * oom_error_code = NULL; nih_local char * block = NULL; nih_local char * handler_name = NULL; nih_local TypeFunc *handler_func = NULL; NihListEntry * attrib; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (property != NULL); nih_assert (prototypes != NULL); nih_assert (handlers != NULL); nih_assert (structs != NULL); dbus_signature_iter_init (&iter, property->type); nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&property_structs); /* The function returns an integer, and accepts an arguments for * the D-Bus object, message and a message iterator. */ name = symbol_impl (NULL, prefix, interface->name, property->name, "get"); if (! name) return NULL; func = type_func_new (NULL, "int", name); if (! func) return NULL; arg = type_var_new (func, "NihDBusObject *", "object"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "NihDBusMessage *", "message"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "DBusMessageIter *", "iter"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); /* The function requires a local iterator for the variant. Rather * than deal with it by hand, it's far easier to put it on the * locals list and deal with it along with the rest. */ iter_var = type_var_new (NULL, "DBusMessageIter", "variter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); /* In case of out of memory, simply return and let the caller * decide what to do. */ oom_error_code = nih_strdup (NULL, "dbus_message_iter_abandon_container (iter, &variter);\n" "nih_error_raise_no_memory ();\n" "return -1;\n"); if (! oom_error_code) return NULL; block = marshal (NULL, &iter, "variter", "value", oom_error_code, &inputs, &locals, prefix, interface->symbol, property->symbol, NULL, &property_structs); if (! block) return NULL; /* Begin the handler calling block */ handler_name = symbol_extern (NULL, prefix, interface->symbol, "get", property->symbol, NULL); if (! handler_name) return NULL; if (! nih_strcat_sprintf (&code_block, NULL, "/* Call the handler function */\n" "if (%s (object->data, message", handler_name)) return NULL; handler_func = type_func_new (NULL, "int", handler_name); if (! handler_func) return NULL; attrib = nih_list_entry_new (handler_func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "warn_unused_result"); if (! attrib->str) return NULL; nih_list_add (&handler_func->attribs, &attrib->entry); arg = type_var_new (handler_func, "void *", "data"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); arg = type_var_new (handler_func, "NihDBusMessage *", "message"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); /* Each of the inputs to the marshalling code becomes a local * variable to our function that we pass the address of to the * implementation function. */ NIH_LIST_FOREACH_SAFE (&inputs, iter) { TypeVar *var = (TypeVar *)iter; if (! nih_strcat_sprintf (&code_block, NULL, ", &%s", var->name)) return NULL; nih_list_add (&locals, &var->entry); /* Handler argument is pointer */ arg = type_var_new (handler_func, var->type, var->name); if (! arg) return NULL; if (! type_to_pointer (&arg->type, arg)) return NULL; nih_list_add (&handler_func->args, &arg->entry); } /* Finish up the calling block, in case of error we again just * return and let our caller deal with it. */ if (! nih_strcat_sprintf (&code_block, NULL, ") < 0)\n" "\treturn -1;\n" "\n")) return NULL; /* Surround the marshalling code by appending a variant onto the * passed-in message iterator, and closing it once complete. */ if (! nih_strcat_sprintf (&code_block, NULL, "/* Append a variant onto the message to contain the property value. */\n" "if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, \"%s\", &variter)) {\n" "\tnih_error_raise_no_memory ();\n" "\treturn -1;\n" "}\n" "\n" "%s" "\n" "/* Finish the variant */\n" "if (! dbus_message_iter_close_container (iter, &variter)) {\n" "\tnih_error_raise_no_memory ();\n" "\treturn -1;\n" "}\n", property->type, block)) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "nih_assert (object != NULL);\n" "nih_assert (message != NULL);\n" "nih_assert (iter != NULL);\n" "\n" "%s" "\n" "return 0;\n", vars_block, code_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the functions to the prototypes and handlers lists */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); nih_list_add (handlers, &handler_func->entry); nih_ref (handler_func, code); NIH_LIST_FOREACH_SAFE (&property_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } return code; } /** * property_object_set_function: * @parent: parent object for new string, * @prefix: prefix for function name, * @interface: interface of @property, * @property: property to generate function for, * @prototypes: list to append function prototypes to, * @handlers: list to append definitions of required handlers to, * @structs: list to append structure definitions to. * * Generates C code for a function that will extract the new value of * property @property on @interface from a variant at the D-Bus message * iterator passed. The new value of the property is then passed to * a handler function. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * The prototype for the handler function is returned as a TypeFunc object * added to the @handlers list. * * The names of both the returned function and handled function prototype * will be generated using information in @interface and @property, prefixed * with @prefix. * * If the property type requires a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @property. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * property_object_set_function (const void *parent, const char *prefix, Interface * interface, Property * property, NihList * prototypes, NihList * handlers, NihList * structs) { DBusSignatureIter iter; NihList outputs; NihList locals; NihList property_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * reply_var = NULL; nih_local char * demarshal_block = NULL; nih_local char * oom_error_code = NULL; nih_local char * type_error_code = NULL; nih_local char * block = NULL; nih_local char * call_block = NULL; nih_local char * handler_name = NULL; nih_local TypeFunc *handler_func = NULL; NihListEntry * attrib; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (property != NULL); nih_assert (prototypes != NULL); nih_assert (handlers != NULL); nih_assert (structs != NULL); dbus_signature_iter_init (&iter, property->type); nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&property_structs); /* The function returns an integer, which means success when zero * or a raised error when non-zero and accepts arguments for the * D-Bus object, message and a message iterator. */ name = symbol_impl (NULL, prefix, interface->name, property->name, "set"); if (! name) return NULL; func = type_func_new (NULL, "int", name); if (! func) return NULL; arg = type_var_new (func, "NihDBusObject *", "object"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "NihDBusMessage *", "message"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "DBusMessageIter *", "iter"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); /* The function requires a local iterator for the variant. Rather * than deal with this by hand, it's far easier to put it on the * locals list and deal with them along with the rest. */ iter_var = type_var_new (NULL, "DBusMessageIter", "variter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); /* Make sure that the iterator points to a variant, then open the * variant. */ if (! nih_strcat_sprintf (&demarshal_block, NULL, "/* Recurse into the variant */\n" "if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) {\n" "\tnih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,\n" "\t \"Invalid arguments to %s property\");\n" "\treturn -1;\n" "}\n" "\n" "dbus_message_iter_recurse (iter, &variter);\n" "\n", property->name)) return NULL; /* In case of out of memory, or type error, return a raised error * to the caller. */ oom_error_code = nih_strdup (NULL, "nih_error_raise_no_memory ();\n" "return -1;\n"); if (! oom_error_code) return NULL; type_error_code = nih_sprintf (NULL, "nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,\n" " \"Invalid arguments to %s property\");\n" "return -1;\n", property->name); if (! type_error_code) return NULL; block = demarshal (NULL, &iter, "message", "variter", "value", oom_error_code, type_error_code, &outputs, &locals, prefix, interface->symbol, property->symbol, NULL, &property_structs); if (! block) return NULL; /* Complete the demarshalling block, checking for any unexpected * arguments which we also want to error on and begin the handler * calling block. */ handler_name = symbol_extern (NULL, prefix, interface->symbol, "set", property->symbol, NULL); if (! handler_name) return NULL; if (! nih_strcat_sprintf (&call_block, NULL, "dbus_message_iter_next (iter);\n" "\n" "if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) {\n" "\tnih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,\n" "\t \"Invalid arguments to %s property\");\n" "\treturn -1;\n" "}\n" "\n" "/* Call the handler function */\n" "if (%s (object->data, message", property->name, handler_name)) return NULL; handler_func = type_func_new (NULL, "int", handler_name); if (! handler_func) return NULL; attrib = nih_list_entry_new (handler_func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "warn_unused_result"); if (! attrib->str) return NULL; nih_list_add (&handler_func->attribs, &attrib->entry); arg = type_var_new (handler_func, "void *", "data"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); arg = type_var_new (handler_func, "NihDBusMessage *", "message"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); /* Each of the outputs from the demarshalling code becomes a local * variable to our function that we pass to the implementation * function. */ NIH_LIST_FOREACH_SAFE (&outputs, iter) { TypeVar *var = (TypeVar *)iter; if (! nih_strcat_sprintf (&call_block, NULL, ", %s", var->name)) return NULL; nih_list_add (&locals, &var->entry); /* Handler argument is const */ arg = type_var_new (handler_func, var->type, var->name); if (! arg) return NULL; if (! type_to_const (&arg->type, arg)) return NULL; nih_list_add (&handler_func->args, &arg->entry); } /* Finish up the calling block, in case of out of memory error we * return and let D-Bus deal with it, other errors generate an * error reply. */ if (! nih_strcat_sprintf (&call_block, NULL, ") < 0)\n" "\treturn -1;\n")) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "nih_assert (object != NULL);\n" "nih_assert (message != NULL);\n" "nih_assert (iter != NULL);\n" "\n" "%s" "%s" "\n" "%s" "\n" "return 0;\n", vars_block, demarshal_block, block, call_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the functions to the prototypes and handlers lists */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); nih_list_add (handlers, &handler_func->entry); nih_ref (handler_func, code); NIH_LIST_FOREACH_SAFE (&property_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } return code; } /** * property_proxy_get_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface of @property, * @property: property to generate function for, * @prototypes: list to append function prototypes to, * @structs: list to append structure definitions to. * * Generates C code for a function that will make an asynchronous method * call to obtain the value of the property @property on @interface, * calling a notify function when the method call completes. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * The names of both the returned function and notify function prototype * will be generated using information in @interface and @property, prefixed * with @prefix. * * The notify function will call a handler function passed in if the * reply is valid. The name and type for this can be obtained from * property_proxy_get_notify_function(). * * If the property type requires a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @property. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * property_proxy_get_function (const void *parent, const char *prefix, Interface * interface, Property * property, NihList * prototypes, NihList * structs) { NihList locals; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; NihListEntry * attrib; nih_local char * assert_block = NULL; nih_local char * handler_type = NULL; nih_local TypeVar * message_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * pending_var = NULL; nih_local TypeVar * data_var = NULL; nih_local TypeVar * interface_var = NULL; nih_local TypeVar * property_var = NULL; nih_local char * call_block = NULL; nih_local char * notify_name = NULL; nih_local char * block = NULL; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (property != NULL); nih_assert (prototypes != NULL); nih_assert (structs != NULL); nih_list_init (&locals); /* The function returns a pending call, and takes the proxy object * as the only argument. The pending call also indicates whether * an error occurred, so we want warning if the result isn't used. * We don't have a malloc attribute, since we can't guarantee that * D-Bus doesn't cache them. Since this is used by the client, we * also add a deprecated attribute if the property is deprecated. */ name = symbol_extern (NULL, prefix, interface->symbol, "get", property->symbol, NULL); if (! name) return NULL; func = type_func_new (NULL, "DBusPendingCall *", name); if (! func) return NULL; attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "warn_unused_result"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); if (property->deprecated) { attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "deprecated"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); } arg = type_var_new (func, "NihDBusProxy *", "proxy"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (proxy != NULL);\n")) return NULL; /* We also require a handler (which receives the property value), * error handler (in case of error) and data arguments to pass to * both as well as a timeout for the method call. Unlike the * method call case, we don't allow for no-reply calls since * they're nonsensical. */ handler_type = symbol_typedef (NULL, prefix, interface->symbol, "Get", property->symbol, "Reply"); if (! handler_type) return NULL; arg = type_var_new (func, handler_type, "handler"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "NihDBusErrorHandler", "error_handler"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "void *", "data"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert ((handler != NULL) && (error_handler != NULL));\n")) return NULL; arg = type_var_new (func, "int", "timeout"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); /* The function requires a message pointer, which we allocate, * and an iterator for it to append the arguments. We also need * a return pending call pointer and data structure as well. * Rather than deal with these by hand, it's far easier to put them * on the locals list and deal with them along with the rest. */ message_var = type_var_new (NULL, "DBusMessage *", "method_call"); if (! message_var) return NULL; nih_list_add (&locals, &message_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); pending_var = type_var_new (NULL, "DBusPendingCall *", "pending_call"); if (! pending_var) return NULL; nih_list_add (&locals, &pending_var->entry); data_var = type_var_new (NULL, "NihDBusPendingData *", "pending_data"); if (! data_var) return NULL; nih_list_add (&locals, &data_var->entry); /* Annoyingly we also need variables for the interface and * property names, since D-Bus wants their address and can't just * take a constant string. */ interface_var = type_var_new (NULL, "const char *", "interface"); if (! interface_var) return NULL; nih_list_add (&locals, &interface_var->entry); property_var = type_var_new (NULL, "const char *", "property"); if (! property_var) return NULL; nih_list_add (&locals, &property_var->entry); /* Create the method call to get the property, the property * interface gets specified as an argument - the method call * interface is the D-Bus properties one. */ if (! nih_strcat_sprintf (&call_block, NULL, "/* Construct the method call message. */\n" "method_call = dbus_message_new_method_call (proxy->name, proxy->path, \"%s\", \"Get\");\n" "if (! method_call)\n" "\tnih_return_no_memory_error (NULL);\n" "\n" "dbus_message_set_auto_start (method_call, proxy->auto_start);\n" "\n" "dbus_message_iter_init_append (method_call, &iter);\n" "\n" "interface = \"%s\";\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n" "property = \"%s\";\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n", DBUS_INTERFACE_PROPERTIES, interface->name, property->name)) return NULL; /* FIXME autostart? */ /* Complete the marshalling block by sending the message and checking * for error replies. */ notify_name = symbol_impl (NULL, prefix, interface->name, property->name, "get_notify"); if (! notify_name) return NULL; if (! nih_strcat_sprintf (&call_block, NULL, "/* Send the message and set up the reply notification. */\n" "pending_data = nih_dbus_pending_data_new (NULL, proxy->connection,\n" " (NihDBusReplyHandler)handler,\n" " error_handler, data);\n" "if (! pending_data) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n" "pending_call = NULL;\n" "if (! dbus_connection_send_with_reply (proxy->connection, method_call,\n" " &pending_call, timeout)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_free (pending_data);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n" "dbus_message_unref (method_call);\n" "\n" "if (! pending_call) {\n" "\tnih_dbus_error_raise (DBUS_ERROR_DISCONNECTED,\n" "\t \"Connection is closed\");\n" "\tnih_free (pending_data);\n" "\treturn NULL;\n" "}\n" "\n" "NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)%s,\n" " pending_data, (DBusFreeFunction)nih_discard));\n", notify_name)) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "\n" "return pending_call;\n", vars_block, assert_block, call_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the function to the prototypes list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); return code; } /** * property_proxy_get_notify_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface of @property, * @property: property to generate function for, * @prototypes: list to append function prototypes to, * @typedefs: list to append function pointer typedef definitions to, * @structs: list to append structure definitions to. * * Generates C code for a function to handle the notification of * a complete pending call to obtain the value of the property @property * on @interface by calling either the handler function on success or * error function on failure. * * The notify function will call a handler function passed in if the * reply is valid, the typedef name for this handler must be passed as * @handler_type. The actual type for this can be obtained from the * entry added to @typedefs. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * The typedef for the handler function is returned as a TypeFunc object * added to the @typedefs list. * * If the property type requires a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @property. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * property_proxy_get_notify_function (const void *parent, const char *prefix, Interface * interface, Property * property, NihList * prototypes, NihList * typedefs, NihList * structs) { DBusSignatureIter iter; NihList outputs; NihList locals; NihList property_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; nih_local char * assert_block = NULL; nih_local TypeVar * reply_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * variter_var = NULL; nih_local TypeVar * error_var = NULL; nih_local TypeVar * parent_var = NULL; nih_local char * steal_block = NULL; nih_local char * demarshal_block = NULL; nih_local char * call_block = NULL; nih_local char * handler_type = NULL; nih_local char * handler_name = NULL; nih_local TypeFunc *handler_func = NULL; nih_local char * oom_error_code = NULL; nih_local char * type_error_code = NULL; nih_local char * block = NULL; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (property != NULL); nih_assert (prototypes != NULL); nih_assert (typedefs != NULL); nih_assert (structs != NULL); dbus_signature_iter_init (&iter, property->type); nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&property_structs); /* The function takes the pending call being notified and the * associated data structure. We don't mark the function deprecated * since it's used internally, it's enough to mark the method * call function deprecated. */ name = symbol_impl (NULL, prefix, interface->name, property->name, "get_notify"); if (! name) return NULL; func = type_func_new (NULL, "void", name); if (! func) return NULL; arg = type_var_new (func, "DBusPendingCall *", "pending_call"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (pending_call != NULL);\n")) return NULL; arg = type_var_new (func, "NihDBusPendingData *", "pending_data"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (pending_data != NULL);\n")) return NULL; /* The function requires a message pointer, stolen from the * pending call and iterators for the message and variant. We * also need a parent message context for any allocations we make, * as well as an error object. */ reply_var = type_var_new (NULL, "DBusMessage *", "reply"); if (! reply_var) return NULL; nih_list_add (&locals, &reply_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); variter_var = type_var_new (NULL, "DBusMessageIter", "variter"); if (! variter_var) return NULL; nih_list_add (&locals, &variter_var->entry); parent_var = type_var_new (NULL, "NihDBusMessage *", "message"); if (! parent_var) return NULL; nih_list_add (&locals, &parent_var->entry); error_var = type_var_new (NULL, "DBusError", "error"); if (! error_var) return NULL; nih_list_add (&locals, &error_var->entry); /* Assert that the pending call is, in fact, complete then * steal the message from it; handling it immediately if it's an * error. */ if (! nih_strcat (&steal_block, NULL, "nih_assert (dbus_pending_call_get_completed (pending_call));\n" "\n" "/* Steal the reply from the pending call. */\n" "reply = dbus_pending_call_steal_reply (pending_call);\n" "nih_assert (reply != NULL);\n" "\n" "/* Handle error replies */\n" "if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {\n" "\tmessage = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply));\n" "\n" "\tdbus_error_init (&error);\n" "\tdbus_set_error_from_message (&error, message->message);\n" "\n" "\tnih_error_push_context ();\n" "\tnih_dbus_error_raise (error.name, error.message);\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tdbus_error_free (&error);\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n" "nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN);\n" "\n")) return NULL; /* To deal with out-of-memory situations, we have to loop until we've * extracted all of the arguments, so this now happens in a different * code block. Create a message context and initialise the iterator, * recursing into the variant. */ if (! nih_strcat (&demarshal_block, NULL, "/* Create a message context for the reply, and iterate\n" " * over and recurse into the arguments.\n" " */\n" "message = nih_dbus_message_new (pending_data, pending_data->connection, reply);\n" "if (! message)\n" "\tgoto enomem;\n" "\n" "dbus_message_iter_init (message->message, &iter);\n" "\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) {\n" "\tnih_error_push_context ();\n" "\tnih_error_raise (NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n" "dbus_message_iter_recurse (&iter, &variter);\n" "\n")) return NULL; /* Begin the handler calling block, the handler is not permitted * to reply. */ handler_type = symbol_typedef (NULL, prefix, interface->symbol, "Get", property->symbol, "Reply"); if (! handler_type) return NULL; if (! nih_strcat_sprintf (&call_block, NULL, "/* Call the handler function */\n" "nih_error_push_context ();\n" "((%s)pending_data->handler) (pending_data->data, message", handler_type)) return NULL; handler_name = nih_sprintf (NULL, "(*%s)", handler_type); if (! handler_name) return NULL; handler_func = type_func_new (NULL, "typedef void", handler_name); if (! handler_func) return NULL; arg = type_var_new (handler_func, "void *", "data"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); arg = type_var_new (handler_func, "NihDBusMessage *", "message"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); /* In case of out of memory, we can't just return because we've * already made the method call so we loop over the code instead. * But in case of type error in the returned arguments, all we * can do is return an error. */ oom_error_code = nih_sprintf (NULL, "nih_free (message);\n" "message = NULL;\n" "goto enomem;\n"); if (! oom_error_code) return NULL; type_error_code = nih_strdup (NULL, "nih_error_push_context ();\n" "nih_error_raise (NIH_DBUS_INVALID_ARGS,\n" " _(NIH_DBUS_INVALID_ARGS_STR));\n" "pending_data->error_handler (pending_data->data, message);\n" "nih_error_pop_context ();\n" "\n" "nih_free (message);\n" "dbus_message_unref (reply);\n" "return;\n"); if (! type_error_code) return NULL; block = demarshal (NULL, &iter, "message", "variter", "value", oom_error_code, type_error_code, &outputs, &locals, prefix, interface->symbol, property->symbol, NULL, &property_structs); if (! block) return NULL; if (! nih_strcat_sprintf (&demarshal_block, NULL, "%s" "\n", block)) return NULL; /* Each of the outputs from the demarshalling code becomes a local * variable to our function that we store the value in, and passed * to the handler function. */ NIH_LIST_FOREACH_SAFE (&outputs, iter) { TypeVar *var = (TypeVar *)iter; TypeVar *arg; if (! nih_strcat_sprintf (&call_block, NULL, ", %s", var->name)) return NULL; nih_list_add (&locals, &var->entry); nih_ref (var, demarshal_block); /* Handler arg is const */ arg = type_var_new (handler_func, var->type, var->name); if (! arg) return NULL; if (! type_to_const (&arg->type, arg)) return NULL; nih_list_add (&handler_func->args, &arg->entry); } /* Complete the demarshalling block, checking for any unexpected * reply arguments which we also want to error on. */ if (! nih_strcat_sprintf (&demarshal_block, NULL, "dbus_message_iter_next (&iter);\n" "\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {\n" "\tnih_error_push_context ();\n" "\tnih_error_raise (NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n")) return NULL; /* Complete the call block. */ if (! nih_strcat (&call_block, NULL, ");\n" "nih_error_pop_context ();\n" "\n" "nih_free (message);\n" "dbus_message_unref (reply);\n")) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! indent (&demarshal_block, NULL, 1)) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "do {\n" "\t__label__ enomem;\n" "\n" "%s" "enomem: __attribute__ ((unused));\n" "} while (! message);\n" "\n" "%s", vars_block, assert_block, steal_block, demarshal_block, call_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the functions to the prototypes and typedefs list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); nih_list_add (typedefs, &handler_func->entry); nih_ref (handler_func, code); NIH_LIST_FOREACH_SAFE (&property_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } return code; } /** * property_proxy_set_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface of @property, * @property: property to generate function for, * @prototypes: list to append function prototypes to, * @structs: list to append structure definitions to. * * Generates C code for a function that will make an asynchronous method * call to set the value of the property @property on @interface, * calling a notify function when the method call completes. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * The names of both the returned function and notify function prototype * will be generated using information in @interface and @property, prefixed * with @prefix. * * The notify function will call a handler function passed in if the * reply is valid. The name and type for this can be obtained from * property_proxy_set_notify_function(). * * If the property type requires a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @property. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * property_proxy_set_function (const void *parent, const char *prefix, Interface * interface, Property * property, NihList * prototypes, NihList * structs) { DBusSignatureIter iter; NihList inputs; NihList locals; NihList property_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; NihListEntry * attrib; nih_local char * assert_block = NULL; nih_local char * handler_type = NULL; nih_local TypeVar * message_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * variter_var = NULL; nih_local TypeVar * pending_var = NULL; nih_local TypeVar * data_var = NULL; nih_local TypeVar * interface_var = NULL; nih_local TypeVar * property_var = NULL; nih_local char * marshal_block = NULL; nih_local char * call_block = NULL; nih_local char * notify_name = NULL; nih_local char * block = NULL; nih_local char * vars_block = NULL; nih_local char * oom_error_code = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (property != NULL); nih_assert (prototypes != NULL); nih_assert (structs != NULL); dbus_signature_iter_init (&iter, property->type); nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&property_structs); /* The function returns a pending call, and takes the proxy object * as argument along with the new property value. The pending call * also indicates whether an error occurred, so we want warning if * the result isn't used. We don't have a malloc attribute, since * we can't guarantee that D-Bus doesn't cache them. Since this is * used by the client, we also add a deprecated attribute if the * property is deprecated. */ name = symbol_extern (NULL, prefix, interface->symbol, "set", property->symbol, NULL); if (! name) return NULL; func = type_func_new (NULL, "DBusPendingCall *", name); if (! func) return NULL; attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "warn_unused_result"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); if (property->deprecated) { attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "deprecated"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); } arg = type_var_new (func, "NihDBusProxy *", "proxy"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (proxy != NULL);\n")) return NULL; /* The function requires a message pointer, which we allocate, * and an iterator for it to append the arguments, as well as an * iterator for the variant. We also need a return pending call * pointer and data structure as well. */ message_var = type_var_new (NULL, "DBusMessage *", "method_call"); if (! message_var) return NULL; nih_list_add (&locals, &message_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); variter_var = type_var_new (NULL, "DBusMessageIter", "variter"); if (! variter_var) return NULL; nih_list_add (&locals, &variter_var->entry); pending_var = type_var_new (NULL, "DBusPendingCall *", "pending_call"); if (! pending_var) return NULL; nih_list_add (&locals, &pending_var->entry); data_var = type_var_new (NULL, "NihDBusPendingData *", "pending_data"); if (! data_var) return NULL; nih_list_add (&locals, &data_var->entry); /* Annoyingly we also need variables for the interface and * property names, since D-Bus wants their address and can't just * take a constant string. */ interface_var = type_var_new (NULL, "const char *", "interface"); if (! interface_var) return NULL; nih_list_add (&locals, &interface_var->entry); property_var = type_var_new (NULL, "const char *", "property"); if (! property_var) return NULL; nih_list_add (&locals, &property_var->entry); /* Create the method call to get the property, the property * interface gets specified as an argument - the method call * interface is the D-Bus properties one. */ if (! nih_strcat_sprintf (&marshal_block, NULL, "/* Construct the method call message. */\n" "method_call = dbus_message_new_method_call (proxy->name, proxy->path, \"%s\", \"Set\");\n" "if (! method_call)\n" "\tnih_return_no_memory_error (NULL);\n" "\n" "dbus_message_set_auto_start (method_call, proxy->auto_start);\n" "\n" "dbus_message_iter_init_append (method_call, &iter);\n" "\n" "interface = \"%s\";\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n" "property = \"%s\";\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n" "if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, \"%s\", &variter)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n", DBUS_INTERFACE_PROPERTIES, interface->name, property->name, property->type)) return NULL; /* FIXME autostart? */ /* In case of out of memory, we just return the error to the caller * since we haven't made the method call yet. */ oom_error_code = nih_sprintf (NULL, "dbus_message_iter_abandon_container (&iter, &variter);\n" "dbus_message_unref (method_call);\n" "nih_return_no_memory_error (NULL);\n"); if (! oom_error_code) return NULL; block = marshal (NULL, &iter, "variter", "value", oom_error_code, &inputs, &locals, prefix, interface->symbol, property->symbol, NULL, &property_structs); if (! block) return NULL; if (! nih_strcat_sprintf (&marshal_block, NULL, "%s" "\n", block)) return NULL; /* Each of the inputs of the marshalling code becomes a const * argument to our function that we obtain the value from. */ NIH_LIST_FOREACH_SAFE (&inputs, iter) { TypeVar *var = (TypeVar *)iter; if (! type_to_const (&var->type, var)) return NULL; if (! type_strcat_assert (&assert_block, NULL, var, func->args.prev != &func->args ? (TypeVar *)func->args.prev : NULL, _iter.next != &inputs ? (TypeVar *)_iter.next : NULL)) return NULL; nih_list_add (&func->args, &var->entry); nih_ref (var, func); } /* Complete the marshalling block by closing the container. */ if (! nih_strcat_sprintf (&marshal_block, NULL, "if (! dbus_message_iter_close_container (&iter, &variter)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n")) return NULL; /* We also have an argument for an optional handler that notifies * of a successful property set and an error handler which notifies * of an error. The error handler is optional only if the handler * itself is NULL. A data argument is passed to both, and we also * have the timeout for the method call. */ handler_type = symbol_typedef (NULL, prefix, interface->symbol, "Set", property->symbol, "Reply"); if (! handler_type) return NULL; arg = type_var_new (func, handler_type, "handler"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "NihDBusErrorHandler", "error_handler"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "void *", "data"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert ((handler == NULL) || (error_handler != NULL));\n")) return NULL; arg = type_var_new (func, "int", "timeout"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); /* Send the message and check for error replies, or arguments * in the reply (which is an error). */ notify_name = symbol_impl (NULL, prefix, interface->name, property->name, "set_notify"); if (! notify_name) return NULL; if (! nih_strcat_sprintf (&call_block, NULL, "/* Handle a fire-and-forget message */\n" "if (! error_handler) {\n" "\tdbus_message_set_no_reply (method_call, TRUE);\n" "\tif (! dbus_connection_send (proxy->connection, method_call, NULL)) {\n" "\t\tdbus_message_unref (method_call);\n" "\t\tnih_return_no_memory_error (NULL);\n" "\t}\n" "\n" "\tdbus_message_unref (method_call);\n" "\treturn (DBusPendingCall *)TRUE;\n" "}\n" "\n" "/* Send the message and set up the reply notification. */\n" "pending_data = nih_dbus_pending_data_new (NULL, proxy->connection,\n" " (NihDBusReplyHandler)handler,\n" " error_handler, data);\n" "if (! pending_data) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n" "pending_call = NULL;\n" "if (! dbus_connection_send_with_reply (proxy->connection, method_call,\n" " &pending_call, timeout)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_free (pending_data);\n" "\tnih_return_no_memory_error (NULL);\n" "}\n" "\n" "dbus_message_unref (method_call);\n" "\n" "if (! pending_call) {\n" "\tnih_dbus_error_raise (DBUS_ERROR_DISCONNECTED,\n" "\t \"Connection is closed\");\n" "\tnih_free (pending_data);\n" "\treturn NULL;\n" "}\n" "\n" "NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)%s,\n" " pending_data, (DBusFreeFunction)nih_discard));\n", notify_name)) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "%s" "\n" "return pending_call;\n", vars_block, assert_block, marshal_block, call_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the function to the prototypes list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); NIH_LIST_FOREACH_SAFE (&property_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } return code; } /** * property_proxy_set_notify_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface of @property, * @property: property to generate function for, * @prototypes: list to append function prototypes to, * @typedefs: list to append function pointer typedef definitions to, * @structs: list to append structure definitions to. * * Generates C code for a function to handle the notification of * a complete pending call to set the value of the property @property * on @interface by calling either the handler function on success or * error function on failure. * * The notify function will call a handler function passed in if the * reply is valid, the typedef name for this handler must be passed as * @handler_type. The actual type for this can be obtained from the * entry added to @typedefs. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * The typedef for the handler function is returned as a TypeFunc object * added to the @typedefs list. * * If the property type requires a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @property. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * property_proxy_set_notify_function (const void *parent, const char *prefix, Interface * interface, Property * property, NihList * prototypes, NihList * typedefs, NihList * structs) { DBusSignatureIter iter; NihList outputs; NihList locals; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; nih_local char * assert_block = NULL; nih_local TypeVar * reply_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * error_var = NULL; nih_local TypeVar * parent_var = NULL; nih_local char * steal_block = NULL; nih_local char * call_block = NULL; nih_local char * handler_type = NULL; nih_local char * handler_name = NULL; nih_local TypeFunc *handler_func = NULL; nih_local char * oom_error_code = NULL; nih_local char * type_error_code = NULL; nih_local char * block = NULL; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (property != NULL); nih_assert (prototypes != NULL); nih_assert (typedefs != NULL); nih_assert (structs != NULL); dbus_signature_iter_init (&iter, property->type); nih_list_init (&outputs); nih_list_init (&locals); /* The function takes the pending call being notified and the * associated data structure. We don't mark the function deprecated * since it's used internally, it's enough to mark the method * call function deprecated. */ name = symbol_impl (NULL, prefix, interface->name, property->name, "set_notify"); if (! name) return NULL; func = type_func_new (NULL, "void", name); if (! func) return NULL; arg = type_var_new (func, "DBusPendingCall *", "pending_call"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (pending_call != NULL);\n")) return NULL; arg = type_var_new (func, "NihDBusPendingData *", "pending_data"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (pending_data != NULL);\n")) return NULL; /* The function requires a message pointer, stolen from the * pending call and an iterator for the message. We also need * a parent message context for any allocations we make, as well * as an error object. */ reply_var = type_var_new (NULL, "DBusMessage *", "reply"); if (! reply_var) return NULL; nih_list_add (&locals, &reply_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); parent_var = type_var_new (NULL, "NihDBusMessage *", "message"); if (! parent_var) return NULL; nih_list_add (&locals, &parent_var->entry); error_var = type_var_new (NULL, "DBusError", "error"); if (! error_var) return NULL; nih_list_add (&locals, &error_var->entry); /* Assert that the pending call is, in fact, complete then * steal the message from it; handling it immediately if it's an * error. */ if (! nih_strcat (&steal_block, NULL, "nih_assert (dbus_pending_call_get_completed (pending_call));\n" "\n" "/* Steal the reply from the pending call. */\n" "reply = dbus_pending_call_steal_reply (pending_call);\n" "nih_assert (reply != NULL);\n" "\n" "/* Handle error replies */\n" "if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {\n" "\tmessage = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply));\n" "\n" "\tdbus_error_init (&error);\n" "\tdbus_set_error_from_message (&error, message->message);\n" "\n" "\tnih_error_push_context ();\n" "\tnih_dbus_error_raise (error.name, error.message);\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tdbus_error_free (&error);\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n" "nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN);\n" "\n")) return NULL; /* Create a message context, and check that the reply had no * arguments before calling the handler. */ handler_type = symbol_typedef (NULL, prefix, interface->symbol, "Set", property->symbol, "Reply"); if (! handler_type) return NULL; if (! nih_strcat_sprintf (&call_block, NULL, "/* Create a message context for the reply, and check\n" " * there are no arguments.\n" " */\n" "message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply));\n" "dbus_message_iter_init (message->message, &iter);\n" "\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {\n" "\tnih_error_push_context ();\n" "\tnih_error_raise (NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "\tpending_data->error_handler (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "\n" "\tnih_free (message);\n" "\tdbus_message_unref (reply);\n" "\treturn;\n" "}\n" "\n" "/* Call the handler function */\n" "if (pending_data->handler) {\n" "\tnih_error_push_context ();\n" "\t((%s)pending_data->handler) (pending_data->data, message);\n" "\tnih_error_pop_context ();\n" "}\n" "\n" "nih_free (message);\n" "dbus_message_unref (reply);\n", handler_type)) return NULL; handler_name = nih_sprintf (NULL, "(*%s)", handler_type); if (! handler_name) return NULL; handler_func = type_func_new (NULL, "typedef void", handler_name); if (! handler_func) return NULL; arg = type_var_new (handler_func, "void *", "data"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); arg = type_var_new (handler_func, "NihDBusMessage *", "message"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "%s", vars_block, assert_block, steal_block, call_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the functions to the prototypes and typedefs list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); nih_list_add (typedefs, &handler_func->entry); nih_ref (handler_func, code); return code; } /** * property_proxy_get_sync_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface of @property, * @property: property to generate function for, * @prototypes: list to append function prototypes to, * @structs: list to append structure definitions to. * * Generates C code for a function that will make a synchronous method * call to obtain the value of the property @property on @interface. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list, with the name as @name itself. * * If the property type requires a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @property. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * property_proxy_get_sync_function (const void *parent, const char *prefix, Interface * interface, Property * property, NihList * prototypes, NihList * structs) { DBusSignatureIter iter; NihList outputs; NihList locals; NihList property_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; NihListEntry * attrib; nih_local char * assert_block = NULL; nih_local TypeVar * message_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * variter_var = NULL; nih_local TypeVar * error_var = NULL; nih_local TypeVar * reply_var = NULL; nih_local TypeVar * interface_var = NULL; nih_local TypeVar * property_var = NULL; nih_local char * call_block = NULL; nih_local char * demarshal_block = NULL; nih_local char * oom_error_code = NULL; nih_local char * type_error_code = NULL; nih_local char * block = NULL; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (property != NULL); nih_assert (prototypes != NULL); nih_assert (structs != NULL); dbus_signature_iter_init (&iter, property->type); nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&property_structs); /* The function returns an integer, and takes a parent object and * the proxy object as the argument along with an output argument * for the property value. The integer is negative if a raised * error occurred, so we want warning if the result isn't used. * Since this is used by the client, we also add a deprecated * attribute if the property is deprecated. */ name = symbol_extern (NULL, prefix, interface->symbol, "get", property->symbol, "sync"); if (! name) return NULL; func = type_func_new (NULL, "int", name); if (! func) return NULL; attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "warn_unused_result"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); if (property->deprecated) { attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "deprecated"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); } arg = type_var_new (func, "const void *", "parent"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "NihDBusProxy *", "proxy"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (proxy != NULL);\n")) return NULL; /* The function requires a message pointer, which we allocate, * and an iterator for it to append the arguments. We also need * a reply message pointer as well and an error object. * Rather than deal with these by hand, it's far easier to put them * on the locals list and deal with them along with the rest. */ message_var = type_var_new (NULL, "DBusMessage *", "method_call"); if (! message_var) return NULL; nih_list_add (&locals, &message_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); variter_var = type_var_new (NULL, "DBusMessageIter", "variter"); if (! variter_var) return NULL; nih_list_add (&locals, &variter_var->entry); error_var = type_var_new (NULL, "DBusError", "error"); if (! error_var) return NULL; nih_list_add (&locals, &error_var->entry); reply_var = type_var_new (NULL, "DBusMessage *", "reply"); if (! reply_var) return NULL; nih_list_add (&locals, &reply_var->entry); /* Annoyingly we also need variables for the interface and * property names, since D-Bus wants their address and can't just * take a constant string. */ interface_var = type_var_new (NULL, "const char *", "interface"); if (! interface_var) return NULL; nih_list_add (&locals, &interface_var->entry); property_var = type_var_new (NULL, "const char *", "property"); if (! property_var) return NULL; nih_list_add (&locals, &property_var->entry); /* Create the method call to get the property, the property * interface gets specified as an argument - the method call * interface is the D-Bus properties one. */ if (! nih_strcat_sprintf (&call_block, NULL, "/* Construct the method call message. */\n" "method_call = dbus_message_new_method_call (proxy->name, proxy->path, \"%s\", \"Get\");\n" "if (! method_call)\n" "\tnih_return_no_memory_error (-1);\n" "\n" "dbus_message_set_auto_start (method_call, proxy->auto_start);\n" "\n" "dbus_message_iter_init_append (method_call, &iter);\n" "\n" "interface = \"%s\";\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (-1);\n" "}\n" "\n" "property = \"%s\";\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (-1);\n" "}\n" "\n", DBUS_INTERFACE_PROPERTIES, interface->name, property->name)) return NULL; /* FIXME autostart? */ /* Complete the marshalling block by sending the message and checking * for error replies. */ if (! nih_strcat_sprintf (&call_block, NULL, "/* Send the message, and wait for the reply. */\n" "dbus_error_init (&error);\n" "\n" "reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error);\n" "if (! reply) {\n" "\tdbus_message_unref (method_call);\n" "\n" "\tif (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) {\n" "\t\tnih_error_raise_no_memory ();\n" "\t} else {\n" "\t\tnih_dbus_error_raise (error.name, error.message);\n" "\t}\n" "\n" "\tdbus_error_free (&error);\n" "\treturn -1;\n" "}\n" "\n")) return NULL; /* Begin the demarshalling block, making sure the first argument * is a variant and recursing into it and also making sure that * there are no subsequent arguments before we allocate the * return value. */ if (! nih_strcat_sprintf (&demarshal_block, NULL, "dbus_message_unref (method_call);\n" "\n" "/* Iterate the method arguments, recursing into the variant */\n" "dbus_message_iter_init (reply, &iter);\n" "\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) {\n" "\tdbus_message_unref (reply);\n" "\tnih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "}\n" "\n" "dbus_message_iter_recurse (&iter, &variter);\n" "\n" "dbus_message_iter_next (&iter);\n" "\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {\n" "\tdbus_message_unref (reply);\n" "\tnih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "}\n" "\n")) return NULL; /* In case of out of memory, we can't just return because we've * already made the method call so we loop over the code instead. * But in case of type error in the returned arguments, all we * can do is return an error. */ oom_error_code = nih_sprintf (NULL, "*value = NULL;\n" "goto enomem;\n"); if (! oom_error_code) return NULL; type_error_code = nih_strdup (NULL, "dbus_message_unref (reply);\n" "nih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" " _(NIH_DBUS_INVALID_ARGS_STR));\n"); if (! type_error_code) return NULL; block = demarshal (NULL, &iter, "parent", "variter", "local", oom_error_code, type_error_code, &outputs, &locals, prefix, interface->symbol, property->symbol, NULL, &property_structs); if (! block) return NULL; if (! nih_strcat (&block, NULL, "\n")) return NULL; /* Each of the outputs from the demarshalling code becomes a local * variable to our function that we store the value in, and an * argument to the function that we set when done. */ NIH_LIST_FOREACH_SAFE (&outputs, iter) { TypeVar * var = (TypeVar *)iter; nih_local char *arg_type = NULL; const char * suffix; nih_local char *arg_name = NULL; TypeVar * arg; /* Output variable */ arg_type = nih_strdup (NULL, var->type); if (! arg_type) return NULL; if (! type_to_pointer (&arg_type, NULL)) return NULL; nih_assert (! strncmp (var->name, "local", 5)); suffix = var->name + 5; arg_name = nih_sprintf (NULL, "value%s", suffix); if (! arg_name) return NULL; arg = type_var_new (func, arg_type, arg_name); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat_sprintf (&assert_block, NULL, "nih_assert (%s != NULL);\n", arg->name)) return NULL; /* Copy from local variable to output */ if (! nih_strcat_sprintf (&block, NULL, "*%s = %s;\n", arg->name, var->name)) return NULL; nih_list_add (&locals, &var->entry); nih_ref (var, demarshal_block); } /* Loop over the demarshalling code for out-of-memory situations */ if (! indent (&block, NULL, 1)) return NULL; if (! nih_strcat_sprintf (&demarshal_block, NULL, "do {\n" "\t__label__ enomem;\n" "\n" "%s" "enomem: __attribute__ ((unused));\n" "} while (! *value);\n" "\n" "dbus_message_unref (reply);\n", block)) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "%s" "\n" "return 0;\n", vars_block, assert_block, call_block, demarshal_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the function to the prototypes list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); NIH_LIST_FOREACH_SAFE (&property_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } return code; } /** * property_proxy_set_sync_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface of @property, * @property: property to generate function for, * @prototypes: list to append function prototypes to, * @structs: list to append structure definitions to. * * Generates C code for a function that will make a synchronous method * call to set the value of the property @property on @interface. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list, with the name as @name itself. * * If the property type requires a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @property. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * property_proxy_set_sync_function (const void *parent, const char *prefix, Interface * interface, Property * property, NihList * prototypes, NihList * structs) { DBusSignatureIter iter; NihList inputs; NihList locals; NihList property_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; NihListEntry * attrib; nih_local char * assert_block = NULL; nih_local TypeVar * message_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * variter_var = NULL; nih_local TypeVar * error_var = NULL; nih_local TypeVar * reply_var = NULL; nih_local TypeVar * interface_var = NULL; nih_local TypeVar * property_var = NULL; nih_local char * marshal_block = NULL; nih_local char * call_block = NULL; nih_local char * oom_error_code = NULL; nih_local char * block = NULL; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (property != NULL); nih_assert (prototypes != NULL); nih_assert (structs != NULL); dbus_signature_iter_init (&iter, property->type); nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&property_structs); /* The function returns an integer, and takes the proxy object * as the argument along with an input argument for the property * value. The integer is negative if a raised error occurred, * so we want warning if the result isn't used. Since this is * used by the client, we also add a deprecated attribute if * the property is deprecated. */ name = symbol_extern (NULL, prefix, interface->symbol, "set", property->symbol, "sync"); if (! name) return NULL; func = type_func_new (NULL, "int", name); if (! func) return NULL; attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "warn_unused_result"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); if (property->deprecated) { attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "deprecated"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); } arg = type_var_new (func, "const void *", "parent"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "NihDBusProxy *", "proxy"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (proxy != NULL);\n")) return NULL; /* The function requires a message pointer, which we allocate, * and an iterator for it to append the arguments. We also need * a reply message pointer as well and an error object. * Rather than deal with these by hand, it's far easier to put them * on the locals list and deal with them along with the rest. */ message_var = type_var_new (NULL, "DBusMessage *", "method_call"); if (! message_var) return NULL; nih_list_add (&locals, &message_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); variter_var = type_var_new (NULL, "DBusMessageIter", "variter"); if (! variter_var) return NULL; nih_list_add (&locals, &variter_var->entry); error_var = type_var_new (NULL, "DBusError", "error"); if (! error_var) return NULL; nih_list_add (&locals, &error_var->entry); reply_var = type_var_new (NULL, "DBusMessage *", "reply"); if (! reply_var) return NULL; nih_list_add (&locals, &reply_var->entry); /* Annoyingly we also need variables for the interface and * property names, since D-Bus wants their address and can't just * take a constant string. */ interface_var = type_var_new (NULL, "const char *", "interface"); if (! interface_var) return NULL; nih_list_add (&locals, &interface_var->entry); property_var = type_var_new (NULL, "const char *", "property"); if (! property_var) return NULL; nih_list_add (&locals, &property_var->entry); /* Create the method call to set the property, the property * interface gets specified as an argument - the method call * interface is the D-Bus properties one. Append a variant * which is where we put the new value. */ if (! nih_strcat_sprintf (&marshal_block, NULL, "/* Construct the method call message. */\n" "method_call = dbus_message_new_method_call (proxy->name, proxy->path, \"%s\", \"Set\");\n" "if (! method_call)\n" "\tnih_return_no_memory_error (-1);\n" "\n" "dbus_message_set_auto_start (method_call, proxy->auto_start);\n" "\n" "dbus_message_iter_init_append (method_call, &iter);\n" "\n" "interface = \"%s\";\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (-1);\n" "}\n" "\n" "property = \"%s\";\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (-1);\n" "}\n" "\n" "if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, \"%s\", &variter)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (-1);\n" "}\n" "\n", DBUS_INTERFACE_PROPERTIES, interface->name, property->name, property->type)) return NULL; /* FIXME autostart? */ /* In case of out of memory, we just return the error to the caller * since we haven't made the method call yet. */ oom_error_code = nih_sprintf (NULL, "dbus_message_iter_abandon_container (&iter, &variter);\n" "dbus_message_unref (method_call);\n" "nih_return_no_memory_error (-1);\n"); if (! oom_error_code) return NULL; block = marshal (NULL, &iter, "variter", "value", oom_error_code, &inputs, &locals, prefix, interface->symbol, property->symbol, NULL, &property_structs); if (! block) return NULL; if (! nih_strcat_sprintf (&marshal_block, NULL, "%s" "\n", block)) return NULL; /* Each of the inputs of the marshalling code becomes a const * argument to our function that we obtain the value from. */ NIH_LIST_FOREACH_SAFE (&inputs, iter) { TypeVar *var = (TypeVar *)iter; if (! type_to_const (&var->type, var)) return NULL; if (! type_strcat_assert (&assert_block, NULL, var, func->args.prev != &func->args ? (TypeVar *)func->args.prev : NULL, _iter.next != &inputs ? (TypeVar *)_iter.next : NULL)) return NULL; nih_list_add (&func->args, &var->entry); nih_ref (var, func); } /* Complete the marshalling block by closing the container. */ if (! nih_strcat_sprintf (&marshal_block, NULL, "if (! dbus_message_iter_close_container (&iter, &variter)) {\n" "\tdbus_message_unref (method_call);\n" "\tnih_return_no_memory_error (-1);\n" "}\n" "\n")) return NULL; /* Send the message and check for error replies, or arguments * in the reply (which is an error). */ if (! nih_strcat_sprintf (&call_block, NULL, "/* Send the message, and wait for the reply. */\n" "dbus_error_init (&error);\n" "\n" "reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error);\n" "if (! reply) {\n" "\tdbus_message_unref (method_call);\n" "\n" "\tif (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) {\n" "\t\tnih_error_raise_no_memory ();\n" "\t} else {\n" "\t\tnih_dbus_error_raise (error.name, error.message);\n" "\t}\n" "\n" "\tdbus_error_free (&error);\n" "\treturn -1;\n" "}\n" "\n" "/* Check the reply has no arguments */\n" "dbus_message_unref (method_call);\n" "dbus_message_iter_init (reply, &iter);\n" "\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {\n" "\tdbus_message_unref (reply);\n" "\tnih_return_error (-1, NIH_DBUS_INVALID_ARGS,\n" "\t _(NIH_DBUS_INVALID_ARGS_STR));\n" "}\n" "\n" "dbus_message_unref (reply);\n")) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "%s" "\n" "return 0;\n", vars_block, assert_block, marshal_block, call_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the function to the prototypes list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); NIH_LIST_FOREACH_SAFE (&property_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } return code; } libnih-1.0.3/nih-dbus-tool/output.h0000644000175000017500000000257311445765555014126 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_OUTPUT_H #define NIH_DBUS_TOOL_OUTPUT_H #include #include "node.h" NIH_BEGIN_EXTERN char *output_package; int output (const char *source_path, int source_fd, const char *header_path, int header_fd, const char *prefix, Node *node, int object) __attribute__ ((warn_unused_result)); char *output_preamble (const void *parent, const char *path) __attribute__ ((warn_unused_result, malloc)); char *output_sentinel (const void *parent, const char *path) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_OUTPUT_H */ libnih-1.0.3/nih-dbus-tool/demarshal.h0000644000175000017500000000257111445765555014524 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_DEMARSHAL_H #define NIH_DBUS_TOOL_DEMARSHAL_H #include #include #include NIH_BEGIN_EXTERN char *demarshal (const void *parent, DBusSignatureIter *iter, const char *parent_name, const char *iter_name, const char *name, const char *oom_error_code, const char *type_error_code, NihList *outputs, NihList *locals, const char *prefix, const char *interface_symbol, const char *member_symbol, const char *symbol, NihList *structs) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_DEMARSHAL_H */ libnih-1.0.3/nih-dbus-tool/signal.c0000644000175000017500000007707211445765555014044 00000000000000/* nih-dbus-tool * * signal.c - signal parsing and generation * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include "symbol.h" #include "indent.h" #include "type.h" #include "marshal.h" #include "demarshal.h" #include "interface.h" #include "signal.h" #include "argument.h" #include "parse.h" #include "errors.h" /** * signal_name_valid: * @name: Member name to verify. * * Verifies whether @name matches the specification for a D-Bus interface * member name, and thus is valid for a signal. * * Returns: TRUE if valid, FALSE if not. **/ int signal_name_valid (const char *name) { nih_assert (name != NULL); /* We can get away with just using strlen() here even through name * is in UTF-8 because all the valid characters are ASCII. */ for (size_t i = 0; i < strlen (name); i++) { /* Names may contain digits, but not at the beginning. */ if ((name[i] >= '0') && (name[i] <= '9')) { if (i == 0) return FALSE; continue; } /* Valid characters anywhere are [A-Za-z_] */ if ( ((name[i] < 'A') || (name[i] > 'Z')) && ((name[i] < 'a') || (name[i] > 'z')) && (name[i] != '_')) return FALSE; } /* Name must be at least 1 character and no more than 255 characters */ if ((strlen (name) < 1) || (strlen (name) > 255)) return FALSE; return TRUE; } /** * signal_new: * @parent: parent object for new signal, * @name: D-Bus name of signal. * * Allocates a new D-Bus object Signal data structure, with the D-Bus name * set to @name. The returned structure is not placed into any list and * has no arguments. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned signal. When all parents * of the returned signal are freed, the returned signal will also be * freed. * * Returns: the new signal or NULL if the allocation failed. **/ Signal * signal_new (const void *parent, const char *name) { Signal *signal; nih_assert (name != NULL); signal = nih_new (parent, Signal); if (! signal) return NULL; nih_list_init (&signal->entry); nih_alloc_set_destructor (signal, nih_list_destroy); signal->name = nih_strdup (signal, name); if (! signal->name) { nih_free (signal); return NULL; } signal->symbol = NULL; signal->deprecated = FALSE; nih_list_init (&signal->arguments); return signal; } /** * signal_start_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed, * @attr: NULL-terminated array of attribute name and value pairs. * * This function is called by parse_start_tag() for a "signal" * start tag, a child of the "interface" tag that defines a signal the * D-Bus interface specifies. * * If the method does not appear within an interface tag a warning is * emitted and the tag will be ignored. * * Signals must have a "name" attribute containing the D-Bus name * of the signal. * * Any unknown attributes result in a warning and will be ignored. * * A Signal object will be allocated and pushed onto the stack, this is * not added to the interface until the end tag is found. * * Returns: zero on success, negative value on raised error. **/ int signal_start_tag (XML_Parser xmlp, const char * tag, char * const *attr) { ParseContext * context; ParseStack * parent; nih_local Signal *signal = NULL; char * const * key; char * const * value; const char * name = NULL; nih_assert (xmlp != NULL); nih_assert (tag != NULL); nih_assert (attr != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); /* Signals should only appear inside interfaces. */ parent = parse_stack_top (&context->stack); if ((! parent) || (parent->type != PARSE_INTERFACE)) { nih_warn ("%s:%zu:%zu: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unexpected tag")); if (! parse_stack_push (NULL, &context->stack, PARSE_IGNORED, NULL)) nih_return_system_error (-1); return 0; } /* Retrieve the name from the attributes */ for (key = attr; key && *key; key += 2) { value = key + 1; nih_assert (value && *value); if (! strcmp (*key, "name")) { name = *value; } else { nih_warn ("%s:%zu:%zu: %s: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unknown attribute"), *key); } } /* Check we have a name and that it's valid */ if (! name) nih_return_error (-1, SIGNAL_MISSING_NAME, _(SIGNAL_MISSING_NAME_STR)); if (! signal_name_valid (name)) nih_return_error (-1, SIGNAL_INVALID_NAME, _(SIGNAL_INVALID_NAME_STR)); /* Allocate a Signal object and push onto the stack */ signal = signal_new (NULL, name); if (! signal) nih_return_system_error (-1); if (! parse_stack_push (NULL, &context->stack, PARSE_SIGNAL, signal)) { nih_error_raise_system (); return -1; } return 0; } /** * signal_end_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed. * * This function is called by parse_end_tag() for a "signal" end * tag, and matches a call to signal_start_tag() made at the same parsing * level. * * The signal is added to the list of signals defined by the parent * interface. * * Returns: zero on success, negative value on raised error. **/ int signal_end_tag (XML_Parser xmlp, const char *tag) { ParseContext *context; ParseStack * entry; ParseStack * parent; Signal * signal; Signal * conflict; Interface * interface; nih_assert (xmlp != NULL); nih_assert (tag != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); entry = parse_stack_top (&context->stack); nih_assert (entry != NULL); nih_assert (entry->type == PARSE_SIGNAL); signal = entry->signal; /* Generate a symbol from the name */ if (! signal->symbol) { signal->symbol = symbol_from_name (signal, signal->name); if (! signal->symbol) nih_return_no_memory_error (-1); } nih_list_remove (&entry->entry); parent = parse_stack_top (&context->stack); nih_assert (parent != NULL); nih_assert (parent->type == PARSE_INTERFACE); interface = parent->interface; /* Make sure there's not a conflict before adding the signal */ conflict = signal_lookup (interface, signal->symbol); if (conflict) { nih_error_raise_printf (SIGNAL_DUPLICATE_SYMBOL, _(SIGNAL_DUPLICATE_SYMBOL_STR), signal->symbol, conflict->name); return -1; } nih_debug ("Add %s signal to %s interface", signal->name, interface->name); nih_list_add (&interface->signals, &signal->entry); nih_ref (signal, interface); nih_free (entry); return 0; } /** * signal_annotation: * @signal: signal object annotation applies to, * @name: annotation name, * @value: annotation value. * * Handles applying the annotation @name with value @value to the signal * @signal. Signals may be annotated as deprecated or may have an alternate * symbol name specified. * * Unknown annotations or illegal values to the known annotations result * in an error being raised. * * Returns: zero on success, negative value on raised error. **/ int signal_annotation (Signal * signal, const char *name, const char *value) { nih_assert (signal != NULL); nih_assert (name != NULL); nih_assert (value != NULL); if (! strcmp (name, "org.freedesktop.DBus.Deprecated")) { if (! strcmp (value, "true")) { nih_debug ("Marked %s signal as deprecated", signal->name); signal->deprecated = TRUE; } else if (! strcmp (value, "false")) { nih_debug ("Marked %s signal as not deprecated", signal->name); signal->deprecated = FALSE; } else { nih_return_error (-1, SIGNAL_ILLEGAL_DEPRECATED, _(SIGNAL_ILLEGAL_DEPRECATED_STR)); } } else if (! strcmp (name, "com.netsplit.Nih.Symbol")) { if (symbol_valid (value)) { if (signal->symbol) nih_unref (signal->symbol, signal); signal->symbol = nih_strdup (signal, value); if (! signal->symbol) nih_return_no_memory_error (-1); nih_debug ("Set %s signal symbol to %s", signal->name, signal->symbol); } else { nih_return_error (-1, SIGNAL_INVALID_SYMBOL, _(SIGNAL_INVALID_SYMBOL_STR)); } } else { nih_error_raise_printf (SIGNAL_UNKNOWN_ANNOTATION, "%s: %s: %s", _(SIGNAL_UNKNOWN_ANNOTATION_STR), signal->name, name); return -1; } return 0; } /** * signal_lookup: * @interface: interface to search, * @symbol: signal symbol to find. * * Finds a signal in @interface's signals list which has the generated * or supplied C symbol @symbol. * * Returns: signal found or NULL if no signal matches. **/ Signal * signal_lookup (Interface * interface, const char *symbol) { nih_assert (interface != NULL); nih_assert (symbol != NULL); NIH_LIST_FOREACH (&interface->signals, iter) { Signal *signal = (Signal *)iter; if (signal->symbol && (! strcmp (signal->symbol, symbol))) return signal; } return NULL; } /** * signal_lookup_argument: * @signal: signal to search, * @symbol: argument symbol to find. * * Finds a argument in @signal's arguments list which has the generated * or supplied C symbol @symbol. * * Returns: argument found or NULL if no argument matches. **/ Argument * signal_lookup_argument (Signal * signal, const char *symbol) { nih_assert (signal != NULL); nih_assert (symbol != NULL); NIH_LIST_FOREACH (&signal->arguments, iter) { Argument *argument = (Argument *)iter; if (argument->symbol && (! strcmp (argument->symbol, symbol))) return argument; } return NULL; } /** * signal_object_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface of @signal, * @signal: signal to generate function for, * @prototypes: list to append function prototypes to, * @structs: list to append structure definitions to. * * Generates C code for a function to emit a signal @signal on @interface by * marshalling the arguments. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * If any of the arguments require a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @signal. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * signal_object_function (const void *parent, const char *prefix, Interface * interface, Signal * signal, NihList * prototypes, NihList * structs) { NihList locals; NihList signal_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; NihListEntry * attrib; nih_local char * assert_block = NULL; nih_local TypeVar * signal_var = NULL; nih_local TypeVar * iter_var = NULL; nih_local char * marshal_block = NULL; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code = NULL; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (signal != NULL); nih_assert (prototypes != NULL); nih_assert (structs != NULL); nih_list_init (&locals); nih_list_init (&signal_structs); /* The function returns an integer, and accepts an argument for * the connection and origin path. The integer indicates whether * an error occurred, so we want a warning if the result isn't used. */ name = symbol_extern (NULL, prefix, interface->symbol, "emit", signal->symbol, NULL); if (! name) return NULL; func = type_func_new (NULL, "int", name); if (! func) return NULL; attrib = nih_list_entry_new (func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "warn_unused_result"); if (! attrib->str) return NULL; nih_list_add (&func->attribs, &attrib->entry); arg = type_var_new (func, "DBusConnection *", "connection"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (connection != NULL);\n")) return NULL; arg = type_var_new (func, "const char *", "origin_path"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (origin_path != NULL);\n")) return NULL; /* The function requires a message pointer, which we allocate, * and an iterator for it to append the arguments. Rather than * deal with these by hand, it's far easier to put them on the * locals list and deal with them along with the rest. */ signal_var = type_var_new (NULL, "DBusMessage *", "signal"); if (! signal_var) return NULL; nih_list_add (&locals, &signal_var->entry); iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); /* Create the signal and set up the iterator to append to it. */ if (! nih_strcat_sprintf (&marshal_block, NULL, "/* Construct the message. */\n" "signal = dbus_message_new_signal (origin_path, \"%s\", \"%s\");\n" "if (! signal)\n" "\treturn -1;\n" "\n" "dbus_message_iter_init_append (signal, &iter);\n" "\n", interface->name, signal->name)) return NULL; /* Iterate over the signal's output arguments, for each one we * append the code to the marshalling code and at the same time * build up our own expected arguments themselves. */ NIH_LIST_FOREACH (&signal->arguments, iter) { Argument * argument = (Argument *)iter; NihList arg_vars; NihList arg_locals; NihList arg_structs; DBusSignatureIter iter; nih_local char * oom_error_code = NULL; nih_local char * type_error_code = NULL; nih_local char * block = NULL; if (argument->direction != NIH_DBUS_ARG_OUT) continue; nih_list_init (&arg_vars); nih_list_init (&arg_locals); nih_list_init (&arg_structs); dbus_signature_iter_init (&iter, argument->type); /* In case of out of memory, simply return; the caller * can try again. */ oom_error_code = nih_strdup (NULL, "dbus_message_unref (signal);\n" "return -1;\n"); if (! oom_error_code) return NULL; block = marshal (NULL, &iter, "iter", argument->symbol, oom_error_code, &arg_vars, &arg_locals, prefix, interface->symbol, signal->symbol, argument->symbol, &arg_structs); if (! block) return NULL; if (! nih_strcat_sprintf (&marshal_block, NULL, "%s" "\n", block)) return NULL; /* We take a parameter of the expected type and name of * the marshal input variable; if it's a pointer, we * assert that it's not NULL and make sure it's const. */ NIH_LIST_FOREACH_SAFE (&arg_vars, iter) { TypeVar *var = (TypeVar *)iter; if (! type_to_const (&var->type, var)) return NULL; if (! type_strcat_assert (&assert_block, NULL, var, func->args.prev != &func->args ? (TypeVar *)func->args.prev : NULL, _iter.next != &arg_vars ? (TypeVar *)_iter.next : NULL)) return NULL; nih_list_add (&func->args, &var->entry); nih_ref (var, func); } NIH_LIST_FOREACH_SAFE (&arg_locals, iter) { TypeVar *var = (TypeVar *)iter; nih_list_add (&locals, &var->entry); nih_ref (var, marshal_block); } NIH_LIST_FOREACH_SAFE (&arg_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_list_add (&signal_structs, &structure->entry); nih_ref (structure, marshal_block); } } /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "/* Send the signal, appending it to the outgoing queue. */\n" "if (! dbus_connection_send (connection, signal, NULL)) {\n" "\tdbus_message_unref (signal);\n" "\treturn -1;\n" "}\n" "\n" "dbus_message_unref (signal);\n" "\n" "return 0;\n", vars_block, assert_block, marshal_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the function to the prototypes list */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); NIH_LIST_FOREACH_SAFE (&signal_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } return code; } /** * signal_proxy_function: * @parent: parent object for new string. * @prefix: prefix for function name, * @interface: interface of @signal, * @signal: signal to generate function for, * @prototypes: list to append function prototypes to, * @typedefs: list to append function pointer typedef definitions to, * @structs: list to append structure definitions to. * * Generates C code for a function that acts as a D-Bus connection filter * function checking that the incoming message matches @signal on @itnerface * and calls a handler function after demarshalling the arguments. * * The prototype of the returned function is returned as a TypeFunc object * appended to the @prototypes list. * * The typedef of the handler function is returned as a TypeFunc object * appended to the @typedefs list. * * If any of the arguments require a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and @signal. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * signal_proxy_function (const void *parent, const char *prefix, Interface * interface, Signal * signal, NihList * prototypes, NihList * typedefs, NihList * structs) { NihList locals; NihList signal_structs; nih_local char * name = NULL; nih_local TypeFunc *func = NULL; TypeVar * arg; nih_local char * assert_block = NULL; nih_local TypeVar * iter_var = NULL; nih_local TypeVar * parent_var = NULL; nih_local char * demarshal_block = NULL; nih_local char * call_block = NULL; nih_local char * handler_type = NULL; nih_local char * handler_name = NULL; nih_local TypeFunc *handler_func = NULL; NihListEntry * attrib; nih_local char * vars_block = NULL; nih_local char * body = NULL; char * code; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (signal != NULL); nih_assert (prototypes != NULL); nih_assert (typedefs != NULL); nih_assert (structs != NULL); nih_list_init (&locals); nih_list_init (&signal_structs); /* The function returns a D-Bus handler result, accepting arguments * for the connection, received message and proxied signal structure. */ name = symbol_impl (NULL, prefix, interface->name, signal->name, "signal"); if (! name) return NULL; func = type_func_new (NULL, "DBusHandlerResult", name); if (! func) return NULL; arg = type_var_new (func, "DBusConnection *", "connection"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (connection != NULL);\n")) return NULL; arg = type_var_new (func, "DBusMessage *", "signal"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (signal != NULL);\n")) return NULL; arg = type_var_new (func, "NihDBusProxySignal *", "proxied"); if (! arg) return NULL; nih_list_add (&func->args, &arg->entry); if (! nih_strcat (&assert_block, NULL, "nih_assert (proxied != NULL);\n")) return NULL; if (! nih_strcat (&assert_block, NULL, "nih_assert (connection == proxied->proxy->connection);\n")) return NULL; /* The function requires a message context to act as the parent of * arguments and is passed to the handler function; we also need * an iterator for it. */ iter_var = type_var_new (NULL, "DBusMessageIter", "iter"); if (! iter_var) return NULL; nih_list_add (&locals, &iter_var->entry); parent_var = type_var_new (NULL, "NihDBusMessage *", "message"); if (! parent_var) return NULL; nih_list_add (&locals, &parent_var->entry); /* Begin the demarshalling block by checking that the message is * the signal we're looking for, and then if it is, allocating a * message context and iterating the arguments. */ if (! nih_strcat_sprintf (&demarshal_block, NULL, "if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name))\n" "\treturn DBUS_HANDLER_RESULT_NOT_YET_HANDLED;\n" "\n" "if (! dbus_message_has_path (signal, proxied->proxy->path))\n" "\treturn DBUS_HANDLER_RESULT_NOT_YET_HANDLED;\n" "\n" "if (proxied->proxy->name)\n" "\tif (! dbus_message_has_sender (signal, proxied->proxy->owner))\n" "\t\treturn DBUS_HANDLER_RESULT_NOT_YET_HANDLED;\n" "\n" "message = nih_dbus_message_new (NULL, connection, signal);\n" "if (! message)\n" "\treturn DBUS_HANDLER_RESULT_NEED_MEMORY;\n" "\n" "/* Iterate the arguments to the signal and demarshal into arguments\n" " * for our own function call.\n" " */\n" "dbus_message_iter_init (message->message, &iter);\n" "\n")) return NULL; /* Begin the handler calling block, which is not permitted to * reply. Build up the typedef for it, which we mostly use for * type passing reasons. */ handler_type = symbol_typedef (NULL, prefix, interface->symbol, NULL, signal->symbol, "Handler"); if (! handler_type) return NULL; if (! nih_strcat_sprintf (&call_block, NULL, "/* Call the handler function */\n" "nih_error_push_context ();\n" "((%s)proxied->handler) (proxied->data, message", handler_type)) return NULL; handler_name = nih_sprintf (NULL, "(*%s)", handler_type); if (! handler_name) return NULL; handler_func = type_func_new (NULL, "typedef void", handler_name); if (! handler_func) return NULL; if (signal->deprecated) { attrib = nih_list_entry_new (handler_func); if (! attrib) return NULL; attrib->str = nih_strdup (attrib, "deprecated"); if (! attrib->str) return NULL; nih_list_add (&handler_func->attribs, &attrib->entry); } arg = type_var_new (handler_func, "void *", "data"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); arg = type_var_new (handler_func, "NihDBusMessage *", "message"); if (! arg) return NULL; nih_list_add (&handler_func->args, &arg->entry); /* Iterate over the signal arguments, for each output argument * we append the code to the the demarshalling code. At the * same time, we build up the handler call itself and transfer * the actual arguments to the locals list. */ NIH_LIST_FOREACH (&signal->arguments, iter) { Argument * argument = (Argument *)iter; NihList arg_vars; NihList arg_locals; NihList arg_structs; DBusSignatureIter iter; nih_local char * local_name = NULL; nih_local char * oom_error_code = NULL; nih_local char * type_error_code = NULL; nih_local char * block = NULL; if (argument->direction != NIH_DBUS_ARG_OUT) continue; nih_list_init (&arg_vars); nih_list_init (&arg_locals); nih_list_init (&arg_structs); dbus_signature_iter_init (&iter, argument->type); /* In case of out of memory, we just return and D-Bus will * call us again. In case of type error, just ignore the * signal entirely. */ oom_error_code = nih_sprintf (NULL, "nih_free (message);\n" "return DBUS_HANDLER_RESULT_NEED_MEMORY;\n"); if (! oom_error_code) return NULL; type_error_code = nih_strdup (NULL, "nih_free (message);\n" "return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;\n"); if (! type_error_code) return NULL; block = demarshal (NULL, &iter, "message", "iter", argument->symbol, oom_error_code, type_error_code, &arg_vars, &arg_locals, prefix, interface->symbol, signal->symbol, argument->symbol, &arg_structs); if (! block) return NULL; if (! nih_strcat (&block, NULL, "\n")) return NULL; NIH_LIST_FOREACH_SAFE (&arg_vars, iter) { TypeVar *var = (TypeVar *)iter; TypeVar *arg; if (! nih_strcat_sprintf (&call_block, NULL, ", %s", var->name)) return NULL; nih_list_add (&locals, &var->entry); nih_ref (var, call_block); /* Handler argument is const */ arg = type_var_new (handler_func, var->type, var->name); if (! arg) return NULL; if (! type_to_const (&arg->type, arg)) return NULL; nih_list_add (&handler_func->args, &arg->entry); } NIH_LIST_FOREACH_SAFE (&arg_locals, iter) { TypeVar *var = (TypeVar *)iter; nih_list_add (&locals, &var->entry); nih_ref (var, demarshal_block); } NIH_LIST_FOREACH_SAFE (&arg_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_list_add (&signal_structs, &structure->entry); nih_ref (structure, demarshal_block); } if (! nih_strcat (&demarshal_block, NULL, block)) return NULL; } /* Complete the demarshalling block, checking for any unexpected * arguments which we also want to error on. */ if (! nih_strcat_sprintf (&demarshal_block, NULL, "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {\n" "\tnih_free (message);\n" "\treturn DBUS_HANDLER_RESULT_NOT_YET_HANDLED;\n" "}\n" "\n")) return NULL; /* Complete the call block */ if (! nih_strcat (&call_block, NULL, ");\n" "nih_error_pop_context ();\n" "nih_free (message);\n" "\n")) return NULL; /* Lay out the function body, indenting it all before placing it * in the function code. */ vars_block = type_var_layout (NULL, &locals); if (! vars_block) return NULL; if (! nih_strcat_sprintf (&body, NULL, "%s" "\n" "%s" "\n" "%s" "%s" "return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;\n", vars_block, assert_block, demarshal_block, call_block)) return NULL; if (! indent (&body, NULL, 1)) return NULL; /* Function header */ code = type_func_to_string (parent, func); if (! code) return NULL; if (! nih_strcat_sprintf (&code, parent, "{\n" "%s" "}\n", body)) { nih_free (code); return NULL; } /* Append the functions to the prototypes and typedefs lists */ nih_list_add (prototypes, &func->entry); nih_ref (func, code); nih_list_add (typedefs, &handler_func->entry); nih_ref (handler_func, code); NIH_LIST_FOREACH_SAFE (&signal_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } return code; } /** * signal_args_array: * @parent: parent object for new string, * @prefix: prefix for array name, * @interface: interface of @signal, * @signal: signal to generate array for, * @prototypes: list to append prototype to. * * Generates C code to declare an array of NihDBusArg variables containing * information about the arguments of the signal @signal on @interface. * * The prototype of the returned variable declaration is returned as a * TypeVar object appended to the @prototypes list. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * signal_args_array (const void *parent, const char *prefix, Interface * interface, Signal * signal, NihList * prototypes) { nih_local char *name = NULL; size_t max_name = 0; size_t max_type = 0; nih_local char *block = NULL; char * code; TypeVar * var; nih_assert (prefix != NULL); nih_assert (interface != NULL); nih_assert (signal != NULL); nih_assert (prototypes != NULL); name = symbol_impl (NULL, prefix, interface->name, signal->name, "signal_args"); if (! name) return NULL; /* Figure out the longest argument name and signature */ NIH_LIST_FOREACH (&signal->arguments, iter) { Argument *argument = (Argument *)iter; if (argument->name) { if (strlen (argument->name) > max_name) max_name = strlen (argument->name); } else { if (max_name < 4) max_name = 4; } if (strlen (argument->type) > max_type) max_type = strlen (argument->type); } /* Append each argument such that the names, types and directions * are all lined up with each other. */ NIH_LIST_FOREACH (&signal->arguments, iter) { Argument * argument = (Argument *)iter; nih_local char *line = NULL; char * dest; line = nih_alloc (NULL, max_name + max_type + 31); if (! line) return NULL; dest = line; memcpy (dest, "{ ", 2); dest += 2; if (argument->name) { memcpy (dest, "\"", 1); dest += 1; memcpy (dest, argument->name, strlen (argument->name)); dest += strlen (argument->name); memcpy (dest, "\", ", 3); dest += 3; memset (dest, ' ', max_name - strlen (argument->name)); dest += max_name - strlen (argument->name); } else { memcpy (dest, "NULL, ", 6); dest += 6; memset (dest, ' ', max_name - 2); dest += max_name - 2; } memcpy (dest, "\"", 1); dest += 1; memcpy (dest, argument->type, strlen (argument->type)); dest += strlen (argument->type); memcpy (dest, "\", ", 3); dest += 3; memset (dest, ' ', max_type - strlen (argument->type)); dest += max_type - strlen (argument->type); memcpy (dest, "NIH_DBUS_ARG_OUT", 16); dest += 16; memcpy (dest, " },\n", 4); dest += 4; *dest = '\0'; if (! nih_strcat (&block, NULL, line)) return NULL; } /* Append the final element to the block of elements, indent and * surround with the structure definition. */ if (! nih_strcat (&block, NULL, "{ NULL }\n")) return NULL; if (! indent (&block, NULL, 1)) return NULL; code = nih_sprintf (parent, "const NihDBusArg %s[] = {\n" "%s" "};\n", name, block); if (! code) return NULL; /* Append the prototype to the list */ var = type_var_new (code, "const NihDBusArg", name); if (! var) { nih_free (code); return NULL; } var->array = TRUE; nih_list_add (prototypes, &var->entry); return code; } libnih-1.0.3/nih-dbus-tool/Makefile.in0000644000175000017500000037645311503251217014451 00000000000000# Makefile.in generated by automake 1.11.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, # 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, # Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ bin_PROGRAMS = nih-dbus-tool$(EXEEXT) TESTS = test_main$(EXEEXT) test_symbol$(EXEEXT) test_indent$(EXEEXT) \ test_type$(EXEEXT) test_marshal$(EXEEXT) \ test_demarshal$(EXEEXT) test_node$(EXEEXT) \ test_interface$(EXEEXT) test_method$(EXEEXT) \ test_signal$(EXEEXT) test_property$(EXEEXT) \ test_argument$(EXEEXT) test_annotation$(EXEEXT) \ test_parse$(EXEEXT) test_output$(EXEEXT) \ test_com.netsplit.Nih.Test_object$(EXEEXT) \ test_com.netsplit.Nih.Test_proxy$(EXEEXT) check_PROGRAMS = $(am__EXEEXT_1) marshal_factory$(EXEEXT) \ demarshal_factory$(EXEEXT) interface_factory$(EXEEXT) \ method_factory$(EXEEXT) signal_factory$(EXEEXT) \ property_factory$(EXEEXT) subdir = nih-dbus-tool DIST_COMMON = $(dist_man_MANS) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/codeset.m4 \ $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/glibc2.m4 \ $(top_srcdir)/m4/glibc21.m4 $(top_srcdir)/m4/iconv.m4 \ $(top_srcdir)/m4/intdiv0.m4 $(top_srcdir)/m4/intl.m4 \ $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/intmax.m4 \ $(top_srcdir)/m4/inttypes-pri.m4 \ $(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/lcmessage.m4 \ $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libnih.m4 \ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/lock.m4 \ $(top_srcdir)/m4/longlong.m4 $(top_srcdir)/m4/ltoptions.m4 \ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \ $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/m4/po.m4 \ $(top_srcdir)/m4/printf-posix.m4 $(top_srcdir)/m4/progtest.m4 \ $(top_srcdir)/m4/size_max.m4 $(top_srcdir)/m4/stdint_h.m4 \ $(top_srcdir)/m4/uintmax_t.m4 $(top_srcdir)/m4/visibility.m4 \ $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/m4/wint_t.m4 \ $(top_srcdir)/m4/xsize.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" am__EXEEXT_1 = test_main$(EXEEXT) test_symbol$(EXEEXT) \ test_indent$(EXEEXT) test_type$(EXEEXT) test_marshal$(EXEEXT) \ test_demarshal$(EXEEXT) test_node$(EXEEXT) \ test_interface$(EXEEXT) test_method$(EXEEXT) \ test_signal$(EXEEXT) test_property$(EXEEXT) \ test_argument$(EXEEXT) test_annotation$(EXEEXT) \ test_parse$(EXEEXT) test_output$(EXEEXT) \ test_com.netsplit.Nih.Test_object$(EXEEXT) \ test_com.netsplit.Nih.Test_proxy$(EXEEXT) PROGRAMS = $(bin_PROGRAMS) am_demarshal_factory_OBJECTS = demarshal_factory.$(OBJEXT) demarshal_factory_OBJECTS = $(am_demarshal_factory_OBJECTS) am__DEPENDENCIES_1 = demarshal_factory_DEPENDENCIES = demarshal.o type.o indent.o symbol.o \ ../nih/libnih.la $(am__DEPENDENCIES_1) AM_V_lt = $(am__v_lt_$(V)) am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) am__v_lt_0 = --silent demarshal_factory_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(demarshal_factory_LDFLAGS) $(LDFLAGS) \ -o $@ am_interface_factory_OBJECTS = interface_factory.$(OBJEXT) interface_factory_OBJECTS = $(am_interface_factory_OBJECTS) interface_factory_DEPENDENCIES = demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o ../nih/libnih.la \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) interface_factory_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(interface_factory_LDFLAGS) $(LDFLAGS) \ -o $@ am_marshal_factory_OBJECTS = marshal_factory.$(OBJEXT) marshal_factory_OBJECTS = $(am_marshal_factory_OBJECTS) marshal_factory_DEPENDENCIES = marshal.o type.o indent.o symbol.o \ ../nih/libnih.la $(am__DEPENDENCIES_1) marshal_factory_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(marshal_factory_LDFLAGS) $(LDFLAGS) \ -o $@ am_method_factory_OBJECTS = method_factory.$(OBJEXT) method_factory_OBJECTS = $(am_method_factory_OBJECTS) method_factory_DEPENDENCIES = demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o ../nih/libnih.la \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) method_factory_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(method_factory_LDFLAGS) $(LDFLAGS) -o \ $@ am_nih_dbus_tool_OBJECTS = main.$(OBJEXT) symbol.$(OBJEXT) \ indent.$(OBJEXT) type.$(OBJEXT) marshal.$(OBJEXT) \ demarshal.$(OBJEXT) node.$(OBJEXT) interface.$(OBJEXT) \ method.$(OBJEXT) signal.$(OBJEXT) property.$(OBJEXT) \ argument.$(OBJEXT) annotation.$(OBJEXT) parse.$(OBJEXT) \ output.$(OBJEXT) nih_dbus_tool_OBJECTS = $(am_nih_dbus_tool_OBJECTS) nih_dbus_tool_DEPENDENCIES = ../nih/libnih.la $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) am_property_factory_OBJECTS = property_factory.$(OBJEXT) property_factory_OBJECTS = $(am_property_factory_OBJECTS) property_factory_DEPENDENCIES = demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o ../nih/libnih.la \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) property_factory_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(property_factory_LDFLAGS) $(LDFLAGS) \ -o $@ am_signal_factory_OBJECTS = signal_factory.$(OBJEXT) signal_factory_OBJECTS = $(am_signal_factory_OBJECTS) signal_factory_DEPENDENCIES = demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o ../nih/libnih.la \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) signal_factory_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(signal_factory_LDFLAGS) $(LDFLAGS) -o \ $@ am_test_annotation_OBJECTS = test_annotation.$(OBJEXT) test_annotation_OBJECTS = $(am_test_annotation_OBJECTS) test_annotation_DEPENDENCIES = demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o ../nih/libnih.la \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) test_annotation_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(test_annotation_LDFLAGS) $(LDFLAGS) \ -o $@ am_test_argument_OBJECTS = test_argument.$(OBJEXT) test_argument_OBJECTS = $(am_test_argument_OBJECTS) test_argument_DEPENDENCIES = demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o ../nih/libnih.la \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) test_argument_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_argument_LDFLAGS) $(LDFLAGS) -o $@ am_test_com_netsplit_Nih_Test_object_OBJECTS = \ test_com.netsplit.Nih.Test_object.$(OBJEXT) \ com.netsplit.Nih.Test_impl.$(OBJEXT) am__objects_1 = com.netsplit.Nih.Test_object.$(OBJEXT) nodist_test_com_netsplit_Nih_Test_object_OBJECTS = $(am__objects_1) test_com_netsplit_Nih_Test_object_OBJECTS = \ $(am_test_com_netsplit_Nih_Test_object_OBJECTS) \ $(nodist_test_com_netsplit_Nih_Test_object_OBJECTS) test_com_netsplit_Nih_Test_object_DEPENDENCIES = \ ../nih-dbus/libnih-dbus.la ../nih/libnih.la \ $(am__DEPENDENCIES_1) test_com_netsplit_Nih_Test_object_LINK = $(LIBTOOL) $(AM_V_lt) \ --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link \ $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_com_netsplit_Nih_Test_object_LDFLAGS) $(LDFLAGS) -o $@ am_test_com_netsplit_Nih_Test_proxy_OBJECTS = \ test_com.netsplit.Nih.Test_proxy.$(OBJEXT) \ com.netsplit.Nih.Test_impl.$(OBJEXT) am__objects_2 = com.netsplit.Nih.Test_proxy.$(OBJEXT) nodist_test_com_netsplit_Nih_Test_proxy_OBJECTS = $(am__objects_1) \ $(am__objects_2) test_com_netsplit_Nih_Test_proxy_OBJECTS = \ $(am_test_com_netsplit_Nih_Test_proxy_OBJECTS) \ $(nodist_test_com_netsplit_Nih_Test_proxy_OBJECTS) test_com_netsplit_Nih_Test_proxy_DEPENDENCIES = \ ../nih-dbus/libnih-dbus.la ../nih/libnih.la \ $(am__DEPENDENCIES_1) test_com_netsplit_Nih_Test_proxy_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) \ $(test_com_netsplit_Nih_Test_proxy_LDFLAGS) $(LDFLAGS) -o $@ am_test_demarshal_OBJECTS = test_demarshal.$(OBJEXT) nodist_test_demarshal_OBJECTS = demarshal_code.$(OBJEXT) test_demarshal_OBJECTS = $(am_test_demarshal_OBJECTS) \ $(nodist_test_demarshal_OBJECTS) test_demarshal_DEPENDENCIES = demarshal.o type.o indent.o symbol.o \ ../nih/libnih.la $(am__DEPENDENCIES_1) test_demarshal_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(test_demarshal_LDFLAGS) $(LDFLAGS) -o \ $@ am_test_indent_OBJECTS = test_indent.$(OBJEXT) test_indent_OBJECTS = $(am_test_indent_OBJECTS) test_indent_DEPENDENCIES = indent.o ../nih/libnih.la test_indent_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_indent_LDFLAGS) $(LDFLAGS) -o $@ am_test_interface_OBJECTS = test_interface.$(OBJEXT) nodist_test_interface_OBJECTS = interface_code.$(OBJEXT) test_interface_OBJECTS = $(am_test_interface_OBJECTS) \ $(nodist_test_interface_OBJECTS) test_interface_DEPENDENCIES = demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o ../nih-dbus/libnih-dbus.la \ ../nih/libnih.la $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) test_interface_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(test_interface_LDFLAGS) $(LDFLAGS) -o \ $@ am_test_main_OBJECTS = test_main-test_main.$(OBJEXT) \ test_main-main.$(OBJEXT) test_main_OBJECTS = $(am_test_main_OBJECTS) test_main_DEPENDENCIES = ../nih/libnih.la test_main_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(test_main_CFLAGS) \ $(CFLAGS) $(test_main_LDFLAGS) $(LDFLAGS) -o $@ am_test_marshal_OBJECTS = test_marshal.$(OBJEXT) nodist_test_marshal_OBJECTS = marshal_code.$(OBJEXT) test_marshal_OBJECTS = $(am_test_marshal_OBJECTS) \ $(nodist_test_marshal_OBJECTS) test_marshal_DEPENDENCIES = marshal.o type.o indent.o symbol.o \ ../nih/libnih.la $(am__DEPENDENCIES_1) test_marshal_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_marshal_LDFLAGS) $(LDFLAGS) -o $@ am_test_method_OBJECTS = test_method.$(OBJEXT) nodist_test_method_OBJECTS = method_code.$(OBJEXT) test_method_OBJECTS = $(am_test_method_OBJECTS) \ $(nodist_test_method_OBJECTS) test_method_DEPENDENCIES = demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o ../nih-dbus/libnih-dbus.la \ ../nih/libnih.la $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) test_method_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_method_LDFLAGS) $(LDFLAGS) -o $@ am_test_node_OBJECTS = test_node.$(OBJEXT) test_node_OBJECTS = $(am_test_node_OBJECTS) test_node_DEPENDENCIES = demarshal.o marshal.o type.o indent.o parse.o \ annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o ../nih/libnih.la \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) test_node_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_node_LDFLAGS) $(LDFLAGS) -o $@ am_test_output_OBJECTS = test_output.$(OBJEXT) test_output_OBJECTS = $(am_test_output_OBJECTS) test_output_DEPENDENCIES = demarshal.o marshal.o type.o indent.o \ output.o parse.o annotation.o argument.o property.o signal.o \ method.o interface.o node.o symbol.o ../nih/libnih.la \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) test_output_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_output_LDFLAGS) $(LDFLAGS) -o $@ am_test_parse_OBJECTS = test_parse.$(OBJEXT) test_parse_OBJECTS = $(am_test_parse_OBJECTS) test_parse_DEPENDENCIES = demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o ../nih/libnih.la \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) test_parse_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_parse_LDFLAGS) $(LDFLAGS) -o $@ am_test_property_OBJECTS = test_property.$(OBJEXT) nodist_test_property_OBJECTS = property_code.$(OBJEXT) test_property_OBJECTS = $(am_test_property_OBJECTS) \ $(nodist_test_property_OBJECTS) test_property_DEPENDENCIES = demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o ../nih-dbus/libnih-dbus.la \ ../nih/libnih.la $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) test_property_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_property_LDFLAGS) $(LDFLAGS) -o $@ am_test_signal_OBJECTS = test_signal.$(OBJEXT) nodist_test_signal_OBJECTS = signal_code.$(OBJEXT) test_signal_OBJECTS = $(am_test_signal_OBJECTS) \ $(nodist_test_signal_OBJECTS) test_signal_DEPENDENCIES = demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o ../nih-dbus/libnih-dbus.la \ ../nih/libnih.la $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) test_signal_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_signal_LDFLAGS) $(LDFLAGS) -o $@ am_test_symbol_OBJECTS = test_symbol.$(OBJEXT) test_symbol_OBJECTS = $(am_test_symbol_OBJECTS) test_symbol_DEPENDENCIES = symbol.o ../nih/libnih.la test_symbol_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_symbol_LDFLAGS) $(LDFLAGS) -o $@ am_test_type_OBJECTS = test_type.$(OBJEXT) test_type_OBJECTS = $(am_test_type_OBJECTS) test_type_DEPENDENCIES = type.o indent.o symbol.o ../nih/libnih.la \ $(am__DEPENDENCIES_1) test_type_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(test_type_LDFLAGS) $(LDFLAGS) -o $@ DEFAULT_INCLUDES = depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ $(AM_CFLAGS) $(CFLAGS) AM_V_CC = $(am__v_CC_$(V)) am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) am__v_CC_0 = @echo " CC " $@; AM_V_at = $(am__v_at_$(V)) am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) am__v_at_0 = @ CCLD = $(CC) LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_CCLD = $(am__v_CCLD_$(V)) am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) am__v_CCLD_0 = @echo " CCLD " $@; AM_V_GEN = $(am__v_GEN_$(V)) am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) am__v_GEN_0 = @echo " GEN " $@; SOURCES = $(demarshal_factory_SOURCES) $(interface_factory_SOURCES) \ $(marshal_factory_SOURCES) $(method_factory_SOURCES) \ $(nih_dbus_tool_SOURCES) $(property_factory_SOURCES) \ $(signal_factory_SOURCES) $(test_annotation_SOURCES) \ $(test_argument_SOURCES) \ $(test_com_netsplit_Nih_Test_object_SOURCES) \ $(nodist_test_com_netsplit_Nih_Test_object_SOURCES) \ $(test_com_netsplit_Nih_Test_proxy_SOURCES) \ $(nodist_test_com_netsplit_Nih_Test_proxy_SOURCES) \ $(test_demarshal_SOURCES) $(nodist_test_demarshal_SOURCES) \ $(test_indent_SOURCES) $(test_interface_SOURCES) \ $(nodist_test_interface_SOURCES) $(test_main_SOURCES) \ $(test_marshal_SOURCES) $(nodist_test_marshal_SOURCES) \ $(test_method_SOURCES) $(nodist_test_method_SOURCES) \ $(test_node_SOURCES) $(test_output_SOURCES) \ $(test_parse_SOURCES) $(test_property_SOURCES) \ $(nodist_test_property_SOURCES) $(test_signal_SOURCES) \ $(nodist_test_signal_SOURCES) $(test_symbol_SOURCES) \ $(test_type_SOURCES) DIST_SOURCES = $(demarshal_factory_SOURCES) \ $(interface_factory_SOURCES) $(marshal_factory_SOURCES) \ $(method_factory_SOURCES) $(nih_dbus_tool_SOURCES) \ $(property_factory_SOURCES) $(signal_factory_SOURCES) \ $(test_annotation_SOURCES) $(test_argument_SOURCES) \ $(test_com_netsplit_Nih_Test_object_SOURCES) \ $(test_com_netsplit_Nih_Test_proxy_SOURCES) \ $(test_demarshal_SOURCES) $(test_indent_SOURCES) \ $(test_interface_SOURCES) $(test_main_SOURCES) \ $(test_marshal_SOURCES) $(test_method_SOURCES) \ $(test_node_SOURCES) $(test_output_SOURCES) \ $(test_parse_SOURCES) $(test_property_SOURCES) \ $(test_signal_SOURCES) $(test_symbol_SOURCES) \ $(test_type_SOURCES) am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' man1dir = $(mandir)/man1 NROFF = nroff MANS = $(dist_man_MANS) ETAGS = etags CTAGS = ctags # If stdout is a non-dumb tty, use colors. If test -t is not supported, # then this fails; a conservative approach. Of course do not redirect # stdout here, just stderr. am__tty_colors = \ red=; grn=; lgn=; blu=; std=; \ test "X$(AM_COLOR_TESTS)" != Xno \ && test "X$$TERM" != Xdumb \ && { test "X$(AM_COLOR_TESTS)" = Xalways || test -t 1 2>/dev/null; } \ && { \ red=''; \ grn=''; \ lgn=''; \ blu=''; \ std=''; \ } DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ ALLOCA = @ALLOCA@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@ CATOBJEXT = @CATOBJEXT@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CFLAG_VISIBILITY = @CFLAG_VISIBILITY@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DATADIRNAME = @DATADIRNAME@ DBUS_CFLAGS = @DBUS_CFLAGS@ DBUS_LIBS = @DBUS_LIBS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ EXPAT_LIBS = @EXPAT_LIBS@ FGREP = @FGREP@ GENCAT = @GENCAT@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ GLIBC2 = @GLIBC2@ GLIBC21 = @GLIBC21@ GMSGFMT = @GMSGFMT@ GMSGFMT_015 = @GMSGFMT_015@ GREP = @GREP@ HAVE_ASPRINTF = @HAVE_ASPRINTF@ HAVE_POSIX_PRINTF = @HAVE_POSIX_PRINTF@ HAVE_SNPRINTF = @HAVE_SNPRINTF@ HAVE_VISIBILITY = @HAVE_VISIBILITY@ HAVE_WPRINTF = @HAVE_WPRINTF@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INSTOBJEXT = @INSTOBJEXT@ INTLBISON = @INTLBISON@ INTLLIBS = @INTLLIBS@ INTLOBJS = @INTLOBJS@ INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@ INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBMULTITHREAD = @LIBMULTITHREAD@ LIBOBJS = @LIBOBJS@ LIBPTH = @LIBPTH@ LIBPTH_PREFIX = @LIBPTH_PREFIX@ LIBS = @LIBS@ LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBC = @LTLIBC@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ LTLIBMULTITHREAD = @LTLIBMULTITHREAD@ LTLIBOBJS = @LTLIBOBJS@ LTLIBPTH = @LTLIBPTH@ LTLIBTHREAD = @LTLIBTHREAD@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ NIH_DBUS_TOOL = @NIH_DBUS_TOOL@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_COPYRIGHT = @PACKAGE_COPYRIGHT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ POSUB = @POSUB@ PRI_MACROS_BROKEN = @PRI_MACROS_BROKEN@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@ USE_NLS = @USE_NLS@ VERSION = @VERSION@ VERSION_SCRIPT_ARG = @VERSION_SCRIPT_ARG@ WINDRES = @WINDRES@ WOE32 = @WOE32@ WOE32DLL = @WOE32DLL@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AM_CFLAGS = \ $(DBUS_CFLAGS) AM_CPPFLAGS = \ -DLOCALEDIR="\"$(localedir)\"" \ -I$(top_builddir) -I$(top_srcdir) -iquote$(builddir) -iquote$(srcdir) \ -I$(top_srcdir)/intl dist_man_MANS = \ man/nih-dbus-tool.1 nih_dbus_tool_SOURCES = \ main.c \ symbol.c symbol.h \ indent.c indent.h \ type.c type.h \ marshal.c marshal.h \ demarshal.c demarshal.h \ node.c node.h \ interface.c interface.h \ method.c method.h \ signal.c signal.h \ property.c property.h \ argument.c argument.h \ annotation.c annotation.h \ parse.c parse.h \ output.c output.h \ errors.h nih_dbus_tool_LDADD = \ ../nih/libnih.la \ $(LTLIBINTL) \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_main_SOURCES = tests/test_main.c main.c test_main_CFLAGS = $(AM_CFLAGS) -DTEST test_main_LDFLAGS = -static test_main_LDADD = ../nih/libnih.la test_symbol_SOURCES = tests/test_symbol.c test_symbol_LDFLAGS = -static test_symbol_LDADD = \ symbol.o \ ../nih/libnih.la test_indent_SOURCES = tests/test_indent.c test_indent_LDFLAGS = -static test_indent_LDADD = \ indent.o \ ../nih/libnih.la test_type_SOURCES = tests/test_type.c test_type_LDFLAGS = -static test_type_LDADD = \ type.o indent.o symbol.o \ ../nih/libnih.la \ $(DBUS_LIBS) test_marshal_SOURCES = \ tests/test_marshal.c tests/marshal_code.h nodist_test_marshal_SOURCES = \ tests/marshal_code.c test_marshal_LDFLAGS = -static test_marshal_LDADD = \ marshal.o type.o indent.o symbol.o \ ../nih/libnih.la \ $(DBUS_LIBS) test_demarshal_SOURCES = \ tests/test_demarshal.c tests/demarshal_code.h nodist_test_demarshal_SOURCES = \ tests/demarshal_code.c test_demarshal_LDFLAGS = -static test_demarshal_LDADD = \ demarshal.o type.o indent.o symbol.o \ ../nih/libnih.la \ $(DBUS_LIBS) test_node_SOURCES = tests/test_node.c test_node_LDFLAGS = -static test_node_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_interface_SOURCES = \ tests/test_interface.c tests/interface_code.h nodist_test_interface_SOURCES = \ tests/interface_code.c test_interface_LDFLAGS = -static test_interface_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih-dbus/libnih-dbus.la \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_method_SOURCES = \ tests/test_method.c tests/method_code.h nodist_test_method_SOURCES = \ tests/method_code.c test_method_LDFLAGS = -static test_method_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih-dbus/libnih-dbus.la \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_signal_SOURCES = \ tests/test_signal.c tests/signal_code.h nodist_test_signal_SOURCES = \ tests/signal_code.c test_signal_LDFLAGS = -static test_signal_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih-dbus/libnih-dbus.la \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_property_SOURCES = \ tests/test_property.c tests/property_code.h nodist_test_property_SOURCES = \ tests/property_code.c test_property_LDFLAGS = -static test_property_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih-dbus/libnih-dbus.la \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_argument_SOURCES = tests/test_argument.c test_argument_LDFLAGS = -static test_argument_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_annotation_SOURCES = tests/test_annotation.c test_annotation_LDFLAGS = -static test_annotation_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_parse_SOURCES = tests/test_parse.c test_parse_LDFLAGS = -static test_parse_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_output_SOURCES = tests/test_output.c test_output_LDFLAGS = -static test_output_LDADD = \ demarshal.o marshal.o type.o indent.o \ output.o parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) test_com_netsplit_Nih_Test_object_SOURCES = \ tests/test_com.netsplit.Nih.Test_object.c \ tests/com.netsplit.Nih.Test_impl.c tests/com.netsplit.Nih.Test_impl.h nodist_test_com_netsplit_Nih_Test_object_SOURCES = \ $(com_netsplit_Nih_Test_object_OUTPUTS) test_com_netsplit_Nih_Test_object_LDFLAGS = -static test_com_netsplit_Nih_Test_object_LDADD = ../nih-dbus/libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_com_netsplit_Nih_Test_proxy_SOURCES = \ tests/test_com.netsplit.Nih.Test_proxy.c \ tests/com.netsplit.Nih.Test_impl.c tests/com.netsplit.Nih.Test_impl.h nodist_test_com_netsplit_Nih_Test_proxy_SOURCES = \ $(com_netsplit_Nih_Test_object_OUTPUTS) \ $(com_netsplit_Nih_Test_proxy_OUTPUTS) test_com_netsplit_Nih_Test_proxy_LDFLAGS = -static test_com_netsplit_Nih_Test_proxy_LDADD = ../nih-dbus/libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) com_netsplit_Nih_Test_object_OUTPUTS = \ tests/com.netsplit.Nih.Test_object.c \ tests/com.netsplit.Nih.Test_object.h com_netsplit_Nih_Test_object_XML = \ tests/com.netsplit.Nih.Test.xml com_netsplit_Nih_Test_proxy_OUTPUTS = \ tests/com.netsplit.Nih.Test_proxy.c \ tests/com.netsplit.Nih.Test_proxy.h com_netsplit_Nih_Test_proxy_XML = \ tests/com.netsplit.Nih.Test.xml # These have to be built sources because we can't compile test_*.o without # the header file existing first. BUILT_SOURCES = \ $(com_netsplit_Nih_Test_object_OUTPUTS) \ $(com_netsplit_Nih_Test_proxy_OUTPUTS) EXTRA_DIST = $(com_netsplit_Nih_Test_object_XML) \ $(com_netsplit_Nih_Test_proxy_XML) \ tests/expected/test_interface_proxy_get_all_function_standard.c \ tests/expected/test_interface_proxy_get_all_notify_function_standard.c \ tests/expected/test_interface_proxy_get_all_notify_function_structure.c \ tests/expected/test_interface_proxy_get_all_sync_function_standard.c \ tests/expected/test_interface_proxy_get_all_sync_function_structure.c \ tests/expected/test_method_object_function_standard.c \ tests/expected/test_method_object_function_no_input.c \ tests/expected/test_method_object_function_no_output.c \ tests/expected/test_method_object_function_structure_input.c \ tests/expected/test_method_object_function_structure_output.c \ tests/expected/test_method_object_function_no_args.c \ tests/expected/test_method_object_function_async.c \ tests/expected/test_method_object_function_deprecated.c \ tests/expected/test_method_reply_function_standard.c \ tests/expected/test_method_reply_function_no_args.c \ tests/expected/test_method_reply_function_structure.c \ tests/expected/test_method_reply_function_array.c \ tests/expected/test_method_reply_function_deprecated.c \ tests/expected/test_method_proxy_function_standard.c \ tests/expected/test_method_proxy_function_no_args.c \ tests/expected/test_method_proxy_function_structure.c \ tests/expected/test_method_proxy_function_array.c \ tests/expected/test_method_proxy_function_deprecated.c \ tests/expected/test_method_proxy_notify_function_standard.c \ tests/expected/test_method_proxy_notify_function_no_args.c \ tests/expected/test_method_proxy_notify_function_structure.c \ tests/expected/test_method_proxy_notify_function_array.c \ tests/expected/test_method_proxy_sync_function_standard.c \ tests/expected/test_method_proxy_sync_function_no_input.c \ tests/expected/test_method_proxy_sync_function_no_output.c \ tests/expected/test_method_proxy_sync_function_no_args.c \ tests/expected/test_method_proxy_sync_function_structure_input.c \ tests/expected/test_method_proxy_sync_function_structure_output.c \ tests/expected/test_method_proxy_sync_function_array_input.c \ tests/expected/test_method_proxy_sync_function_deprecated.c \ tests/expected/test_signal_object_function_standard.c \ tests/expected/test_signal_object_function_no_args.c \ tests/expected/test_signal_object_function_structure.c \ tests/expected/test_signal_object_function_array.c \ tests/expected/test_signal_object_function_deprecated.c \ tests/expected/test_signal_proxy_function_standard.c \ tests/expected/test_signal_proxy_function_no_args.c \ tests/expected/test_signal_proxy_function_structure.c \ tests/expected/test_signal_proxy_function_deprecated.c \ tests/expected/test_property_object_get_function_standard.c \ tests/expected/test_property_object_get_function_structure.c \ tests/expected/test_property_object_get_function_deprecated.c \ tests/expected/test_property_object_set_function_standard.c \ tests/expected/test_property_object_set_function_structure.c \ tests/expected/test_property_object_set_function_deprecated.c \ tests/expected/test_property_proxy_get_function_standard.c \ tests/expected/test_property_proxy_get_function_deprecated.c \ tests/expected/test_property_proxy_get_notify_function_standard.c \ tests/expected/test_property_proxy_get_notify_function_structure.c \ tests/expected/test_property_proxy_get_notify_function_deprecated.c \ tests/expected/test_property_proxy_set_function_standard.c \ tests/expected/test_property_proxy_set_function_structure.c \ tests/expected/test_property_proxy_set_function_array.c \ tests/expected/test_property_proxy_set_function_deprecated.c \ tests/expected/test_property_proxy_set_notify_function_standard.c \ tests/expected/test_property_proxy_set_notify_function_deprecated.c \ tests/expected/test_property_proxy_get_sync_function_standard.c \ tests/expected/test_property_proxy_get_sync_function_structure.c \ tests/expected/test_property_proxy_get_sync_function_deprecated.c \ tests/expected/test_property_proxy_set_sync_function_standard.c \ tests/expected/test_property_proxy_set_sync_function_structure.c \ tests/expected/test_property_proxy_set_sync_function_array.c \ tests/expected/test_property_proxy_set_sync_function_deprecated.c \ tests/expected/test_node_interfaces_array_object.c \ tests/expected/test_node_interfaces_array_proxy.c \ tests/expected/test_node_interfaces_array_none.c \ tests/expected/test_node_object_functions_standard.c \ tests/expected/test_node_object_functions_no_methods.c \ tests/expected/test_node_object_functions_no_signals.c \ tests/expected/test_node_object_functions_no_properties.c \ tests/expected/test_node_object_functions_only_properties.c \ tests/expected/test_node_object_functions_structure.c \ tests/expected/test_node_proxy_functions_standard.c \ tests/expected/test_node_proxy_functions_no_methods.c \ tests/expected/test_node_proxy_functions_no_signals.c \ tests/expected/test_node_proxy_functions_no_properties.c \ tests/expected/test_node_proxy_functions_only_properties.c \ tests/expected/test_node_proxy_functions_structure.c \ tests/expected/test_output_proxy_standard.c \ tests/expected/test_output_proxy_standard.h \ tests/expected/test_output_proxy_no_interfaces.c \ tests/expected/test_output_proxy_no_interfaces.h \ tests/expected/test_output_object_standard.c \ tests/expected/test_output_object_standard.h \ tests/expected/test_output_object_no_interfaces.c \ tests/expected/test_output_object_no_interfaces.h marshal_factory_SOURCES = tests/marshal_factory.c marshal_factory_LDFLAGS = -static marshal_factory_LDADD = \ marshal.o type.o indent.o symbol.o \ ../nih/libnih.la \ $(DBUS_LIBS) demarshal_factory_SOURCES = tests/demarshal_factory.c demarshal_factory_LDFLAGS = -static demarshal_factory_LDADD = \ demarshal.o type.o indent.o symbol.o \ ../nih/libnih.la \ $(DBUS_LIBS) interface_factory_SOURCES = tests/interface_factory.c interface_factory_LDFLAGS = -static interface_factory_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) method_factory_SOURCES = tests/method_factory.c method_factory_LDFLAGS = -static method_factory_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) signal_factory_SOURCES = tests/signal_factory.c signal_factory_LDFLAGS = -static signal_factory_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) property_factory_SOURCES = tests/property_factory.c property_factory_LDFLAGS = -static property_factory_LDADD = \ demarshal.o marshal.o type.o indent.o \ parse.o annotation.o argument.o property.o signal.o method.o \ interface.o node.o symbol.o \ ../nih/libnih.la \ $(EXPAT_LIBS) \ $(DBUS_LIBS) CLEANFILES = \ $(com_netsplit_Nih_Test_object_OUTPUTS) \ $(com_netsplit_Nih_Test_proxy_OUTPUTS) \ $(nodist_test_marshal_SOURCES) \ $(nodist_test_demarshal_SOURCES) \ $(nodist_test_interface_SOURCES) \ $(nodist_test_method_SOURCES) \ $(nodist_test_signal_SOURCES) \ $(nodist_test_property_SOURCES) all: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu nih-dbus-tool/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu nih-dbus-tool/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ for p in $$list; do echo "$$p $$p"; done | \ sed 's/$(EXEEXT)$$//' | \ while read p p1; do if test -f $$p || test -f $$p1; \ then echo "$$p"; echo "$$p"; else :; fi; \ done | \ sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ sed 'N;N;N;s,\n, ,g' | \ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ if ($$2 == $$4) files[d] = files[d] " " $$1; \ else { print "f", $$3 "/" $$4, $$1; } } \ END { for (d in files) print "f", d, files[d] }' | \ while read type dir files; do \ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ test -z "$$files" || { \ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ } \ ; done uninstall-binPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ files=`for p in $$list; do echo "$$p"; done | \ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ -e 's/$$/$(EXEEXT)/' `; \ test -n "$$list" || exit 0; \ echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(bindir)" && rm -f $$files clean-binPROGRAMS: @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \ echo " rm -f" $$list; \ rm -f $$list || exit $$?; \ test -n "$(EXEEXT)" || exit 0; \ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list clean-checkPROGRAMS: @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \ echo " rm -f" $$list; \ rm -f $$list || exit $$?; \ test -n "$(EXEEXT)" || exit 0; \ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list demarshal_factory$(EXEEXT): $(demarshal_factory_OBJECTS) $(demarshal_factory_DEPENDENCIES) @rm -f demarshal_factory$(EXEEXT) $(AM_V_CCLD)$(demarshal_factory_LINK) $(demarshal_factory_OBJECTS) $(demarshal_factory_LDADD) $(LIBS) interface_factory$(EXEEXT): $(interface_factory_OBJECTS) $(interface_factory_DEPENDENCIES) @rm -f interface_factory$(EXEEXT) $(AM_V_CCLD)$(interface_factory_LINK) $(interface_factory_OBJECTS) $(interface_factory_LDADD) $(LIBS) marshal_factory$(EXEEXT): $(marshal_factory_OBJECTS) $(marshal_factory_DEPENDENCIES) @rm -f marshal_factory$(EXEEXT) $(AM_V_CCLD)$(marshal_factory_LINK) $(marshal_factory_OBJECTS) $(marshal_factory_LDADD) $(LIBS) method_factory$(EXEEXT): $(method_factory_OBJECTS) $(method_factory_DEPENDENCIES) @rm -f method_factory$(EXEEXT) $(AM_V_CCLD)$(method_factory_LINK) $(method_factory_OBJECTS) $(method_factory_LDADD) $(LIBS) nih-dbus-tool$(EXEEXT): $(nih_dbus_tool_OBJECTS) $(nih_dbus_tool_DEPENDENCIES) @rm -f nih-dbus-tool$(EXEEXT) $(AM_V_CCLD)$(LINK) $(nih_dbus_tool_OBJECTS) $(nih_dbus_tool_LDADD) $(LIBS) property_factory$(EXEEXT): $(property_factory_OBJECTS) $(property_factory_DEPENDENCIES) @rm -f property_factory$(EXEEXT) $(AM_V_CCLD)$(property_factory_LINK) $(property_factory_OBJECTS) $(property_factory_LDADD) $(LIBS) signal_factory$(EXEEXT): $(signal_factory_OBJECTS) $(signal_factory_DEPENDENCIES) @rm -f signal_factory$(EXEEXT) $(AM_V_CCLD)$(signal_factory_LINK) $(signal_factory_OBJECTS) $(signal_factory_LDADD) $(LIBS) test_annotation$(EXEEXT): $(test_annotation_OBJECTS) $(test_annotation_DEPENDENCIES) @rm -f test_annotation$(EXEEXT) $(AM_V_CCLD)$(test_annotation_LINK) $(test_annotation_OBJECTS) $(test_annotation_LDADD) $(LIBS) test_argument$(EXEEXT): $(test_argument_OBJECTS) $(test_argument_DEPENDENCIES) @rm -f test_argument$(EXEEXT) $(AM_V_CCLD)$(test_argument_LINK) $(test_argument_OBJECTS) $(test_argument_LDADD) $(LIBS) test_com.netsplit.Nih.Test_object$(EXEEXT): $(test_com_netsplit_Nih_Test_object_OBJECTS) $(test_com_netsplit_Nih_Test_object_DEPENDENCIES) @rm -f test_com.netsplit.Nih.Test_object$(EXEEXT) $(AM_V_CCLD)$(test_com_netsplit_Nih_Test_object_LINK) $(test_com_netsplit_Nih_Test_object_OBJECTS) $(test_com_netsplit_Nih_Test_object_LDADD) $(LIBS) test_com.netsplit.Nih.Test_proxy$(EXEEXT): $(test_com_netsplit_Nih_Test_proxy_OBJECTS) $(test_com_netsplit_Nih_Test_proxy_DEPENDENCIES) @rm -f test_com.netsplit.Nih.Test_proxy$(EXEEXT) $(AM_V_CCLD)$(test_com_netsplit_Nih_Test_proxy_LINK) $(test_com_netsplit_Nih_Test_proxy_OBJECTS) $(test_com_netsplit_Nih_Test_proxy_LDADD) $(LIBS) test_demarshal$(EXEEXT): $(test_demarshal_OBJECTS) $(test_demarshal_DEPENDENCIES) @rm -f test_demarshal$(EXEEXT) $(AM_V_CCLD)$(test_demarshal_LINK) $(test_demarshal_OBJECTS) $(test_demarshal_LDADD) $(LIBS) test_indent$(EXEEXT): $(test_indent_OBJECTS) $(test_indent_DEPENDENCIES) @rm -f test_indent$(EXEEXT) $(AM_V_CCLD)$(test_indent_LINK) $(test_indent_OBJECTS) $(test_indent_LDADD) $(LIBS) test_interface$(EXEEXT): $(test_interface_OBJECTS) $(test_interface_DEPENDENCIES) @rm -f test_interface$(EXEEXT) $(AM_V_CCLD)$(test_interface_LINK) $(test_interface_OBJECTS) $(test_interface_LDADD) $(LIBS) test_main$(EXEEXT): $(test_main_OBJECTS) $(test_main_DEPENDENCIES) @rm -f test_main$(EXEEXT) $(AM_V_CCLD)$(test_main_LINK) $(test_main_OBJECTS) $(test_main_LDADD) $(LIBS) test_marshal$(EXEEXT): $(test_marshal_OBJECTS) $(test_marshal_DEPENDENCIES) @rm -f test_marshal$(EXEEXT) $(AM_V_CCLD)$(test_marshal_LINK) $(test_marshal_OBJECTS) $(test_marshal_LDADD) $(LIBS) test_method$(EXEEXT): $(test_method_OBJECTS) $(test_method_DEPENDENCIES) @rm -f test_method$(EXEEXT) $(AM_V_CCLD)$(test_method_LINK) $(test_method_OBJECTS) $(test_method_LDADD) $(LIBS) test_node$(EXEEXT): $(test_node_OBJECTS) $(test_node_DEPENDENCIES) @rm -f test_node$(EXEEXT) $(AM_V_CCLD)$(test_node_LINK) $(test_node_OBJECTS) $(test_node_LDADD) $(LIBS) test_output$(EXEEXT): $(test_output_OBJECTS) $(test_output_DEPENDENCIES) @rm -f test_output$(EXEEXT) $(AM_V_CCLD)$(test_output_LINK) $(test_output_OBJECTS) $(test_output_LDADD) $(LIBS) test_parse$(EXEEXT): $(test_parse_OBJECTS) $(test_parse_DEPENDENCIES) @rm -f test_parse$(EXEEXT) $(AM_V_CCLD)$(test_parse_LINK) $(test_parse_OBJECTS) $(test_parse_LDADD) $(LIBS) test_property$(EXEEXT): $(test_property_OBJECTS) $(test_property_DEPENDENCIES) @rm -f test_property$(EXEEXT) $(AM_V_CCLD)$(test_property_LINK) $(test_property_OBJECTS) $(test_property_LDADD) $(LIBS) test_signal$(EXEEXT): $(test_signal_OBJECTS) $(test_signal_DEPENDENCIES) @rm -f test_signal$(EXEEXT) $(AM_V_CCLD)$(test_signal_LINK) $(test_signal_OBJECTS) $(test_signal_LDADD) $(LIBS) test_symbol$(EXEEXT): $(test_symbol_OBJECTS) $(test_symbol_DEPENDENCIES) @rm -f test_symbol$(EXEEXT) $(AM_V_CCLD)$(test_symbol_LINK) $(test_symbol_OBJECTS) $(test_symbol_LDADD) $(LIBS) test_type$(EXEEXT): $(test_type_OBJECTS) $(test_type_DEPENDENCIES) @rm -f test_type$(EXEEXT) $(AM_V_CCLD)$(test_type_LINK) $(test_type_OBJECTS) $(test_type_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/annotation.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/argument.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/com.netsplit.Nih.Test_impl.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/com.netsplit.Nih.Test_object.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/com.netsplit.Nih.Test_proxy.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/demarshal.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/demarshal_code.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/demarshal_factory.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/indent.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/interface.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/interface_code.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/interface_factory.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/marshal.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/marshal_code.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/marshal_factory.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/method.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/method_code.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/method_factory.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/node.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/output.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parse.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/property.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/property_code.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/property_factory.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signal.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signal_code.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signal_factory.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/symbol.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_annotation.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_argument.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_com.netsplit.Nih.Test_object.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_com.netsplit.Nih.Test_proxy.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_demarshal.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_indent.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_interface.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_main-main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_main-test_main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_marshal.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_method.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_node.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_output.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_parse.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_property.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_signal.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_symbol.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_type.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/type.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< demarshal_factory.o: tests/demarshal_factory.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT demarshal_factory.o -MD -MP -MF $(DEPDIR)/demarshal_factory.Tpo -c -o demarshal_factory.o `test -f 'tests/demarshal_factory.c' || echo '$(srcdir)/'`tests/demarshal_factory.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/demarshal_factory.Tpo $(DEPDIR)/demarshal_factory.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/demarshal_factory.c' object='demarshal_factory.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o demarshal_factory.o `test -f 'tests/demarshal_factory.c' || echo '$(srcdir)/'`tests/demarshal_factory.c demarshal_factory.obj: tests/demarshal_factory.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT demarshal_factory.obj -MD -MP -MF $(DEPDIR)/demarshal_factory.Tpo -c -o demarshal_factory.obj `if test -f 'tests/demarshal_factory.c'; then $(CYGPATH_W) 'tests/demarshal_factory.c'; else $(CYGPATH_W) '$(srcdir)/tests/demarshal_factory.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/demarshal_factory.Tpo $(DEPDIR)/demarshal_factory.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/demarshal_factory.c' object='demarshal_factory.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o demarshal_factory.obj `if test -f 'tests/demarshal_factory.c'; then $(CYGPATH_W) 'tests/demarshal_factory.c'; else $(CYGPATH_W) '$(srcdir)/tests/demarshal_factory.c'; fi` interface_factory.o: tests/interface_factory.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interface_factory.o -MD -MP -MF $(DEPDIR)/interface_factory.Tpo -c -o interface_factory.o `test -f 'tests/interface_factory.c' || echo '$(srcdir)/'`tests/interface_factory.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/interface_factory.Tpo $(DEPDIR)/interface_factory.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/interface_factory.c' object='interface_factory.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o interface_factory.o `test -f 'tests/interface_factory.c' || echo '$(srcdir)/'`tests/interface_factory.c interface_factory.obj: tests/interface_factory.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interface_factory.obj -MD -MP -MF $(DEPDIR)/interface_factory.Tpo -c -o interface_factory.obj `if test -f 'tests/interface_factory.c'; then $(CYGPATH_W) 'tests/interface_factory.c'; else $(CYGPATH_W) '$(srcdir)/tests/interface_factory.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/interface_factory.Tpo $(DEPDIR)/interface_factory.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/interface_factory.c' object='interface_factory.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o interface_factory.obj `if test -f 'tests/interface_factory.c'; then $(CYGPATH_W) 'tests/interface_factory.c'; else $(CYGPATH_W) '$(srcdir)/tests/interface_factory.c'; fi` marshal_factory.o: tests/marshal_factory.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT marshal_factory.o -MD -MP -MF $(DEPDIR)/marshal_factory.Tpo -c -o marshal_factory.o `test -f 'tests/marshal_factory.c' || echo '$(srcdir)/'`tests/marshal_factory.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/marshal_factory.Tpo $(DEPDIR)/marshal_factory.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/marshal_factory.c' object='marshal_factory.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o marshal_factory.o `test -f 'tests/marshal_factory.c' || echo '$(srcdir)/'`tests/marshal_factory.c marshal_factory.obj: tests/marshal_factory.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT marshal_factory.obj -MD -MP -MF $(DEPDIR)/marshal_factory.Tpo -c -o marshal_factory.obj `if test -f 'tests/marshal_factory.c'; then $(CYGPATH_W) 'tests/marshal_factory.c'; else $(CYGPATH_W) '$(srcdir)/tests/marshal_factory.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/marshal_factory.Tpo $(DEPDIR)/marshal_factory.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/marshal_factory.c' object='marshal_factory.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o marshal_factory.obj `if test -f 'tests/marshal_factory.c'; then $(CYGPATH_W) 'tests/marshal_factory.c'; else $(CYGPATH_W) '$(srcdir)/tests/marshal_factory.c'; fi` method_factory.o: tests/method_factory.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT method_factory.o -MD -MP -MF $(DEPDIR)/method_factory.Tpo -c -o method_factory.o `test -f 'tests/method_factory.c' || echo '$(srcdir)/'`tests/method_factory.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/method_factory.Tpo $(DEPDIR)/method_factory.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/method_factory.c' object='method_factory.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o method_factory.o `test -f 'tests/method_factory.c' || echo '$(srcdir)/'`tests/method_factory.c method_factory.obj: tests/method_factory.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT method_factory.obj -MD -MP -MF $(DEPDIR)/method_factory.Tpo -c -o method_factory.obj `if test -f 'tests/method_factory.c'; then $(CYGPATH_W) 'tests/method_factory.c'; else $(CYGPATH_W) '$(srcdir)/tests/method_factory.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/method_factory.Tpo $(DEPDIR)/method_factory.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/method_factory.c' object='method_factory.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o method_factory.obj `if test -f 'tests/method_factory.c'; then $(CYGPATH_W) 'tests/method_factory.c'; else $(CYGPATH_W) '$(srcdir)/tests/method_factory.c'; fi` property_factory.o: tests/property_factory.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT property_factory.o -MD -MP -MF $(DEPDIR)/property_factory.Tpo -c -o property_factory.o `test -f 'tests/property_factory.c' || echo '$(srcdir)/'`tests/property_factory.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/property_factory.Tpo $(DEPDIR)/property_factory.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/property_factory.c' object='property_factory.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o property_factory.o `test -f 'tests/property_factory.c' || echo '$(srcdir)/'`tests/property_factory.c property_factory.obj: tests/property_factory.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT property_factory.obj -MD -MP -MF $(DEPDIR)/property_factory.Tpo -c -o property_factory.obj `if test -f 'tests/property_factory.c'; then $(CYGPATH_W) 'tests/property_factory.c'; else $(CYGPATH_W) '$(srcdir)/tests/property_factory.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/property_factory.Tpo $(DEPDIR)/property_factory.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/property_factory.c' object='property_factory.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o property_factory.obj `if test -f 'tests/property_factory.c'; then $(CYGPATH_W) 'tests/property_factory.c'; else $(CYGPATH_W) '$(srcdir)/tests/property_factory.c'; fi` signal_factory.o: tests/signal_factory.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT signal_factory.o -MD -MP -MF $(DEPDIR)/signal_factory.Tpo -c -o signal_factory.o `test -f 'tests/signal_factory.c' || echo '$(srcdir)/'`tests/signal_factory.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/signal_factory.Tpo $(DEPDIR)/signal_factory.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/signal_factory.c' object='signal_factory.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o signal_factory.o `test -f 'tests/signal_factory.c' || echo '$(srcdir)/'`tests/signal_factory.c signal_factory.obj: tests/signal_factory.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT signal_factory.obj -MD -MP -MF $(DEPDIR)/signal_factory.Tpo -c -o signal_factory.obj `if test -f 'tests/signal_factory.c'; then $(CYGPATH_W) 'tests/signal_factory.c'; else $(CYGPATH_W) '$(srcdir)/tests/signal_factory.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/signal_factory.Tpo $(DEPDIR)/signal_factory.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/signal_factory.c' object='signal_factory.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o signal_factory.obj `if test -f 'tests/signal_factory.c'; then $(CYGPATH_W) 'tests/signal_factory.c'; else $(CYGPATH_W) '$(srcdir)/tests/signal_factory.c'; fi` test_annotation.o: tests/test_annotation.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_annotation.o -MD -MP -MF $(DEPDIR)/test_annotation.Tpo -c -o test_annotation.o `test -f 'tests/test_annotation.c' || echo '$(srcdir)/'`tests/test_annotation.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_annotation.Tpo $(DEPDIR)/test_annotation.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_annotation.c' object='test_annotation.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_annotation.o `test -f 'tests/test_annotation.c' || echo '$(srcdir)/'`tests/test_annotation.c test_annotation.obj: tests/test_annotation.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_annotation.obj -MD -MP -MF $(DEPDIR)/test_annotation.Tpo -c -o test_annotation.obj `if test -f 'tests/test_annotation.c'; then $(CYGPATH_W) 'tests/test_annotation.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_annotation.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_annotation.Tpo $(DEPDIR)/test_annotation.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_annotation.c' object='test_annotation.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_annotation.obj `if test -f 'tests/test_annotation.c'; then $(CYGPATH_W) 'tests/test_annotation.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_annotation.c'; fi` test_argument.o: tests/test_argument.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_argument.o -MD -MP -MF $(DEPDIR)/test_argument.Tpo -c -o test_argument.o `test -f 'tests/test_argument.c' || echo '$(srcdir)/'`tests/test_argument.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_argument.Tpo $(DEPDIR)/test_argument.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_argument.c' object='test_argument.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_argument.o `test -f 'tests/test_argument.c' || echo '$(srcdir)/'`tests/test_argument.c test_argument.obj: tests/test_argument.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_argument.obj -MD -MP -MF $(DEPDIR)/test_argument.Tpo -c -o test_argument.obj `if test -f 'tests/test_argument.c'; then $(CYGPATH_W) 'tests/test_argument.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_argument.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_argument.Tpo $(DEPDIR)/test_argument.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_argument.c' object='test_argument.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_argument.obj `if test -f 'tests/test_argument.c'; then $(CYGPATH_W) 'tests/test_argument.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_argument.c'; fi` test_com.netsplit.Nih.Test_object.o: tests/test_com.netsplit.Nih.Test_object.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_com.netsplit.Nih.Test_object.o -MD -MP -MF $(DEPDIR)/test_com.netsplit.Nih.Test_object.Tpo -c -o test_com.netsplit.Nih.Test_object.o `test -f 'tests/test_com.netsplit.Nih.Test_object.c' || echo '$(srcdir)/'`tests/test_com.netsplit.Nih.Test_object.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_com.netsplit.Nih.Test_object.Tpo $(DEPDIR)/test_com.netsplit.Nih.Test_object.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_com.netsplit.Nih.Test_object.c' object='test_com.netsplit.Nih.Test_object.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_com.netsplit.Nih.Test_object.o `test -f 'tests/test_com.netsplit.Nih.Test_object.c' || echo '$(srcdir)/'`tests/test_com.netsplit.Nih.Test_object.c test_com.netsplit.Nih.Test_object.obj: tests/test_com.netsplit.Nih.Test_object.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_com.netsplit.Nih.Test_object.obj -MD -MP -MF $(DEPDIR)/test_com.netsplit.Nih.Test_object.Tpo -c -o test_com.netsplit.Nih.Test_object.obj `if test -f 'tests/test_com.netsplit.Nih.Test_object.c'; then $(CYGPATH_W) 'tests/test_com.netsplit.Nih.Test_object.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_com.netsplit.Nih.Test_object.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_com.netsplit.Nih.Test_object.Tpo $(DEPDIR)/test_com.netsplit.Nih.Test_object.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_com.netsplit.Nih.Test_object.c' object='test_com.netsplit.Nih.Test_object.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_com.netsplit.Nih.Test_object.obj `if test -f 'tests/test_com.netsplit.Nih.Test_object.c'; then $(CYGPATH_W) 'tests/test_com.netsplit.Nih.Test_object.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_com.netsplit.Nih.Test_object.c'; fi` com.netsplit.Nih.Test_impl.o: tests/com.netsplit.Nih.Test_impl.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT com.netsplit.Nih.Test_impl.o -MD -MP -MF $(DEPDIR)/com.netsplit.Nih.Test_impl.Tpo -c -o com.netsplit.Nih.Test_impl.o `test -f 'tests/com.netsplit.Nih.Test_impl.c' || echo '$(srcdir)/'`tests/com.netsplit.Nih.Test_impl.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/com.netsplit.Nih.Test_impl.Tpo $(DEPDIR)/com.netsplit.Nih.Test_impl.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/com.netsplit.Nih.Test_impl.c' object='com.netsplit.Nih.Test_impl.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o com.netsplit.Nih.Test_impl.o `test -f 'tests/com.netsplit.Nih.Test_impl.c' || echo '$(srcdir)/'`tests/com.netsplit.Nih.Test_impl.c com.netsplit.Nih.Test_impl.obj: tests/com.netsplit.Nih.Test_impl.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT com.netsplit.Nih.Test_impl.obj -MD -MP -MF $(DEPDIR)/com.netsplit.Nih.Test_impl.Tpo -c -o com.netsplit.Nih.Test_impl.obj `if test -f 'tests/com.netsplit.Nih.Test_impl.c'; then $(CYGPATH_W) 'tests/com.netsplit.Nih.Test_impl.c'; else $(CYGPATH_W) '$(srcdir)/tests/com.netsplit.Nih.Test_impl.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/com.netsplit.Nih.Test_impl.Tpo $(DEPDIR)/com.netsplit.Nih.Test_impl.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/com.netsplit.Nih.Test_impl.c' object='com.netsplit.Nih.Test_impl.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o com.netsplit.Nih.Test_impl.obj `if test -f 'tests/com.netsplit.Nih.Test_impl.c'; then $(CYGPATH_W) 'tests/com.netsplit.Nih.Test_impl.c'; else $(CYGPATH_W) '$(srcdir)/tests/com.netsplit.Nih.Test_impl.c'; fi` com.netsplit.Nih.Test_object.o: tests/com.netsplit.Nih.Test_object.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT com.netsplit.Nih.Test_object.o -MD -MP -MF $(DEPDIR)/com.netsplit.Nih.Test_object.Tpo -c -o com.netsplit.Nih.Test_object.o `test -f 'tests/com.netsplit.Nih.Test_object.c' || echo '$(srcdir)/'`tests/com.netsplit.Nih.Test_object.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/com.netsplit.Nih.Test_object.Tpo $(DEPDIR)/com.netsplit.Nih.Test_object.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/com.netsplit.Nih.Test_object.c' object='com.netsplit.Nih.Test_object.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o com.netsplit.Nih.Test_object.o `test -f 'tests/com.netsplit.Nih.Test_object.c' || echo '$(srcdir)/'`tests/com.netsplit.Nih.Test_object.c com.netsplit.Nih.Test_object.obj: tests/com.netsplit.Nih.Test_object.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT com.netsplit.Nih.Test_object.obj -MD -MP -MF $(DEPDIR)/com.netsplit.Nih.Test_object.Tpo -c -o com.netsplit.Nih.Test_object.obj `if test -f 'tests/com.netsplit.Nih.Test_object.c'; then $(CYGPATH_W) 'tests/com.netsplit.Nih.Test_object.c'; else $(CYGPATH_W) '$(srcdir)/tests/com.netsplit.Nih.Test_object.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/com.netsplit.Nih.Test_object.Tpo $(DEPDIR)/com.netsplit.Nih.Test_object.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/com.netsplit.Nih.Test_object.c' object='com.netsplit.Nih.Test_object.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o com.netsplit.Nih.Test_object.obj `if test -f 'tests/com.netsplit.Nih.Test_object.c'; then $(CYGPATH_W) 'tests/com.netsplit.Nih.Test_object.c'; else $(CYGPATH_W) '$(srcdir)/tests/com.netsplit.Nih.Test_object.c'; fi` test_com.netsplit.Nih.Test_proxy.o: tests/test_com.netsplit.Nih.Test_proxy.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_com.netsplit.Nih.Test_proxy.o -MD -MP -MF $(DEPDIR)/test_com.netsplit.Nih.Test_proxy.Tpo -c -o test_com.netsplit.Nih.Test_proxy.o `test -f 'tests/test_com.netsplit.Nih.Test_proxy.c' || echo '$(srcdir)/'`tests/test_com.netsplit.Nih.Test_proxy.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_com.netsplit.Nih.Test_proxy.Tpo $(DEPDIR)/test_com.netsplit.Nih.Test_proxy.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_com.netsplit.Nih.Test_proxy.c' object='test_com.netsplit.Nih.Test_proxy.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_com.netsplit.Nih.Test_proxy.o `test -f 'tests/test_com.netsplit.Nih.Test_proxy.c' || echo '$(srcdir)/'`tests/test_com.netsplit.Nih.Test_proxy.c test_com.netsplit.Nih.Test_proxy.obj: tests/test_com.netsplit.Nih.Test_proxy.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_com.netsplit.Nih.Test_proxy.obj -MD -MP -MF $(DEPDIR)/test_com.netsplit.Nih.Test_proxy.Tpo -c -o test_com.netsplit.Nih.Test_proxy.obj `if test -f 'tests/test_com.netsplit.Nih.Test_proxy.c'; then $(CYGPATH_W) 'tests/test_com.netsplit.Nih.Test_proxy.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_com.netsplit.Nih.Test_proxy.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_com.netsplit.Nih.Test_proxy.Tpo $(DEPDIR)/test_com.netsplit.Nih.Test_proxy.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_com.netsplit.Nih.Test_proxy.c' object='test_com.netsplit.Nih.Test_proxy.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_com.netsplit.Nih.Test_proxy.obj `if test -f 'tests/test_com.netsplit.Nih.Test_proxy.c'; then $(CYGPATH_W) 'tests/test_com.netsplit.Nih.Test_proxy.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_com.netsplit.Nih.Test_proxy.c'; fi` com.netsplit.Nih.Test_proxy.o: tests/com.netsplit.Nih.Test_proxy.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT com.netsplit.Nih.Test_proxy.o -MD -MP -MF $(DEPDIR)/com.netsplit.Nih.Test_proxy.Tpo -c -o com.netsplit.Nih.Test_proxy.o `test -f 'tests/com.netsplit.Nih.Test_proxy.c' || echo '$(srcdir)/'`tests/com.netsplit.Nih.Test_proxy.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/com.netsplit.Nih.Test_proxy.Tpo $(DEPDIR)/com.netsplit.Nih.Test_proxy.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/com.netsplit.Nih.Test_proxy.c' object='com.netsplit.Nih.Test_proxy.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o com.netsplit.Nih.Test_proxy.o `test -f 'tests/com.netsplit.Nih.Test_proxy.c' || echo '$(srcdir)/'`tests/com.netsplit.Nih.Test_proxy.c com.netsplit.Nih.Test_proxy.obj: tests/com.netsplit.Nih.Test_proxy.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT com.netsplit.Nih.Test_proxy.obj -MD -MP -MF $(DEPDIR)/com.netsplit.Nih.Test_proxy.Tpo -c -o com.netsplit.Nih.Test_proxy.obj `if test -f 'tests/com.netsplit.Nih.Test_proxy.c'; then $(CYGPATH_W) 'tests/com.netsplit.Nih.Test_proxy.c'; else $(CYGPATH_W) '$(srcdir)/tests/com.netsplit.Nih.Test_proxy.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/com.netsplit.Nih.Test_proxy.Tpo $(DEPDIR)/com.netsplit.Nih.Test_proxy.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/com.netsplit.Nih.Test_proxy.c' object='com.netsplit.Nih.Test_proxy.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o com.netsplit.Nih.Test_proxy.obj `if test -f 'tests/com.netsplit.Nih.Test_proxy.c'; then $(CYGPATH_W) 'tests/com.netsplit.Nih.Test_proxy.c'; else $(CYGPATH_W) '$(srcdir)/tests/com.netsplit.Nih.Test_proxy.c'; fi` test_demarshal.o: tests/test_demarshal.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_demarshal.o -MD -MP -MF $(DEPDIR)/test_demarshal.Tpo -c -o test_demarshal.o `test -f 'tests/test_demarshal.c' || echo '$(srcdir)/'`tests/test_demarshal.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_demarshal.Tpo $(DEPDIR)/test_demarshal.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_demarshal.c' object='test_demarshal.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_demarshal.o `test -f 'tests/test_demarshal.c' || echo '$(srcdir)/'`tests/test_demarshal.c test_demarshal.obj: tests/test_demarshal.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_demarshal.obj -MD -MP -MF $(DEPDIR)/test_demarshal.Tpo -c -o test_demarshal.obj `if test -f 'tests/test_demarshal.c'; then $(CYGPATH_W) 'tests/test_demarshal.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_demarshal.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_demarshal.Tpo $(DEPDIR)/test_demarshal.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_demarshal.c' object='test_demarshal.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_demarshal.obj `if test -f 'tests/test_demarshal.c'; then $(CYGPATH_W) 'tests/test_demarshal.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_demarshal.c'; fi` demarshal_code.o: tests/demarshal_code.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT demarshal_code.o -MD -MP -MF $(DEPDIR)/demarshal_code.Tpo -c -o demarshal_code.o `test -f 'tests/demarshal_code.c' || echo '$(srcdir)/'`tests/demarshal_code.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/demarshal_code.Tpo $(DEPDIR)/demarshal_code.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/demarshal_code.c' object='demarshal_code.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o demarshal_code.o `test -f 'tests/demarshal_code.c' || echo '$(srcdir)/'`tests/demarshal_code.c demarshal_code.obj: tests/demarshal_code.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT demarshal_code.obj -MD -MP -MF $(DEPDIR)/demarshal_code.Tpo -c -o demarshal_code.obj `if test -f 'tests/demarshal_code.c'; then $(CYGPATH_W) 'tests/demarshal_code.c'; else $(CYGPATH_W) '$(srcdir)/tests/demarshal_code.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/demarshal_code.Tpo $(DEPDIR)/demarshal_code.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/demarshal_code.c' object='demarshal_code.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o demarshal_code.obj `if test -f 'tests/demarshal_code.c'; then $(CYGPATH_W) 'tests/demarshal_code.c'; else $(CYGPATH_W) '$(srcdir)/tests/demarshal_code.c'; fi` test_indent.o: tests/test_indent.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_indent.o -MD -MP -MF $(DEPDIR)/test_indent.Tpo -c -o test_indent.o `test -f 'tests/test_indent.c' || echo '$(srcdir)/'`tests/test_indent.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_indent.Tpo $(DEPDIR)/test_indent.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_indent.c' object='test_indent.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_indent.o `test -f 'tests/test_indent.c' || echo '$(srcdir)/'`tests/test_indent.c test_indent.obj: tests/test_indent.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_indent.obj -MD -MP -MF $(DEPDIR)/test_indent.Tpo -c -o test_indent.obj `if test -f 'tests/test_indent.c'; then $(CYGPATH_W) 'tests/test_indent.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_indent.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_indent.Tpo $(DEPDIR)/test_indent.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_indent.c' object='test_indent.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_indent.obj `if test -f 'tests/test_indent.c'; then $(CYGPATH_W) 'tests/test_indent.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_indent.c'; fi` test_interface.o: tests/test_interface.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_interface.o -MD -MP -MF $(DEPDIR)/test_interface.Tpo -c -o test_interface.o `test -f 'tests/test_interface.c' || echo '$(srcdir)/'`tests/test_interface.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_interface.Tpo $(DEPDIR)/test_interface.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_interface.c' object='test_interface.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_interface.o `test -f 'tests/test_interface.c' || echo '$(srcdir)/'`tests/test_interface.c test_interface.obj: tests/test_interface.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_interface.obj -MD -MP -MF $(DEPDIR)/test_interface.Tpo -c -o test_interface.obj `if test -f 'tests/test_interface.c'; then $(CYGPATH_W) 'tests/test_interface.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_interface.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_interface.Tpo $(DEPDIR)/test_interface.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_interface.c' object='test_interface.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_interface.obj `if test -f 'tests/test_interface.c'; then $(CYGPATH_W) 'tests/test_interface.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_interface.c'; fi` interface_code.o: tests/interface_code.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interface_code.o -MD -MP -MF $(DEPDIR)/interface_code.Tpo -c -o interface_code.o `test -f 'tests/interface_code.c' || echo '$(srcdir)/'`tests/interface_code.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/interface_code.Tpo $(DEPDIR)/interface_code.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/interface_code.c' object='interface_code.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o interface_code.o `test -f 'tests/interface_code.c' || echo '$(srcdir)/'`tests/interface_code.c interface_code.obj: tests/interface_code.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interface_code.obj -MD -MP -MF $(DEPDIR)/interface_code.Tpo -c -o interface_code.obj `if test -f 'tests/interface_code.c'; then $(CYGPATH_W) 'tests/interface_code.c'; else $(CYGPATH_W) '$(srcdir)/tests/interface_code.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/interface_code.Tpo $(DEPDIR)/interface_code.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/interface_code.c' object='interface_code.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o interface_code.obj `if test -f 'tests/interface_code.c'; then $(CYGPATH_W) 'tests/interface_code.c'; else $(CYGPATH_W) '$(srcdir)/tests/interface_code.c'; fi` test_main-test_main.o: tests/test_main.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_main_CFLAGS) $(CFLAGS) -MT test_main-test_main.o -MD -MP -MF $(DEPDIR)/test_main-test_main.Tpo -c -o test_main-test_main.o `test -f 'tests/test_main.c' || echo '$(srcdir)/'`tests/test_main.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_main-test_main.Tpo $(DEPDIR)/test_main-test_main.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_main.c' object='test_main-test_main.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_main_CFLAGS) $(CFLAGS) -c -o test_main-test_main.o `test -f 'tests/test_main.c' || echo '$(srcdir)/'`tests/test_main.c test_main-test_main.obj: tests/test_main.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_main_CFLAGS) $(CFLAGS) -MT test_main-test_main.obj -MD -MP -MF $(DEPDIR)/test_main-test_main.Tpo -c -o test_main-test_main.obj `if test -f 'tests/test_main.c'; then $(CYGPATH_W) 'tests/test_main.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_main.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_main-test_main.Tpo $(DEPDIR)/test_main-test_main.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_main.c' object='test_main-test_main.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_main_CFLAGS) $(CFLAGS) -c -o test_main-test_main.obj `if test -f 'tests/test_main.c'; then $(CYGPATH_W) 'tests/test_main.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_main.c'; fi` test_main-main.o: main.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_main_CFLAGS) $(CFLAGS) -MT test_main-main.o -MD -MP -MF $(DEPDIR)/test_main-main.Tpo -c -o test_main-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_main-main.Tpo $(DEPDIR)/test_main-main.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='main.c' object='test_main-main.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_main_CFLAGS) $(CFLAGS) -c -o test_main-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c test_main-main.obj: main.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_main_CFLAGS) $(CFLAGS) -MT test_main-main.obj -MD -MP -MF $(DEPDIR)/test_main-main.Tpo -c -o test_main-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_main-main.Tpo $(DEPDIR)/test_main-main.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='main.c' object='test_main-main.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_main_CFLAGS) $(CFLAGS) -c -o test_main-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi` test_marshal.o: tests/test_marshal.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_marshal.o -MD -MP -MF $(DEPDIR)/test_marshal.Tpo -c -o test_marshal.o `test -f 'tests/test_marshal.c' || echo '$(srcdir)/'`tests/test_marshal.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_marshal.Tpo $(DEPDIR)/test_marshal.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_marshal.c' object='test_marshal.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_marshal.o `test -f 'tests/test_marshal.c' || echo '$(srcdir)/'`tests/test_marshal.c test_marshal.obj: tests/test_marshal.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_marshal.obj -MD -MP -MF $(DEPDIR)/test_marshal.Tpo -c -o test_marshal.obj `if test -f 'tests/test_marshal.c'; then $(CYGPATH_W) 'tests/test_marshal.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_marshal.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_marshal.Tpo $(DEPDIR)/test_marshal.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_marshal.c' object='test_marshal.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_marshal.obj `if test -f 'tests/test_marshal.c'; then $(CYGPATH_W) 'tests/test_marshal.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_marshal.c'; fi` marshal_code.o: tests/marshal_code.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT marshal_code.o -MD -MP -MF $(DEPDIR)/marshal_code.Tpo -c -o marshal_code.o `test -f 'tests/marshal_code.c' || echo '$(srcdir)/'`tests/marshal_code.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/marshal_code.Tpo $(DEPDIR)/marshal_code.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/marshal_code.c' object='marshal_code.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o marshal_code.o `test -f 'tests/marshal_code.c' || echo '$(srcdir)/'`tests/marshal_code.c marshal_code.obj: tests/marshal_code.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT marshal_code.obj -MD -MP -MF $(DEPDIR)/marshal_code.Tpo -c -o marshal_code.obj `if test -f 'tests/marshal_code.c'; then $(CYGPATH_W) 'tests/marshal_code.c'; else $(CYGPATH_W) '$(srcdir)/tests/marshal_code.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/marshal_code.Tpo $(DEPDIR)/marshal_code.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/marshal_code.c' object='marshal_code.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o marshal_code.obj `if test -f 'tests/marshal_code.c'; then $(CYGPATH_W) 'tests/marshal_code.c'; else $(CYGPATH_W) '$(srcdir)/tests/marshal_code.c'; fi` test_method.o: tests/test_method.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_method.o -MD -MP -MF $(DEPDIR)/test_method.Tpo -c -o test_method.o `test -f 'tests/test_method.c' || echo '$(srcdir)/'`tests/test_method.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_method.Tpo $(DEPDIR)/test_method.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_method.c' object='test_method.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_method.o `test -f 'tests/test_method.c' || echo '$(srcdir)/'`tests/test_method.c test_method.obj: tests/test_method.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_method.obj -MD -MP -MF $(DEPDIR)/test_method.Tpo -c -o test_method.obj `if test -f 'tests/test_method.c'; then $(CYGPATH_W) 'tests/test_method.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_method.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_method.Tpo $(DEPDIR)/test_method.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_method.c' object='test_method.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_method.obj `if test -f 'tests/test_method.c'; then $(CYGPATH_W) 'tests/test_method.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_method.c'; fi` method_code.o: tests/method_code.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT method_code.o -MD -MP -MF $(DEPDIR)/method_code.Tpo -c -o method_code.o `test -f 'tests/method_code.c' || echo '$(srcdir)/'`tests/method_code.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/method_code.Tpo $(DEPDIR)/method_code.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/method_code.c' object='method_code.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o method_code.o `test -f 'tests/method_code.c' || echo '$(srcdir)/'`tests/method_code.c method_code.obj: tests/method_code.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT method_code.obj -MD -MP -MF $(DEPDIR)/method_code.Tpo -c -o method_code.obj `if test -f 'tests/method_code.c'; then $(CYGPATH_W) 'tests/method_code.c'; else $(CYGPATH_W) '$(srcdir)/tests/method_code.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/method_code.Tpo $(DEPDIR)/method_code.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/method_code.c' object='method_code.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o method_code.obj `if test -f 'tests/method_code.c'; then $(CYGPATH_W) 'tests/method_code.c'; else $(CYGPATH_W) '$(srcdir)/tests/method_code.c'; fi` test_node.o: tests/test_node.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_node.o -MD -MP -MF $(DEPDIR)/test_node.Tpo -c -o test_node.o `test -f 'tests/test_node.c' || echo '$(srcdir)/'`tests/test_node.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_node.Tpo $(DEPDIR)/test_node.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_node.c' object='test_node.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_node.o `test -f 'tests/test_node.c' || echo '$(srcdir)/'`tests/test_node.c test_node.obj: tests/test_node.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_node.obj -MD -MP -MF $(DEPDIR)/test_node.Tpo -c -o test_node.obj `if test -f 'tests/test_node.c'; then $(CYGPATH_W) 'tests/test_node.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_node.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_node.Tpo $(DEPDIR)/test_node.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_node.c' object='test_node.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_node.obj `if test -f 'tests/test_node.c'; then $(CYGPATH_W) 'tests/test_node.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_node.c'; fi` test_output.o: tests/test_output.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_output.o -MD -MP -MF $(DEPDIR)/test_output.Tpo -c -o test_output.o `test -f 'tests/test_output.c' || echo '$(srcdir)/'`tests/test_output.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_output.Tpo $(DEPDIR)/test_output.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_output.c' object='test_output.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_output.o `test -f 'tests/test_output.c' || echo '$(srcdir)/'`tests/test_output.c test_output.obj: tests/test_output.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_output.obj -MD -MP -MF $(DEPDIR)/test_output.Tpo -c -o test_output.obj `if test -f 'tests/test_output.c'; then $(CYGPATH_W) 'tests/test_output.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_output.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_output.Tpo $(DEPDIR)/test_output.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_output.c' object='test_output.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_output.obj `if test -f 'tests/test_output.c'; then $(CYGPATH_W) 'tests/test_output.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_output.c'; fi` test_parse.o: tests/test_parse.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_parse.o -MD -MP -MF $(DEPDIR)/test_parse.Tpo -c -o test_parse.o `test -f 'tests/test_parse.c' || echo '$(srcdir)/'`tests/test_parse.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_parse.Tpo $(DEPDIR)/test_parse.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_parse.c' object='test_parse.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_parse.o `test -f 'tests/test_parse.c' || echo '$(srcdir)/'`tests/test_parse.c test_parse.obj: tests/test_parse.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_parse.obj -MD -MP -MF $(DEPDIR)/test_parse.Tpo -c -o test_parse.obj `if test -f 'tests/test_parse.c'; then $(CYGPATH_W) 'tests/test_parse.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_parse.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_parse.Tpo $(DEPDIR)/test_parse.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_parse.c' object='test_parse.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_parse.obj `if test -f 'tests/test_parse.c'; then $(CYGPATH_W) 'tests/test_parse.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_parse.c'; fi` test_property.o: tests/test_property.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_property.o -MD -MP -MF $(DEPDIR)/test_property.Tpo -c -o test_property.o `test -f 'tests/test_property.c' || echo '$(srcdir)/'`tests/test_property.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_property.Tpo $(DEPDIR)/test_property.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_property.c' object='test_property.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_property.o `test -f 'tests/test_property.c' || echo '$(srcdir)/'`tests/test_property.c test_property.obj: tests/test_property.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_property.obj -MD -MP -MF $(DEPDIR)/test_property.Tpo -c -o test_property.obj `if test -f 'tests/test_property.c'; then $(CYGPATH_W) 'tests/test_property.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_property.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_property.Tpo $(DEPDIR)/test_property.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_property.c' object='test_property.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_property.obj `if test -f 'tests/test_property.c'; then $(CYGPATH_W) 'tests/test_property.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_property.c'; fi` property_code.o: tests/property_code.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT property_code.o -MD -MP -MF $(DEPDIR)/property_code.Tpo -c -o property_code.o `test -f 'tests/property_code.c' || echo '$(srcdir)/'`tests/property_code.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/property_code.Tpo $(DEPDIR)/property_code.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/property_code.c' object='property_code.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o property_code.o `test -f 'tests/property_code.c' || echo '$(srcdir)/'`tests/property_code.c property_code.obj: tests/property_code.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT property_code.obj -MD -MP -MF $(DEPDIR)/property_code.Tpo -c -o property_code.obj `if test -f 'tests/property_code.c'; then $(CYGPATH_W) 'tests/property_code.c'; else $(CYGPATH_W) '$(srcdir)/tests/property_code.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/property_code.Tpo $(DEPDIR)/property_code.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/property_code.c' object='property_code.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o property_code.obj `if test -f 'tests/property_code.c'; then $(CYGPATH_W) 'tests/property_code.c'; else $(CYGPATH_W) '$(srcdir)/tests/property_code.c'; fi` test_signal.o: tests/test_signal.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_signal.o -MD -MP -MF $(DEPDIR)/test_signal.Tpo -c -o test_signal.o `test -f 'tests/test_signal.c' || echo '$(srcdir)/'`tests/test_signal.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_signal.Tpo $(DEPDIR)/test_signal.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_signal.c' object='test_signal.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_signal.o `test -f 'tests/test_signal.c' || echo '$(srcdir)/'`tests/test_signal.c test_signal.obj: tests/test_signal.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_signal.obj -MD -MP -MF $(DEPDIR)/test_signal.Tpo -c -o test_signal.obj `if test -f 'tests/test_signal.c'; then $(CYGPATH_W) 'tests/test_signal.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_signal.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_signal.Tpo $(DEPDIR)/test_signal.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_signal.c' object='test_signal.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_signal.obj `if test -f 'tests/test_signal.c'; then $(CYGPATH_W) 'tests/test_signal.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_signal.c'; fi` signal_code.o: tests/signal_code.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT signal_code.o -MD -MP -MF $(DEPDIR)/signal_code.Tpo -c -o signal_code.o `test -f 'tests/signal_code.c' || echo '$(srcdir)/'`tests/signal_code.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/signal_code.Tpo $(DEPDIR)/signal_code.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/signal_code.c' object='signal_code.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o signal_code.o `test -f 'tests/signal_code.c' || echo '$(srcdir)/'`tests/signal_code.c signal_code.obj: tests/signal_code.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT signal_code.obj -MD -MP -MF $(DEPDIR)/signal_code.Tpo -c -o signal_code.obj `if test -f 'tests/signal_code.c'; then $(CYGPATH_W) 'tests/signal_code.c'; else $(CYGPATH_W) '$(srcdir)/tests/signal_code.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/signal_code.Tpo $(DEPDIR)/signal_code.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/signal_code.c' object='signal_code.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o signal_code.obj `if test -f 'tests/signal_code.c'; then $(CYGPATH_W) 'tests/signal_code.c'; else $(CYGPATH_W) '$(srcdir)/tests/signal_code.c'; fi` test_symbol.o: tests/test_symbol.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_symbol.o -MD -MP -MF $(DEPDIR)/test_symbol.Tpo -c -o test_symbol.o `test -f 'tests/test_symbol.c' || echo '$(srcdir)/'`tests/test_symbol.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_symbol.Tpo $(DEPDIR)/test_symbol.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_symbol.c' object='test_symbol.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_symbol.o `test -f 'tests/test_symbol.c' || echo '$(srcdir)/'`tests/test_symbol.c test_symbol.obj: tests/test_symbol.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_symbol.obj -MD -MP -MF $(DEPDIR)/test_symbol.Tpo -c -o test_symbol.obj `if test -f 'tests/test_symbol.c'; then $(CYGPATH_W) 'tests/test_symbol.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_symbol.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_symbol.Tpo $(DEPDIR)/test_symbol.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_symbol.c' object='test_symbol.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_symbol.obj `if test -f 'tests/test_symbol.c'; then $(CYGPATH_W) 'tests/test_symbol.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_symbol.c'; fi` test_type.o: tests/test_type.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_type.o -MD -MP -MF $(DEPDIR)/test_type.Tpo -c -o test_type.o `test -f 'tests/test_type.c' || echo '$(srcdir)/'`tests/test_type.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_type.Tpo $(DEPDIR)/test_type.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_type.c' object='test_type.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_type.o `test -f 'tests/test_type.c' || echo '$(srcdir)/'`tests/test_type.c test_type.obj: tests/test_type.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_type.obj -MD -MP -MF $(DEPDIR)/test_type.Tpo -c -o test_type.obj `if test -f 'tests/test_type.c'; then $(CYGPATH_W) 'tests/test_type.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_type.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_type.Tpo $(DEPDIR)/test_type.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_type.c' object='test_type.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_type.obj `if test -f 'tests/test_type.c'; then $(CYGPATH_W) 'tests/test_type.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_type.c'; fi` mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-man1: $(dist_man_MANS) @$(NORMAL_INSTALL) test -z "$(man1dir)" || $(MKDIR_P) "$(DESTDIR)$(man1dir)" @list=''; test -n "$(man1dir)" || exit 0; \ { for i in $$list; do echo "$$i"; done; \ l2='$(dist_man_MANS)'; for i in $$l2; do echo "$$i"; done | \ sed -n '/\.1[a-z]*$$/p'; \ } | while read p; do \ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; echo "$$p"; \ done | \ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \ sed 'N;N;s,\n, ,g' | { \ list=; while read file base inst; do \ if test "$$base" = "$$inst"; then list="$$list $$file"; else \ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man1dir)/$$inst'"; \ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man1dir)/$$inst" || exit $$?; \ fi; \ done; \ for i in $$list; do echo "$$i"; done | $(am__base_list) | \ while read files; do \ test -z "$$files" || { \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man1dir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(man1dir)" || exit $$?; }; \ done; } uninstall-man1: @$(NORMAL_UNINSTALL) @list=''; test -n "$(man1dir)" || exit 0; \ files=`{ for i in $$list; do echo "$$i"; done; \ l2='$(dist_man_MANS)'; for i in $$l2; do echo "$$i"; done | \ sed -n '/\.1[a-z]*$$/p'; \ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \ test -z "$$files" || { \ echo " ( cd '$(DESTDIR)$(man1dir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(man1dir)" && rm -f $$files; } ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) set x; \ here=`pwd`; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags check-TESTS: $(TESTS) @failed=0; all=0; xfail=0; xpass=0; skip=0; \ srcdir=$(srcdir); export srcdir; \ list=' $(TESTS) '; \ $(am__tty_colors); \ if test -n "$$list"; then \ for tst in $$list; do \ if test -f ./$$tst; then dir=./; \ elif test -f $$tst; then dir=; \ else dir="$(srcdir)/"; fi; \ if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ all=`expr $$all + 1`; \ case " $(XFAIL_TESTS) " in \ *[\ \ ]$$tst[\ \ ]*) \ xpass=`expr $$xpass + 1`; \ failed=`expr $$failed + 1`; \ col=$$red; res=XPASS; \ ;; \ *) \ col=$$grn; res=PASS; \ ;; \ esac; \ elif test $$? -ne 77; then \ all=`expr $$all + 1`; \ case " $(XFAIL_TESTS) " in \ *[\ \ ]$$tst[\ \ ]*) \ xfail=`expr $$xfail + 1`; \ col=$$lgn; res=XFAIL; \ ;; \ *) \ failed=`expr $$failed + 1`; \ col=$$red; res=FAIL; \ ;; \ esac; \ else \ skip=`expr $$skip + 1`; \ col=$$blu; res=SKIP; \ fi; \ echo "$${col}$$res$${std}: $$tst"; \ done; \ if test "$$all" -eq 1; then \ tests="test"; \ All=""; \ else \ tests="tests"; \ All="All "; \ fi; \ if test "$$failed" -eq 0; then \ if test "$$xfail" -eq 0; then \ banner="$$All$$all $$tests passed"; \ else \ if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ fi; \ else \ if test "$$xpass" -eq 0; then \ banner="$$failed of $$all $$tests failed"; \ else \ if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ fi; \ fi; \ dashes="$$banner"; \ skipped=""; \ if test "$$skip" -ne 0; then \ if test "$$skip" -eq 1; then \ skipped="($$skip test was not run)"; \ else \ skipped="($$skip tests were not run)"; \ fi; \ test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ dashes="$$skipped"; \ fi; \ report=""; \ if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ report="Please report to $(PACKAGE_BUGREPORT)"; \ test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ dashes="$$report"; \ fi; \ dashes=`echo "$$dashes" | sed s/./=/g`; \ if test "$$failed" -eq 0; then \ echo "$$grn$$dashes"; \ else \ echo "$$red$$dashes"; \ fi; \ echo "$$banner"; \ test -z "$$skipped" || echo "$$skipped"; \ test -z "$$report" || echo "$$report"; \ echo "$$dashes$$std"; \ test "$$failed" -eq 0; \ else :; fi distdir: $(DISTFILES) @list='$(MANS)'; if test -n "$$list"; then \ list=`for p in $$list; do \ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ if test -f "$$d$$p"; then echo "$$d$$p"; else :; fi; done`; \ if test -n "$$list" && \ grep 'ab help2man is required to generate this page' $$list >/dev/null; then \ echo "error: found man pages containing the \`missing help2man' replacement text:" >&2; \ grep -l 'ab help2man is required to generate this page' $$list | sed 's/^/ /' >&2; \ echo " to fix them, install help2man, remove and regenerate the man pages;" >&2; \ echo " typically \`make maintainer-clean' will remove them" >&2; \ exit 1; \ else :; fi; \ else :; fi @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) check-am all-am: Makefile $(PROGRAMS) $(MANS) installdirs: for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ `test -z '$(STRIP)' || \ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install mostlyclean-generic: clean-generic: -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) clean: clean-am clean-am: clean-binPROGRAMS clean-checkPROGRAMS clean-generic \ clean-libtool clean-local mostlyclean-am distclean: distclean-am -rm -rf ./$(DEPDIR) -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-man install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-binPROGRAMS install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-man1 install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -rf ./$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic \ maintainer-clean-local mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-binPROGRAMS uninstall-man uninstall-man: uninstall-man1 .MAKE: all check check-am install install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \ clean-binPROGRAMS clean-checkPROGRAMS clean-generic \ clean-libtool clean-local ctags distclean distclean-compile \ distclean-generic distclean-libtool distclean-tags distdir dvi \ dvi-am html html-am info info-am install install-am \ install-binPROGRAMS install-data install-data-am install-dvi \ install-dvi-am install-exec install-exec-am install-html \ install-html-am install-info install-info-am install-man \ install-man1 install-pdf install-pdf-am install-ps \ install-ps-am install-strip installcheck installcheck-am \ installdirs maintainer-clean maintainer-clean-generic \ maintainer-clean-local mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags uninstall uninstall-am uninstall-binPROGRAMS \ uninstall-man uninstall-man1 $(com_netsplit_Nih_Test_object_OUTPUTS): $(com_netsplit_Nih_Test_object_XML) $(builddir)/nih-dbus-tool $(AM_V_GEN)$(MKDIR_P) `echo "$@" | \ sed '/\//!d;s,/[^/]*$$,,' | \ sort -u` && \ $(NIH_DBUS_TOOL) --mode=object --prefix=my --output=$@ $< $(com_netsplit_Nih_Test_proxy_OUTPUTS): $(com_netsplit_Nih_Test_proxy_XML) $(builddir)/nih-dbus-tool $(AM_V_GEN)$(MKDIR_P) `echo "$@" | \ sed '/\//!d;s,/[^/]*$$,,' | \ sort -u` && \ $(NIH_DBUS_TOOL) --mode=proxy --prefix=proxy --output=$@ $< tests/marshal_code.c: $(builddir)/marshal_factory $(AM_V_GEN)$(builddir)/marshal_factory > $@ tests/demarshal_code.c: $(builddir)/demarshal_factory $(AM_V_GEN)$(builddir)/demarshal_factory > $@ tests/interface_code.c: $(builddir)/interface_factory $(AM_V_GEN)$(builddir)/interface_factory > $@ tests/method_code.c: $(builddir)/method_factory $(AM_V_GEN)$(builddir)/method_factory > $@ tests/signal_code.c: $(builddir)/signal_factory $(AM_V_GEN)$(builddir)/signal_factory > $@ tests/property_code.c: $(builddir)/property_factory $(AM_V_GEN)$(builddir)/property_factory > $@ .PHONY: tests tests: $(BUILT_SOURCES) $(check_PROGRAMS) clean-local: rm -f *.gcno *.gcda maintainer-clean-local: rm -f *.gcov # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: libnih-1.0.3/nih-dbus-tool/node.c0000644000175000017500000007343011445765555013506 00000000000000/* nih-dbus-tool * * node.c - top-level object parsing and handling * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include "symbol.h" #include "indent.h" #include "type.h" #include "node.h" #include "interface.h" #include "parse.h" #include "errors.h" /** * node_path_valid: * @path: Object path to verify. * * Verifies whether @path matches the specification for D-Bus object paths. * * Returns: TRUE if valid, FALSE if not. **/ int node_path_valid (const char *path) { nih_assert (path != NULL); /* Path must begin with a '/' character */ if (path[0] != '/') return FALSE; /* We can get away with just using strlen() here even through path * is in UTF-8 because all the valid characters are ASCII. */ for (size_t i = 1; i < strlen (path); i++) { /* Path components may be separated by single '/' characters, * multiple ones are not allowed. */ if (path[i] == '/') { if (path[i-1] == '/') return FALSE; continue; } /* Valid characters are [A-Za-z0-9_] */ if ( ((path[i] < 'A') || (path[i] > 'Z')) && ((path[i] < 'a') || (path[i] > 'z')) && ((path[i] < '0') || (path[i] > '9')) && (path[i] != '_')) return FALSE; } /* Final character may not be '/' unless it's the root object. */ if ((strlen (path) > 1) && (path[strlen (path) - 1] == '/')) return FALSE; return TRUE; } /** * node_new: * @parent: parent object for new node, * @path: D-Bus path of node. * * Allocates a new D-Bus object Node data structure, with the path optionally * set to @path. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned node. When all parents * of the returned node are freed, the returned node will also be * freed. * * Returns: the new node or NULL if the allocation failed. **/ Node * node_new (const void *parent, const char *path) { Node *node; node = nih_new (parent, Node); if (! node) return NULL; if (path) { node->path = nih_strdup (node, path); if (! node->path) { nih_free (node); return NULL; } } else { node->path = NULL; } nih_list_init (&node->interfaces); return node; } /** * node_start_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed, * @attr: NULL-terminated array of attribute name and value pairs. * * This function is called by parse_start_tag() for a "node" start * tag, the top-level of the introspection data and defining a D-Bus * object. * * If the node does not appear at the top-level a warning is emitted * (unless directly inside another node tag) and the tag will be ignored. * * Nodes may have a "name" attribute containing the D-Bus object path * of the node. * * Any unknown attributes result in a warning and will be ignored. * * A Node object will be allocated and pushed onto the stack, this is not * saved into the context until the end tag is found. * * Returns: zero on success, negative value on raised error. **/ int node_start_tag (XML_Parser xmlp, const char * tag, char * const *attr) { ParseContext * context; ParseStack * parent; nih_local Node *node = NULL; char * const * key; char * const * value; const char * name = NULL; nih_assert (xmlp != NULL); nih_assert (tag != NULL); nih_assert (attr != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); /* Nodes should only appear at the top-level, unless they're within * another node in which case we just ignore them. */ parent = parse_stack_top (&context->stack); if (parent) { if (parent->type != PARSE_NODE) { nih_warn ("%s:%zu:%zu: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unexpected tag")); } if (! parse_stack_push (NULL, &context->stack, PARSE_IGNORED, NULL)) nih_return_system_error (-1); return 0; } /* Retrieve the name from the attributes */ for (key = attr; key && *key; key += 2) { value = key + 1; nih_assert (value && *value); if (! strcmp (*key, "name")) { name = *value; } else { nih_warn ("%s:%zu:%zu: %s: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unknown attribute"), *key); } } /* If we have a name check that it's valid */ if (name && (! node_path_valid (name))) nih_return_error (-1, NODE_INVALID_PATH, _(NODE_INVALID_PATH_STR)); /* Allocate a Node object and push onto the stack */ node = node_new (NULL, name); if (! node) nih_return_system_error (-1); if (! parse_stack_push (NULL, &context->stack, PARSE_NODE, node)) { nih_error_raise_system (); return -1; } return 0; } /** * node_end_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed. * * This function is called by parse_end_tag() for a "node" end * tag, and matches a call to node_start_tag() made at the same parsing * level. * * The node is set in the context so it can be returned once the parser * completes. * * Returns: zero on success, negative value on raised error. **/ int node_end_tag (XML_Parser xmlp, const char *tag) { ParseContext *context; ParseStack * entry; nih_assert (xmlp != NULL); nih_assert (tag != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); entry = parse_stack_top (&context->stack); nih_assert (entry != NULL); nih_assert (entry->type == PARSE_NODE); nih_debug ("Set parsed node to %s", entry->node->path ?: "(unknown)"); nih_assert (context->node == NULL); context->node = entry->node; nih_ref (entry->node, context->parent); nih_unref (entry->node, entry); nih_free (entry); return 0; } /** * node_lookup_interface: * @node: node to search, * @symbol: interface symbol to find. * * Finds an interface in @node's interfaces list which has the generated * or supplied C symbol @symbol. If @symbol is NULL, the default interface * will be returned. * * Returns: interface found or NULL if no interface matches. **/ Interface * node_lookup_interface (Node * node, const char *symbol) { nih_assert (node != NULL); NIH_LIST_FOREACH (&node->interfaces, iter) { Interface *interface = (Interface *)iter; if ((interface->symbol && symbol && (! strcmp (interface->symbol, symbol))) || ((! interface->symbol) && (! symbol))) return interface; } return NULL; } /** * node_interfaces_array: * @parent: parent object for new string, * @prefix: prefix for array name, * @node: node to generate array for, * @object: whether array is for an object or proxy, * @prototypes: list to append prototypes to. * * Generates C code to declare an array of NihDBusInterface pointers for * the node @node, the code includes each of the NihDBusInterface structure * definitions individually as well as the array definitions for methods, * signals, properties and their arguments in them. * * If @object is TRUE, the array will be for an object definition so method * handler function and property getter and setter function pointers will * be filled in. If @object is FALSE, the array will be for a proxy * definition so the signal filter function pointers will be filled in. * * The prototype of the returned variable declaration, and the prototypes * of the interface structures, are returned as TypeVar objects appended * to the @prototypes list. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * node_interfaces_array (const void *parent, const char *prefix, Node * node, int object, NihList * prototypes) { nih_local char *name = NULL; nih_local char *block = NULL; char * code = NULL; TypeVar * var; nih_assert (prefix != NULL); nih_assert (node != NULL); nih_assert (prototypes != NULL); name = symbol_extern (NULL, prefix, NULL, NULL, "interfaces", NULL); if (! name) return NULL; /* Append the address of each of the interface structures to the * block we build, and the code to the interfaces list. */ NIH_LIST_FOREACH (&node->interfaces, iter) { Interface * interface = (Interface *)iter; NihList struct_prototypes; nih_local char *struct_code = NULL; nih_list_init (&struct_prototypes); struct_code = interface_struct (NULL, prefix, interface, object, &struct_prototypes); if (! struct_code) { if (code) nih_free (code); return NULL; } nih_assert (! NIH_LIST_EMPTY (&struct_prototypes)); var = (TypeVar *)struct_prototypes.next; if (! nih_strcat_sprintf (&code, parent, "%s\n", struct_code)) { if (code) nih_free (code); return NULL; } if (! nih_strcat_sprintf (&block, NULL, "&%s,\n", var->name)) { if (code) nih_free (code); return NULL; } /* Copy the prototypes to the list we return, since we * want to export those as well. */ NIH_LIST_FOREACH_SAFE (&struct_prototypes, iter) { var = (TypeVar *)iter; if (! type_to_extern (&var->type, var)) { if (code) nih_free (code); return NULL; } nih_ref (var, code); nih_list_add (prototypes, &var->entry); } } /* Append the final element to the block of elements, indent and * surround with the structure definition. */ if (! nih_strcat (&block, NULL, "NULL\n")) { if (code) nih_free (code); return NULL; } if (! indent (&block, NULL, 1)) { if (code) nih_free (code); return NULL; } if (! nih_strcat_sprintf (&code, parent, "const NihDBusInterface *%s[] = {\n" "%s" "};\n", name, block)) { if (code) nih_free (code); return NULL; } /* Append the prototype to the list */ var = type_var_new (code, "const NihDBusInterface *", name); if (! var) { nih_free (code); return NULL; } var->array = TRUE; if (! type_to_extern (&var->type, var)) { if (code) nih_free (code); return NULL; } nih_list_add (prototypes, &var->entry); return code; } /** * node_object_functions: * @parent: parent object for new string, * @prefix: prefix for function names, * @node: node to generate functions for, * @prototypes: list to append prototypes to, * @handlers: list to append handler prototypes to, * @structs: list to append structure definitions to, * @externs: list to append prototypes of extern functions to. * * Generates C code for all of the functions that @node would require to * wrap existing C functions and implement the D-Bus interfaces described * for the object. * * Functions in the returned code to implement method handlers and property * getter and setters will be declared static and their prototypes returned * as TypeFunc objects appended to the @prototypes list. You normally ensure * that these receive a forward declaration. * * Those functions will call implementation functions that other code is * expected to provide, the names and prototypes of these expected functions * are returned as TypeFunc objects appended to the @handlers list. You * must implement these elsewhere, and ensure that the prototype has a * forward declaration. * * Functions in the returned code to implement signal emissions are part of * a public API that your own code may call. The names and prototypes are * returned as TypeFunc objects appended to the @externs list, you would * normally place these in a header file. * * If any of the function arguments require a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and the method, * signal or property the function is for. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * node_object_functions (const void *parent, const char *prefix, Node * node, NihList * prototypes, NihList * handlers, NihList * structs, NihList * externs) { char *code = NULL; int first = TRUE; nih_assert (prefix != NULL); nih_assert (node != NULL); nih_assert (prototypes != NULL); nih_assert (handlers != NULL); nih_assert (structs != NULL); nih_assert (externs != NULL); code = nih_strdup (parent, ""); if (! code) return NULL; NIH_LIST_FOREACH (&node->interfaces, interface_iter) { Interface *interface = (Interface *)interface_iter; NIH_LIST_FOREACH (&interface->methods, method_iter) { Method * method = (Method *)method_iter; NihList method_prototypes; NihList method_handlers; NihList method_structs; NihList method_externs; nih_local char *object_func = NULL; nih_local char *reply_func = NULL; nih_list_init (&method_prototypes); nih_list_init (&method_handlers); nih_list_init (&method_structs); nih_list_init (&method_externs); if (! first) if (! nih_strcat (&code, parent, "\n\n")) goto error; first = FALSE; object_func = method_object_function ( NULL, prefix, interface, method, &method_prototypes, &method_handlers, &method_structs); if (! object_func) goto error; if (! nih_strcat_sprintf (&code, parent, "static %s", object_func)) goto error; if (method->async) { reply_func = method_reply_function ( NULL, prefix, interface, method, &method_externs, &method_structs); if (! reply_func) goto error; if (! nih_strcat_sprintf (&code, parent, "\n" "%s", reply_func)) goto error; } NIH_LIST_FOREACH_SAFE (&method_prototypes, iter) { TypeFunc *func = (TypeFunc *)iter; if (! type_to_static (&func->type, func)) goto error; nih_ref (func, code); nih_list_add (prototypes, &func->entry); } NIH_LIST_FOREACH_SAFE (&method_handlers, iter) { TypeFunc *func = (TypeFunc *)iter; if (! type_to_extern (&func->type, func)) goto error; nih_ref (func, code); nih_list_add (handlers, &func->entry); } NIH_LIST_FOREACH_SAFE (&method_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } NIH_LIST_FOREACH_SAFE (&method_externs, iter) { TypeFunc *func = (TypeFunc *)iter; nih_ref (func, code); nih_list_add (externs, &func->entry); } } NIH_LIST_FOREACH (&interface->signals, signal_iter) { Signal * signal = (Signal *)signal_iter; NihList signal_structs; NihList signal_externs; nih_local char *object_func = NULL; nih_list_init (&signal_structs); nih_list_init (&signal_externs); object_func = signal_object_function ( NULL, prefix, interface, signal, &signal_externs, &signal_structs); if (! object_func) goto error; if (! first) if (! nih_strcat (&code, parent, "\n\n")) goto error; first = FALSE; if (! nih_strcat (&code, parent, object_func)) goto error; NIH_LIST_FOREACH_SAFE (&signal_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } NIH_LIST_FOREACH_SAFE (&signal_externs, iter) { TypeFunc *func = (TypeFunc *)iter; nih_ref (func, code); nih_list_add (externs, &func->entry); } } NIH_LIST_FOREACH (&interface->properties, property_iter) { Property * property = (Property *)property_iter; NihList property_prototypes; NihList property_handlers; NihList property_structs; nih_local char *get_func = NULL; nih_local char *set_func = NULL; nih_list_init (&property_prototypes); nih_list_init (&property_handlers); nih_list_init (&property_structs); if (! first) if (! nih_strcat (&code, parent, "\n\n")) goto error; first = FALSE; if (property->access != NIH_DBUS_WRITE) { get_func = property_object_get_function ( NULL, prefix, interface, property, &property_prototypes, &property_handlers, &property_structs); if (! get_func) goto error; if (! nih_strcat_sprintf (&code, parent, "static %s", get_func)) goto error; } if (property->access == NIH_DBUS_READWRITE) { if (! nih_strcat (&code, parent, "\n")) goto error; /* Don't duplicate structures; these will * get freed automatically. */ nih_list_init (&property_structs); } if (property->access != NIH_DBUS_READ) { set_func = property_object_set_function ( NULL, prefix, interface, property, &property_prototypes, &property_handlers, &property_structs); if (! set_func) goto error; if (! nih_strcat_sprintf (&code, parent, "static %s", set_func)) goto error; } NIH_LIST_FOREACH_SAFE (&property_prototypes, iter) { TypeFunc *func = (TypeFunc *)iter; if (! type_to_static (&func->type, func)) goto error; nih_ref (func, code); nih_list_add (prototypes, &func->entry); } NIH_LIST_FOREACH_SAFE (&property_handlers, iter) { TypeFunc *func = (TypeFunc *)iter; if (! type_to_extern (&func->type, func)) goto error; nih_ref (func, code); nih_list_add (handlers, &func->entry); } NIH_LIST_FOREACH_SAFE (&property_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } } } return code; error: nih_free (code); return NULL; } /** * node_proxy_functions: * @parent: parent object for new string, * @prefix: prefix for function names, * @node: node to generate functions for, * @prototypes: list to append prototypes to, * @structs: list to append structure definitions to, * @typedefs: list to append callback typedefs to, * @externs: list to append prototypes of extern functions to. * * Generates C code for all of the functions that @node would require to * provide remote object access. * * Functions in the returned code to implement signal filter functions * will be declared static and their prototypes returned as TypeFunc objects * appended to the @prototypes list. You normally ensure that these receive * a forward declaration. * * Functions in the returned code to implement method and property get/set * proxy functions are part of a public API that your own code may call. * The names and prototypes are returned as TypeFunc objects appended to * the @externs list, you would normally place these in a header file. * * Both sets of these functions will call handler and callback functions * that other code is expected to provide, either passed directly to the * function (for method and proxy functions) or passed to * nih_dbus_proxy_connect() (for signal functions). The typedef for those * functions are returned as TypeFunc objects appended to the @typedefs list. * You would normally place these in a header file. * * If any of the function arguments require a structure to be defined, the * definition is returned as a TypeStruct object appended to the @structs * list. The name is generated from @prefix, @interface and the method, * signal or property the function is for. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the return string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * node_proxy_functions (const void *parent, const char *prefix, Node * node, NihList * prototypes, NihList * structs, NihList * typedefs, NihList * externs) { char *code = NULL; int first = TRUE; nih_assert (prefix != NULL); nih_assert (node != NULL); nih_assert (prototypes != NULL); nih_assert (structs != NULL); nih_assert (typedefs != NULL); nih_assert (externs != NULL); code = nih_strdup (parent, ""); if (! code) return NULL; NIH_LIST_FOREACH (&node->interfaces, interface_iter) { Interface *interface = (Interface *)interface_iter; NihList discard; nih_list_init (&discard); NIH_LIST_FOREACH (&interface->methods, method_iter) { Method * method = (Method *)method_iter; NihList method_prototypes; NihList method_structs; NihList method_typedefs; NihList method_externs; nih_local char *proxy_func = NULL; nih_local char *notify_func = NULL; nih_local char *sync_func = NULL; nih_list_init (&method_prototypes); nih_list_init (&method_structs); nih_list_init (&method_typedefs); nih_list_init (&method_externs); if (! first) if (! nih_strcat (&code, parent, "\n\n")) goto error; first = FALSE; proxy_func = method_proxy_function ( NULL, prefix, interface, method, &method_externs, &discard); if (! proxy_func) goto error; notify_func = method_proxy_notify_function ( NULL, prefix, interface, method, &method_prototypes, &method_typedefs, &discard); if (! notify_func) goto error; sync_func = method_proxy_sync_function ( NULL, prefix, interface, method, &method_externs, &method_structs); if (! sync_func) goto error; if (! nih_strcat_sprintf (&code, parent, "%s" "\n" "static %s" "\n" "%s", proxy_func, notify_func, sync_func)) goto error; NIH_LIST_FOREACH_SAFE (&method_prototypes, iter) { TypeFunc *func = (TypeFunc *)iter; if (! type_to_static (&func->type, func)) goto error; nih_ref (func, code); nih_list_add (prototypes, &func->entry); } NIH_LIST_FOREACH_SAFE (&method_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } NIH_LIST_FOREACH_SAFE (&method_typedefs, iter) { TypeFunc *func = (TypeFunc *)iter; nih_ref (func, code); nih_list_add (typedefs, &func->entry); } NIH_LIST_FOREACH_SAFE (&method_externs, iter) { TypeFunc *func = (TypeFunc *)iter; nih_ref (func, code); nih_list_add (externs, &func->entry); } } NIH_LIST_FOREACH (&interface->signals, signal_iter) { Signal * signal = (Signal *)signal_iter; NihList signal_prototypes; NihList signal_structs; NihList signal_typedefs; nih_local char *proxy_func = NULL; nih_list_init (&signal_prototypes); nih_list_init (&signal_structs); nih_list_init (&signal_typedefs); if (! first) if (! nih_strcat (&code, parent, "\n\n")) goto error; first = FALSE; proxy_func = signal_proxy_function ( NULL, prefix, interface, signal, &signal_prototypes, &signal_typedefs, &signal_structs); if (! proxy_func) goto error; if (! nih_strcat_sprintf (&code, parent, "static %s", proxy_func)) goto error; NIH_LIST_FOREACH_SAFE (&signal_prototypes, iter) { TypeFunc *func = (TypeFunc *)iter; if (! type_to_static (&func->type, func)) goto error; nih_ref (func, code); nih_list_add (prototypes, &func->entry); } NIH_LIST_FOREACH_SAFE (&signal_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } NIH_LIST_FOREACH_SAFE (&signal_typedefs, iter) { TypeFunc *func = (TypeFunc *)iter; nih_ref (func, code); nih_list_add (typedefs, &func->entry); } } NIH_LIST_FOREACH (&interface->properties, property_iter) { Property * property = (Property *)property_iter; NihList property_prototypes; NihList property_structs; NihList property_typedefs; NihList property_externs; nih_local char *get_func = NULL; nih_local char *get_notify_func = NULL; nih_local char *get_sync_func = NULL; nih_local char *set_func = NULL; nih_local char *set_notify_func = NULL; nih_local char *set_sync_func = NULL; nih_list_init (&property_prototypes); nih_list_init (&property_structs); nih_list_init (&property_typedefs); nih_list_init (&property_externs); if (! first) if (! nih_strcat (&code, parent, "\n\n")) goto error; first = FALSE; if (property->access != NIH_DBUS_WRITE) { get_func = property_proxy_get_function ( NULL, prefix, interface, property, &property_externs, &discard); if (! get_func) goto error; get_notify_func = property_proxy_get_notify_function ( NULL, prefix, interface, property, &property_prototypes, &property_typedefs, &discard); if (! get_notify_func) goto error; get_sync_func = property_proxy_get_sync_function ( NULL, prefix, interface, property, &property_externs, &discard); if (! get_sync_func) goto error; if (! nih_strcat_sprintf (&code, parent, "%s" "\n" "static %s" "\n" "%s", get_func, get_notify_func, get_sync_func)) goto error; } if (property->access == NIH_DBUS_READWRITE) if (! nih_strcat (&code, parent, "\n")) goto error; if (property->access != NIH_DBUS_READ) { set_func = property_proxy_set_function ( NULL, prefix, interface, property, &property_externs, &discard); if (! set_func) goto error; set_notify_func = property_proxy_set_notify_function ( NULL, prefix, interface, property, &property_prototypes, &property_typedefs, &discard); if (! set_notify_func) goto error; set_sync_func = property_proxy_set_sync_function ( NULL, prefix, interface, property, &property_externs, (property->access == NIH_DBUS_WRITE ? &property_structs : &discard)); if (! set_sync_func) goto error; if (! nih_strcat_sprintf (&code, parent, "%s" "\n" "static %s" "\n" "%s", set_func, set_notify_func, set_sync_func)) goto error; } NIH_LIST_FOREACH_SAFE (&property_prototypes, iter) { TypeFunc *func = (TypeFunc *)iter; if (! type_to_static (&func->type, func)) goto error; nih_ref (func, code); nih_list_add (prototypes, &func->entry); } NIH_LIST_FOREACH_SAFE (&property_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } NIH_LIST_FOREACH_SAFE (&property_typedefs, iter) { TypeFunc *func = (TypeFunc *)iter; nih_ref (func, code); nih_list_add (typedefs, &func->entry); } NIH_LIST_FOREACH_SAFE (&property_externs, iter) { TypeFunc *func = (TypeFunc *)iter; nih_ref (func, code); nih_list_add (externs, &func->entry); } } /* Functions to obtain all of the properties */ if (! NIH_LIST_EMPTY (&interface->properties)) { NihList all_prototypes; NihList all_structs; NihList all_typedefs; NihList all_externs; nih_local char *get_all_func = NULL; nih_local char *get_all_notify_func = NULL; nih_local char *get_all_sync_func = NULL; nih_list_init (&all_prototypes); nih_list_init (&all_structs); nih_list_init (&all_typedefs); nih_list_init (&all_externs); if (! first) if (! nih_strcat (&code, parent, "\n\n")) goto error; first = FALSE; get_all_func = interface_proxy_get_all_function ( NULL, prefix, interface, &all_externs, &discard); if (! get_all_func) goto error; get_all_notify_func = interface_proxy_get_all_notify_function ( NULL, prefix, interface, &all_prototypes, &all_typedefs, &discard); if (! get_all_notify_func) goto error; get_all_sync_func = interface_proxy_get_all_sync_function ( NULL, prefix, interface, &all_externs, &all_structs); if (! get_all_sync_func) goto error; if (! nih_strcat_sprintf (&code, parent, "%s" "\n" "static %s" "\n" "%s", get_all_func, get_all_notify_func, get_all_sync_func)) goto error; NIH_LIST_FOREACH_SAFE (&all_prototypes, iter) { TypeFunc *func = (TypeFunc *)iter; if (! type_to_static (&func->type, func)) goto error; nih_ref (func, code); nih_list_add (prototypes, &func->entry); } NIH_LIST_FOREACH_SAFE (&all_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } NIH_LIST_FOREACH_SAFE (&all_typedefs, iter) { TypeFunc *func = (TypeFunc *)iter; nih_ref (func, code); nih_list_add (typedefs, &func->entry); } NIH_LIST_FOREACH_SAFE (&all_externs, iter) { TypeFunc *func = (TypeFunc *)iter; nih_ref (func, code); nih_list_add (externs, &func->entry); } } } return code; error: nih_free (code); return NULL; } libnih-1.0.3/nih-dbus-tool/parse.c0000644000175000017500000002555111445765555013674 00000000000000/* nih-dbus-tool * * parse.c - parse XML introspection data and tool-specific annotations * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include "node.h" #include "interface.h" #include "method.h" #include "signal.h" #include "property.h" #include "argument.h" #include "annotation.h" #include "parse.h" #include "errors.h" /** * BUF_SIZE: * * Size of buffer we use when parsing. **/ #define BUF_SIZE 80 /** * parse_stack_push: * @parent: parent object of new stack entry, * @stack: stack to push onto, * @type: type of object to push, * @data: pointer to object data. * * Allocates a new Stack object with the @type and @data specified * and pushes it onto @stack. * * The entry can be removed from the stack by freeing it, though this will * not free the associated @data unless you arrange that by references. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned entry. When all parents * of the returned node are freed, the returned entry will also be * freed. * * Returns: new entry or NULL if the allocation failed. **/ ParseStack * parse_stack_push (const void * parent, NihList * stack, ParseStackType type, void * data) { ParseStack *entry; nih_assert (stack != NULL); entry = nih_new (parent, ParseStack); if (! entry) return NULL; nih_list_init (&entry->entry); nih_alloc_set_destructor (entry, nih_list_destroy); entry->type = type; entry->data = data; if ((entry->type != PARSE_IGNORED) && (entry->type != PARSE_ANNOTATION)) { nih_assert (entry->data != NULL); nih_ref (entry->data, entry); } else { nih_assert (entry->data == NULL); } nih_list_add_after (stack, &entry->entry); return entry; } /** * parse_stack_top: * @stack: stack to return from. * * Returns: the top entry in @stack or NULL if the stack is empty. **/ ParseStack * parse_stack_top (NihList *stack) { nih_assert (stack != NULL); if (! NIH_LIST_EMPTY (stack)) { return (ParseStack *)stack->next; } else { return NULL; } } /** * parse_start_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed, * @attr: NULL-terminated array of attribute name and value pairs. * * This function is intended to be used as the start element handler for * the XML parser @xmlp and called by that parser. It looks at the tag * name @tag and calls one of the other *_start_tag() functions to * handle the tag. * * Unknown tags result in a warning and are otherwise ignored, the stack * contains an ignore element and the content of those tags will also be * ignored with no warnings generated. * * Errors are raised and reported by stopping the parser, other element * handlers should check that the parsing status is not finished as they * may be called as part of the unwinding process. XML_ParseBuffer will * return to indicate an error, the XML error code will be XML_ERROR_ABORTED * and the actual error can be retrieved with nih_error_get(). **/ void parse_start_tag (XML_Parser xmlp, const char * tag, char * const *attr) { XML_ParsingStatus status; ParseContext * context; ParseStack * parent; int ret = 0; nih_assert (xmlp != NULL); nih_assert (tag != NULL); nih_assert (attr != NULL); XML_GetParsingStatus (xmlp, &status); if (status.parsing == XML_FINISHED) return; nih_debug ("Parsed '%s' tag", tag); context = XML_GetUserData (xmlp); nih_assert (context != NULL); /* Ignore any tag inside an ignored tag */ parent = parse_stack_top (&context->stack); if (parent && (parent->type == PARSE_IGNORED)) { if (! parse_stack_push (NULL, &context->stack, PARSE_IGNORED, NULL)) { nih_error_raise_system (); ret = -1; } goto exit; } /* Otherwise call out to handle the tag */ if (! strcmp (tag, "node")) { ret = node_start_tag (xmlp, tag, attr); } else if (! strcmp (tag, "interface")) { ret = interface_start_tag (xmlp, tag, attr); } else if (! strcmp (tag, "method")) { ret = method_start_tag (xmlp, tag, attr); } else if (! strcmp (tag, "signal")) { ret = signal_start_tag (xmlp, tag, attr); } else if (! strcmp (tag, "property")) { ret = property_start_tag (xmlp, tag, attr); } else if (! strcmp (tag, "arg")) { ret = argument_start_tag (xmlp, tag, attr); } else if (! strcmp (tag, "annotation")) { ret = annotation_start_tag (xmlp, tag, attr); } else { nih_warn ("%s:%zu:%zu: %s: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unknown tag"), tag); if (! parse_stack_push (NULL, &context->stack, PARSE_IGNORED, NULL)) { nih_error_raise_system (); ret = -1; } } exit: if (ret < 0) nih_assert (XML_StopParser (xmlp, FALSE) == XML_STATUS_OK); } /** * parse_end_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed. * * This function is intended to be used as the end element handler for * the XML parser @xmlp and called by that parser. It looks at the tag * name @tag and calls one of the other *_end_tag() functions to * handle the tag. * * The end tags whose start was ignored are ignored without any warning. * * Errors are raised and reported by stopping the parser, other element * handlers should check that the parsing status is not finished as they * may be called as part of the unwinding process. XML_ParseBuffer will * return to indicate an error, the XML error code will be XML_ERROR_ABORTED * and the actual error can be retrieved with nih_error_get(). **/ void parse_end_tag (XML_Parser xmlp, const char *tag) { XML_ParsingStatus status; ParseContext * context; ParseStack * entry; int ret = 0; nih_assert (xmlp != NULL); nih_assert (tag != NULL); XML_GetParsingStatus (xmlp, &status); if (status.parsing == XML_FINISHED) return; nih_debug ("Parsed '%s' end tag", tag); context = XML_GetUserData (xmlp); nih_assert (context != NULL); /* Ignore the end tag of any ignored tag */ entry = parse_stack_top (&context->stack); nih_assert (entry != NULL); if (entry->type == PARSE_IGNORED) { nih_free (entry); goto exit; } /* Otherwise call out to handle the tag */ if (! strcmp (tag, "node")) { ret = node_end_tag (xmlp, tag); } else if (! strcmp (tag, "interface")) { ret = interface_end_tag (xmlp, tag); } else if (! strcmp (tag, "method")) { ret = method_end_tag (xmlp, tag); } else if (! strcmp (tag, "signal")) { ret = signal_end_tag (xmlp, tag); } else if (! strcmp (tag, "property")) { ret = property_end_tag (xmlp, tag); } else if (! strcmp (tag, "arg")) { ret = argument_end_tag (xmlp, tag); } else if (! strcmp (tag, "annotation")) { ret = annotation_end_tag (xmlp, tag); } else { nih_assert_not_reached (); } exit: if (ret < 0) nih_assert (XML_StopParser (xmlp, FALSE) == XML_STATUS_OK); } /** * parse_xml: * @parent: parent object of new node, * @fd: file descriptor to parse from, * @filename: filename for error reporting. * * Parse XML data from @fd according to the D-Bus Introspection * specification, returning the top-level Node which contains the * Interfaces defined by that object. * * Errors in parsing are output within this function, since it has the * line and column number available to it. @filename is used when reporting * these errors. * * In general, the parser is fairly liberal and will ignore unexpected tags, * attributes and any character data. However it is strict about restrictions * in the specification, for example it will not allow missing attributes or * unknown values in them. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned node. When all parents * of the returned node are freed, the returned node will also be * freed. * * Returns: newly allocated Node on success, NULL on error. **/ Node * parse_xml (const void *parent, int fd, const char *filename) { ParseContext context; XML_Parser xmlp; ssize_t len; context.parent = parent; nih_list_init (&context.stack); context.filename = filename; context.node = NULL; xmlp = XML_ParserCreate ("UTF-8"); if (! xmlp) { nih_error ("%s: %s", _("Unable to create XML Parser"), strerror (ENOMEM)); return NULL; } XML_SetUserData (xmlp, &context); XML_UseParserAsHandlerArg (xmlp); XML_SetElementHandler (xmlp, (XML_StartElementHandler)parse_start_tag, (XML_EndElementHandler)parse_end_tag); do { enum XML_Status status; enum XML_Error error; void * buf; buf = XML_GetBuffer (xmlp, BUF_SIZE); if (! buf) { error = XML_GetErrorCode (xmlp); nih_error ("%s: %s", _("Unable to allocate parsing buffer"), XML_ErrorString (error)); goto error; } len = read (fd, buf, BUF_SIZE); if (len < 0) { nih_error ("%s: %s: %s", context.filename, _("Read error"), strerror (errno)); goto error; } status = XML_ParseBuffer (xmlp, len, len == 0 ? TRUE : FALSE); if (status != XML_STATUS_OK) { error = XML_GetErrorCode (xmlp); if (error == XML_ERROR_ABORTED) { NihError *err; err = nih_error_get (); nih_error ("%s:%zu:%zu: %s", context.filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), err->message); nih_free (err); } else { nih_error ("%s:%zu:%zu: %s: %s", context.filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("XML parse error"), XML_ErrorString (error)); } goto error; } } while (len > 0); nih_assert (NIH_LIST_EMPTY (&context.stack)); if (! context.node) { nih_error ("%s: %s", context.filename, _("No node present")); goto error; } XML_ParserFree (xmlp); return context.node; error: NIH_LIST_FOREACH_SAFE (&context.stack, iter) { ParseStack *entry = (ParseStack *)iter; nih_free (entry); } if (context.node) nih_free (context.node); XML_ParserFree (xmlp); return NULL; } libnih-1.0.3/nih-dbus-tool/property.h0000644000175000017500000001153211445765555014445 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_PROPERTY_H #define NIH_DBUS_TOOL_PROPERTY_H #include #include #include #include #include "interface.h" /** * Property: * @entry: list header, * @name: D-Bus name of property, * @symbol: name used when constructing C name, * @type: type signature of property, * @access: access of property, * @deprecated: whether this property is deprecated. * * D-Bus interfaces specify zero or more properties, which are identified by * @name over the bus and have the type signature @type. Properties may be * read-only, write-only or read/write depending on @access. * * When generating the C symbol names @symbol will be used. If @symbol * is NULL, @name will be converted into the usual C lowercase and underscore * style and used instead. **/ typedef struct property { NihList entry; char * name; char * symbol; char * type; NihDBusAccess access; int deprecated; } Property; NIH_BEGIN_EXTERN int property_name_valid (const char *name); Property *property_new (const void *parent, const char *name, const char *type, NihDBusAccess access) __attribute__ ((warn_unused_result, malloc)); int property_start_tag (XML_Parser xmlp, const char *tag, char * const *attr) __attribute__ ((warn_unused_result)); int property_end_tag (XML_Parser xmlp, const char *tag) __attribute__ ((warn_unused_result)); int property_annotation (Property *property, const char *name, const char *value) __attribute__ ((warn_unused_result)); Property *property_lookup (Interface *interface, const char *symbol); char * property_object_get_function (const void *parent, const char *prefix, Interface *interface, Property *property, NihList *prototypes, NihList *handlers, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * property_object_set_function (const void *parent, const char *prefix, Interface *interface, Property *property, NihList *prototypes, NihList *handlers, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * property_proxy_get_function (const void *parent, const char *prefix, Interface *interface, Property *property, NihList *prototypes, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * property_proxy_get_notify_function (const void *parent, const char *prefix, Interface *interface, Property *property, NihList *prototypes, NihList *typedefs, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * property_proxy_set_function (const void *parent, const char *prefix, Interface *interface, Property *property, NihList *prototypes, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * property_proxy_set_notify_function (const void *parent, const char *prefix, Interface *interface, Property *property, NihList *prototypes, NihList *typedefs, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * property_proxy_get_sync_function (const void *parent, const char *prefix, Interface *interface, Property *property, NihList *prototypes, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * property_proxy_set_sync_function (const void *parent, const char *prefix, Interface *interface, Property *property, NihList *prototypes, NihList *structs) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_PROPERTY_H */ libnih-1.0.3/nih-dbus-tool/annotation.h0000644000175000017500000000227411445765555014736 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_ANNOTATION_H #define NIH_DBUS_TOOL_ANNOTATION_H #include #include #include NIH_BEGIN_EXTERN int annotation_start_tag (XML_Parser xmlp, const char *tag, char * const *attr) __attribute__ ((warn_unused_result)); int annotation_end_tag (XML_Parser xmlp, const char *tag) __attribute__ ((warn_unused_result)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_ANNOTATION_H */ libnih-1.0.3/nih-dbus-tool/tests/0000755000175000017500000000000011504742363013614 500000000000000libnih-1.0.3/nih-dbus-tool/tests/demarshal_factory.c0000644000175000017500000001223111504707257017371 00000000000000/* nih-dbus-tool * * tests/demarshal_factory.c - generate tests/demarshal_code.c * * Copyright © 2010 Scott James Remnant . * Copyright © 2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include "indent.h" #include "type.h" #include "demarshal.h" static void demarshal_function (const char *name, const char *signature) { DBusSignatureIter iter; nih_local char * code = NULL; NihList outputs; NihList locals; NihList structs; nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&iter, signature); code = demarshal (NULL, &iter, "parent", "iter", "local", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, name, "value", &structs); printf ("int\n" "my_%s_demarshal (const void *parent, DBusMessage *message", name); NIH_LIST_FOREACH (&outputs, iter) { TypeVar * var = (TypeVar *)iter; nih_local char *arg_type = NULL; char * suffix; assert (arg_type = nih_strdup (NULL, var->type)); assert (type_to_pointer (&arg_type, NULL)); suffix = var->name + strlen ("local"); printf (", %s %s%s", arg_type, "value", suffix); } printf (")\n" "{\n" "\tDBusMessageIter iter;\n"); NIH_LIST_FOREACH (&locals, iter) { TypeVar *local_var = (TypeVar *)iter; printf ("\t%s %s;\n", local_var->type, local_var->name); } NIH_LIST_FOREACH (&outputs, iter) { TypeVar *output_var = (TypeVar *)iter; printf ("\t%s %s;\n", output_var->type, output_var->name); } printf ("\n" /* FIXME */ "\tnih_assert (message != NULL);\n" "\n" "\tnih_assert (dbus_message_iter_init (message, &iter));\n" "\n"); assert (indent (&code, NULL, 1)); printf ("%s\n", code); NIH_LIST_FOREACH (&outputs, iter) { TypeVar *var = (TypeVar *)iter; char * suffix; suffix = var->name + strlen ("local"); printf ("\t*%s%s = %s;\n", "value", suffix, var->name); } printf ("\n" "\treturn 0;\n" "}\n" "\n"); } int main (int argc, char *argv[]) { printf ("#include \n" "\n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "\n" "#include \"tests/demarshal_code.h\"\n" "\n"); demarshal_function ("byte", DBUS_TYPE_BYTE_AS_STRING); demarshal_function ("boolean", DBUS_TYPE_BOOLEAN_AS_STRING); demarshal_function ("int16", DBUS_TYPE_INT16_AS_STRING); demarshal_function ("uint16", DBUS_TYPE_UINT16_AS_STRING); demarshal_function ("int32", DBUS_TYPE_INT32_AS_STRING); demarshal_function ("uint32", DBUS_TYPE_UINT32_AS_STRING); demarshal_function ("int64", DBUS_TYPE_INT64_AS_STRING); demarshal_function ("uint64", DBUS_TYPE_UINT64_AS_STRING); demarshal_function ("double", DBUS_TYPE_DOUBLE_AS_STRING); demarshal_function ("string", DBUS_TYPE_STRING_AS_STRING); demarshal_function ("object_path", DBUS_TYPE_OBJECT_PATH_AS_STRING); demarshal_function ("signature", DBUS_TYPE_SIGNATURE_AS_STRING); demarshal_function ("int16_array", (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING)); demarshal_function ("int16_array_array", (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING)); demarshal_function ("string_array", (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)); demarshal_function ("string_array_array", (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)); demarshal_function ("struct", (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING)); demarshal_function ("struct_array", (DBUS_TYPE_ARRAY_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING)); demarshal_function ("dict_entry_array", (DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING)); demarshal_function ("unix_fd", DBUS_TYPE_UNIX_FD_AS_STRING); return 0; } libnih-1.0.3/nih-dbus-tool/tests/test_symbol.c0000644000175000017500000003551311445765555016267 00000000000000/* nih-dbus-tool * * test_symbol.c - test suite for nih-dbus-tool/symbol.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include "symbol.h" void test_valid (void) { TEST_FUNCTION ("symbol_valid"); /* Check that a typical symbol is valid. */ TEST_FEATURE ("with typical symbol"); TEST_TRUE (symbol_valid ("wibble")); /* Check that an symbol is not valid if it is has an * initial period. */ TEST_FEATURE ("with initial period"); TEST_FALSE (symbol_valid (".wibble")); /* Check that an symbol is not valid if it ends with a period */ TEST_FEATURE ("with final period"); TEST_FALSE (symbol_valid ("wibble.")); /* Check that an symbol is not valid if it contains a period */ TEST_FEATURE ("with period"); TEST_FALSE (symbol_valid ("wib.ble")); /* Check that a symbol may contain numbers */ TEST_FEATURE ("with numbers"); TEST_TRUE (symbol_valid ("wib43ble")); /* Check that a symbol may not begin with numbers */ TEST_FEATURE ("with leading digits"); TEST_FALSE (symbol_valid ("43wibble")); /* Check that a symbol may end with numbers */ TEST_FEATURE ("with trailing digits"); TEST_TRUE (symbol_valid ("wibble43")); /* Check that a symbol may contain underscores */ TEST_FEATURE ("with underscore"); TEST_TRUE (symbol_valid ("wib_ble")); /* Check that a symbol may begin with underscores */ TEST_FEATURE ("with initial underscore"); TEST_TRUE (symbol_valid ("_wibble")); /* Check that a symbol may end with underscores */ TEST_FEATURE ("with final underscore"); TEST_TRUE (symbol_valid ("wibble_")); /* Check that other characters are not permitted */ TEST_FEATURE ("with non-permitted characters"); TEST_FALSE (symbol_valid ("wib-ble")); /* Check that an empty symbol is invalid */ TEST_FEATURE ("with empty string"); TEST_FALSE (symbol_valid ("")); } void test_from_name (void) { char *str; TEST_FUNCTION ("symbol_from_name"); /* Check that a CamelCase name is converted to lowercase with an * underscore between the words. */ TEST_FEATURE ("with basic CamelCase name"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "CamelCase"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "camel_case"); nih_free (str); } /* Check that a longer CamelCase name is converted to lowercase with * an underscore between the words. */ TEST_FEATURE ("with longer CamelCase name"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "CamelCaseName"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "camel_case_name"); nih_free (str); } /* Check that a single title-case word is converted to lowercase. */ TEST_FEATURE ("with Title case word"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "Title"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "title"); nih_free (str); } /* Check that name made up up Title case words separated by * underscores is converted to lowercase but additional underscores * are not added. */ TEST_FEATURE ("with Title case name and undescores"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "Title_Case"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "title_case"); nih_free (str); } /* Check that a longer name made up up Title case words separated by * underscores is converted to lowercase but additional underscores * are not added. */ TEST_FEATURE ("with longer Title case name and undescores"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "Title_Case_Name"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "title_case_name"); nih_free (str); } /* Check that an underscore is not inserted between consecutive * capital letters. */ TEST_FEATURE ("with consecutive capital letters"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "DBusTest"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "dbus_test"); nih_free (str); } /* Check that a lowercase word is left alone. */ TEST_FEATURE ("with lowercase word"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "lower"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "lower"); nih_free (str); } /* Check that a lowercase name with words separated by underscores * is left alone. */ TEST_FEATURE ("with lowercase name and underscores"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "lower_case"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "lower_case"); nih_free (str); } /* Check that a longer lowercase name with words separated by * underscores is left alone. */ TEST_FEATURE ("with longer lowercase name and underscores"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "lower_case_name"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "lower_case_name"); nih_free (str); } /* Check that digits after lowercase characters are not separated. */ TEST_FEATURE ("with digits after lowercase"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "lower69"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "lower69"); nih_free (str); } /* Check that digits between lowercase characters are not separated. */ TEST_FEATURE ("with digits between lowercase"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "lower69th"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "lower69th"); nih_free (str); } /* Check that digits after uppercase characters are not separated. */ TEST_FEATURE ("with digits after uppercase"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "X5"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "x5"); nih_free (str); } /* Check that digits before characters are separated. */ TEST_FEATURE ("with digits before uppercase"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "Platform5B"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "platform5_b"); nih_free (str); } /* Check a pathological example. */ TEST_FEATURE ("with pathological example"); TEST_ALLOC_FAIL { str = symbol_from_name (NULL, "CamelCase_but_2nd_Title_Case_bit"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "camel_case_but_2nd_title_case_bit"); nih_free (str); } } void test_impl (void) { char *str; TEST_FUNCTION ("symbol_impl"); /* Check that we can create an implementation function name, * which returns a name that you'd never want to call but is * sufficiently unique for internal structures. */ TEST_FEATURE ("with all arguments"); TEST_ALLOC_FAIL { str = symbol_impl (NULL, "my", "com.netsplit.Nih.Test", "MyMethod", "method"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "my_com_netsplit_Nih_Test_MyMethod_method"); nih_free (str); } /* Check that the symbol name may be omitted, as is the case for * the structure variables. */ TEST_FEATURE ("without symbol"); TEST_ALLOC_FAIL { str = symbol_impl (NULL, "my", "com.netsplit.Nih.Test", NULL, "methods"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "my_com_netsplit_Nih_Test_methods"); nih_free (str); } /* Check that the symbol name and postfix may be omitted, as is * the case for the interface structure variable. */ TEST_FEATURE ("without symbol or postfix"); TEST_ALLOC_FAIL { str = symbol_impl (NULL, "my", "com.netsplit.Nih.Test", NULL, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "my_com_netsplit_Nih_Test"); nih_free (str); } } void test_extern (void) { char *str; TEST_FUNCTION ("symbol_extern"); /* Check that we can create an extern function name, either one the * user is expected to implement or one that they might call, when * passing all arguments - the name should be in a nice format. */ TEST_FEATURE ("with all arguments"); TEST_ALLOC_FAIL { str = symbol_extern (NULL, "my", "test", "get", "my_property", "sync"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "my_test_get_my_property_sync"); nih_free (str); } /* Check that the interface symbol is optional, since the default * interface will not end up having one. */ TEST_FEATURE ("without interface symbol"); TEST_ALLOC_FAIL { str = symbol_extern (NULL, "my", NULL, "get", "my_property", "sync"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "my_get_my_property_sync"); nih_free (str); } /* Check that we don't need to supply the midfix component */ TEST_FEATURE ("without midfix"); TEST_ALLOC_FAIL { str = symbol_extern (NULL, "my", "test", NULL, "my_method", "reply"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "my_test_my_method_reply"); nih_free (str); } /* Check that we don't need to supply the postfix component */ TEST_FEATURE ("without postfix"); TEST_ALLOC_FAIL { str = symbol_extern (NULL, "my", "test", "emit", "my_signal", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "my_test_emit_my_signal"); nih_free (str); } /* Check that we can omit both the interface symbol and the midfix */ TEST_FEATURE ("without interface symbol or midfix"); TEST_ALLOC_FAIL { str = symbol_extern (NULL, "my", NULL, NULL, "my_method", "sync"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "my_my_method_sync"); nih_free (str); } /* Check that we can omit both the interface symbol and the postfix */ TEST_FEATURE ("without interface symbol or postfix"); TEST_ALLOC_FAIL { str = symbol_extern (NULL, "my", NULL, "emit", "my_signal", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "my_emit_my_signal"); nih_free (str); } /* Check that we can pass just the prefix and member symbol, as is * the case for methods on the default interface. */ TEST_FEATURE ("without optional arguments"); TEST_ALLOC_FAIL { str = symbol_extern (NULL, "my", NULL, NULL, "my_method", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "my_my_method"); nih_free (str); } } void test_typedef (void) { char *str; TEST_FUNCTION ("symbol_typedef"); /* Check that we can create an typedef name, which should be of * a similar style to an extern name except that the individual * components are capitalised. */ TEST_FEATURE ("with all arguments"); TEST_ALLOC_FAIL { str = symbol_typedef (NULL, "my", "test", "Get", "my_property", "Reply"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "MyTestGetMyPropertyReply"); nih_free (str); } /* Check that where the prefix has multiple underscore separated * words, they are turned into TitleCase words. */ TEST_FEATURE ("with multiple words in prefix"); TEST_ALLOC_FAIL { str = symbol_typedef (NULL, "my_first", "test", "Get", "my_property", "Reply"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "MyFirstTestGetMyPropertyReply"); nih_free (str); } /* Check that where the interface symbol has multiple underscore * separated words, they are turned into TitleCase words. */ TEST_FEATURE ("with multiple words in interface"); TEST_ALLOC_FAIL { str = symbol_typedef (NULL, "my", "cool_test", "Get", "my_property", "Reply"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "MyCoolTestGetMyPropertyReply"); nih_free (str); } /* Check that the interface symbol is optional, since the default * interface will not end up having one. */ TEST_FEATURE ("without interface symbol"); TEST_ALLOC_FAIL { str = symbol_typedef (NULL, "my", NULL, "Get", "my_property", "Reply"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "MyGetMyPropertyReply"); nih_free (str); } /* Check that we don't need to supply the midfix component */ TEST_FEATURE ("without midfix"); TEST_ALLOC_FAIL { str = symbol_typedef (NULL, "my", "test", NULL, "my_method", "Reply"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "MyTestMyMethodReply"); nih_free (str); } /* Check that we don't need to supply the postfix component */ TEST_FEATURE ("without postfix"); TEST_ALLOC_FAIL { str = symbol_typedef (NULL, "my", "test", NULL, "property_value", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "MyTestPropertyValue"); nih_free (str); } /* Check that we can omit both the interface symbol and the midfix */ TEST_FEATURE ("without interface or midfix"); TEST_ALLOC_FAIL { str = symbol_typedef (NULL, "my", NULL, NULL, "my_method", "Reply"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "MyMyMethodReply"); nih_free (str); } TEST_FEATURE ("without interface or postfix"); TEST_ALLOC_FAIL { str = symbol_typedef (NULL, "my", NULL, "test", "property_value", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "MyTestPropertyValue"); nih_free (str); } /* Check we can omit all of the optional components */ TEST_FEATURE ("without optional components"); TEST_ALLOC_FAIL { str = symbol_typedef (NULL, "my", NULL, NULL, "property_value", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "MyPropertyValue"); nih_free (str); } } int main (int argc, char *argv[]) { test_valid (); test_from_name (); test_impl (); test_extern (); test_typedef (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/property_factory.c0000644000175000017500000001156611445765555017340 00000000000000/* nih-dbus-tool * * tests/property_factory.c - generate tests/property_code.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include "type.h" #include "interface.h" #include "property.h" int main (int argc, char *argv[]) { NihList prototypes; NihList handlers; NihList typedefs; NihList structs; nih_local Interface *interface = NULL; nih_local Property * property = NULL; nih_local char * code = NULL; nih_local char * block = NULL; printf ("#include \n" "\n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "\n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "\n" "#include \"tests/property_code.h\"\n" "\n" "\n"); interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); code = property_object_get_function (NULL, "my", interface, property, &prototypes, &handlers, &structs); NIH_LIST_FOREACH (&handlers, iter) { TypeFunc *func = (TypeFunc *)iter; NIH_MUST (type_to_extern (&func->type, func)); } block = type_func_layout (NULL, &handlers); printf ("%s\n", block); printf ("%s", code); printf ("\n" "\n"); nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); code = property_object_set_function (NULL, "my", interface, property, &prototypes, &handlers, &structs); NIH_LIST_FOREACH (&handlers, iter) { TypeFunc *func = (TypeFunc *)iter; NIH_MUST (type_to_extern (&func->type, func)); } block = type_func_layout (NULL, &handlers); printf ("%s\n", block); printf ("%s", code); printf ("\n" "\n"); nih_list_init (&prototypes); nih_list_init (&structs); property->name = "test_property"; property->symbol = "test_property"; code = property_proxy_get_function (NULL, "my", interface, property, &prototypes, &structs); printf ("extern void my_com_netsplit_Nih_Test_test_property_get_notify (DBusPendingCall *pending_call, " "NihDBusPendingData *pending_data);\n"); printf ("\n"); printf ("%s" "\n", code); nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); property->name = "property"; property->symbol = "property"; code = property_proxy_get_notify_function (NULL, "my", interface, property, &prototypes, &typedefs, &structs); printf ("%s", code); printf ("\n" "\n"); nih_list_init (&prototypes); nih_list_init (&structs); property->name = "test_property"; property->symbol = "test_property"; code = property_proxy_set_function (NULL, "my", interface, property, &prototypes, &structs); printf ("extern void my_com_netsplit_Nih_Test_test_property_set_notify (DBusPendingCall *pending_call, " "NihDBusPendingData *pending_data);\n"); printf ("\n"); printf ("%s" "\n", code); nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); property->name = "property"; property->symbol = "property"; code = property_proxy_set_notify_function (NULL, "my", interface, property, &prototypes, &typedefs, &structs); printf ("%s", code); printf ("\n" "\n"); nih_list_init (&prototypes); nih_list_init (&structs); code = property_proxy_get_sync_function (NULL, "my", interface, property, &prototypes, &structs); printf ("%s" "\n", code); nih_list_init (&prototypes); nih_list_init (&structs); code = property_proxy_set_sync_function (NULL, "my", interface, property, &prototypes, &structs); printf ("%s", code); return 0; } libnih-1.0.3/nih-dbus-tool/tests/test_main.c0000644000175000017500000002505311445765555015704 00000000000000/* nih-dbus-tool * * test_main.c - test suite for nih-dbus-tool/main.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include extern int mode_option (NihOption *option, const char *arg); void test_mode_option (void) { NihOption opt; int value; FILE * output; int ret = 0; TEST_FUNCTION ("mode_option"); opt.value = &value; output = tmpfile (); /* Check that the mode_option function takes the argument as a * string and sets the value to TRUE if it is "object". */ TEST_FEATURE ("with object"); TEST_ALLOC_FAIL { value = -1; ret = mode_option (&opt, "object"); TEST_EQ (ret, 0); TEST_EQ (value, TRUE); } /* Check that the mode_option function takes the argument as a * string and sets the value to FALSE if it is "proxy". */ TEST_FEATURE ("with proxy"); TEST_ALLOC_FAIL { value = -1; ret = mode_option (&opt, "proxy"); TEST_EQ (ret, 0); TEST_EQ (value, FALSE); } /* Check that when the argument is an unknown string, an error * message is output to standard error along with a suggestion of * how to get help. */ TEST_FEATURE ("with unknown argument"); TEST_ALLOC_FAIL { value = -1; TEST_DIVERT_STDERR (output) { ret = mode_option (&opt, "frodo"); } rewind (output); TEST_LT (ret, 0); TEST_FILE_EQ (output, "test: illegal output mode: frodo\n"); TEST_FILE_EQ (output, "Try `test --help' for more information.\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } fclose (output); } extern char *source_file_path (const void *parent, const char *output_path, const char *filename) __attribute__ ((warn_unused_result, malloc)); extern char *header_file_path (const void *parent, const char *output_path, const char *filename) __attribute__ ((warn_unused_result, malloc)); void test_source_file_path (void) { char *str; TEST_FUNCTION ("source_file_path"); /* Check that when given an output path for the source file with * the expected extension, the function returns the path unchanged. */ TEST_FEATURE ("with expected extension for output path"); TEST_ALLOC_FAIL { str = source_file_path (NULL, "/path/to/output.c", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "/path/to/output.c"); nih_free (str); } /* Check that when given an output path for the source file with * a different extension than expected, the function still returns * the path unchanged. */ TEST_FEATURE ("with unusual extension for output path"); TEST_ALLOC_FAIL { str = source_file_path (NULL, "/path/to/output.cpp", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "/path/to/output.cpp"); nih_free (str); } /* Check that when given an output path with no extension at all, * the function still returns the path unchanged. */ TEST_FEATURE ("with no extension for output path"); TEST_ALLOC_FAIL { str = source_file_path (NULL, "/path/to/output", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "/path/to/output"); nih_free (str); } /* Check that when given an output path for the header file, the * function returns the path with the extension changed to be * the expected extension for a source file. */ TEST_FEATURE ("with header extension for output path"); TEST_ALLOC_FAIL { str = source_file_path (NULL, "/path/to/output.h", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "/path/to/output.c"); nih_free (str); } /* Check that when given an input filename with the usual extension, * the directory is stripped and the extension is replaced with the * expected extension for a source file. */ TEST_FEATURE ("with expected extension for input filename"); TEST_ALLOC_FAIL { str = source_file_path (NULL, NULL, "/path/to/input.xml"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "input.c"); nih_free (str); } /* Check that when given an input filename with an unusual extension, * it is still replaced with the expected extension for a source file. */ TEST_FEATURE ("with unusual extension for input filename"); TEST_ALLOC_FAIL { str = source_file_path (NULL, NULL, "/path/to/input.xp"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "input.c"); nih_free (str); } /* Check that when given an input filename with no extension, the * expected extension for a source file is appended. */ TEST_FEATURE ("with no extension for input filename"); TEST_ALLOC_FAIL { str = source_file_path (NULL, NULL, "/path/to/input"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "input.c"); nih_free (str); } /* Check that when given an input filename with the usual extension * for a source file, the extension is duplicated so as not to * overwrite the input even though the directory is stripped. */ TEST_FEATURE ("with source extension for input filename"); TEST_ALLOC_FAIL { str = source_file_path (NULL, NULL, "/path/to/input.c"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "input.c.c"); nih_free (str); } /* Check that when given an input filename with the usual extension * for a header file, the epxected extension for a source file is * appended rather than replaced to match the header file. */ TEST_FEATURE ("with header extension for input filename"); TEST_ALLOC_FAIL { str = source_file_path (NULL, NULL, "/path/to/input.h"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "input.h.c"); nih_free (str); } } void test_header_file_path (void) { char *str; TEST_FUNCTION ("header_file_path"); /* Check that when given an output path for the source file with * the expected extension, the function replaces the extension * with the expected extension for a header file. */ TEST_FEATURE ("with expected extension for output path"); TEST_ALLOC_FAIL { str = header_file_path (NULL, "/path/to/output.c", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "/path/to/output.h"); nih_free (str); } /* Check that when given an output path for the source file with * a different extension than expected, the function still replaces * the extension with the expected extension for a header file. */ TEST_FEATURE ("with unusual extension for output path"); TEST_ALLOC_FAIL { str = header_file_path (NULL, "/path/to/output.cpp", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "/path/to/output.h"); nih_free (str); } /* Check that when given an output path with no extension at all, * the function appends the expected extension for a header file. */ TEST_FEATURE ("with no extension for output path"); TEST_ALLOC_FAIL { str = header_file_path (NULL, "/path/to/output", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "/path/to/output.h"); nih_free (str); } /* Check that when given an output path for the header file, the * function returns the path unchanged. */ TEST_FEATURE ("with header extension for output path"); TEST_ALLOC_FAIL { str = header_file_path (NULL, "/path/to/output.h", NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "/path/to/output.h"); nih_free (str); } /* Check that when given an input filename with the usual extension, * the directory is stripped and the extension is replaced with the * expected extension for a header file. */ TEST_FEATURE ("with expected extension for input filename"); TEST_ALLOC_FAIL { str = header_file_path (NULL, NULL, "/path/to/input.xml"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "input.h"); nih_free (str); } /* Check that when given an input filename with an unusual extension, * it is still replaced with the expected extension for a source file. */ TEST_FEATURE ("with unusual extension for input filename"); TEST_ALLOC_FAIL { str = header_file_path (NULL, NULL, "/path/to/input.xp"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "input.h"); nih_free (str); } /* Check that when given an input filename with no extension, the * expected extension for a header file is appended. */ TEST_FEATURE ("with no extension for input filename"); TEST_ALLOC_FAIL { str = header_file_path (NULL, NULL, "/path/to/input"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "input.h"); nih_free (str); } /* Check that when given an input filename with the usual extension * for a source file, the extension is duplicated so as not to * overwrite the input even though the directory is stripped. */ TEST_FEATURE ("with source extension for input filename"); TEST_ALLOC_FAIL { str = header_file_path (NULL, NULL, "/path/to/input.c"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "input.c.h"); nih_free (str); } /* Check that when given an input filename with the usual extension * for a header file, the expected extension for a header file is * appended rather than replaced to match the source file. */ TEST_FEATURE ("with header extension for input filename"); TEST_ALLOC_FAIL { str = header_file_path (NULL, NULL, "/path/to/input.h"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "input.h.h"); nih_free (str); } } int main (int argc, char *argv[]) { program_name = "test"; test_mode_option (); test_source_file_path (); test_header_file_path (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/test_indent.c0000644000175000017500000002366111445765555016244 00000000000000/* nih-dbus-tool * * test_indent.c - test suite for nih-dbus-tool/indent.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include "indent.h" void test_indent (void) { char *str; char *ret; TEST_FUNCTION ("indent"); /* Check that we can indent a typical multi-line string, with each * line being indented including the first and last, but that an * indent isn't appended after the trailing newline. */ TEST_FEATURE ("with multi-line string"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, ("This is a test\n" "of a multi-line\n" "string.\n")); } ret = indent (&str, NULL, 1); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, ("\tThis is a test\n" "\tof a multi-line\n" "\tstring.\n")); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } /* Check that we can apply multiple levels of indent to a string * at once, to save calling the function multiple times. */ TEST_FEATURE ("with multiple indent levels"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, ("This is a test\n" "of a multi-line\n" "string.\n")); } ret = indent (&str, NULL, 3); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, ("\t\t\tThis is a test\n" "\t\t\tof a multi-line\n" "\t\t\tstring.\n")); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } /* Check that a missing final newline doesn't stop the last line * being indented. */ TEST_FEATURE ("with missing final newline"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, ("This is a test\n" "of a multi-line\n" "string.")); } ret = indent (&str, NULL, 1); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, ("\tThis is a test\n" "\tof a multi-line\n" "\tstring.")); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } /* Check that a blank line does not have an indent added. */ TEST_FEATURE ("with blank line"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, ("This is a test\n\n" "of a multi-line\n" "string.\n")); } ret = indent (&str, NULL, 1); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, ("\tThis is a test\n\n" "\tof a multi-line\n" "\tstring.\n")); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } /* Check that consecutive blank lines are handled just as well * as a single one, and that none of the lines get an indent * added. */ TEST_FEATURE ("with consecutive blank lines"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, ("This is a test\n\n\n" "of a multi-line\n\n" "string.\n")); } ret = indent (&str, NULL, 1); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, ("\tThis is a test\n\n\n" "\tof a multi-line\n\n" "\tstring.\n")); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } /* Check that the initial line may be blank, in which case it * too does not get an indent added. */ TEST_FEATURE ("with initial blank line"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, ("\n" "This is a test\n" "of a multi-line\n" "string.\n")); } ret = indent (&str, NULL, 1); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, ("\n" "\tThis is a test\n" "\tof a multi-line\n" "\tstring.\n")); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } /* Check that a single-line string is indented with no * indent after the trailing new line. */ TEST_FEATURE ("with single-line string"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "This is a test\n"); } ret = indent (&str, NULL, 1); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, "\tThis is a test\n"); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } /* Check that a simple string is indented. */ TEST_FEATURE ("with simple string"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "This is a test"); } ret = indent (&str, NULL, 1); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, "\tThis is a test"); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } } void test_comment (void) { char *str; char *ret; TEST_FUNCTION ("comment"); /* Check that a multi-line string can be commented out, with each * line including the first and last being prefixed with comment * characters; but that a comment character doesn't appear after * the trailing newline. */ TEST_FEATURE ("with multi-line string"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, ("This is a test\n" "of a multi-line\n" "string.\n")); } ret = comment (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, (" * This is a test\n" " * of a multi-line\n" " * string.\n")); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } /* Check that a missing final newline doesn't stop the last line * being commented. */ TEST_FEATURE ("with missing final newline"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, ("This is a test\n" "of a multi-line\n" "string.")); } ret = comment (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, (" * This is a test\n" " * of a multi-line\n" " * string.")); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } /* Check that a blank line still has comment markers added, * but that there is no trailing space before the newline. */ TEST_FEATURE ("with blank line"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, ("This is a test\n\n" "of a multi-line\n" "string.\n")); } ret = comment (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, (" * This is a test\n" " *\n" " * of a multi-line\n" " * string.\n")); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } /* Check that consecutive blank lines are handled just as well * as a single one, and that all of the lines get comment markers * added with no trailing spaces. */ TEST_FEATURE ("with consecutive blank lines"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, ("This is a test\n\n\n" "of a multi-line\n\n" "string.\n")); } ret = comment (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, (" * This is a test\n" " *\n" " *\n" " * of a multi-line\n" " *\n" " * string.\n")); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } /* Check that the initial line may be blank, in which case it * too still gets a comment marker added with no trailing space. */ TEST_FEATURE ("with initial blank line"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, ("\n" "This is a test\n" "of a multi-line\n" "string.\n")); } ret = comment (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, (" *\n" " * This is a test\n" " * of a multi-line\n" " * string.\n")); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } /* Check that a single-line string is commented with no * marker after the trailing new line. */ TEST_FEATURE ("with single-line string"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "This is a test\n"); } ret = comment (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, " * This is a test\n"); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } /* Check that a simple string is commented out. */ TEST_FEATURE ("with simple string"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "This is a test"); } ret = comment (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_NE_P (str, NULL); nih_free (str); continue; } TEST_EQ_STR (ret, " * This is a test"); TEST_ALLOC_SIZE (ret, strlen (ret) + 1); nih_free (ret); } } int main (int argc, char *argv[]) { test_indent (); test_comment (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/test_signal.c0000644000175000017500000020260711445765555016237 00000000000000/* nih-dbus-tool * * test_signal.c - test suite for nih-dbus-tool/signal.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "type.h" #include "node.h" #include "signal.h" #include "argument.h" #include "parse.h" #include "errors.h" #include "tests/signal_code.h" void test_name_valid (void) { TEST_FUNCTION ("signal_name_valid"); /* Check that a typical signal name is valid. */ TEST_FEATURE ("with typical signal name"); TEST_TRUE (signal_name_valid ("Wibble")); /* Check that an signal name is not valid if it is has an * initial period. */ TEST_FEATURE ("with initial period"); TEST_FALSE (signal_name_valid (".Wibble")); /* Check that an signal name is not valid if it ends with a period */ TEST_FEATURE ("with final period"); TEST_FALSE (signal_name_valid ("Wibble.")); /* Check that an signal name is not valid if it contains a period */ TEST_FEATURE ("with period"); TEST_FALSE (signal_name_valid ("Wib.ble")); /* Check that a signal name may contain numbers */ TEST_FEATURE ("with numbers"); TEST_TRUE (signal_name_valid ("Wib43ble")); /* Check that a signal name may not begin with numbers */ TEST_FEATURE ("with leading digits"); TEST_FALSE (signal_name_valid ("43Wibble")); /* Check that a signal name may end with numbers */ TEST_FEATURE ("with trailing digits"); TEST_TRUE (signal_name_valid ("Wibble43")); /* Check that a signal name may contain underscores */ TEST_FEATURE ("with underscore"); TEST_TRUE (signal_name_valid ("Wib_ble")); /* Check that a signal name may begin with underscores */ TEST_FEATURE ("with initial underscore"); TEST_TRUE (signal_name_valid ("_Wibble")); /* Check that a signal name may end with underscores */ TEST_FEATURE ("with final underscore"); TEST_TRUE (signal_name_valid ("Wibble_")); /* Check that other characters are not permitted */ TEST_FEATURE ("with non-permitted characters"); TEST_FALSE (signal_name_valid ("Wib-ble")); /* Check that an empty signal name is invalid */ TEST_FEATURE ("with empty string"); TEST_FALSE (signal_name_valid ("")); /* Check that an signal name may not exceed 255 characters */ TEST_FEATURE ("with overly long name"); TEST_FALSE (signal_name_valid ("ReallyLongSignalNameThatNobody" "InTheirRightMindWouldEverUseNo" "tInTheLeastBecauseThenYoudEndU" "pWithAnEvenLongerInterfaceName" "AndThatJustWontWorkWhenCombine" "dButStillWeTestThisShitJustInc" "aseSomeoneTriesItBecauseThatsW" "hatTestDrivenDevelopmentIsAllA" "bout.YayThereNow")); } void test_new (void) { Signal *signal; /* Check that an Signal object is allocated with the structure * filled in properly, but not placed in a list. */ TEST_FUNCTION ("signal_new"); TEST_ALLOC_FAIL { signal = signal_new (NULL, "Yahoo"); if (test_alloc_failed) { TEST_EQ_P (signal, NULL); continue; } TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_LIST_EMPTY (&signal->entry); TEST_EQ_STR (signal->name, "Yahoo"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_P (signal->symbol, NULL); TEST_FALSE (signal->deprecated); TEST_LIST_EMPTY (&signal->arguments); nih_free (signal); } } void test_start_tag (void) { ParseContext context; ParseStack * parent = NULL; ParseStack * entry; XML_Parser xmlp; Node * node = NULL; Interface * interface = NULL; Signal * signal; char * attr[5]; int ret = 0; NihError * err; FILE * output; TEST_FUNCTION ("signal_start_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); output = tmpfile (); /* Check that an signal tag for an interface with the usual name * attribute results in an Signal member being created and pushed * onto the stack with that attribute filled in correctly. */ TEST_FEATURE ("with signal"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } attr[0] = "name"; attr[1] = "TestSignal"; attr[2] = NULL; ret = signal_start_tag (xmlp, "signal", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->signals); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_SIGNAL); signal = entry->signal; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, entry); TEST_EQ_STR (signal->name, "TestSignal"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_P (signal->symbol, NULL); TEST_LIST_EMPTY (&signal->arguments); TEST_LIST_EMPTY (&interface->signals); nih_free (entry); nih_free (parent); } /* Check that a signal with a missing name attribute results * in an error being raised. */ TEST_FEATURE ("with missing name"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = NULL; } ret = signal_start_tag (xmlp, "signal", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->signals); err = nih_error_get (); TEST_EQ (err->number, SIGNAL_MISSING_NAME); nih_free (err); nih_free (parent); } /* Check that a signal with an invalid name results in an * error being raised. */ TEST_FEATURE ("with invalid name"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "Test Signal"; attr[2] = NULL; } ret = signal_start_tag (xmlp, "signal", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->signals); err = nih_error_get (); TEST_EQ (err->number, SIGNAL_INVALID_NAME); nih_free (err); nih_free (parent); } /* Check that an unknown signal attribute results in a warning * being printed to standard error, but is otherwise ignored * and the normal processing finished. */ TEST_FEATURE ("with unknown attribute"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "TestSignal"; attr[2] = "frodo"; attr[3] = "baggins"; attr[4] = NULL; } TEST_DIVERT_STDERR (output) { ret = signal_start_tag (xmlp, "signal", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_SIGNAL); signal = entry->signal; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, entry); TEST_EQ_STR (signal->name, "TestSignal"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_P (signal->symbol, NULL); TEST_LIST_EMPTY (&signal->arguments); TEST_LIST_EMPTY (&interface->signals); TEST_FILE_EQ (output, ("test:foo:1:0: Ignored unknown attribute: " "frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } /* Check that a signal on an empty stack (ie. a top-level * signal element) results in a warning being printed on * standard error and an ignored element being pushed onto the * stack. */ TEST_FEATURE ("with empty stack"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { attr[0] = "name"; attr[1] = "TestSignal"; attr[2] = NULL; } TEST_DIVERT_STDERR (output) { ret = signal_start_tag (xmlp, "signal", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), NULL); TEST_FILE_RESET (output); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unexpected tag\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); } /* Check that a signal on top of a stack entry that's not an * interface results in a warning being printed on * standard error and an ignored element being pushed onto the * stack. */ TEST_FEATURE ("with non-interface on stack"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); attr[0] = "name"; attr[1] = "TestSignal"; attr[2] = NULL; } TEST_DIVERT_STDERR (output) { ret = signal_start_tag (xmlp, "signal", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unexpected tag\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } XML_ParserFree (xmlp); fclose (output); } void test_end_tag (void) { ParseContext context; ParseStack * parent = NULL; ParseStack * entry = NULL; XML_Parser xmlp; Interface * interface = NULL; Signal * signal = NULL; Signal * other = NULL; int ret; NihError * err; TEST_FUNCTION ("signal_end_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); /* Check that when we parse the end tag for a signal, we pop * the Signal object off the stack (freeing and removing it) * and append it to the parent interface's signals list, adding a * reference to the interface as well. A symbol should be generated * for the signal by convering its name to C style. */ TEST_FEATURE ("with no assigned symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); signal = signal_new (NULL, "TestSignal"); entry = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); } TEST_FREE_TAG (entry); ret = signal_end_tag (xmlp, "signal"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->signals); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (signal, interface); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_EQ_P (interface->signals.next, &signal->entry); TEST_EQ_STR (signal->symbol, "test_signal"); TEST_ALLOC_PARENT (signal->symbol, signal); nih_free (parent); } /* Check that when the symbol has been pre-assigned by the data, * it's not overridden and is used even if different. */ TEST_FEATURE ("with assigned symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); signal = signal_new (NULL, "TestSignal"); signal->symbol = nih_strdup (signal, "foo"); entry = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); } TEST_FREE_TAG (entry); ret = signal_end_tag (xmlp, "signal"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->signals); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (signal, interface); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_EQ_P (interface->signals.next, &signal->entry); TEST_EQ_STR (signal->symbol, "foo"); TEST_ALLOC_PARENT (signal->symbol, signal); nih_free (parent); } /* Check that we don't generate a duplicate symbol, and instead * raise an error and allow the user to deal with it using * the Symbol annotation. The reason we don't work around this * with a counter or similar is that the function names then * become unpredicatable (introspection data isn't ordered). */ TEST_FEATURE ("with conflicting symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); other = signal_new (interface, "Test"); other->symbol = nih_strdup (other, "test_signal"); nih_list_add (&interface->signals, &other->entry); signal = signal_new (NULL, "TestSignal"); entry = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); } ret = signal_end_tag (xmlp, "signal"); TEST_LT (ret, 0); err = nih_error_get (); if ((! test_alloc_failed) || (err->number != ENOMEM)) TEST_EQ (err->number, SIGNAL_DUPLICATE_SYMBOL); nih_free (err); nih_free (entry); nih_free (parent); } XML_ParserFree (xmlp); } void test_annotation (void) { Signal * signal = NULL; char * symbol; int ret; NihError *err; TEST_FUNCTION ("signal_annotation"); /* Check that the annotation to mark a signal as deprecated is * handled, and the Signal is marked deprecated. */ TEST_FEATURE ("with deprecated annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); } ret = signal_annotation (signal, "org.freedesktop.DBus.Deprecated", "true"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_FALSE (signal->deprecated); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (signal); continue; } TEST_EQ (ret, 0); TEST_TRUE (signal->deprecated); nih_free (signal); } /* Check that the annotation to mark a signal as deprecated can be * given a false value to explicitly mark the Signal non-deprecated. */ TEST_FEATURE ("with explicitly non-deprecated annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); signal->deprecated = TRUE; } ret = signal_annotation (signal, "org.freedesktop.DBus.Deprecated", "false"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_TRUE (signal->deprecated); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (signal); continue; } TEST_EQ (ret, 0); TEST_FALSE (signal->deprecated); nih_free (signal); } /* Check that an annotation to add a symbol to the signal is * handled, and the new symbol is stored in the signal. */ TEST_FEATURE ("with symbol annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); } ret = signal_annotation (signal, "com.netsplit.Nih.Symbol", "foo"); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (signal); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (signal->symbol, "foo"); TEST_ALLOC_PARENT (signal->symbol, signal); nih_free (signal); } /* Check that an annotation to add a symbol to the signal * replaces any previous symbol applied (e.g. by a previous * annotation). */ TEST_FEATURE ("with symbol annotation and existing symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); signal->symbol = nih_strdup (signal, "test_arg"); } symbol = signal->symbol; TEST_FREE_TAG (symbol); ret = signal_annotation (signal, "com.netsplit.Nih.Symbol", "foo"); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (signal); continue; } TEST_EQ (ret, 0); TEST_FREE (symbol); TEST_EQ_STR (signal->symbol, "foo"); TEST_ALLOC_PARENT (signal->symbol, signal); nih_free (signal); } /* Check that an invalid value for the deprecated annotation results * in an error being raised. */ TEST_FEATURE ("with invalid value for deprecated annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); } ret = signal_annotation (signal, "org.freedesktop.DBus.Deprecated", "foo"); TEST_LT (ret, 0); TEST_EQ_P (signal->symbol, NULL); err = nih_error_get (); TEST_EQ (err->number, SIGNAL_ILLEGAL_DEPRECATED); nih_free (err); nih_free (signal); } /* Check that an invalid symbol in an annotation results in an * error being raised. */ TEST_FEATURE ("with invalid symbol in annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); } ret = signal_annotation (signal, "com.netsplit.Nih.Symbol", "foo bar"); TEST_LT (ret, 0); TEST_EQ_P (signal->symbol, NULL); err = nih_error_get (); TEST_EQ (err->number, SIGNAL_INVALID_SYMBOL); nih_free (err); nih_free (signal); } /* Check that an unknown annotation results in an error being * raised. */ TEST_FEATURE ("with unknown annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); } ret = signal_annotation (signal, "com.netsplit.Nih.Unknown", "true"); TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, SIGNAL_UNKNOWN_ANNOTATION); nih_free (err); nih_free (signal); } } void test_lookup (void) { Interface *interface = NULL; Signal * signal1 = NULL; Signal * signal2 = NULL; Signal * signal3 = NULL; Signal * ret; TEST_FUNCTION ("signal_lookup"); /* Check that the function returns the signal if there is one * with the given symbol. */ TEST_FEATURE ("with matching symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); signal1 = signal_new (interface, "Test"); signal1->symbol = nih_strdup (signal1, "test"); nih_list_add (&interface->signals, &signal1->entry); signal2 = signal_new (interface, "Foo"); nih_list_add (&interface->signals, &signal2->entry); signal3 = signal_new (interface, "Bar"); signal3->symbol = nih_strdup (signal3, "bar"); nih_list_add (&interface->signals, &signal3->entry); } ret = signal_lookup (interface, "bar"); TEST_EQ_P (ret, signal3); nih_free (interface); } /* Check that the function returns NULL if there is no signal * with the given symbol. */ TEST_FEATURE ("with non-matching symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); signal1 = signal_new (interface, "Test"); signal1->symbol = nih_strdup (signal1, "test"); nih_list_add (&interface->signals, &signal1->entry); signal2 = signal_new (interface, "Foo"); nih_list_add (&interface->signals, &signal2->entry); signal3 = signal_new (interface, "Bar"); signal3->symbol = nih_strdup (signal3, "bar"); nih_list_add (&interface->signals, &signal3->entry); } ret = signal_lookup (interface, "baz"); TEST_EQ_P (ret, NULL); nih_free (interface); } } void test_lookup_argument (void) { Signal * signal = NULL; Argument *argument1 = NULL; Argument *argument2 = NULL; Argument *argument3 = NULL; Argument *ret; TEST_FUNCTION ("signal_lookup_argument"); /* Check that the function returns the argument if there is one * with the given symbol. */ TEST_FEATURE ("with matching symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "com.netsplit.Nih.Test"); argument1 = argument_new (signal, "Test", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "test"); nih_list_add (&signal->arguments, &argument1->entry); argument2 = argument_new (signal, "Foo", "s", NIH_DBUS_ARG_IN); nih_list_add (&signal->arguments, &argument2->entry); argument3 = argument_new (signal, "Bar", "s", NIH_DBUS_ARG_IN); argument3->symbol = nih_strdup (argument3, "bar"); nih_list_add (&signal->arguments, &argument3->entry); } ret = signal_lookup_argument (signal, "bar"); TEST_EQ_P (ret, argument3); nih_free (signal); } /* Check that the function returns NULL if there is no argument * with the given symbol. */ TEST_FEATURE ("with non-matching symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "com.netsplit.Nih.Test"); argument1 = argument_new (signal, "Test", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "test"); nih_list_add (&signal->arguments, &argument1->entry); argument2 = argument_new (signal, "Foo", "s", NIH_DBUS_ARG_IN); nih_list_add (&signal->arguments, &argument2->entry); argument3 = argument_new (signal, "Bar", "s", NIH_DBUS_ARG_IN); argument3->symbol = nih_strdup (argument3, "bar"); nih_list_add (&signal->arguments, &argument3->entry); } ret = signal_lookup_argument (signal, "baz"); TEST_EQ_P (ret, NULL); nih_free (signal); } } void test_object_function (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihList prototypes; NihList structs; Interface * interface = NULL; Signal * signal = NULL; Argument * argument = NULL; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; NihListEntry * attrib; DBusMessageIter iter; DBusMessage * sig; DBusError dbus_error; int ret; TEST_FUNCTION ("signal_object_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that marhals its arguments * into a D-Bus message and sends it as a signal. */ TEST_FEATURE ("with signal"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; signal = signal_new (NULL, "Signal"); signal->symbol = nih_strdup (signal, "signal"); argument = argument_new (signal, "Msg", "s", NIH_DBUS_ARG_OUT); argument->symbol = nih_strdup (argument, "msg"); nih_list_add (&signal->arguments, &argument->entry); } str = signal_object_function (NULL, "my", interface, signal, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (signal); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_signal_object_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_emit_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "msg"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (signal); nih_free (interface); } /* Check that a signal with no arguments can still have * a correctly generated function. */ TEST_FEATURE ("with no arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; signal = signal_new (NULL, "Signal"); signal->symbol = nih_strdup (signal, "signal"); } str = signal_object_function (NULL, "my", interface, signal, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (signal); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_signal_object_function_no_args.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_emit_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (signal); nih_free (interface); } /* Check that a signal with a structure argument is correctly * generated, with the structure type passed back in the * structs array. */ TEST_FEATURE ("with structure argument"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; signal = signal_new (NULL, "Signal"); signal->symbol = nih_strdup (signal, "signal"); argument = argument_new (signal, "structure", "(su)", NIH_DBUS_ARG_OUT); argument->symbol = nih_strdup (argument, "structure"); nih_list_add (&signal->arguments, &argument->entry); } str = signal_object_function (NULL, "my", interface, signal, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (signal); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_signal_object_function_structure.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_emit_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MySignalStructure *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "structure"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MySignalStructure"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (signal); nih_free (interface); } /* Check that a signal with an array argument can have that argument * as NULL if length is zero. */ TEST_FEATURE ("with array argument"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; signal = signal_new (NULL, "Signal"); signal->symbol = nih_strdup (signal, "signal"); argument = argument_new (signal, "Value", "ai", NIH_DBUS_ARG_OUT); argument->symbol = nih_strdup (argument, "value"); nih_list_add (&signal->arguments, &argument->entry); } str = signal_object_function (NULL, "my", interface, signal, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (signal); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_signal_object_function_array.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_emit_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const int32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "size_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value_len"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (signal); nih_free (interface); } /* Check that we can use the generated code to emit a signal and * that we can receive it. */ TEST_FEATURE ("with signal (generated code)"); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (server_conn, "type='signal'", &dbus_error); ret = my_emit_signal (client_conn, "/com/netsplit/Nih/Test", "this is a test"); if (test_alloc_failed && (ret < 0)) { continue; } TEST_EQ (ret, 0); TEST_DBUS_MESSAGE (server_conn, sig); TEST_EQ (dbus_message_get_type (sig), DBUS_MESSAGE_TYPE_SIGNAL); dbus_message_iter_init (sig, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str); TEST_EQ_STR (str, "this is a test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (sig); } /* Check that a deprecated signal does not have the attribute * added, since we want to be able to emit it without a gcc * warning. */ TEST_FEATURE ("with deprecated signal"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; signal = signal_new (NULL, "Signal"); signal->symbol = nih_strdup (signal, "signal"); signal->deprecated = TRUE; argument = argument_new (signal, "Msg", "s", NIH_DBUS_ARG_OUT); argument->symbol = nih_strdup (argument, "msg"); nih_list_add (&signal->arguments, &argument->entry); } str = signal_object_function (NULL, "my", interface, signal, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (signal); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_signal_object_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_emit_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "msg"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (signal); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int my_signal_handler_called = FALSE; static void my_signal_handler (void * data, NihDBusMessage *message, const char * msg) { my_signal_handler_called++; TEST_EQ_P (data, &my_signal_handler_called); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_ALLOC_PARENT (msg, message); TEST_EQ_STR (msg, "this is a test"); } const NihDBusSignal my_interface_signals[] = { { "Signal", NULL, my_com_netsplit_Nih_Test_Signal_signal }, { NULL } }; const NihDBusInterface my_interface = { "com.netsplit.Nih", NULL, my_interface_signals, NULL }; void test_proxy_function (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; DBusConnection * other_conn; NihList prototypes; NihList typedefs; NihList structs; Interface * interface = NULL; Signal * signal = NULL; Argument * argument = NULL; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; NihListEntry * attrib; NihDBusProxy * proxy = NULL; NihDBusProxySignal *proxied = NULL; DBusMessage * sig; DBusMessageIter iter; DBusError dbus_error; TEST_FUNCTION ("signal_proxy_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a filter function that checks and * demarshals the arguments of a received signal and calls a * handler function for it. */ TEST_FEATURE ("with signal"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; signal = signal_new (NULL, "Signal"); signal->symbol = nih_strdup (signal, "signal"); argument = argument_new (signal, "Msg", "s", NIH_DBUS_ARG_OUT); argument->symbol = nih_strdup (argument, "msg"); nih_list_add (&signal->arguments, &argument->entry); } str = signal_proxy_function (NULL, "my", interface, signal, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (signal); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_signal_proxy_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Signal_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MySignalHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "msg"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (signal); nih_free (interface); } /* Check that we can still generate a filter function for a signal * with no arguments. */ TEST_FEATURE ("with no arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; signal = signal_new (NULL, "Signal"); signal->symbol = nih_strdup (signal, "signal"); } str = signal_proxy_function (NULL, "my", interface, signal, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (signal); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_signal_proxy_function_no_args.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Signal_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MySignalHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (signal); nih_free (interface); } /* Check that a signal with a structure argument is correctly * generated, with the structure type passed back in the structs * array. */ TEST_FEATURE ("with structure argument"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; signal = signal_new (NULL, "Signal"); signal->symbol = nih_strdup (signal, "signal"); argument = argument_new (signal, "structure", "(su)", NIH_DBUS_ARG_OUT); argument->symbol = nih_strdup (argument, "structure"); nih_list_add (&signal->arguments, &argument->entry); } str = signal_proxy_function (NULL, "my", interface, signal, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (signal); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_signal_proxy_function_structure.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Signal_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MySignalHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MySignalStructure *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "structure"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MySignalStructure"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (signal); nih_free (interface); } /* Check that we can use the generated code to catch a signal * with a peer-to-peer proxy and make a call to the handler with the * expected arguments. */ TEST_FEATURE ("with signal and peer-to-peer (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, NULL, "/com/netsplit/Nih", NULL, NULL); proxied = nih_dbus_proxy_connect (proxy, &my_interface, "Signal", (NihDBusSignalHandler)my_signal_handler, &my_signal_handler_called); } dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); dbus_error_free (&dbus_error); sig = dbus_message_new_signal ("/com/netsplit/Nih", "com.netsplit.Nih", "Signal"); dbus_message_iter_init_append (sig, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); dbus_connection_send (server_conn, sig, NULL); dbus_connection_flush (server_conn); dbus_message_unref (sig); my_signal_handler_called = FALSE; TEST_DBUS_DISPATCH (client_conn); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); dbus_error_free (&dbus_error); TEST_TRUE (my_signal_handler_called); TEST_ALLOC_SAFE { nih_free (proxied); nih_free (proxy); } } /* Check that we can use the generated code to catch a signal * with a unique name proxy and make a call to the handler with the * expected arguments. */ TEST_FEATURE ("with signal and unique name (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); proxied = nih_dbus_proxy_connect (proxy, &my_interface, "Signal", (NihDBusSignalHandler)my_signal_handler, &my_signal_handler_called); } sig = dbus_message_new_signal ("/com/netsplit/Nih", "com.netsplit.Nih", "Signal"); dbus_message_iter_init_append (sig, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); dbus_connection_send (server_conn, sig, NULL); dbus_connection_flush (server_conn); dbus_message_unref (sig); my_signal_handler_called = FALSE; TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (my_signal_handler_called); TEST_ALLOC_SAFE { nih_free (proxied); nih_free (proxy); } } /* Check that we can use the generated code to catch a signal * with a well-known name name proxy and make a call to the handler * with the expected arguments. */ TEST_FEATURE ("with signal and well-known name (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (other_conn); assert (dbus_bus_request_name (other_conn, "com.netsplit.Nih", 0, NULL) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, "com.netsplit.Nih", "/com/netsplit/Nih", NULL, NULL); proxied = nih_dbus_proxy_connect (proxy, &my_interface, "Signal", (NihDBusSignalHandler)my_signal_handler, &my_signal_handler_called); } sig = dbus_message_new_signal ("/com/netsplit/Nih", "com.netsplit.Nih", "Signal"); dbus_message_iter_init_append (sig, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); dbus_connection_send (other_conn, sig, NULL); dbus_connection_flush (other_conn); dbus_message_unref (sig); my_signal_handler_called = FALSE; TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (my_signal_handler_called); TEST_ALLOC_SAFE { nih_free (proxied); nih_free (proxy); } TEST_DBUS_CLOSE (other_conn); } /* Check that a deprecated signal generates a warning since we * don't want people catching them (passing the pointer should be * enough I think). */ TEST_FEATURE ("with deprecated signal"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; signal = signal_new (NULL, "Signal"); signal->symbol = nih_strdup (signal, "signal"); signal->deprecated = TRUE; argument = argument_new (signal, "Msg", "s", NIH_DBUS_ARG_OUT); argument->symbol = nih_strdup (argument, "msg"); nih_list_add (&signal->arguments, &argument->entry); } str = signal_proxy_function (NULL, "my", interface, signal, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (signal); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_signal_proxy_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Signal_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MySignalHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "msg"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "deprecated"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (signal); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_args_array (void) { NihList prototypes; Interface *interface = NULL; Signal * signal = NULL; Argument * arg1 = NULL; Argument * arg2 = NULL; Argument * arg3 = NULL; char * str; TypeVar * var; TEST_FUNCTION ("signal_args_array"); /* Check that we can generate an array of argument definitions for * a signal, with each name and type lined up with each other and * the final part lined up too. Arguments without names should have * NULL in place of the name. */ TEST_FEATURE ("with arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; signal = signal_new (interface, "Signal"); signal->symbol = "signal"; nih_list_add (&interface->signals, &signal->entry); arg1 = argument_new (signal, "foo", "as", NIH_DBUS_ARG_OUT); arg1->symbol = "foo"; nih_list_add (&signal->arguments, &arg1->entry); arg2 = argument_new (signal, "wibble", "i", NIH_DBUS_ARG_OUT); arg2->symbol = "wibble"; nih_list_add (&signal->arguments, &arg2->entry); arg3 = argument_new (signal, NULL, "a(iii)", NIH_DBUS_ARG_OUT); arg3->symbol = "arg3"; nih_list_add (&signal->arguments, &arg3->entry); } str = signal_args_array (NULL, "my", interface, signal, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "const NihDBusArg my_com_netsplit_Nih_Test_Signal_signal_args[] = {\n" "\t{ \"foo\", \"as\", NIH_DBUS_ARG_OUT },\n" "\t{ \"wibble\", \"i\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL, \"a(iii)\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL }\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusArg"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test_Signal_signal_args"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } /* Check that a signal with no arguments has an empty array * returned. */ TEST_FEATURE ("with no arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; signal = signal_new (interface, "Signal"); signal->symbol = "signal"; nih_list_add (&interface->signals, &signal->entry); } str = signal_args_array (NULL, "my", interface, signal, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "const NihDBusArg my_com_netsplit_Nih_Test_Signal_signal_args[] = {\n" "\t{ NULL }\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusArg"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test_Signal_signal_args"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } } int main (int argc, char *argv[]) { program_name = "test"; nih_error_init (); test_name_valid (); test_new (); test_start_tag (); test_end_tag (); test_annotation (); test_lookup (); test_lookup_argument (); test_object_function (); test_proxy_function (); test_args_array (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/0000755000175000017500000000000011504742363015415 500000000000000libnih-1.0.3/nih-dbus-tool/tests/expected/test_signal_proxy_function_no_args.c0000644000175000017500000000265311445765555024715 00000000000000DBusHandlerResult my_com_netsplit_Nih_Test_Signal_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MySignalHandler)proxied->handler) (proxied->data, message); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_sync_function_structure_output.c0000644000175000017500000000716211445765555030004 00000000000000int my_method_sync (const void * parent, NihDBusProxy * proxy, MyMethodStructure **structure) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; MyMethodStructure *structure_local; DBusMessageIter structure_local_iter; const char * structure_local_item0_dbus; char * structure_local_item0; uint32_t structure_local_item1; nih_assert (proxy != NULL); nih_assert (structure != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Method"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); do { __label__ enomem; /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRUCT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &structure_local_iter); structure_local = nih_new (parent, MyMethodStructure); if (! structure_local) { *structure = NULL; goto enomem; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&structure_local_iter) != DBUS_TYPE_STRING) { nih_free (structure_local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&structure_local_iter, &structure_local_item0_dbus); structure_local_item0 = nih_strdup (structure_local, structure_local_item0_dbus); if (! structure_local_item0) { nih_free (structure_local); *structure = NULL; goto enomem; } dbus_message_iter_next (&structure_local_iter); structure_local->item0 = structure_local_item0; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&structure_local_iter) != DBUS_TYPE_UINT32) { nih_free (structure_local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&structure_local_iter, &structure_local_item1); dbus_message_iter_next (&structure_local_iter); structure_local->item1 = structure_local_item1; if (dbus_message_iter_get_arg_type (&structure_local_iter) != DBUS_TYPE_INVALID) { nih_free (structure_local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&iter); *structure = structure_local; enomem: __attribute__ ((unused)); } while (! *structure); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (structure_local); *structure = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_output_object_standard.h0000644000175000017500000000216711445765555023335 00000000000000/* test * * Copyright (C) 2009 Joe Bloggs. * * This file was automatically generated; see the source for copying * conditions. */ #ifndef TEST_TEST_H #define TEST_TEST_H #include #include #include #include #include typedef struct my_foo_preferences { uint32_t item0; char * item1; } MyFooPreferences; NIH_BEGIN_EXTERN extern const NihDBusInterface my_com_netsplit_Nih_Test; extern const NihDBusInterface my_com_netsplit_Nih_Foo; extern const NihDBusInterface *my_interfaces[]; int my_test_peek_reply (NihDBusMessage *message, const char *value) __attribute__ ((warn_unused_result)); int my_test_emit_bounce (DBusConnection *connection, const char *origin_path, uint32_t height, int32_t velocity) __attribute__ ((warn_unused_result)); int my_test_emit_exploded (DBusConnection *connection, const char *origin_path) __attribute__ ((warn_unused_result)); int my_foo_emit_new_result (DBusConnection *connection, const char *origin_path) __attribute__ ((warn_unused_result)); NIH_END_EXTERN #endif /* TEST_TEST_H */ libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_proxy_functions_only_properties.c0000644000175000017500000013035611445765555026357 00000000000000DBusPendingCall * my_test_get_colour (NihDBusProxy * proxy, MyTestGetColourReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_colour_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_colour_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; const char * value_dbus; char * value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyTestGetColourReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_colour_sync (const void * parent, NihDBusProxy *proxy, char ** value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; const char * local_dbus; char * local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &local_dbus); local = nih_strdup (parent, local_dbus); if (! local) { *value = NULL; goto enomem; } dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_set_colour (NihDBusProxy * proxy, const char * value, MyTestSetColourReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_colour_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_colour_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestSetColourReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_set_colour_sync (const void * parent, NihDBusProxy *proxy, const char * value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_get_size (NihDBusProxy * proxy, MyTestGetSizeReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "size"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_size_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_size_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; uint32_t value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &value); dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyTestGetSizeReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_size_sync (const void * parent, NihDBusProxy *proxy, uint32_t * value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; uint32_t local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "size"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &local); dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_set_touch (NihDBusProxy * proxy, int value, MyTestSetTouchReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "touch"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "b", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_BOOLEAN, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_touch_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_touch_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestSetTouchReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_set_touch_sync (const void * parent, NihDBusProxy *proxy, int value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "touch"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "b", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_BOOLEAN, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_get_all (NihDBusProxy * proxy, MyTestGetAllReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_get_all_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_get_all_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; NihDBusMessage * message; DBusError error; const char * property; MyTestProperties *properties; size_t property_count; char * colour; const char * colour_dbus; uint32_t size; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } properties = NIH_MUST (nih_new (message, MyTestProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "colour")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &colour_dbus); colour = nih_strdup (properties, colour_dbus); if (! colour) { goto enomem; } dbus_message_iter_next (&variter); properties->colour = colour; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); properties->size = size; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } if (property_count < 2) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ nih_error_push_context (); ((MyTestGetAllReply)pending_data->handler) (pending_data->data, message, properties); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_all_sync (const void * parent, NihDBusProxy * proxy, MyTestProperties **properties) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; DBusError error; DBusMessage * reply; size_t property_count; const char * interface; const char * property; char * colour; const char * colour_dbus; uint32_t size; nih_assert (proxy != NULL); nih_assert (properties != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } *properties = NIH_MUST (nih_new (parent, MyTestProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "colour")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &colour_dbus); colour = nih_strdup (*properties, colour_dbus); if (! colour) { goto enomem; } dbus_message_iter_next (&variter); (*properties)->colour = colour; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); (*properties)->size = size; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } if (property_count < 2) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_get_notify_function_standard.c0000644000175000017500000000623211445765555027720 00000000000000void my_com_netsplit_Nih_Test_property_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; const char * value_dbus; char * value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyGetPropertyReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_set_function_deprecated.c0000644000175000017500000000645411445765555026652 00000000000000DBusPendingCall * my_set_test_property (NihDBusProxy * proxy, const char * value, MySetTestPropertyReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "test_property"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_test_property_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_function_deprecated.c0000644000175000017500000000522211445765555025363 00000000000000DBusPendingCall * my_test_method (NihDBusProxy * proxy, const char * str, int32_t flags, MyTestMethodReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert (str != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "TestMethod"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_TestMethod_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_sync_function_array_input.c0000644000175000017500000000426711445765555026664 00000000000000int my_method_sync (const void * parent, NihDBusProxy * proxy, const int32_t *value, size_t value_len) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; DBusMessageIter value_iter; nih_assert (proxy != NULL); nih_assert ((value_len == 0) || (value != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Method"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal an array onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "i", &value_iter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } for (size_t value_i = 0; value_i < value_len; value_i++) { int32_t value_element; value_element = value[value_i]; /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_INT32, &value_element)) { dbus_message_iter_abandon_container (&iter, &value_iter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } } if (! dbus_message_iter_close_container (&iter, &value_iter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_object_functions_standard.c0000644000175000017500000005050211445765555025001 00000000000000static DBusHandlerResult my_com_netsplit_Nih_Test_Poke_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; uint32_t address; char * value; const char * value_dbus; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Poke method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &address); dbus_message_iter_next (&iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Poke method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Poke method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_test_poke (object->data, message, address, value) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } static DBusHandlerResult my_com_netsplit_Nih_Test_Peek_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; uint32_t address; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Peek method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &address); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Peek method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_test_peek (object->data, message, address) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); return DBUS_HANDLER_RESULT_HANDLED; } int my_test_peek_reply (NihDBusMessage *message, const char * value) { DBusMessage * reply; DBusMessageIter iter; nih_assert (message != NULL); nih_assert (value != NULL); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return 0; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) return -1; dbus_message_iter_init_append (reply, &iter); /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) { dbus_message_unref (reply); return -1; } /* Send the reply, appending it to the outgoing queue. */ if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return -1; } dbus_message_unref (reply); return 0; } static DBusHandlerResult my_com_netsplit_Nih_Test_IsValidAddress_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; uint32_t address; int is_valid; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to IsValidAddress method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &address); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to IsValidAddress method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_test_is_valid_address (object->data, message, address, &is_valid) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &is_valid)) { dbus_message_unref (reply); reply = NULL; goto enomem; } enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } int my_test_emit_bounce (DBusConnection *connection, const char * origin_path, uint32_t height, int32_t velocity) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Bounce"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &height)) { dbus_message_unref (signal); return -1; } /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &velocity)) { dbus_message_unref (signal); return -1; } /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } int my_test_emit_exploded (DBusConnection *connection, const char * origin_path) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Exploded"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } static int my_com_netsplit_Nih_Test_colour_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_test_get_colour (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "s", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int my_com_netsplit_Nih_Test_colour_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; const char * value_dbus; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_error_raise_no_memory (); return -1; } dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } /* Call the handler function */ if (my_test_set_colour (object->data, message, value) < 0) return -1; return 0; } static int my_com_netsplit_Nih_Test_size_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; uint32_t value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_test_get_size (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "u", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &value)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int my_com_netsplit_Nih_Test_touch_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; int value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a int from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_BOOLEAN) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } dbus_message_iter_get_basic (&variter, &value); dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } /* Call the handler function */ if (my_test_set_touch (object->data, message, value) < 0) return -1; return 0; } static DBusHandlerResult my_com_netsplit_Nih_Foo_Bing_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Bing method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_foo_bing (object->data, message) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } int my_foo_emit_new_result (DBusConnection *connection, const char * origin_path) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Foo", "NewResult"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_object_set_function_deprecated.c0000644000175000017500000000271311445765555026731 00000000000000int my_com_netsplit_Nih_Test_property_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; const char * value_dbus; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to property property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to property property"); return -1; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_error_raise_no_memory (); return -1; } dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to property property"); return -1; } /* Call the handler function */ if (my_set_property (object->data, message, value) < 0) return -1; return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_set_function_structure.c0000644000175000017500000001046611445765555026610 00000000000000DBusPendingCall * my_set_test_property (NihDBusProxy * proxy, const MyTestProperty * value, MySetTestPropertyReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; DBusMessageIter value_iter; const char * value_item0; uint32_t value_item1; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "test_property"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(su)", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } value_item0 = value->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item0)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } value_item1 = value->item1; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_UINT32, &value_item1)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_test_property_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_function_structure.c0000644000175000017500000000657111445765555025333 00000000000000DBusPendingCall * my_test_method (NihDBusProxy * proxy, const MyTestMethodStructure *structure, MyTestMethodReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; DBusMessageIter structure_iter; const char * structure_item0; uint32_t structure_item1; nih_assert (proxy != NULL); nih_assert (structure != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "TestMethod"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &structure_iter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } structure_item0 = structure->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_STRING, &structure_item0)) { dbus_message_iter_abandon_container (&iter, &structure_iter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } structure_item1 = structure->item1; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_UINT32, &structure_item1)) { dbus_message_iter_abandon_container (&iter, &structure_iter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &structure_iter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_TestMethod_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_function_array.c0000644000175000017500000000607011445765555024403 00000000000000DBusPendingCall * my_test_method (NihDBusProxy * proxy, const int32_t * value, size_t value_len, MyTestMethodReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; DBusMessageIter value_iter; nih_assert (proxy != NULL); nih_assert ((value_len == 0) || (value != NULL)); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "TestMethod"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal an array onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "i", &value_iter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } for (size_t value_i = 0; value_i < value_len; value_i++) { int32_t value_element; value_element = value[value_i]; /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_INT32, &value_element)) { dbus_message_iter_abandon_container (&iter, &value_iter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } } if (! dbus_message_iter_close_container (&iter, &value_iter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_TestMethod_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_signal_proxy_function_deprecated.c0000644000175000017500000000354411445765555025365 00000000000000DBusHandlerResult my_com_netsplit_Nih_Test_Signal_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; char * msg; const char * msg_dbus; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&iter, &msg_dbus); msg = nih_strdup (message, msg_dbus); if (! msg) { nih_free (message); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MySignalHandler)proxied->handler) (proxied->data, message, msg); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_set_sync_function_deprecated.c0000644000175000017500000000456211445765555027704 00000000000000int my_set_property_sync (const void * parent, NihDBusProxy *proxy, const char * value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "property"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_function_no_args.c0000644000175000017500000000424311445765555024715 00000000000000DBusPendingCall * my_test_method (NihDBusProxy * proxy, MyTestMethodReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "TestMethod"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_TestMethod_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_get_function_deprecated.c0000644000175000017500000000450111445765555026625 00000000000000DBusPendingCall * my_get_test_property (NihDBusProxy * proxy, MyGetTestPropertyReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "test_property"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_test_property_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_object_function_structure_output.c0000644000175000017500000000715611445765555027040 00000000000000DBusHandlerResult my_com_netsplit_Nih_Test_Method_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; MyMethodStructure *structure; DBusMessageIter structure_iter; const char * structure_item0; uint32_t structure_item1; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_method (object->data, message, &structure) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &structure_iter)) { dbus_message_unref (reply); reply = NULL; goto enomem; } structure_item0 = structure->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_STRING, &structure_item0)) { dbus_message_iter_abandon_container (&iter, &structure_iter); dbus_message_unref (reply); reply = NULL; goto enomem; } structure_item1 = structure->item1; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_UINT32, &structure_item1)) { dbus_message_iter_abandon_container (&iter, &structure_iter); dbus_message_unref (reply); reply = NULL; goto enomem; } if (! dbus_message_iter_close_container (&iter, &structure_iter)) { dbus_message_unref (reply); reply = NULL; goto enomem; } enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_interfaces_array_proxy.c0000644000175000017500000000437711445765555024356 00000000000000static const NihDBusArg my_com_netsplit_Nih_Test_Poke_method_args[] = { { "address", "u", NIH_DBUS_ARG_IN }, { "value", "s", NIH_DBUS_ARG_IN }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_Peek_method_args[] = { { "address", "u", NIH_DBUS_ARG_IN }, { "value", "s", NIH_DBUS_ARG_OUT }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_IsValidAddress_method_args[] = { { "address", "u", NIH_DBUS_ARG_IN }, { NULL } }; static const NihDBusMethod my_com_netsplit_Nih_Test_methods[] = { { "Poke", my_com_netsplit_Nih_Test_Poke_method_args, NULL }, { "Peek", my_com_netsplit_Nih_Test_Peek_method_args, NULL }, { "IsValidAddress", my_com_netsplit_Nih_Test_IsValidAddress_method_args, NULL }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_Bounce_signal_args[] = { { "height", "u", NIH_DBUS_ARG_OUT }, { "velocity", "i", NIH_DBUS_ARG_OUT }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_Exploded_signal_args[] = { { NULL } }; static const NihDBusSignal my_com_netsplit_Nih_Test_signals[] = { { "Bounce", my_com_netsplit_Nih_Test_Bounce_signal_args, my_com_netsplit_Nih_Test_Bounce_signal }, { "Exploded", my_com_netsplit_Nih_Test_Exploded_signal_args, my_com_netsplit_Nih_Test_Exploded_signal }, { NULL } }; static const NihDBusProperty my_com_netsplit_Nih_Test_properties[] = { { "colour", "s", NIH_DBUS_READWRITE, NULL, NULL }, { "size", "u", NIH_DBUS_READ, NULL, NULL }, { "touch", "b", NIH_DBUS_WRITE, NULL, NULL }, { NULL } }; const NihDBusInterface my_com_netsplit_Nih_Test = { "com.netsplit.Nih.Test", my_com_netsplit_Nih_Test_methods, my_com_netsplit_Nih_Test_signals, my_com_netsplit_Nih_Test_properties }; static const NihDBusMethod my_com_netsplit_Nih_Foo_methods[] = { { NULL } }; static const NihDBusSignal my_com_netsplit_Nih_Foo_signals[] = { { NULL } }; static const NihDBusProperty my_com_netsplit_Nih_Foo_properties[] = { { NULL } }; const NihDBusInterface my_com_netsplit_Nih_Foo = { "com.netsplit.Nih.Foo", my_com_netsplit_Nih_Foo_methods, my_com_netsplit_Nih_Foo_signals, my_com_netsplit_Nih_Foo_properties }; const NihDBusInterface *my_interfaces[] = { &my_com_netsplit_Nih_Test, &my_com_netsplit_Nih_Foo, NULL }; libnih-1.0.3/nih-dbus-tool/tests/expected/test_interface_proxy_get_all_sync_function_structure.c0000644000175000017500000001666211445765555030540 00000000000000int my_get_all_sync (const void * parent, NihDBusProxy * proxy, MyProperties **properties) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; DBusError error; DBusMessage * reply; size_t property_count; const char * interface; const char * property; char * name; const char * name_dbus; uint32_t size; MyBirthday * birthday; DBusMessageIter birthday_iter; int32_t birthday_item0; int32_t birthday_item1; int32_t birthday_item2; nih_assert (proxy != NULL); nih_assert (properties != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } *properties = NIH_MUST (nih_new (parent, MyProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "name")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &name_dbus); name = nih_strdup (*properties, name_dbus); if (! name) { goto enomem; } dbus_message_iter_next (&variter); (*properties)->name = name; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); (*properties)->size = size; nih_assert (++property_count); } if (! strcmp (property, "birthday")) { /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&variter, &birthday_iter); birthday = nih_new (*properties, MyBirthday); if (! birthday) { goto enomem; } /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&birthday_iter) != DBUS_TYPE_INT32) { nih_free (birthday); nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&birthday_iter, &birthday_item0); dbus_message_iter_next (&birthday_iter); birthday->item0 = birthday_item0; /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&birthday_iter) != DBUS_TYPE_INT32) { nih_free (birthday); nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&birthday_iter, &birthday_item1); dbus_message_iter_next (&birthday_iter); birthday->item1 = birthday_item1; /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&birthday_iter) != DBUS_TYPE_INT32) { nih_free (birthday); nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&birthday_iter, &birthday_item2); dbus_message_iter_next (&birthday_iter); birthday->item2 = birthday_item2; if (dbus_message_iter_get_arg_type (&birthday_iter) != DBUS_TYPE_INVALID) { nih_free (birthday); nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&variter); (*properties)->birthday = birthday; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } if (property_count < 3) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_set_function_standard.c0000644000175000017500000000645411445765555026352 00000000000000DBusPendingCall * my_set_test_property (NihDBusProxy * proxy, const char * value, MySetTestPropertyReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "test_property"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_test_property_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_reply_function_deprecated.c0000644000175000017500000000267611445765555025347 00000000000000int my_async_method_reply (NihDBusMessage *message, char * const * output) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter output_iter; nih_assert (message != NULL); nih_assert (output != NULL); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return 0; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) return -1; dbus_message_iter_init_append (reply, &iter); /* Marshal an array onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s", &output_iter)) { dbus_message_unref (reply); return -1; } for (size_t output_i = 0; output[output_i]; output_i++) { const char *output_element; output_element = output[output_i]; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&output_iter, DBUS_TYPE_STRING, &output_element)) { dbus_message_iter_abandon_container (&iter, &output_iter); dbus_message_unref (reply); return -1; } } if (! dbus_message_iter_close_container (&iter, &output_iter)) { dbus_message_unref (reply); return -1; } /* Send the reply, appending it to the outgoing queue. */ if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return -1; } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_sync_function_no_input.c0000644000175000017500000001032611445765555026153 00000000000000int my_method_sync (const void * parent, NihDBusProxy *proxy, char *** output, int32_t * length) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; char ** output_local; DBusMessageIter output_local_iter; size_t output_local_size; int32_t length_local; nih_assert (proxy != NULL); nih_assert (output != NULL); nih_assert (length != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Method"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); do { __label__ enomem; /* Demarshal an array from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &output_local_iter); output_local_size = 0; output_local = NULL; output_local = nih_alloc (parent, sizeof (char *)); if (! output_local) { *output = NULL; goto enomem; } output_local[output_local_size] = NULL; while (dbus_message_iter_get_arg_type (&output_local_iter) != DBUS_TYPE_INVALID) { const char *output_local_element_dbus; char ** output_local_tmp; char * output_local_element; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&output_local_iter) != DBUS_TYPE_STRING) { if (output_local) nih_free (output_local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&output_local_iter, &output_local_element_dbus); output_local_element = nih_strdup (output_local, output_local_element_dbus); if (! output_local_element) { if (output_local) nih_free (output_local); *output = NULL; goto enomem; } dbus_message_iter_next (&output_local_iter); if (output_local_size + 2 > SIZE_MAX / sizeof (char *)) { if (output_local) nih_free (output_local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } output_local_tmp = nih_realloc (output_local, parent, sizeof (char *) * (output_local_size + 2)); if (! output_local_tmp) { if (output_local) nih_free (output_local); *output = NULL; goto enomem; } output_local = output_local_tmp; output_local[output_local_size] = output_local_element; output_local[output_local_size + 1] = NULL; output_local_size++; } dbus_message_iter_next (&iter); *output = output_local; enomem: __attribute__ ((unused)); } while (! *output); do { __label__ enomem; /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) { nih_free (output_local); *output = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&iter, &length_local); dbus_message_iter_next (&iter); *length = length_local; enomem: __attribute__ ((unused)); } while (! *length); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (output_local); *output = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_reply_function_standard.c0000644000175000017500000000267611445765555025047 00000000000000int my_async_method_reply (NihDBusMessage *message, char * const * output) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter output_iter; nih_assert (message != NULL); nih_assert (output != NULL); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return 0; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) return -1; dbus_message_iter_init_append (reply, &iter); /* Marshal an array onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s", &output_iter)) { dbus_message_unref (reply); return -1; } for (size_t output_i = 0; output[output_i]; output_i++) { const char *output_element; output_element = output[output_i]; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&output_iter, DBUS_TYPE_STRING, &output_element)) { dbus_message_iter_abandon_container (&iter, &output_iter); dbus_message_unref (reply); return -1; } } if (! dbus_message_iter_close_container (&iter, &output_iter)) { dbus_message_unref (reply); return -1; } /* Send the reply, appending it to the outgoing queue. */ if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return -1; } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_object_function_no_input.c0000644000175000017500000000645311445765555025212 00000000000000DBusHandlerResult my_com_netsplit_Nih_Test_Method_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; char ** output; DBusMessageIter output_iter; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_method (object->data, message, &output) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); /* Marshal an array onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s", &output_iter)) { dbus_message_unref (reply); reply = NULL; goto enomem; } for (size_t output_i = 0; output[output_i]; output_i++) { const char *output_element; output_element = output[output_i]; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&output_iter, DBUS_TYPE_STRING, &output_element)) { dbus_message_iter_abandon_container (&iter, &output_iter); dbus_message_unref (reply); reply = NULL; goto enomem; } } if (! dbus_message_iter_close_container (&iter, &output_iter)) { dbus_message_unref (reply); reply = NULL; goto enomem; } enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_signal_object_function_standard.c0000644000175000017500000000151211445765555025143 00000000000000int my_emit_signal (DBusConnection *connection, const char * origin_path, const char * msg) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); nih_assert (msg != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Signal"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &msg)) { dbus_message_unref (signal); return -1; } /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_set_sync_function_structure.c0000644000175000017500000000656611445765555027652 00000000000000int my_set_property_sync (const void * parent, NihDBusProxy * proxy, const MyProperty *value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; DBusMessageIter value_iter; const char * value_item0; uint32_t value_item1; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "property"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(su)", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } value_item0 = value->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item0)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } value_item1 = value->item1; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_UINT32, &value_item1)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_sync_function_standard.c0000644000175000017500000001126511445765555026123 00000000000000int my_method_sync (const void * parent, NihDBusProxy *proxy, const char * str, int32_t flags, char *** output, int32_t * length) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; char ** output_local; DBusMessageIter output_local_iter; size_t output_local_size; int32_t length_local; nih_assert (proxy != NULL); nih_assert (str != NULL); nih_assert (output != NULL); nih_assert (length != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Method"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); do { __label__ enomem; /* Demarshal an array from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &output_local_iter); output_local_size = 0; output_local = NULL; output_local = nih_alloc (parent, sizeof (char *)); if (! output_local) { *output = NULL; goto enomem; } output_local[output_local_size] = NULL; while (dbus_message_iter_get_arg_type (&output_local_iter) != DBUS_TYPE_INVALID) { const char *output_local_element_dbus; char ** output_local_tmp; char * output_local_element; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&output_local_iter) != DBUS_TYPE_STRING) { if (output_local) nih_free (output_local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&output_local_iter, &output_local_element_dbus); output_local_element = nih_strdup (output_local, output_local_element_dbus); if (! output_local_element) { if (output_local) nih_free (output_local); *output = NULL; goto enomem; } dbus_message_iter_next (&output_local_iter); if (output_local_size + 2 > SIZE_MAX / sizeof (char *)) { if (output_local) nih_free (output_local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } output_local_tmp = nih_realloc (output_local, parent, sizeof (char *) * (output_local_size + 2)); if (! output_local_tmp) { if (output_local) nih_free (output_local); *output = NULL; goto enomem; } output_local = output_local_tmp; output_local[output_local_size] = output_local_element; output_local[output_local_size + 1] = NULL; output_local_size++; } dbus_message_iter_next (&iter); *output = output_local; enomem: __attribute__ ((unused)); } while (! *output); do { __label__ enomem; /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) { nih_free (output_local); *output = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&iter, &length_local); dbus_message_iter_next (&iter); *length = length_local; enomem: __attribute__ ((unused)); } while (! *length); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (output_local); *output = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_notify_function_structure.c0000644000175000017500000001107211445765555026713 00000000000000void my_com_netsplit_Nih_Test_Method_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage * message; DBusError error; MyMethodStructure *structure; DBusMessageIter structure_iter; const char * structure_item0_dbus; char * structure_item0; uint32_t structure_item1; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRUCT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &structure_iter); structure = nih_new (message, MyMethodStructure); if (! structure) { nih_free (message); message = NULL; goto enomem; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_STRING) { nih_free (structure); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&structure_iter, &structure_item0_dbus); structure_item0 = nih_strdup (structure, structure_item0_dbus); if (! structure_item0) { nih_free (structure); nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&structure_iter); structure->item0 = structure_item0; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_UINT32) { nih_free (structure); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&structure_iter, &structure_item1); dbus_message_iter_next (&structure_iter); structure->item1 = structure_item1; if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_INVALID) { nih_free (structure); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyMethodReply)pending_data->handler) (pending_data->data, message, structure); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_interfaces_array_object.c0000644000175000017500000000475711445765555024445 00000000000000static const NihDBusArg my_com_netsplit_Nih_Test_Poke_method_args[] = { { "address", "u", NIH_DBUS_ARG_IN }, { "value", "s", NIH_DBUS_ARG_IN }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_Peek_method_args[] = { { "address", "u", NIH_DBUS_ARG_IN }, { "value", "s", NIH_DBUS_ARG_OUT }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_IsValidAddress_method_args[] = { { "address", "u", NIH_DBUS_ARG_IN }, { NULL } }; static const NihDBusMethod my_com_netsplit_Nih_Test_methods[] = { { "Poke", my_com_netsplit_Nih_Test_Poke_method_args, my_com_netsplit_Nih_Test_Poke_method }, { "Peek", my_com_netsplit_Nih_Test_Peek_method_args, my_com_netsplit_Nih_Test_Peek_method }, { "IsValidAddress", my_com_netsplit_Nih_Test_IsValidAddress_method_args, my_com_netsplit_Nih_Test_IsValidAddress_method }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_Bounce_signal_args[] = { { "height", "u", NIH_DBUS_ARG_OUT }, { "velocity", "i", NIH_DBUS_ARG_OUT }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_Exploded_signal_args[] = { { NULL } }; static const NihDBusSignal my_com_netsplit_Nih_Test_signals[] = { { "Bounce", my_com_netsplit_Nih_Test_Bounce_signal_args, NULL }, { "Exploded", my_com_netsplit_Nih_Test_Exploded_signal_args, NULL }, { NULL } }; static const NihDBusProperty my_com_netsplit_Nih_Test_properties[] = { { "colour", "s", NIH_DBUS_READWRITE, my_com_netsplit_Nih_Test_colour_get, my_com_netsplit_Nih_Test_colour_set }, { "size", "u", NIH_DBUS_READ, my_com_netsplit_Nih_Test_size_get, NULL }, { "touch", "b", NIH_DBUS_WRITE, NULL, my_com_netsplit_Nih_Test_touch_set }, { NULL } }; const NihDBusInterface my_com_netsplit_Nih_Test = { "com.netsplit.Nih.Test", my_com_netsplit_Nih_Test_methods, my_com_netsplit_Nih_Test_signals, my_com_netsplit_Nih_Test_properties }; static const NihDBusMethod my_com_netsplit_Nih_Foo_methods[] = { { NULL } }; static const NihDBusSignal my_com_netsplit_Nih_Foo_signals[] = { { NULL } }; static const NihDBusProperty my_com_netsplit_Nih_Foo_properties[] = { { NULL } }; const NihDBusInterface my_com_netsplit_Nih_Foo = { "com.netsplit.Nih.Foo", my_com_netsplit_Nih_Foo_methods, my_com_netsplit_Nih_Foo_signals, my_com_netsplit_Nih_Foo_properties }; const NihDBusInterface *my_interfaces[] = { &my_com_netsplit_Nih_Test, &my_com_netsplit_Nih_Foo, NULL }; libnih-1.0.3/nih-dbus-tool/tests/expected/test_output_object_no_interfaces.h0000644000175000017500000000065611445765555024355 00000000000000/* test * * Copyright (C) 2009 Joe Bloggs. * * This file was automatically generated; see the source for copying * conditions. */ #ifndef TEST_TEST_H #define TEST_TEST_H #include #include #include #include #include NIH_BEGIN_EXTERN extern const NihDBusInterface *my_interfaces[]; NIH_END_EXTERN #endif /* TEST_TEST_H */ libnih-1.0.3/nih-dbus-tool/tests/expected/test_output_object_no_interfaces.c0000644000175000017500000000120511445765555024337 00000000000000/* test * * test.c - auto-generated D-Bus bindings * * Copyright (C) 2009 Joe Bloggs. * * This file was automatically generated; see the source for copying * conditions. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include #include #include #include "test.h" const NihDBusInterface *my_interfaces[] = { NULL }; libnih-1.0.3/nih-dbus-tool/tests/expected/test_interface_proxy_get_all_notify_function_standard.c0000644000175000017500000001411711445765555030625 00000000000000void my_com_netsplit_Nih_Test_get_all_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; const char * property; MyProperties * properties; size_t property_count; char * name; const char * name_dbus; uint32_t size; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } properties = NIH_MUST (nih_new (message, MyProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "name")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &name_dbus); name = nih_strdup (properties, name_dbus); if (! name) { goto enomem; } dbus_message_iter_next (&variter); properties->name = name; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); properties->size = size; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } if (property_count < 2) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ nih_error_push_context (); ((MyGetAllReply)pending_data->handler) (pending_data->data, message, properties); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_object_function_standard.c0000644000175000017500000001127211445765555025152 00000000000000DBusHandlerResult my_com_netsplit_Nih_Test_Method_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; char * str; const char * str_dbus; int32_t flags; char ** output; DBusMessageIter output_iter; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &str_dbus); str = nih_strdup (message, str_dbus); if (! str) { return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&iter); /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &flags); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_method (object->data, message, str, flags, &output) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); /* Marshal an array onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s", &output_iter)) { dbus_message_unref (reply); reply = NULL; goto enomem; } for (size_t output_i = 0; output[output_i]; output_i++) { const char *output_element; output_element = output[output_i]; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&output_iter, DBUS_TYPE_STRING, &output_element)) { dbus_message_iter_abandon_container (&iter, &output_iter); dbus_message_unref (reply); reply = NULL; goto enomem; } } if (! dbus_message_iter_close_container (&iter, &output_iter)) { dbus_message_unref (reply); reply = NULL; goto enomem; } enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_get_notify_function_structure.c0000644000175000017500000001156711445765555030167 00000000000000void my_com_netsplit_Nih_Test_property_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; DBusMessageIter value_iter; const char * value_item0_dbus; char * value_item0; uint32_t value_item1; MyProperty * value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&variter, &value_iter); value = nih_new (message, MyProperty); if (! value) { nih_free (message); message = NULL; goto enomem; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_STRING) { nih_free (value); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&value_iter, &value_item0_dbus); value_item0 = nih_strdup (value, value_item0_dbus); if (! value_item0) { nih_free (value); nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&value_iter); value->item0 = value_item0; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_UINT32) { nih_free (value); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&value_iter, &value_item1); dbus_message_iter_next (&value_iter); value->item1 = value_item1; if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) { nih_free (value); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyGetPropertyReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_object_set_function_standard.c0000644000175000017500000000271311445765555026431 00000000000000int my_com_netsplit_Nih_Test_property_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; const char * value_dbus; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to property property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to property property"); return -1; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_error_raise_no_memory (); return -1; } dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to property property"); return -1; } /* Call the handler function */ if (my_set_property (object->data, message, value) < 0) return -1; return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_get_sync_function_structure.c0000644000175000017500000000773211445765555027632 00000000000000int my_get_property_sync (const void * parent, NihDBusProxy *proxy, MyProperty ** value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; DBusMessageIter local_iter; const char * local_item0_dbus; char * local_item0; uint32_t local_item1; MyProperty * local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "property"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&variter, &local_iter); local = nih_new (parent, MyProperty); if (! local) { *value = NULL; goto enomem; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_STRING) { nih_free (local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&local_iter, &local_item0_dbus); local_item0 = nih_strdup (local, local_item0_dbus); if (! local_item0) { nih_free (local); *value = NULL; goto enomem; } dbus_message_iter_next (&local_iter); local->item0 = local_item0; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_UINT32) { nih_free (local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&local_iter, &local_item1); dbus_message_iter_next (&local_iter); local->item1 = local_item1; if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_INVALID) { nih_free (local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_interface_proxy_get_all_notify_function_structure.c0000644000175000017500000002210011445765555031054 00000000000000void my_com_netsplit_Nih_Test_get_all_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; const char * property; MyProperties * properties; size_t property_count; char * name; const char * name_dbus; uint32_t size; MyBirthday * birthday; DBusMessageIter birthday_iter; int32_t birthday_item0; int32_t birthday_item1; int32_t birthday_item2; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } properties = NIH_MUST (nih_new (message, MyProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "name")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &name_dbus); name = nih_strdup (properties, name_dbus); if (! name) { goto enomem; } dbus_message_iter_next (&variter); properties->name = name; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); properties->size = size; nih_assert (++property_count); } if (! strcmp (property, "birthday")) { /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&variter, &birthday_iter); birthday = nih_new (properties, MyBirthday); if (! birthday) { goto enomem; } /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&birthday_iter) != DBUS_TYPE_INT32) { nih_free (birthday); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&birthday_iter, &birthday_item0); dbus_message_iter_next (&birthday_iter); birthday->item0 = birthday_item0; /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&birthday_iter) != DBUS_TYPE_INT32) { nih_free (birthday); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&birthday_iter, &birthday_item1); dbus_message_iter_next (&birthday_iter); birthday->item1 = birthday_item1; /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&birthday_iter) != DBUS_TYPE_INT32) { nih_free (birthday); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&birthday_iter, &birthday_item2); dbus_message_iter_next (&birthday_iter); birthday->item2 = birthday_item2; if (dbus_message_iter_get_arg_type (&birthday_iter) != DBUS_TYPE_INVALID) { nih_free (birthday); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&variter); properties->birthday = birthday; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } if (property_count < 3) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ nih_error_push_context (); ((MyGetAllReply)pending_data->handler) (pending_data->data, message, properties); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_object_get_function_deprecated.c0000644000175000017500000000177511445765555026724 00000000000000int my_com_netsplit_Nih_Test_property_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_get_property (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "s", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_reply_function_array.c0000644000175000017500000000301111445765555024345 00000000000000int my_async_method_reply (NihDBusMessage *message, const int32_t * output, size_t output_len) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter output_iter; nih_assert (message != NULL); nih_assert ((output_len == 0) || (output != NULL)); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return 0; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) return -1; dbus_message_iter_init_append (reply, &iter); /* Marshal an array onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "i", &output_iter)) { dbus_message_unref (reply); return -1; } for (size_t output_i = 0; output_i < output_len; output_i++) { int32_t output_element; output_element = output[output_i]; /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&output_iter, DBUS_TYPE_INT32, &output_element)) { dbus_message_iter_abandon_container (&iter, &output_iter); dbus_message_unref (reply); return -1; } } if (! dbus_message_iter_close_container (&iter, &output_iter)) { dbus_message_unref (reply); return -1; } /* Send the reply, appending it to the outgoing queue. */ if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return -1; } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_object_functions_structure.c0000644000175000017500000004400611445765555025243 00000000000000static DBusHandlerResult my_com_netsplit_Nih_Test_Search_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; MyTestSearchItem *item; DBusMessageIter item_iter; const char * item_item0_dbus; char * item_item0; uint32_t item_item1; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRUCT) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Search method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_recurse (&iter, &item_iter); item = nih_new (message, MyTestSearchItem); if (! item) { return DBUS_HANDLER_RESULT_NEED_MEMORY; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&item_iter) != DBUS_TYPE_STRING) { nih_free (item); reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Search method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&item_iter, &item_item0_dbus); item_item0 = nih_strdup (item, item_item0_dbus); if (! item_item0) { nih_free (item); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&item_iter); item->item0 = item_item0; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&item_iter) != DBUS_TYPE_UINT32) { nih_free (item); reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Search method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&item_iter, &item_item1); dbus_message_iter_next (&item_iter); item->item1 = item_item1; if (dbus_message_iter_get_arg_type (&item_iter) != DBUS_TYPE_INVALID) { nih_free (item); reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Search method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Search method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_test_search (object->data, message, item) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); return DBUS_HANDLER_RESULT_HANDLED; } int my_test_search_reply (NihDBusMessage * message, const MyTestSearchResult *result) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter result_iter; const char * result_item0; const char * result_item1; nih_assert (message != NULL); nih_assert (result != NULL); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return 0; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) return -1; dbus_message_iter_init_append (reply, &iter); /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &result_iter)) { dbus_message_unref (reply); return -1; } result_item0 = result->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&result_iter, DBUS_TYPE_STRING, &result_item0)) { dbus_message_iter_abandon_container (&iter, &result_iter); dbus_message_unref (reply); return -1; } result_item1 = result->item1; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&result_iter, DBUS_TYPE_STRING, &result_item1)) { dbus_message_iter_abandon_container (&iter, &result_iter); dbus_message_unref (reply); return -1; } if (! dbus_message_iter_close_container (&iter, &result_iter)) { dbus_message_unref (reply); return -1; } /* Send the reply, appending it to the outgoing queue. */ if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return -1; } dbus_message_unref (reply); return 0; } int my_test_emit_new_search (DBusConnection * connection, const char * origin_path, const MyTestNewSearchQuery *query) { DBusMessage * signal; DBusMessageIter iter; DBusMessageIter query_iter; const char * query_item0; const char * query_item1; uint32_t query_item2; nih_assert (connection != NULL); nih_assert (origin_path != NULL); nih_assert (query != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "NewSearch"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &query_iter)) { dbus_message_unref (signal); return -1; } query_item0 = query->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&query_iter, DBUS_TYPE_STRING, &query_item0)) { dbus_message_iter_abandon_container (&iter, &query_iter); dbus_message_unref (signal); return -1; } query_item1 = query->item1; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&query_iter, DBUS_TYPE_STRING, &query_item1)) { dbus_message_iter_abandon_container (&iter, &query_iter); dbus_message_unref (signal); return -1; } query_item2 = query->item2; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&query_iter, DBUS_TYPE_UINT32, &query_item2)) { dbus_message_iter_abandon_container (&iter, &query_iter); dbus_message_unref (signal); return -1; } if (! dbus_message_iter_close_container (&iter, &query_iter)) { dbus_message_unref (signal); return -1; } /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } static int my_com_netsplit_Nih_Test_last_search_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; DBusMessageIter value_iter; const char * value_item0; uint32_t value_item1; MyTestLastSearch *value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_test_get_last_search (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(su)", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &value_iter)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } value_item0 = value->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item0)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } value_item1 = value->item1; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_UINT32, &value_item1)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int my_com_netsplit_Nih_Test_annotation_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; DBusMessageIter value_iter; const char * value_item0_dbus; char * value_item0; const char * value_item1_dbus; char * value_item1; MyTestAnnotation *value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to annotation property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to annotation property"); return -1; } dbus_message_iter_recurse (&variter, &value_iter); value = nih_new (message, MyTestAnnotation); if (! value) { nih_error_raise_no_memory (); return -1; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_STRING) { nih_free (value); nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to annotation property"); return -1; } dbus_message_iter_get_basic (&value_iter, &value_item0_dbus); value_item0 = nih_strdup (value, value_item0_dbus); if (! value_item0) { nih_free (value); nih_error_raise_no_memory (); return -1; } dbus_message_iter_next (&value_iter); value->item0 = value_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_STRING) { nih_free (value); nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to annotation property"); return -1; } dbus_message_iter_get_basic (&value_iter, &value_item1_dbus); value_item1 = nih_strdup (value, value_item1_dbus); if (! value_item1) { nih_free (value); nih_error_raise_no_memory (); return -1; } dbus_message_iter_next (&value_iter); value->item1 = value_item1; if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) { nih_free (value); nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to annotation property"); return -1; } dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to annotation property"); return -1; } /* Call the handler function */ if (my_test_set_annotation (object->data, message, value) < 0) return -1; return 0; } static int my_com_netsplit_Nih_Test_preferences_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; DBusMessageIter value_iter; uint32_t value_item0; const char * value_item1; MyTestPreferences *value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_test_get_preferences (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(us)", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &value_iter)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } value_item0 = value->item0; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_UINT32, &value_item0)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } value_item1 = value->item1; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item1)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int my_com_netsplit_Nih_Test_preferences_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; DBusMessageIter value_iter; uint32_t value_item0; const char * value_item1_dbus; char * value_item1; MyTestPreferences *value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to preferences property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to preferences property"); return -1; } dbus_message_iter_recurse (&variter, &value_iter); value = nih_new (message, MyTestPreferences); if (! value) { nih_error_raise_no_memory (); return -1; } /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_UINT32) { nih_free (value); nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to preferences property"); return -1; } dbus_message_iter_get_basic (&value_iter, &value_item0); dbus_message_iter_next (&value_iter); value->item0 = value_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_STRING) { nih_free (value); nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to preferences property"); return -1; } dbus_message_iter_get_basic (&value_iter, &value_item1_dbus); value_item1 = nih_strdup (value, value_item1_dbus); if (! value_item1) { nih_free (value); nih_error_raise_no_memory (); return -1; } dbus_message_iter_next (&value_iter); value->item1 = value_item1; if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) { nih_free (value); nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to preferences property"); return -1; } dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to preferences property"); return -1; } /* Call the handler function */ if (my_test_set_preferences (object->data, message, value) < 0) return -1; return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_object_functions_only_properties.c0000644000175000017500000001137411445765555026442 00000000000000static int my_com_netsplit_Nih_Test_colour_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_test_get_colour (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "s", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int my_com_netsplit_Nih_Test_colour_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; const char * value_dbus; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_error_raise_no_memory (); return -1; } dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } /* Call the handler function */ if (my_test_set_colour (object->data, message, value) < 0) return -1; return 0; } static int my_com_netsplit_Nih_Test_size_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; uint32_t value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_test_get_size (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "u", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &value)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int my_com_netsplit_Nih_Test_touch_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; int value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a int from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_BOOLEAN) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } dbus_message_iter_get_basic (&variter, &value); dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } /* Call the handler function */ if (my_test_set_touch (object->data, message, value) < 0) return -1; return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_interfaces_array_none.c0000644000175000017500000000006511445765555024122 00000000000000const NihDBusInterface *my_interfaces[] = { NULL }; libnih-1.0.3/nih-dbus-tool/tests/expected/test_output_object_standard.c0000644000175000017500000007652111445765555023335 00000000000000/* test * * test.c - auto-generated D-Bus bindings * * Copyright (C) 2009 Joe Bloggs. * * This file was automatically generated; see the source for copying * conditions. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include #include #include #include "test.h" /* Prototypes for static functions */ static DBusHandlerResult my_com_netsplit_Nih_Test_Poke_method (NihDBusObject *object, NihDBusMessage *message); static DBusHandlerResult my_com_netsplit_Nih_Test_Peek_method (NihDBusObject *object, NihDBusMessage *message); static DBusHandlerResult my_com_netsplit_Nih_Test_IsValidAddress_method (NihDBusObject *object, NihDBusMessage *message); static int my_com_netsplit_Nih_Test_colour_get (NihDBusObject *object, NihDBusMessage *message, DBusMessageIter *iter); static int my_com_netsplit_Nih_Test_colour_set (NihDBusObject *object, NihDBusMessage *message, DBusMessageIter *iter); static int my_com_netsplit_Nih_Test_size_get (NihDBusObject *object, NihDBusMessage *message, DBusMessageIter *iter); static int my_com_netsplit_Nih_Test_touch_set (NihDBusObject *object, NihDBusMessage *message, DBusMessageIter *iter); static DBusHandlerResult my_com_netsplit_Nih_Foo_Bing_method (NihDBusObject *object, NihDBusMessage *message); static int my_com_netsplit_Nih_Foo_preferences_get (NihDBusObject *object, NihDBusMessage *message, DBusMessageIter *iter); static int my_com_netsplit_Nih_Foo_preferences_set (NihDBusObject *object, NihDBusMessage *message, DBusMessageIter *iter); /* Prototypes for externally implemented handler functions */ extern int my_test_poke (void *data, NihDBusMessage *message, uint32_t address, const char *value) __attribute__ ((warn_unused_result)); extern int my_test_peek (void *data, NihDBusMessage *message, uint32_t address) __attribute__ ((warn_unused_result)); extern int my_test_is_valid_address (void *data, NihDBusMessage *message, uint32_t address, int *is_valid) __attribute__ ((warn_unused_result)); extern int my_test_get_colour (void *data, NihDBusMessage *message, char **value) __attribute__ ((warn_unused_result)); extern int my_test_set_colour (void *data, NihDBusMessage *message, const char *value) __attribute__ ((warn_unused_result)); extern int my_test_get_size (void *data, NihDBusMessage *message, uint32_t *value) __attribute__ ((warn_unused_result)); extern int my_test_set_touch (void *data, NihDBusMessage *message, int value) __attribute__ ((warn_unused_result)); extern int my_foo_bing (void *data, NihDBusMessage *message) __attribute__ ((warn_unused_result)); extern int my_foo_get_preferences (void *data, NihDBusMessage *message, MyFooPreferences **value) __attribute__ ((warn_unused_result)); extern int my_foo_set_preferences (void *data, NihDBusMessage *message, const MyFooPreferences *value) __attribute__ ((warn_unused_result)); static const NihDBusArg my_com_netsplit_Nih_Test_Poke_method_args[] = { { "address", "u", NIH_DBUS_ARG_IN }, { "value", "s", NIH_DBUS_ARG_IN }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_Peek_method_args[] = { { "address", "u", NIH_DBUS_ARG_IN }, { "value", "s", NIH_DBUS_ARG_OUT }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_IsValidAddress_method_args[] = { { "address", "u", NIH_DBUS_ARG_IN }, { "is_valid", "b", NIH_DBUS_ARG_OUT }, { NULL } }; static const NihDBusMethod my_com_netsplit_Nih_Test_methods[] = { { "Poke", my_com_netsplit_Nih_Test_Poke_method_args, my_com_netsplit_Nih_Test_Poke_method }, { "Peek", my_com_netsplit_Nih_Test_Peek_method_args, my_com_netsplit_Nih_Test_Peek_method }, { "IsValidAddress", my_com_netsplit_Nih_Test_IsValidAddress_method_args, my_com_netsplit_Nih_Test_IsValidAddress_method }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_Bounce_signal_args[] = { { "height", "u", NIH_DBUS_ARG_OUT }, { "velocity", "i", NIH_DBUS_ARG_OUT }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_Exploded_signal_args[] = { { NULL } }; static const NihDBusSignal my_com_netsplit_Nih_Test_signals[] = { { "Bounce", my_com_netsplit_Nih_Test_Bounce_signal_args, NULL }, { "Exploded", my_com_netsplit_Nih_Test_Exploded_signal_args, NULL }, { NULL } }; static const NihDBusProperty my_com_netsplit_Nih_Test_properties[] = { { "colour", "s", NIH_DBUS_READWRITE, my_com_netsplit_Nih_Test_colour_get, my_com_netsplit_Nih_Test_colour_set }, { "size", "u", NIH_DBUS_READ, my_com_netsplit_Nih_Test_size_get, NULL }, { "touch", "b", NIH_DBUS_WRITE, NULL, my_com_netsplit_Nih_Test_touch_set }, { NULL } }; const NihDBusInterface my_com_netsplit_Nih_Test = { "com.netsplit.Nih.Test", my_com_netsplit_Nih_Test_methods, my_com_netsplit_Nih_Test_signals, my_com_netsplit_Nih_Test_properties }; static const NihDBusArg my_com_netsplit_Nih_Foo_Bing_method_args[] = { { NULL } }; static const NihDBusMethod my_com_netsplit_Nih_Foo_methods[] = { { "Bing", my_com_netsplit_Nih_Foo_Bing_method_args, my_com_netsplit_Nih_Foo_Bing_method }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Foo_NewResult_signal_args[] = { { NULL } }; static const NihDBusSignal my_com_netsplit_Nih_Foo_signals[] = { { "NewResult", my_com_netsplit_Nih_Foo_NewResult_signal_args, NULL }, { NULL } }; static const NihDBusProperty my_com_netsplit_Nih_Foo_properties[] = { { "preferences", "(us)", NIH_DBUS_READWRITE, my_com_netsplit_Nih_Foo_preferences_get, my_com_netsplit_Nih_Foo_preferences_set }, { NULL } }; const NihDBusInterface my_com_netsplit_Nih_Foo = { "com.netsplit.Nih.Foo", my_com_netsplit_Nih_Foo_methods, my_com_netsplit_Nih_Foo_signals, my_com_netsplit_Nih_Foo_properties }; const NihDBusInterface *my_interfaces[] = { &my_com_netsplit_Nih_Test, &my_com_netsplit_Nih_Foo, NULL }; static DBusHandlerResult my_com_netsplit_Nih_Test_Poke_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; uint32_t address; char * value; const char * value_dbus; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Poke method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &address); dbus_message_iter_next (&iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Poke method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Poke method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_test_poke (object->data, message, address, value) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } static DBusHandlerResult my_com_netsplit_Nih_Test_Peek_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; uint32_t address; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Peek method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &address); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Peek method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_test_peek (object->data, message, address) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); return DBUS_HANDLER_RESULT_HANDLED; } int my_test_peek_reply (NihDBusMessage *message, const char * value) { DBusMessage * reply; DBusMessageIter iter; nih_assert (message != NULL); nih_assert (value != NULL); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return 0; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) return -1; dbus_message_iter_init_append (reply, &iter); /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) { dbus_message_unref (reply); return -1; } /* Send the reply, appending it to the outgoing queue. */ if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return -1; } dbus_message_unref (reply); return 0; } static DBusHandlerResult my_com_netsplit_Nih_Test_IsValidAddress_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; uint32_t address; int is_valid; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to IsValidAddress method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &address); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to IsValidAddress method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_test_is_valid_address (object->data, message, address, &is_valid) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &is_valid)) { dbus_message_unref (reply); reply = NULL; goto enomem; } enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } int my_test_emit_bounce (DBusConnection *connection, const char * origin_path, uint32_t height, int32_t velocity) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Bounce"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &height)) { dbus_message_unref (signal); return -1; } /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &velocity)) { dbus_message_unref (signal); return -1; } /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } int my_test_emit_exploded (DBusConnection *connection, const char * origin_path) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Exploded"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } static int my_com_netsplit_Nih_Test_colour_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_test_get_colour (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "s", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int my_com_netsplit_Nih_Test_colour_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; const char * value_dbus; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_error_raise_no_memory (); return -1; } dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } /* Call the handler function */ if (my_test_set_colour (object->data, message, value) < 0) return -1; return 0; } static int my_com_netsplit_Nih_Test_size_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; uint32_t value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_test_get_size (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "u", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &value)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int my_com_netsplit_Nih_Test_touch_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; int value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a int from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_BOOLEAN) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } dbus_message_iter_get_basic (&variter, &value); dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } /* Call the handler function */ if (my_test_set_touch (object->data, message, value) < 0) return -1; return 0; } static DBusHandlerResult my_com_netsplit_Nih_Foo_Bing_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Bing method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_foo_bing (object->data, message) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } int my_foo_emit_new_result (DBusConnection *connection, const char * origin_path) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Foo", "NewResult"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } static int my_com_netsplit_Nih_Foo_preferences_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; DBusMessageIter value_iter; uint32_t value_item0; const char * value_item1; MyFooPreferences *value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_foo_get_preferences (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(us)", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &value_iter)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } value_item0 = value->item0; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_UINT32, &value_item0)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } value_item1 = value->item1; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item1)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int my_com_netsplit_Nih_Foo_preferences_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; DBusMessageIter value_iter; uint32_t value_item0; const char * value_item1_dbus; char * value_item1; MyFooPreferences *value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to preferences property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to preferences property"); return -1; } dbus_message_iter_recurse (&variter, &value_iter); value = nih_new (message, MyFooPreferences); if (! value) { nih_error_raise_no_memory (); return -1; } /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_UINT32) { nih_free (value); nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to preferences property"); return -1; } dbus_message_iter_get_basic (&value_iter, &value_item0); dbus_message_iter_next (&value_iter); value->item0 = value_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_STRING) { nih_free (value); nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to preferences property"); return -1; } dbus_message_iter_get_basic (&value_iter, &value_item1_dbus); value_item1 = nih_strdup (value, value_item1_dbus); if (! value_item1) { nih_free (value); nih_error_raise_no_memory (); return -1; } dbus_message_iter_next (&value_iter); value->item1 = value_item1; if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) { nih_free (value); nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to preferences property"); return -1; } dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to preferences property"); return -1; } /* Call the handler function */ if (my_foo_set_preferences (object->data, message, value) < 0) return -1; return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_set_function_array.c0000644000175000017500000001007311445765555025660 00000000000000DBusPendingCall * my_set_test_property (NihDBusProxy * proxy, const int32_t * value, size_t value_len, MySetTestPropertyReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; DBusMessageIter value_iter; nih_assert (proxy != NULL); nih_assert ((value_len == 0) || (value != NULL)); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "test_property"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "ai", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal an array onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, "i", &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } for (size_t value_i = 0; value_i < value_len; value_i++) { int32_t value_element; value_element = value[value_i]; /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_INT32, &value_element)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_test_property_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_interface_proxy_get_all_sync_function_standard.c0000644000175000017500000001170011445765555030264 00000000000000int my_get_all_sync (const void * parent, NihDBusProxy * proxy, MyProperties **properties) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; DBusError error; DBusMessage * reply; size_t property_count; const char * interface; const char * property; char * name; const char * name_dbus; uint32_t size; nih_assert (proxy != NULL); nih_assert (properties != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } *properties = NIH_MUST (nih_new (parent, MyProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "name")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &name_dbus); name = nih_strdup (*properties, name_dbus); if (! name) { goto enomem; } dbus_message_iter_next (&variter); (*properties)->name = name; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); (*properties)->size = size; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } if (property_count < 2) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_sync_function_structure_input.c0000644000175000017500000000473311445765555027604 00000000000000int my_method_sync (const void * parent, NihDBusProxy * proxy, const MyMethodStructure *structure) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; DBusMessageIter structure_iter; const char * structure_item0; uint32_t structure_item1; nih_assert (proxy != NULL); nih_assert (structure != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Method"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &structure_iter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } structure_item0 = structure->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_STRING, &structure_item0)) { dbus_message_iter_abandon_container (&iter, &structure_iter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } structure_item1 = structure->item1; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_UINT32, &structure_item1)) { dbus_message_iter_abandon_container (&iter, &structure_iter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &structure_iter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_get_sync_function_standard.c0000644000175000017500000000532711445765555027370 00000000000000int my_get_property_sync (const void * parent, NihDBusProxy *proxy, char ** value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; const char * local_dbus; char * local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "property"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &local_dbus); local = nih_strdup (parent, local_dbus); if (! local) { *value = NULL; goto enomem; } dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_object_get_function_structure.c0000644000175000017500000000364411445765555026661 00000000000000int my_com_netsplit_Nih_Test_property_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; DBusMessageIter value_iter; const char * value_item0; uint32_t value_item1; MyProperty * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_get_property (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(su)", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &value_iter)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } value_item0 = value->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item0)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } value_item1 = value->item1; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_UINT32, &value_item1)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_interface_proxy_get_all_function_standard.c0000644000175000017500000000404211445765555027231 00000000000000DBusPendingCall * my_get_all (NihDBusProxy * proxy, MyGetAllReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_get_all_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_set_notify_function_standard.c0000644000175000017500000000367511445765555027744 00000000000000void my_com_netsplit_Nih_Test_property_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MySetPropertyReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_reply_function_structure.c0000644000175000017500000000336511445765555025303 00000000000000int my_async_method_reply (NihDBusMessage * message, const MyAsyncMethodStructure *structure) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter structure_iter; const char * structure_item0; uint32_t structure_item1; nih_assert (message != NULL); nih_assert (structure != NULL); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return 0; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) return -1; dbus_message_iter_init_append (reply, &iter); /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &structure_iter)) { dbus_message_unref (reply); return -1; } structure_item0 = structure->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_STRING, &structure_item0)) { dbus_message_iter_abandon_container (&iter, &structure_iter); dbus_message_unref (reply); return -1; } structure_item1 = structure->item1; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_UINT32, &structure_item1)) { dbus_message_iter_abandon_container (&iter, &structure_iter); dbus_message_unref (reply); return -1; } if (! dbus_message_iter_close_container (&iter, &structure_iter)) { dbus_message_unref (reply); return -1; } /* Send the reply, appending it to the outgoing queue. */ if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return -1; } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_signal_proxy_function_structure.c0000644000175000017500000000612511445765555025323 00000000000000DBusHandlerResult my_com_netsplit_Nih_Test_Signal_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage * message; MySignalStructure *structure; DBusMessageIter structure_iter; const char * structure_item0_dbus; char * structure_item0; uint32_t structure_item1; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRUCT) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_recurse (&iter, &structure_iter); structure = nih_new (message, MySignalStructure); if (! structure) { nih_free (message); return DBUS_HANDLER_RESULT_NEED_MEMORY; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_STRING) { nih_free (structure); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&structure_iter, &structure_item0_dbus); structure_item0 = nih_strdup (structure, structure_item0_dbus); if (! structure_item0) { nih_free (structure); nih_free (message); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&structure_iter); structure->item0 = structure_item0; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_UINT32) { nih_free (structure); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&structure_iter, &structure_item1); dbus_message_iter_next (&structure_iter); structure->item1 = structure_item1; if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_INVALID) { nih_free (structure); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MySignalHandler)proxied->handler) (proxied->data, message, structure); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_object_function_no_output.c0000644000175000017500000000762411445765555025414 00000000000000DBusHandlerResult my_com_netsplit_Nih_Test_Method_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; char * str; const char * str_dbus; int32_t flags; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &str_dbus); str = nih_strdup (message, str_dbus); if (! str) { return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&iter); /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &flags); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_method (object->data, message, str, flags) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_get_notify_function_deprecated.c0000644000175000017500000000623211445765555030220 00000000000000void my_com_netsplit_Nih_Test_property_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; const char * value_dbus; char * value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyGetPropertyReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_object_set_function_structure.c0000644000175000017500000000535011445765555026671 00000000000000int my_com_netsplit_Nih_Test_property_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; DBusMessageIter value_iter; const char * value_item0_dbus; char * value_item0; uint32_t value_item1; MyProperty * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to property property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to property property"); return -1; } dbus_message_iter_recurse (&variter, &value_iter); value = nih_new (message, MyProperty); if (! value) { nih_error_raise_no_memory (); return -1; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_STRING) { nih_free (value); nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to property property"); return -1; } dbus_message_iter_get_basic (&value_iter, &value_item0_dbus); value_item0 = nih_strdup (value, value_item0_dbus); if (! value_item0) { nih_free (value); nih_error_raise_no_memory (); return -1; } dbus_message_iter_next (&value_iter); value->item0 = value_item0; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_UINT32) { nih_free (value); nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to property property"); return -1; } dbus_message_iter_get_basic (&value_iter, &value_item1); dbus_message_iter_next (&value_iter); value->item1 = value_item1; if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) { nih_free (value); nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to property property"); return -1; } dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to property property"); return -1; } /* Call the handler function */ if (my_set_property (object->data, message, value) < 0) return -1; return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_sync_function_no_args.c0000644000175000017500000000246411445765555025754 00000000000000int my_method_sync (const void * parent, NihDBusProxy *proxy) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Method"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_signal_object_function_no_args.c0000644000175000017500000000115011445765555024771 00000000000000int my_emit_signal (DBusConnection *connection, const char * origin_path) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Signal"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_object_function_structure_input.c0000644000175000017500000001301711445765555026630 00000000000000DBusHandlerResult my_com_netsplit_Nih_Test_Method_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; MyMethodStructure *structure; DBusMessageIter structure_iter; const char * structure_item0_dbus; char * structure_item0; uint32_t structure_item1; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRUCT) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_recurse (&iter, &structure_iter); structure = nih_new (message, MyMethodStructure); if (! structure) { return DBUS_HANDLER_RESULT_NEED_MEMORY; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_STRING) { nih_free (structure); reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&structure_iter, &structure_item0_dbus); structure_item0 = nih_strdup (structure, structure_item0_dbus); if (! structure_item0) { nih_free (structure); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&structure_iter); structure->item0 = structure_item0; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_UINT32) { nih_free (structure); reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&structure_iter, &structure_item1); dbus_message_iter_next (&structure_iter); structure->item1 = structure_item1; if (dbus_message_iter_get_arg_type (&structure_iter) != DBUS_TYPE_INVALID) { nih_free (structure); reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_method (object->data, message, structure) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_output_proxy_no_interfaces.h0000644000175000017500000000076711445765555024273 00000000000000/* test * * Copyright (C) 2009 Joe Bloggs. * * This file was automatically generated; see the source for copying * conditions. */ #ifndef TEST_TEST_H #define TEST_TEST_H #include #include #include #include #include #include #include NIH_BEGIN_EXTERN extern const NihDBusInterface *my_interfaces[]; NIH_END_EXTERN #endif /* TEST_TEST_H */ libnih-1.0.3/nih-dbus-tool/tests/expected/test_signal_object_function_structure.c0000644000175000017500000000323711445765555025411 00000000000000int my_emit_signal (DBusConnection * connection, const char * origin_path, const MySignalStructure *structure) { DBusMessage * signal; DBusMessageIter iter; DBusMessageIter structure_iter; const char * structure_item0; uint32_t structure_item1; nih_assert (connection != NULL); nih_assert (origin_path != NULL); nih_assert (structure != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Signal"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &structure_iter)) { dbus_message_unref (signal); return -1; } structure_item0 = structure->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_STRING, &structure_item0)) { dbus_message_iter_abandon_container (&iter, &structure_iter); dbus_message_unref (signal); return -1; } structure_item1 = structure->item1; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&structure_iter, DBUS_TYPE_UINT32, &structure_item1)) { dbus_message_iter_abandon_container (&iter, &structure_iter); dbus_message_unref (signal); return -1; } if (! dbus_message_iter_close_container (&iter, &structure_iter)) { dbus_message_unref (signal); return -1; } /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_proxy_functions_standard.c0000644000175000017500000022506311445765555024722 00000000000000DBusPendingCall * my_test_poke (NihDBusProxy * proxy, uint32_t address, const char * value, MyTestPokeReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Poke"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_Poke_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_Poke_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestPokeReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_poke_sync (const void * parent, NihDBusProxy *proxy, uint32_t address, const char * value) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Poke"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_peek (NihDBusProxy * proxy, uint32_t address, MyTestPeekReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Peek"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_Peek_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_Peek_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; char * value; const char * value_dbus; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&iter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestPeekReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_peek_sync (const void * parent, NihDBusProxy *proxy, uint32_t address, char ** value) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; char * value_local; const char * value_local_dbus; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Peek"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); do { __label__ enomem; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&iter, &value_local_dbus); value_local = nih_strdup (parent, value_local_dbus); if (! value_local) { *value = NULL; goto enomem; } dbus_message_iter_next (&iter); *value = value_local; enomem: __attribute__ ((unused)); } while (! *value); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (value_local); *value = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_is_valid_address (NihDBusProxy * proxy, uint32_t address, MyTestIsValidAddressReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "IsValidAddress"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_IsValidAddress_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_IsValidAddress_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestIsValidAddressReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_is_valid_address_sync (const void * parent, NihDBusProxy *proxy, uint32_t address) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "IsValidAddress"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } static DBusHandlerResult my_com_netsplit_Nih_Test_Bounce_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; uint32_t height; int32_t velocity; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&iter, &height); dbus_message_iter_next (&iter); /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&iter, &velocity); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MyTestBounceHandler)proxied->handler) (proxied->data, message, height, velocity); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } static DBusHandlerResult my_com_netsplit_Nih_Test_Exploded_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MyTestExplodedHandler)proxied->handler) (proxied->data, message); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } DBusPendingCall * my_test_get_colour (NihDBusProxy * proxy, MyTestGetColourReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_colour_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_colour_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; const char * value_dbus; char * value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyTestGetColourReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_colour_sync (const void * parent, NihDBusProxy *proxy, char ** value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; const char * local_dbus; char * local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &local_dbus); local = nih_strdup (parent, local_dbus); if (! local) { *value = NULL; goto enomem; } dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_set_colour (NihDBusProxy * proxy, const char * value, MyTestSetColourReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_colour_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_colour_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestSetColourReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_set_colour_sync (const void * parent, NihDBusProxy *proxy, const char * value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_get_size (NihDBusProxy * proxy, MyTestGetSizeReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "size"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_size_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_size_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; uint32_t value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &value); dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyTestGetSizeReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_size_sync (const void * parent, NihDBusProxy *proxy, uint32_t * value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; uint32_t local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "size"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &local); dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_set_touch (NihDBusProxy * proxy, int value, MyTestSetTouchReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "touch"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "b", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_BOOLEAN, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_touch_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_touch_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestSetTouchReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_set_touch_sync (const void * parent, NihDBusProxy *proxy, int value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "touch"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "b", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_BOOLEAN, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_get_all (NihDBusProxy * proxy, MyTestGetAllReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_get_all_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_get_all_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; NihDBusMessage * message; DBusError error; const char * property; MyTestProperties *properties; size_t property_count; char * colour; const char * colour_dbus; uint32_t size; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } properties = NIH_MUST (nih_new (message, MyTestProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "colour")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &colour_dbus); colour = nih_strdup (properties, colour_dbus); if (! colour) { goto enomem; } dbus_message_iter_next (&variter); properties->colour = colour; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); properties->size = size; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } if (property_count < 2) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ nih_error_push_context (); ((MyTestGetAllReply)pending_data->handler) (pending_data->data, message, properties); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_all_sync (const void * parent, NihDBusProxy * proxy, MyTestProperties **properties) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; DBusError error; DBusMessage * reply; size_t property_count; const char * interface; const char * property; char * colour; const char * colour_dbus; uint32_t size; nih_assert (proxy != NULL); nih_assert (properties != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } *properties = NIH_MUST (nih_new (parent, MyTestProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "colour")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &colour_dbus); colour = nih_strdup (*properties, colour_dbus); if (! colour) { goto enomem; } dbus_message_iter_next (&variter); (*properties)->colour = colour; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); (*properties)->size = size; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } if (property_count < 2) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_foo_bing (NihDBusProxy * proxy, MyFooBingReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Foo", "Bing"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Foo_Bing_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Foo_Bing_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyFooBingReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_foo_bing_sync (const void * parent, NihDBusProxy *proxy) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Foo", "Bing"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } static DBusHandlerResult my_com_netsplit_Nih_Foo_NewResult_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MyFooNewResultHandler)proxied->handler) (proxied->data, message); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_notify_function_standard.c0000644000175000017500000001166211445765555026460 00000000000000void my_com_netsplit_Nih_Test_Method_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; char ** output; DBusMessageIter output_iter; size_t output_size; int32_t length; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); /* Demarshal an array from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &output_iter); output_size = 0; output = NULL; output = nih_alloc (message, sizeof (char *)); if (! output) { nih_free (message); message = NULL; goto enomem; } output[output_size] = NULL; while (dbus_message_iter_get_arg_type (&output_iter) != DBUS_TYPE_INVALID) { const char *output_element_dbus; char ** output_tmp; char * output_element; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&output_iter) != DBUS_TYPE_STRING) { if (output) nih_free (output); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&output_iter, &output_element_dbus); output_element = nih_strdup (output, output_element_dbus); if (! output_element) { if (output) nih_free (output); nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&output_iter); if (output_size + 2 > SIZE_MAX / sizeof (char *)) { if (output) nih_free (output); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } output_tmp = nih_realloc (output, message, sizeof (char *) * (output_size + 2)); if (! output_tmp) { if (output) nih_free (output); nih_free (message); message = NULL; goto enomem; } output = output_tmp; output[output_size] = output_element; output[output_size + 1] = NULL; output_size++; } dbus_message_iter_next (&iter); /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&iter, &length); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyMethodReply)pending_data->handler) (pending_data->data, message, output, length); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_object_function_no_args.c0000644000175000017500000000500511445765555024777 00000000000000DBusHandlerResult my_com_netsplit_Nih_Test_Method_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_method (object->data, message) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_object_functions_no_signals.c0000644000175000017500000004405611445765555025344 00000000000000static DBusHandlerResult my_com_netsplit_Nih_Test_Poke_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; uint32_t address; char * value; const char * value_dbus; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Poke method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &address); dbus_message_iter_next (&iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Poke method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Poke method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_test_poke (object->data, message, address, value) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } static DBusHandlerResult my_com_netsplit_Nih_Test_Peek_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; uint32_t address; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Peek method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &address); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Peek method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_test_peek (object->data, message, address) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); return DBUS_HANDLER_RESULT_HANDLED; } int my_test_peek_reply (NihDBusMessage *message, const char * value) { DBusMessage * reply; DBusMessageIter iter; nih_assert (message != NULL); nih_assert (value != NULL); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return 0; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) return -1; dbus_message_iter_init_append (reply, &iter); /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) { dbus_message_unref (reply); return -1; } /* Send the reply, appending it to the outgoing queue. */ if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return -1; } dbus_message_unref (reply); return 0; } static DBusHandlerResult my_com_netsplit_Nih_Test_IsValidAddress_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; uint32_t address; int is_valid; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to IsValidAddress method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &address); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to IsValidAddress method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_test_is_valid_address (object->data, message, address, &is_valid) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &is_valid)) { dbus_message_unref (reply); reply = NULL; goto enomem; } enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } static int my_com_netsplit_Nih_Test_colour_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_test_get_colour (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "s", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int my_com_netsplit_Nih_Test_colour_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; const char * value_dbus; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_error_raise_no_memory (); return -1; } dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } /* Call the handler function */ if (my_test_set_colour (object->data, message, value) < 0) return -1; return 0; } static int my_com_netsplit_Nih_Test_size_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; uint32_t value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_test_get_size (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "u", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &value)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int my_com_netsplit_Nih_Test_touch_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; int value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a int from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_BOOLEAN) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } dbus_message_iter_get_basic (&variter, &value); dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } /* Call the handler function */ if (my_test_set_touch (object->data, message, value) < 0) return -1; return 0; } static DBusHandlerResult my_com_netsplit_Nih_Foo_Bing_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Bing method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_foo_bing (object->data, message) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_object_get_function_standard.c0000644000175000017500000000177511445765555026424 00000000000000int my_com_netsplit_Nih_Test_property_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_get_property (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "s", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_notify_function_array.c0000644000175000017500000001166211445765555025776 00000000000000void my_com_netsplit_Nih_Test_Method_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; char ** output; DBusMessageIter output_iter; size_t output_size; int32_t length; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); /* Demarshal an array from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &output_iter); output_size = 0; output = NULL; output = nih_alloc (message, sizeof (char *)); if (! output) { nih_free (message); message = NULL; goto enomem; } output[output_size] = NULL; while (dbus_message_iter_get_arg_type (&output_iter) != DBUS_TYPE_INVALID) { const char *output_element_dbus; char ** output_tmp; char * output_element; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&output_iter) != DBUS_TYPE_STRING) { if (output) nih_free (output); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&output_iter, &output_element_dbus); output_element = nih_strdup (output, output_element_dbus); if (! output_element) { if (output) nih_free (output); nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&output_iter); if (output_size + 2 > SIZE_MAX / sizeof (char *)) { if (output) nih_free (output); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } output_tmp = nih_realloc (output, message, sizeof (char *) * (output_size + 2)); if (! output_tmp) { if (output) nih_free (output); nih_free (message); message = NULL; goto enomem; } output = output_tmp; output[output_size] = output_element; output[output_size + 1] = NULL; output_size++; } dbus_message_iter_next (&iter); /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&iter, &length); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyMethodReply)pending_data->handler) (pending_data->data, message, output, length); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_sync_function_no_output.c0000644000175000017500000000342311445765555026354 00000000000000int my_method_sync (const void * parent, NihDBusProxy *proxy, const char * str, int32_t flags) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); nih_assert (str != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Method"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_notify_function_no_args.c0000644000175000017500000000404511445765555026305 00000000000000void my_com_netsplit_Nih_Test_Method_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyMethodReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } libnih-1.0.3/nih-dbus-tool/tests/expected/test_output_proxy_standard.c0000644000175000017500000035067711445765555023257 00000000000000/* test * * test.c - auto-generated D-Bus bindings * * Copyright (C) 2009 Joe Bloggs. * * This file was automatically generated; see the source for copying * conditions. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "test.h" /* Prototypes for static functions */ static void my_com_netsplit_Nih_Test_Poke_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); static void my_com_netsplit_Nih_Test_Peek_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); static void my_com_netsplit_Nih_Test_IsValidAddress_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); static DBusHandlerResult my_com_netsplit_Nih_Test_Bounce_signal (DBusConnection *connection, DBusMessage *signal, NihDBusProxySignal *proxied); static DBusHandlerResult my_com_netsplit_Nih_Test_Exploded_signal (DBusConnection *connection, DBusMessage *signal, NihDBusProxySignal *proxied); static void my_com_netsplit_Nih_Test_colour_get_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); static void my_com_netsplit_Nih_Test_colour_set_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); static void my_com_netsplit_Nih_Test_size_get_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); static void my_com_netsplit_Nih_Test_touch_set_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); static void my_com_netsplit_Nih_Test_get_all_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); static void my_com_netsplit_Nih_Foo_Bing_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); static DBusHandlerResult my_com_netsplit_Nih_Foo_NewResult_signal (DBusConnection *connection, DBusMessage *signal, NihDBusProxySignal *proxied); static void my_com_netsplit_Nih_Foo_preferences_get_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); static void my_com_netsplit_Nih_Foo_preferences_set_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); static void my_com_netsplit_Nih_Foo_get_all_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); static const NihDBusArg my_com_netsplit_Nih_Test_Poke_method_args[] = { { "address", "u", NIH_DBUS_ARG_IN }, { "value", "s", NIH_DBUS_ARG_IN }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_Peek_method_args[] = { { "address", "u", NIH_DBUS_ARG_IN }, { "value", "s", NIH_DBUS_ARG_OUT }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_IsValidAddress_method_args[] = { { "address", "u", NIH_DBUS_ARG_IN }, { NULL } }; static const NihDBusMethod my_com_netsplit_Nih_Test_methods[] = { { "Poke", my_com_netsplit_Nih_Test_Poke_method_args, NULL }, { "Peek", my_com_netsplit_Nih_Test_Peek_method_args, NULL }, { "IsValidAddress", my_com_netsplit_Nih_Test_IsValidAddress_method_args, NULL }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_Bounce_signal_args[] = { { "height", "u", NIH_DBUS_ARG_OUT }, { "velocity", "i", NIH_DBUS_ARG_OUT }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Test_Exploded_signal_args[] = { { NULL } }; static const NihDBusSignal my_com_netsplit_Nih_Test_signals[] = { { "Bounce", my_com_netsplit_Nih_Test_Bounce_signal_args, my_com_netsplit_Nih_Test_Bounce_signal }, { "Exploded", my_com_netsplit_Nih_Test_Exploded_signal_args, my_com_netsplit_Nih_Test_Exploded_signal }, { NULL } }; static const NihDBusProperty my_com_netsplit_Nih_Test_properties[] = { { "colour", "s", NIH_DBUS_READWRITE, NULL, NULL }, { "size", "u", NIH_DBUS_READ, NULL, NULL }, { "touch", "b", NIH_DBUS_WRITE, NULL, NULL }, { NULL } }; const NihDBusInterface my_com_netsplit_Nih_Test = { "com.netsplit.Nih.Test", my_com_netsplit_Nih_Test_methods, my_com_netsplit_Nih_Test_signals, my_com_netsplit_Nih_Test_properties }; static const NihDBusArg my_com_netsplit_Nih_Foo_Bing_method_args[] = { { NULL } }; static const NihDBusMethod my_com_netsplit_Nih_Foo_methods[] = { { "Bing", my_com_netsplit_Nih_Foo_Bing_method_args, NULL }, { NULL } }; static const NihDBusArg my_com_netsplit_Nih_Foo_NewResult_signal_args[] = { { NULL } }; static const NihDBusSignal my_com_netsplit_Nih_Foo_signals[] = { { "NewResult", my_com_netsplit_Nih_Foo_NewResult_signal_args, my_com_netsplit_Nih_Foo_NewResult_signal }, { NULL } }; static const NihDBusProperty my_com_netsplit_Nih_Foo_properties[] = { { "preferences", "(us)", NIH_DBUS_READWRITE, NULL, NULL }, { NULL } }; const NihDBusInterface my_com_netsplit_Nih_Foo = { "com.netsplit.Nih.Foo", my_com_netsplit_Nih_Foo_methods, my_com_netsplit_Nih_Foo_signals, my_com_netsplit_Nih_Foo_properties }; const NihDBusInterface *my_interfaces[] = { &my_com_netsplit_Nih_Test, &my_com_netsplit_Nih_Foo, NULL }; DBusPendingCall * my_test_poke (NihDBusProxy * proxy, uint32_t address, const char * value, MyTestPokeReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Poke"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_Poke_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_Poke_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestPokeReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_poke_sync (const void * parent, NihDBusProxy *proxy, uint32_t address, const char * value) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Poke"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_peek (NihDBusProxy * proxy, uint32_t address, MyTestPeekReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Peek"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_Peek_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_Peek_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; char * value; const char * value_dbus; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&iter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestPeekReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_peek_sync (const void * parent, NihDBusProxy *proxy, uint32_t address, char ** value) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; char * value_local; const char * value_local_dbus; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Peek"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); do { __label__ enomem; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&iter, &value_local_dbus); value_local = nih_strdup (parent, value_local_dbus); if (! value_local) { *value = NULL; goto enomem; } dbus_message_iter_next (&iter); *value = value_local; enomem: __attribute__ ((unused)); } while (! *value); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (value_local); *value = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_is_valid_address (NihDBusProxy * proxy, uint32_t address, MyTestIsValidAddressReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "IsValidAddress"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_IsValidAddress_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_IsValidAddress_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestIsValidAddressReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_is_valid_address_sync (const void * parent, NihDBusProxy *proxy, uint32_t address) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "IsValidAddress"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } static DBusHandlerResult my_com_netsplit_Nih_Test_Bounce_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; uint32_t height; int32_t velocity; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&iter, &height); dbus_message_iter_next (&iter); /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&iter, &velocity); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MyTestBounceHandler)proxied->handler) (proxied->data, message, height, velocity); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } static DBusHandlerResult my_com_netsplit_Nih_Test_Exploded_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MyTestExplodedHandler)proxied->handler) (proxied->data, message); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } DBusPendingCall * my_test_get_colour (NihDBusProxy * proxy, MyTestGetColourReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_colour_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_colour_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; const char * value_dbus; char * value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyTestGetColourReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_colour_sync (const void * parent, NihDBusProxy *proxy, char ** value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; const char * local_dbus; char * local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &local_dbus); local = nih_strdup (parent, local_dbus); if (! local) { *value = NULL; goto enomem; } dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_set_colour (NihDBusProxy * proxy, const char * value, MyTestSetColourReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_colour_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_colour_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestSetColourReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_set_colour_sync (const void * parent, NihDBusProxy *proxy, const char * value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_get_size (NihDBusProxy * proxy, MyTestGetSizeReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "size"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_size_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_size_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; uint32_t value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &value); dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyTestGetSizeReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_size_sync (const void * parent, NihDBusProxy *proxy, uint32_t * value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; uint32_t local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "size"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &local); dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_set_touch (NihDBusProxy * proxy, int value, MyTestSetTouchReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "touch"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "b", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_BOOLEAN, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_touch_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_touch_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestSetTouchReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_set_touch_sync (const void * parent, NihDBusProxy *proxy, int value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "touch"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "b", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_BOOLEAN, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_get_all (NihDBusProxy * proxy, MyTestGetAllReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_get_all_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_get_all_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; NihDBusMessage * message; DBusError error; const char * property; MyTestProperties *properties; size_t property_count; char * colour; const char * colour_dbus; uint32_t size; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } properties = NIH_MUST (nih_new (message, MyTestProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "colour")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &colour_dbus); colour = nih_strdup (properties, colour_dbus); if (! colour) { goto enomem; } dbus_message_iter_next (&variter); properties->colour = colour; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); properties->size = size; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } if (property_count < 2) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ nih_error_push_context (); ((MyTestGetAllReply)pending_data->handler) (pending_data->data, message, properties); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_all_sync (const void * parent, NihDBusProxy * proxy, MyTestProperties **properties) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; DBusError error; DBusMessage * reply; size_t property_count; const char * interface; const char * property; char * colour; const char * colour_dbus; uint32_t size; nih_assert (proxy != NULL); nih_assert (properties != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } *properties = NIH_MUST (nih_new (parent, MyTestProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "colour")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &colour_dbus); colour = nih_strdup (*properties, colour_dbus); if (! colour) { goto enomem; } dbus_message_iter_next (&variter); (*properties)->colour = colour; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); (*properties)->size = size; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } if (property_count < 2) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_foo_bing (NihDBusProxy * proxy, MyFooBingReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Foo", "Bing"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Foo_Bing_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Foo_Bing_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyFooBingReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_foo_bing_sync (const void * parent, NihDBusProxy *proxy) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Foo", "Bing"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } static DBusHandlerResult my_com_netsplit_Nih_Foo_NewResult_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MyFooNewResultHandler)proxied->handler) (proxied->data, message); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } DBusPendingCall * my_foo_get_preferences (NihDBusProxy * proxy, MyFooGetPreferencesReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Foo"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "preferences"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Foo_preferences_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Foo_preferences_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage * message; DBusError error; DBusMessageIter value_iter; uint32_t value_item0; const char * value_item1_dbus; char * value_item1; MyFooPreferences *value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&variter, &value_iter); value = nih_new (message, MyFooPreferences); if (! value) { nih_free (message); message = NULL; goto enomem; } /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_UINT32) { nih_free (value); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&value_iter, &value_item0); dbus_message_iter_next (&value_iter); value->item0 = value_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_STRING) { nih_free (value); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&value_iter, &value_item1_dbus); value_item1 = nih_strdup (value, value_item1_dbus); if (! value_item1) { nih_free (value); nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&value_iter); value->item1 = value_item1; if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) { nih_free (value); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyFooGetPreferencesReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_foo_get_preferences_sync (const void * parent, NihDBusProxy * proxy, MyFooPreferences **value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; DBusMessageIter local_iter; uint32_t local_item0; const char * local_item1_dbus; char * local_item1; MyFooPreferences *local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Foo"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "preferences"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&variter, &local_iter); local = nih_new (parent, MyFooPreferences); if (! local) { *value = NULL; goto enomem; } /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_UINT32) { nih_free (local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&local_iter, &local_item0); dbus_message_iter_next (&local_iter); local->item0 = local_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_STRING) { nih_free (local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&local_iter, &local_item1_dbus); local_item1 = nih_strdup (local, local_item1_dbus); if (! local_item1) { nih_free (local); *value = NULL; goto enomem; } dbus_message_iter_next (&local_iter); local->item1 = local_item1; if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_INVALID) { nih_free (local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } DBusPendingCall * my_foo_set_preferences (NihDBusProxy * proxy, const MyFooPreferences * value, MyFooSetPreferencesReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; DBusMessageIter value_iter; uint32_t value_item0; const char * value_item1; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Foo"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "preferences"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(us)", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } value_item0 = value->item0; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_UINT32, &value_item0)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } value_item1 = value->item1; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item1)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Foo_preferences_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Foo_preferences_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyFooSetPreferencesReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_foo_set_preferences_sync (const void * parent, NihDBusProxy * proxy, const MyFooPreferences *value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; DBusMessageIter value_iter; uint32_t value_item0; const char * value_item1; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Foo"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "preferences"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(us)", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } value_item0 = value->item0; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_UINT32, &value_item0)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } value_item1 = value->item1; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item1)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_foo_get_all (NihDBusProxy * proxy, MyFooGetAllReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Foo"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Foo_get_all_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Foo_get_all_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; NihDBusMessage * message; DBusError error; const char * property; MyFooProperties * properties; size_t property_count; MyFooPreferences *preferences; DBusMessageIter preferences_iter; uint32_t preferences_item0; const char * preferences_item1_dbus; char * preferences_item1; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } properties = NIH_MUST (nih_new (message, MyFooProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "preferences")) { /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&variter, &preferences_iter); preferences = nih_new (properties, MyFooPreferences); if (! preferences) { goto enomem; } /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&preferences_iter) != DBUS_TYPE_UINT32) { nih_free (preferences); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&preferences_iter, &preferences_item0); dbus_message_iter_next (&preferences_iter); preferences->item0 = preferences_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&preferences_iter) != DBUS_TYPE_STRING) { nih_free (preferences); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&preferences_iter, &preferences_item1_dbus); preferences_item1 = nih_strdup (preferences, preferences_item1_dbus); if (! preferences_item1) { nih_free (preferences); goto enomem; } dbus_message_iter_next (&preferences_iter); preferences->item1 = preferences_item1; if (dbus_message_iter_get_arg_type (&preferences_iter) != DBUS_TYPE_INVALID) { nih_free (preferences); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&variter); properties->preferences = preferences; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } if (property_count < 1) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ nih_error_push_context (); ((MyFooGetAllReply)pending_data->handler) (pending_data->data, message, properties); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_foo_get_all_sync (const void * parent, NihDBusProxy * proxy, MyFooProperties **properties) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; DBusError error; DBusMessage * reply; size_t property_count; const char * interface; const char * property; MyFooPreferences *preferences; DBusMessageIter preferences_iter; uint32_t preferences_item0; const char * preferences_item1_dbus; char * preferences_item1; nih_assert (proxy != NULL); nih_assert (properties != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Foo"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } *properties = NIH_MUST (nih_new (parent, MyFooProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "preferences")) { /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&variter, &preferences_iter); preferences = nih_new (*properties, MyFooPreferences); if (! preferences) { goto enomem; } /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&preferences_iter) != DBUS_TYPE_UINT32) { nih_free (preferences); nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&preferences_iter, &preferences_item0); dbus_message_iter_next (&preferences_iter); preferences->item0 = preferences_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&preferences_iter) != DBUS_TYPE_STRING) { nih_free (preferences); nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&preferences_iter, &preferences_item1_dbus); preferences_item1 = nih_strdup (preferences, preferences_item1_dbus); if (! preferences_item1) { nih_free (preferences); goto enomem; } dbus_message_iter_next (&preferences_iter); preferences->item1 = preferences_item1; if (dbus_message_iter_get_arg_type (&preferences_iter) != DBUS_TYPE_INVALID) { nih_free (preferences); nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&variter); (*properties)->preferences = preferences; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } if (property_count < 1) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_object_functions_no_properties.c0000644000175000017500000003710411445765555026074 00000000000000static DBusHandlerResult my_com_netsplit_Nih_Test_Poke_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; uint32_t address; char * value; const char * value_dbus; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Poke method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &address); dbus_message_iter_next (&iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Poke method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Poke method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_test_poke (object->data, message, address, value) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } static DBusHandlerResult my_com_netsplit_Nih_Test_Peek_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; uint32_t address; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Peek method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &address); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Peek method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_test_peek (object->data, message, address) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); return DBUS_HANDLER_RESULT_HANDLED; } int my_test_peek_reply (NihDBusMessage *message, const char * value) { DBusMessage * reply; DBusMessageIter iter; nih_assert (message != NULL); nih_assert (value != NULL); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return 0; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) return -1; dbus_message_iter_init_append (reply, &iter); /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) { dbus_message_unref (reply); return -1; } /* Send the reply, appending it to the outgoing queue. */ if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return -1; } dbus_message_unref (reply); return 0; } static DBusHandlerResult my_com_netsplit_Nih_Test_IsValidAddress_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; uint32_t address; int is_valid; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to IsValidAddress method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &address); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to IsValidAddress method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_test_is_valid_address (object->data, message, address, &is_valid) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &is_valid)) { dbus_message_unref (reply); reply = NULL; goto enomem; } enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } int my_test_emit_bounce (DBusConnection *connection, const char * origin_path, uint32_t height, int32_t velocity) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Bounce"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &height)) { dbus_message_unref (signal); return -1; } /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &velocity)) { dbus_message_unref (signal); return -1; } /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } int my_test_emit_exploded (DBusConnection *connection, const char * origin_path) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Exploded"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } static DBusHandlerResult my_com_netsplit_Nih_Foo_Bing_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Bing method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_foo_bing (object->data, message) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } int my_foo_emit_new_result (DBusConnection *connection, const char * origin_path) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Foo", "NewResult"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_reply_function_no_args.c0000644000175000017500000000127211445765555024666 00000000000000int my_async_method_reply (NihDBusMessage *message) { DBusMessage * reply; DBusMessageIter iter; nih_assert (message != NULL); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return 0; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) return -1; dbus_message_iter_init_append (reply, &iter); /* Send the reply, appending it to the outgoing queue. */ if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return -1; } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_proxy_functions_structure.c0000644000175000017500000023560611445765555025166 00000000000000DBusPendingCall * my_test_search (NihDBusProxy * proxy, const MyTestSearchItem *item, MyTestSearchReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; DBusMessageIter item_iter; const char * item_item0; uint32_t item_item1; nih_assert (proxy != NULL); nih_assert (item != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Search"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &item_iter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } item_item0 = item->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&item_iter, DBUS_TYPE_STRING, &item_item0)) { dbus_message_iter_abandon_container (&iter, &item_iter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } item_item1 = item->item1; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&item_iter, DBUS_TYPE_UINT32, &item_item1)) { dbus_message_iter_abandon_container (&iter, &item_iter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &item_iter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_Search_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_Search_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage * message; DBusError error; MyTestSearchResult *result; DBusMessageIter result_iter; const char * result_item0_dbus; char * result_item0; const char * result_item1_dbus; char * result_item1; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRUCT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &result_iter); result = nih_new (message, MyTestSearchResult); if (! result) { nih_free (message); message = NULL; goto enomem; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&result_iter) != DBUS_TYPE_STRING) { nih_free (result); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&result_iter, &result_item0_dbus); result_item0 = nih_strdup (result, result_item0_dbus); if (! result_item0) { nih_free (result); nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&result_iter); result->item0 = result_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&result_iter) != DBUS_TYPE_STRING) { nih_free (result); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&result_iter, &result_item1_dbus); result_item1 = nih_strdup (result, result_item1_dbus); if (! result_item1) { nih_free (result); nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&result_iter); result->item1 = result_item1; if (dbus_message_iter_get_arg_type (&result_iter) != DBUS_TYPE_INVALID) { nih_free (result); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestSearchReply)pending_data->handler) (pending_data->data, message, result); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_search_sync (const void * parent, NihDBusProxy * proxy, const MyTestSearchItem *item, MyTestSearchResult ** result) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; DBusMessageIter item_iter; const char * item_item0; uint32_t item_item1; MyTestSearchResult *result_local; DBusMessageIter result_local_iter; const char * result_local_item0_dbus; char * result_local_item0; const char * result_local_item1_dbus; char * result_local_item1; nih_assert (proxy != NULL); nih_assert (item != NULL); nih_assert (result != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Search"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &item_iter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } item_item0 = item->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&item_iter, DBUS_TYPE_STRING, &item_item0)) { dbus_message_iter_abandon_container (&iter, &item_iter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } item_item1 = item->item1; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&item_iter, DBUS_TYPE_UINT32, &item_item1)) { dbus_message_iter_abandon_container (&iter, &item_iter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &item_iter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); do { __label__ enomem; /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRUCT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &result_local_iter); result_local = nih_new (parent, MyTestSearchResult); if (! result_local) { *result = NULL; goto enomem; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&result_local_iter) != DBUS_TYPE_STRING) { nih_free (result_local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&result_local_iter, &result_local_item0_dbus); result_local_item0 = nih_strdup (result_local, result_local_item0_dbus); if (! result_local_item0) { nih_free (result_local); *result = NULL; goto enomem; } dbus_message_iter_next (&result_local_iter); result_local->item0 = result_local_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&result_local_iter) != DBUS_TYPE_STRING) { nih_free (result_local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&result_local_iter, &result_local_item1_dbus); result_local_item1 = nih_strdup (result_local, result_local_item1_dbus); if (! result_local_item1) { nih_free (result_local); *result = NULL; goto enomem; } dbus_message_iter_next (&result_local_iter); result_local->item1 = result_local_item1; if (dbus_message_iter_get_arg_type (&result_local_iter) != DBUS_TYPE_INVALID) { nih_free (result_local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&iter); *result = result_local; enomem: __attribute__ ((unused)); } while (! *result); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (result_local); *result = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } static DBusHandlerResult my_com_netsplit_Nih_Test_NewSearch_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage * message; MyTestNewSearchQuery *query; DBusMessageIter query_iter; const char * query_item0_dbus; char * query_item0; const char * query_item1_dbus; char * query_item1; uint32_t query_item2; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRUCT) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_recurse (&iter, &query_iter); query = nih_new (message, MyTestNewSearchQuery); if (! query) { nih_free (message); return DBUS_HANDLER_RESULT_NEED_MEMORY; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&query_iter) != DBUS_TYPE_STRING) { nih_free (query); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&query_iter, &query_item0_dbus); query_item0 = nih_strdup (query, query_item0_dbus); if (! query_item0) { nih_free (query); nih_free (message); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&query_iter); query->item0 = query_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&query_iter) != DBUS_TYPE_STRING) { nih_free (query); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&query_iter, &query_item1_dbus); query_item1 = nih_strdup (query, query_item1_dbus); if (! query_item1) { nih_free (query); nih_free (message); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&query_iter); query->item1 = query_item1; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&query_iter) != DBUS_TYPE_UINT32) { nih_free (query); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&query_iter, &query_item2); dbus_message_iter_next (&query_iter); query->item2 = query_item2; if (dbus_message_iter_get_arg_type (&query_iter) != DBUS_TYPE_INVALID) { nih_free (query); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MyTestNewSearchHandler)proxied->handler) (proxied->data, message, query); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } DBusPendingCall * my_test_get_last_search (NihDBusProxy * proxy, MyTestGetLastSearchReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "last_search"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_last_search_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_last_search_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage * message; DBusError error; DBusMessageIter value_iter; const char * value_item0_dbus; char * value_item0; uint32_t value_item1; MyTestLastSearch *value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&variter, &value_iter); value = nih_new (message, MyTestLastSearch); if (! value) { nih_free (message); message = NULL; goto enomem; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_STRING) { nih_free (value); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&value_iter, &value_item0_dbus); value_item0 = nih_strdup (value, value_item0_dbus); if (! value_item0) { nih_free (value); nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&value_iter); value->item0 = value_item0; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_UINT32) { nih_free (value); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&value_iter, &value_item1); dbus_message_iter_next (&value_iter); value->item1 = value_item1; if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) { nih_free (value); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyTestGetLastSearchReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_last_search_sync (const void * parent, NihDBusProxy * proxy, MyTestLastSearch **value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; DBusMessageIter local_iter; const char * local_item0_dbus; char * local_item0; uint32_t local_item1; MyTestLastSearch *local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "last_search"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&variter, &local_iter); local = nih_new (parent, MyTestLastSearch); if (! local) { *value = NULL; goto enomem; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_STRING) { nih_free (local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&local_iter, &local_item0_dbus); local_item0 = nih_strdup (local, local_item0_dbus); if (! local_item0) { nih_free (local); *value = NULL; goto enomem; } dbus_message_iter_next (&local_iter); local->item0 = local_item0; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_UINT32) { nih_free (local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&local_iter, &local_item1); dbus_message_iter_next (&local_iter); local->item1 = local_item1; if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_INVALID) { nih_free (local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_set_annotation (NihDBusProxy * proxy, const MyTestAnnotation * value, MyTestSetAnnotationReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; DBusMessageIter value_iter; const char * value_item0; const char * value_item1; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "annotation"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(ss)", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } value_item0 = value->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item0)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } value_item1 = value->item1; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item1)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_annotation_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_annotation_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestSetAnnotationReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_set_annotation_sync (const void * parent, NihDBusProxy * proxy, const MyTestAnnotation *value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; DBusMessageIter value_iter; const char * value_item0; const char * value_item1; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "annotation"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(ss)", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } value_item0 = value->item0; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item0)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } value_item1 = value->item1; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item1)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_get_preferences (NihDBusProxy * proxy, MyTestGetPreferencesReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "preferences"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_preferences_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_preferences_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage * message; DBusError error; DBusMessageIter value_iter; uint32_t value_item0; const char * value_item1_dbus; char * value_item1; MyTestPreferences *value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&variter, &value_iter); value = nih_new (message, MyTestPreferences); if (! value) { nih_free (message); message = NULL; goto enomem; } /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_UINT32) { nih_free (value); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&value_iter, &value_item0); dbus_message_iter_next (&value_iter); value->item0 = value_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_STRING) { nih_free (value); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&value_iter, &value_item1_dbus); value_item1 = nih_strdup (value, value_item1_dbus); if (! value_item1) { nih_free (value); nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&value_iter); value->item1 = value_item1; if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) { nih_free (value); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyTestGetPreferencesReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_preferences_sync (const void * parent, NihDBusProxy * proxy, MyTestPreferences **value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; DBusMessageIter local_iter; uint32_t local_item0; const char * local_item1_dbus; char * local_item1; MyTestPreferences *local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "preferences"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&variter, &local_iter); local = nih_new (parent, MyTestPreferences); if (! local) { *value = NULL; goto enomem; } /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_UINT32) { nih_free (local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&local_iter, &local_item0); dbus_message_iter_next (&local_iter); local->item0 = local_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_STRING) { nih_free (local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&local_iter, &local_item1_dbus); local_item1 = nih_strdup (local, local_item1_dbus); if (! local_item1) { nih_free (local); *value = NULL; goto enomem; } dbus_message_iter_next (&local_iter); local->item1 = local_item1; if (dbus_message_iter_get_arg_type (&local_iter) != DBUS_TYPE_INVALID) { nih_free (local); dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_set_preferences (NihDBusProxy * proxy, const MyTestPreferences * value, MyTestSetPreferencesReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; DBusMessageIter value_iter; uint32_t value_item0; const char * value_item1; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "preferences"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(us)", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } value_item0 = value->item0; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_UINT32, &value_item0)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } value_item1 = value->item1; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item1)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_preferences_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_preferences_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestSetPreferencesReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_set_preferences_sync (const void * parent, NihDBusProxy * proxy, const MyTestPreferences *value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; DBusMessageIter value_iter; uint32_t value_item0; const char * value_item1; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "preferences"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(us)", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a structure onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } value_item0 = value->item0; /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_UINT32, &value_item0)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } value_item1 = value->item1; /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item1)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_get_all (NihDBusProxy * proxy, MyTestGetAllReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_get_all_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_get_all_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; NihDBusMessage * message; DBusError error; const char * property; MyTestProperties * properties; size_t property_count; MyTestLastSearch * last_search; DBusMessageIter last_search_iter; const char * last_search_item0_dbus; char * last_search_item0; uint32_t last_search_item1; MyTestPreferences *preferences; DBusMessageIter preferences_iter; uint32_t preferences_item0; const char * preferences_item1_dbus; char * preferences_item1; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } properties = NIH_MUST (nih_new (message, MyTestProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "last_search")) { /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&variter, &last_search_iter); last_search = nih_new (properties, MyTestLastSearch); if (! last_search) { goto enomem; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&last_search_iter) != DBUS_TYPE_STRING) { nih_free (last_search); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&last_search_iter, &last_search_item0_dbus); last_search_item0 = nih_strdup (last_search, last_search_item0_dbus); if (! last_search_item0) { nih_free (last_search); goto enomem; } dbus_message_iter_next (&last_search_iter); last_search->item0 = last_search_item0; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&last_search_iter) != DBUS_TYPE_UINT32) { nih_free (last_search); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&last_search_iter, &last_search_item1); dbus_message_iter_next (&last_search_iter); last_search->item1 = last_search_item1; if (dbus_message_iter_get_arg_type (&last_search_iter) != DBUS_TYPE_INVALID) { nih_free (last_search); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&variter); properties->last_search = last_search; nih_assert (++property_count); } if (! strcmp (property, "preferences")) { /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&variter, &preferences_iter); preferences = nih_new (properties, MyTestPreferences); if (! preferences) { goto enomem; } /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&preferences_iter) != DBUS_TYPE_UINT32) { nih_free (preferences); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&preferences_iter, &preferences_item0); dbus_message_iter_next (&preferences_iter); preferences->item0 = preferences_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&preferences_iter) != DBUS_TYPE_STRING) { nih_free (preferences); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&preferences_iter, &preferences_item1_dbus); preferences_item1 = nih_strdup (preferences, preferences_item1_dbus); if (! preferences_item1) { nih_free (preferences); goto enomem; } dbus_message_iter_next (&preferences_iter); preferences->item1 = preferences_item1; if (dbus_message_iter_get_arg_type (&preferences_iter) != DBUS_TYPE_INVALID) { nih_free (preferences); nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&variter); properties->preferences = preferences; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } if (property_count < 2) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ nih_error_push_context (); ((MyTestGetAllReply)pending_data->handler) (pending_data->data, message, properties); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_all_sync (const void * parent, NihDBusProxy * proxy, MyTestProperties **properties) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; DBusError error; DBusMessage * reply; size_t property_count; const char * interface; const char * property; MyTestLastSearch * last_search; DBusMessageIter last_search_iter; const char * last_search_item0_dbus; char * last_search_item0; uint32_t last_search_item1; MyTestPreferences *preferences; DBusMessageIter preferences_iter; uint32_t preferences_item0; const char * preferences_item1_dbus; char * preferences_item1; nih_assert (proxy != NULL); nih_assert (properties != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } *properties = NIH_MUST (nih_new (parent, MyTestProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "last_search")) { /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&variter, &last_search_iter); last_search = nih_new (*properties, MyTestLastSearch); if (! last_search) { goto enomem; } /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&last_search_iter) != DBUS_TYPE_STRING) { nih_free (last_search); nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&last_search_iter, &last_search_item0_dbus); last_search_item0 = nih_strdup (last_search, last_search_item0_dbus); if (! last_search_item0) { nih_free (last_search); goto enomem; } dbus_message_iter_next (&last_search_iter); last_search->item0 = last_search_item0; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&last_search_iter) != DBUS_TYPE_UINT32) { nih_free (last_search); nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&last_search_iter, &last_search_item1); dbus_message_iter_next (&last_search_iter); last_search->item1 = last_search_item1; if (dbus_message_iter_get_arg_type (&last_search_iter) != DBUS_TYPE_INVALID) { nih_free (last_search); nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&variter); (*properties)->last_search = last_search; nih_assert (++property_count); } if (! strcmp (property, "preferences")) { /* Demarshal a structure from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRUCT) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&variter, &preferences_iter); preferences = nih_new (*properties, MyTestPreferences); if (! preferences) { goto enomem; } /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&preferences_iter) != DBUS_TYPE_UINT32) { nih_free (preferences); nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&preferences_iter, &preferences_item0); dbus_message_iter_next (&preferences_iter); preferences->item0 = preferences_item0; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&preferences_iter) != DBUS_TYPE_STRING) { nih_free (preferences); nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&preferences_iter, &preferences_item1_dbus); preferences_item1 = nih_strdup (preferences, preferences_item1_dbus); if (! preferences_item1) { nih_free (preferences); goto enomem; } dbus_message_iter_next (&preferences_iter); preferences->item1 = preferences_item1; if (dbus_message_iter_get_arg_type (&preferences_iter) != DBUS_TYPE_INVALID) { nih_free (preferences); nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&variter); (*properties)->preferences = preferences; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } if (property_count < 2) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_get_sync_function_deprecated.c0000644000175000017500000000532711445765555027670 00000000000000int my_get_property_sync (const void * parent, NihDBusProxy *proxy, char ** value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; const char * local_dbus; char * local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "property"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &local_dbus); local = nih_strdup (parent, local_dbus); if (! local) { *value = NULL; goto enomem; } dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_set_notify_function_deprecated.c0000644000175000017500000000367511445765555030244 00000000000000void my_com_netsplit_Nih_Test_property_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MySetPropertyReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } libnih-1.0.3/nih-dbus-tool/tests/expected/test_signal_object_function_deprecated.c0000644000175000017500000000151211445765555025443 00000000000000int my_emit_signal (DBusConnection *connection, const char * origin_path, const char * msg) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); nih_assert (msg != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Signal"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &msg)) { dbus_message_unref (signal); return -1; } /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_signal_proxy_function_standard.c0000644000175000017500000000354411445765555025065 00000000000000DBusHandlerResult my_com_netsplit_Nih_Test_Signal_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; char * msg; const char * msg_dbus; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&iter, &msg_dbus); msg = nih_strdup (message, msg_dbus); if (! msg) { nih_free (message); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MySignalHandler)proxied->handler) (proxied->data, message, msg); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_proxy_functions_no_properties.c0000644000175000017500000007450311445765555026013 00000000000000DBusPendingCall * my_test_poke (NihDBusProxy * proxy, uint32_t address, const char * value, MyTestPokeReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Poke"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_Poke_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_Poke_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestPokeReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_poke_sync (const void * parent, NihDBusProxy *proxy, uint32_t address, const char * value) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Poke"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_peek (NihDBusProxy * proxy, uint32_t address, MyTestPeekReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Peek"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_Peek_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_Peek_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; char * value; const char * value_dbus; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&iter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestPeekReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_peek_sync (const void * parent, NihDBusProxy *proxy, uint32_t address, char ** value) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; char * value_local; const char * value_local_dbus; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Peek"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); do { __label__ enomem; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&iter, &value_local_dbus); value_local = nih_strdup (parent, value_local_dbus); if (! value_local) { *value = NULL; goto enomem; } dbus_message_iter_next (&iter); *value = value_local; enomem: __attribute__ ((unused)); } while (! *value); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (value_local); *value = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_is_valid_address (NihDBusProxy * proxy, uint32_t address, MyTestIsValidAddressReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "IsValidAddress"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_IsValidAddress_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_IsValidAddress_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestIsValidAddressReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_is_valid_address_sync (const void * parent, NihDBusProxy *proxy, uint32_t address) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "IsValidAddress"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } static DBusHandlerResult my_com_netsplit_Nih_Test_Bounce_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; uint32_t height; int32_t velocity; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&iter, &height); dbus_message_iter_next (&iter); /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&iter, &velocity); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MyTestBounceHandler)proxied->handler) (proxied->data, message, height, velocity); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } static DBusHandlerResult my_com_netsplit_Nih_Test_Exploded_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MyTestExplodedHandler)proxied->handler) (proxied->data, message); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } DBusPendingCall * my_foo_bing (NihDBusProxy * proxy, MyFooBingReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Foo", "Bing"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Foo_Bing_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Foo_Bing_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyFooBingReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_foo_bing_sync (const void * parent, NihDBusProxy *proxy) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Foo", "Bing"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } static DBusHandlerResult my_com_netsplit_Nih_Foo_NewResult_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MyFooNewResultHandler)proxied->handler) (proxied->data, message); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_function_standard.c0000644000175000017500000000522211445765555025063 00000000000000DBusPendingCall * my_test_method (NihDBusProxy * proxy, const char * str, int32_t flags, MyTestMethodReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert (str != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "TestMethod"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_TestMethod_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_output_proxy_standard.h0000644000175000017500000001457211445765555023253 00000000000000/* test * * Copyright (C) 2009 Joe Bloggs. * * This file was automatically generated; see the source for copying * conditions. */ #ifndef TEST_TEST_H #define TEST_TEST_H #include #include #include #include #include #include #include typedef struct my_test_properties { char * colour; uint32_t size; } MyTestProperties; typedef struct my_foo_preferences { uint32_t item0; char * item1; } MyFooPreferences; typedef struct my_foo_properties { MyFooPreferences *preferences; } MyFooProperties; typedef void (*MyTestPokeReply) (void *data, NihDBusMessage *message); typedef void (*MyTestPeekReply) (void *data, NihDBusMessage *message, const char *value); typedef void (*MyTestIsValidAddressReply) (void *data, NihDBusMessage *message); typedef void (*MyTestBounceHandler) (void *data, NihDBusMessage *message, uint32_t height, int32_t velocity); typedef void (*MyTestExplodedHandler) (void *data, NihDBusMessage *message); typedef void (*MyTestGetColourReply) (void *data, NihDBusMessage *message, const char *value); typedef void (*MyTestSetColourReply) (void *data, NihDBusMessage *message); typedef void (*MyTestGetSizeReply) (void *data, NihDBusMessage *message, uint32_t value); typedef void (*MyTestSetTouchReply) (void *data, NihDBusMessage *message); typedef void (*MyTestGetAllReply) (void *data, NihDBusMessage *message, const MyTestProperties *properties); typedef void (*MyFooBingReply) (void *data, NihDBusMessage *message); typedef void (*MyFooNewResultHandler) (void *data, NihDBusMessage *message); typedef void (*MyFooGetPreferencesReply) (void *data, NihDBusMessage *message, const MyFooPreferences *value); typedef void (*MyFooSetPreferencesReply) (void *data, NihDBusMessage *message); typedef void (*MyFooGetAllReply) (void *data, NihDBusMessage *message, const MyFooProperties *properties); NIH_BEGIN_EXTERN extern const NihDBusInterface my_com_netsplit_Nih_Test; extern const NihDBusInterface my_com_netsplit_Nih_Foo; extern const NihDBusInterface *my_interfaces[]; DBusPendingCall *my_test_poke (NihDBusProxy *proxy, uint32_t address, const char *value, MyTestPokeReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); int my_test_poke_sync (const void *parent, NihDBusProxy *proxy, uint32_t address, const char *value) __attribute__ ((warn_unused_result)); DBusPendingCall *my_test_peek (NihDBusProxy *proxy, uint32_t address, MyTestPeekReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); int my_test_peek_sync (const void *parent, NihDBusProxy *proxy, uint32_t address, char **value) __attribute__ ((warn_unused_result)); DBusPendingCall *my_test_is_valid_address (NihDBusProxy *proxy, uint32_t address, MyTestIsValidAddressReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); int my_test_is_valid_address_sync (const void *parent, NihDBusProxy *proxy, uint32_t address) __attribute__ ((warn_unused_result)); DBusPendingCall *my_test_get_colour (NihDBusProxy *proxy, MyTestGetColourReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); int my_test_get_colour_sync (const void *parent, NihDBusProxy *proxy, char **value) __attribute__ ((warn_unused_result)); DBusPendingCall *my_test_set_colour (NihDBusProxy *proxy, const char *value, MyTestSetColourReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); int my_test_set_colour_sync (const void *parent, NihDBusProxy *proxy, const char *value) __attribute__ ((warn_unused_result)); DBusPendingCall *my_test_get_size (NihDBusProxy *proxy, MyTestGetSizeReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); int my_test_get_size_sync (const void *parent, NihDBusProxy *proxy, uint32_t *value) __attribute__ ((warn_unused_result)); DBusPendingCall *my_test_set_touch (NihDBusProxy *proxy, int value, MyTestSetTouchReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); int my_test_set_touch_sync (const void *parent, NihDBusProxy *proxy, int value) __attribute__ ((warn_unused_result)); DBusPendingCall *my_test_get_all (NihDBusProxy *proxy, MyTestGetAllReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); int my_test_get_all_sync (const void *parent, NihDBusProxy *proxy, MyTestProperties **properties) __attribute__ ((warn_unused_result)); DBusPendingCall *my_foo_bing (NihDBusProxy *proxy, MyFooBingReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); int my_foo_bing_sync (const void *parent, NihDBusProxy *proxy) __attribute__ ((warn_unused_result)); DBusPendingCall *my_foo_get_preferences (NihDBusProxy *proxy, MyFooGetPreferencesReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); int my_foo_get_preferences_sync (const void *parent, NihDBusProxy *proxy, MyFooPreferences **value) __attribute__ ((warn_unused_result)); DBusPendingCall *my_foo_set_preferences (NihDBusProxy *proxy, const MyFooPreferences *value, MyFooSetPreferencesReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); int my_foo_set_preferences_sync (const void *parent, NihDBusProxy *proxy, const MyFooPreferences *value) __attribute__ ((warn_unused_result)); DBusPendingCall *my_foo_get_all (NihDBusProxy *proxy, MyFooGetAllReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); int my_foo_get_all_sync (const void *parent, NihDBusProxy *proxy, MyFooProperties **properties) __attribute__ ((warn_unused_result)); NIH_END_EXTERN #endif /* TEST_TEST_H */ libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_set_sync_function_array.c0000644000175000017500000000616411445765555026722 00000000000000int my_set_property_sync (const void * parent, NihDBusProxy * proxy, const int32_t *value, size_t value_len) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; DBusMessageIter value_iter; nih_assert (proxy != NULL); nih_assert ((value_len == 0) || (value != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "property"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "ai", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal an array onto the message */ if (! dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, "i", &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } for (size_t value_i = 0; value_i < value_len; value_i++) { int32_t value_element; value_element = value[value_i]; /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_INT32, &value_element)) { dbus_message_iter_abandon_container (&variter, &value_iter); dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } } if (! dbus_message_iter_close_container (&variter, &value_iter)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_proxy_sync_function_deprecated.c0000644000175000017500000000303011445765555026412 00000000000000int my_method_sync (const void * parent, NihDBusProxy *proxy, int32_t flags) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Method"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_object_functions_no_methods.c0000644000175000017500000001602011445765555025335 00000000000000int my_test_emit_bounce (DBusConnection *connection, const char * origin_path, uint32_t height, int32_t velocity) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Bounce"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &height)) { dbus_message_unref (signal); return -1; } /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &velocity)) { dbus_message_unref (signal); return -1; } /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } int my_test_emit_exploded (DBusConnection *connection, const char * origin_path) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Exploded"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } static int my_com_netsplit_Nih_Test_colour_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_test_get_colour (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "s", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int my_com_netsplit_Nih_Test_colour_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; const char * value_dbus; char * value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_error_raise_no_memory (); return -1; } dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to colour property"); return -1; } /* Call the handler function */ if (my_test_set_colour (object->data, message, value) < 0) return -1; return 0; } static int my_com_netsplit_Nih_Test_size_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; uint32_t value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Call the handler function */ if (my_test_get_size (object->data, message, &value) < 0) return -1; /* Append a variant onto the message to contain the property value. */ if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "u", &variter)) { nih_error_raise_no_memory (); return -1; } /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &value)) { dbus_message_iter_abandon_container (iter, &variter); nih_error_raise_no_memory (); return -1; } /* Finish the variant */ if (! dbus_message_iter_close_container (iter, &variter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int my_com_netsplit_Nih_Test_touch_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter variter; int value; nih_assert (object != NULL); nih_assert (message != NULL); nih_assert (iter != NULL); /* Recurse into the variant */ if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_VARIANT) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } dbus_message_iter_recurse (iter, &variter); /* Demarshal a int from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_BOOLEAN) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } dbus_message_iter_get_basic (&variter, &value); dbus_message_iter_next (&variter); dbus_message_iter_next (iter); if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_INVALID) { nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, "Invalid arguments to touch property"); return -1; } /* Call the handler function */ if (my_test_set_touch (object->data, message, value) < 0) return -1; return 0; } int my_foo_emit_new_result (DBusConnection *connection, const char * origin_path) { DBusMessage * signal; DBusMessageIter iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Foo", "NewResult"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_set_sync_function_standard.c0000644000175000017500000000456211445765555027404 00000000000000int my_set_property_sync (const void * parent, NihDBusProxy *proxy, const char * value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "property"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_signal_object_function_array.c0000644000175000017500000000263211445765555024465 00000000000000int my_emit_signal (DBusConnection *connection, const char * origin_path, const int32_t * value, size_t value_len) { DBusMessage * signal; DBusMessageIter iter; DBusMessageIter value_iter; nih_assert (connection != NULL); nih_assert (origin_path != NULL); nih_assert ((value_len == 0) || (value != NULL)); /* Construct the message. */ signal = dbus_message_new_signal (origin_path, "com.netsplit.Nih.Test", "Signal"); if (! signal) return -1; dbus_message_iter_init_append (signal, &iter); /* Marshal an array onto the message */ if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "i", &value_iter)) { dbus_message_unref (signal); return -1; } for (size_t value_i = 0; value_i < value_len; value_i++) { int32_t value_element; value_element = value[value_i]; /* Marshal a int32_t onto the message */ if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_INT32, &value_element)) { dbus_message_iter_abandon_container (&iter, &value_iter); dbus_message_unref (signal); return -1; } } if (! dbus_message_iter_close_container (&iter, &value_iter)) { dbus_message_unref (signal); return -1; } /* Send the signal, appending it to the outgoing queue. */ if (! dbus_connection_send (connection, signal, NULL)) { dbus_message_unref (signal); return -1; } dbus_message_unref (signal); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_proxy_functions_no_methods.c0000644000175000017500000014220011445765555025250 00000000000000static DBusHandlerResult my_com_netsplit_Nih_Test_Bounce_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; uint32_t height; int32_t velocity; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&iter, &height); dbus_message_iter_next (&iter); /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_message_iter_get_basic (&iter, &velocity); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MyTestBounceHandler)proxied->handler) (proxied->data, message, height, velocity); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } static DBusHandlerResult my_com_netsplit_Nih_Test_Exploded_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MyTestExplodedHandler)proxied->handler) (proxied->data, message); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } DBusPendingCall * my_test_get_colour (NihDBusProxy * proxy, MyTestGetColourReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_colour_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_colour_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; const char * value_dbus; char * value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyTestGetColourReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_colour_sync (const void * parent, NihDBusProxy *proxy, char ** value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; const char * local_dbus; char * local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &local_dbus); local = nih_strdup (parent, local_dbus); if (! local) { *value = NULL; goto enomem; } dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_set_colour (NihDBusProxy * proxy, const char * value, MyTestSetColourReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_colour_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_colour_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestSetColourReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_set_colour_sync (const void * parent, NihDBusProxy *proxy, const char * value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_get_size (NihDBusProxy * proxy, MyTestGetSizeReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "size"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_size_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_size_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; uint32_t value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &value); dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyTestGetSizeReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_size_sync (const void * parent, NihDBusProxy *proxy, uint32_t * value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; uint32_t local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "size"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &local); dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_set_touch (NihDBusProxy * proxy, int value, MyTestSetTouchReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "touch"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "b", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_BOOLEAN, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_touch_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_touch_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestSetTouchReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_set_touch_sync (const void * parent, NihDBusProxy *proxy, int value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "touch"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "b", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_BOOLEAN, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_get_all (NihDBusProxy * proxy, MyTestGetAllReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_get_all_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_get_all_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; NihDBusMessage * message; DBusError error; const char * property; MyTestProperties *properties; size_t property_count; char * colour; const char * colour_dbus; uint32_t size; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } properties = NIH_MUST (nih_new (message, MyTestProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "colour")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &colour_dbus); colour = nih_strdup (properties, colour_dbus); if (! colour) { goto enomem; } dbus_message_iter_next (&variter); properties->colour = colour; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); properties->size = size; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } if (property_count < 2) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ nih_error_push_context (); ((MyTestGetAllReply)pending_data->handler) (pending_data->data, message, properties); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_all_sync (const void * parent, NihDBusProxy * proxy, MyTestProperties **properties) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; DBusError error; DBusMessage * reply; size_t property_count; const char * interface; const char * property; char * colour; const char * colour_dbus; uint32_t size; nih_assert (proxy != NULL); nih_assert (properties != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } *properties = NIH_MUST (nih_new (parent, MyTestProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "colour")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &colour_dbus); colour = nih_strdup (*properties, colour_dbus); if (! colour) { goto enomem; } dbus_message_iter_next (&variter); (*properties)->colour = colour; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); (*properties)->size = size; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } if (property_count < 2) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } static DBusHandlerResult my_com_netsplit_Nih_Foo_NewResult_signal (DBusConnection * connection, DBusMessage * signal, NihDBusProxySignal *proxied) { DBusMessageIter iter; NihDBusMessage *message; nih_assert (connection != NULL); nih_assert (signal != NULL); nih_assert (proxied != NULL); nih_assert (connection == proxied->proxy->connection); if (! dbus_message_is_signal (signal, proxied->interface->name, proxied->signal->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (signal, proxied->proxy->path)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (proxied->proxy->name) if (! dbus_message_has_sender (signal, proxied->proxy->owner)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; message = nih_dbus_message_new (NULL, connection, signal); if (! message) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Iterate the arguments to the signal and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /* Call the handler function */ nih_error_push_context (); ((MyFooNewResultHandler)proxied->handler) (proxied->data, message); nih_error_pop_context (); nih_free (message); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_output_proxy_no_interfaces.c0000644000175000017500000000125411445765555024256 00000000000000/* test * * test.c - auto-generated D-Bus bindings * * Copyright (C) 2009 Joe Bloggs. * * This file was automatically generated; see the source for copying * conditions. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "test.h" const NihDBusInterface *my_interfaces[] = { NULL }; libnih-1.0.3/nih-dbus-tool/tests/expected/test_node_proxy_functions_no_signals.c0000644000175000017500000021324111445765555025251 00000000000000DBusPendingCall * my_test_poke (NihDBusProxy * proxy, uint32_t address, const char * value, MyTestPokeReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Poke"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_Poke_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_Poke_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestPokeReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_poke_sync (const void * parent, NihDBusProxy *proxy, uint32_t address, const char * value) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Poke"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_peek (NihDBusProxy * proxy, uint32_t address, MyTestPeekReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Peek"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_Peek_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_Peek_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; char * value; const char * value_dbus; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&iter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestPeekReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_peek_sync (const void * parent, NihDBusProxy *proxy, uint32_t address, char ** value) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; char * value_local; const char * value_local_dbus; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Peek"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); do { __label__ enomem; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&iter, &value_local_dbus); value_local = nih_strdup (parent, value_local_dbus); if (! value_local) { *value = NULL; goto enomem; } dbus_message_iter_next (&iter); *value = value_local; enomem: __attribute__ ((unused)); } while (! *value); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (value_local); *value = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_is_valid_address (NihDBusProxy * proxy, uint32_t address, MyTestIsValidAddressReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "IsValidAddress"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_IsValidAddress_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_IsValidAddress_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestIsValidAddressReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_is_valid_address_sync (const void * parent, NihDBusProxy *proxy, uint32_t address) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "IsValidAddress"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Marshal a uint32_t onto the message */ if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &address)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_get_colour (NihDBusProxy * proxy, MyTestGetColourReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_colour_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_colour_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; const char * value_dbus; char * value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &value_dbus); value = nih_strdup (message, value_dbus); if (! value) { nih_free (message); message = NULL; goto enomem; } dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyTestGetColourReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_colour_sync (const void * parent, NihDBusProxy *proxy, char ** value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; const char * local_dbus; char * local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &local_dbus); local = nih_strdup (parent, local_dbus); if (! local) { *value = NULL; goto enomem; } dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_set_colour (NihDBusProxy * proxy, const char * value, MyTestSetColourReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_colour_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_colour_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestSetColourReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_set_colour_sync (const void * parent, NihDBusProxy *proxy, const char * value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "colour"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "s", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a char * onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_get_size (NihDBusProxy * proxy, MyTestGetSizeReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "size"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_size_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_size_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter variter; NihDBusMessage *message; DBusError error; uint32_t value; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&iter, &variter); /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &value); dbus_message_iter_next (&variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ nih_error_push_context (); ((MyTestGetSizeReply)pending_data->handler) (pending_data->data, message, value); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_size_sync (const void * parent, NihDBusProxy *proxy, uint32_t * value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; uint32_t local; nih_assert (proxy != NULL); nih_assert (value != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "size"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the variant */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&iter, &variter); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } do { __label__ enomem; /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &local); dbus_message_iter_next (&variter); *value = local; enomem: __attribute__ ((unused)); } while (! *value); dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_set_touch (NihDBusProxy * proxy, int value, MyTestSetTouchReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "touch"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "b", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_BOOLEAN, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_touch_set_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_touch_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and check * there are no arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyTestSetTouchReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_test_set_touch_sync (const void * parent, NihDBusProxy *proxy, int value) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter variter; DBusError error; DBusMessage * reply; const char * interface; const char * property; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Set"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } property = "touch"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "b", &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Marshal a int onto the message */ if (! dbus_message_iter_append_basic (&variter, DBUS_TYPE_BOOLEAN, &value)) { dbus_message_iter_abandon_container (&iter, &variter); dbus_message_unref (method_call); nih_return_no_memory_error (-1); } if (! dbus_message_iter_close_container (&iter, &variter)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } /* Check the reply has no arguments */ dbus_message_unref (method_call); dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_test_get_all (NihDBusProxy * proxy, MyTestGetAllReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_get_all_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Test_get_all_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; NihDBusMessage * message; DBusError error; const char * property; MyTestProperties *properties; size_t property_count; char * colour; const char * colour_dbus; uint32_t size; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); /* Create a message context for the reply, and iterate * over and recurse into the arguments. */ message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } properties = NIH_MUST (nih_new (message, MyTestProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "colour")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &colour_dbus); colour = nih_strdup (properties, colour_dbus); if (! colour) { goto enomem; } dbus_message_iter_next (&variter); properties->colour = colour; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); properties->size = size; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } if (property_count < 2) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } /* Call the handler function */ nih_error_push_context (); ((MyTestGetAllReply)pending_data->handler) (pending_data->data, message, properties); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); } int my_test_get_all_sync (const void * parent, NihDBusProxy * proxy, MyTestProperties **properties) { DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; DBusError error; DBusMessage * reply; size_t property_count; const char * interface; const char * property; char * colour; const char * colour_dbus; uint32_t size; nih_assert (proxy != NULL); nih_assert (properties != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "GetAll"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (-1); } /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the method arguments, recursing into the array */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } *properties = NIH_MUST (nih_new (parent, MyTestProperties)); property_count = 0; dbus_message_iter_recurse (&iter, &arrayiter); while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) { __label__ enomem; if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&arrayiter, &dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&dictiter, &property); dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_recurse (&dictiter, &variter); if (! strcmp (property, "colour")) { /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &colour_dbus); colour = nih_strdup (*properties, colour_dbus); if (! colour) { goto enomem; } dbus_message_iter_next (&variter); (*properties)->colour = colour; nih_assert (++property_count); } if (! strcmp (property, "size")) { /* Demarshal a uint32_t from the message */ if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_get_basic (&variter, &size); dbus_message_iter_next (&variter); (*properties)->size = size; nih_assert (++property_count); } dbus_message_iter_next (&dictiter); if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_iter_next (&arrayiter); enomem: __attribute__ ((unused)); } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } if (property_count < 2) { nih_free (*properties); *properties = NULL; dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } DBusPendingCall * my_foo_bing (NihDBusProxy * proxy, MyFooBingReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; nih_assert (proxy != NULL); nih_assert ((handler == NULL) || (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Foo", "Bing"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Handle a fire-and-forget message */ if (! error_handler) { dbus_message_set_no_reply (method_call, TRUE); if (! dbus_connection_send (proxy->connection, method_call, NULL)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); return (DBusPendingCall *)TRUE; } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Foo_Bing_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } static void my_com_netsplit_Nih_Foo_Bing_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { DBusMessage * reply; DBusMessageIter iter; NihDBusMessage *message; DBusError error; nih_assert (pending_call != NULL); nih_assert (pending_data != NULL); nih_assert (dbus_pending_call_get_completed (pending_call)); /* Steal the reply from the pending call. */ reply = dbus_pending_call_steal_reply (pending_call); nih_assert (reply != NULL); /* Handle error replies */ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply)); dbus_error_init (&error); dbus_set_error_from_message (&error, message->message); nih_error_push_context (); nih_dbus_error_raise (error.name, error.message); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); dbus_error_free (&error); nih_free (message); dbus_message_unref (reply); return; } nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN); do { __label__ enomem; /* Create a message context for the reply, and iterate * over its arguments. */ message = nih_dbus_message_new (pending_data, pending_data->connection, reply); if (! message) goto enomem; dbus_message_iter_init (message->message, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { nih_error_push_context (); nih_error_raise (NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); pending_data->error_handler (pending_data->data, message); nih_error_pop_context (); nih_free (message); dbus_message_unref (reply); return; } enomem: __attribute__ ((unused)); } while (! message); /* Call the handler function */ if (pending_data->handler) { nih_error_push_context (); ((MyFooBingReply)pending_data->handler) (pending_data->data, message); nih_error_pop_context (); } nih_free (message); dbus_message_unref (reply); } int my_foo_bing_sync (const void * parent, NihDBusProxy *proxy) { DBusMessage * method_call; DBusMessageIter iter; DBusError error; DBusMessage * reply; nih_assert (proxy != NULL); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Foo", "Bing"); if (! method_call) nih_return_no_memory_error (-1); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); /* Send the message, and wait for the reply. */ dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error); if (! reply) { dbus_message_unref (method_call); if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return -1; } dbus_message_unref (method_call); /* Iterate the arguments of the reply */ dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { dbus_message_unref (reply); nih_return_error (-1, NIH_DBUS_INVALID_ARGS, _(NIH_DBUS_INVALID_ARGS_STR)); } dbus_message_unref (reply); return 0; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_object_function_async.c0000644000175000017500000000650411445765555024471 00000000000000DBusHandlerResult my_com_netsplit_Nih_Test_AsyncMethod_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; char * str; const char * str_dbus; int32_t flags; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to AsyncMethod method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &str_dbus); str = nih_strdup (message, str_dbus); if (! str) { return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&iter); /* Demarshal a int32_t from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to AsyncMethod method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &flags); dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to AsyncMethod method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_async_method (object->data, message, str, flags) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); return DBUS_HANDLER_RESULT_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_property_proxy_get_function_standard.c0000644000175000017500000000450111445765555026325 00000000000000DBusPendingCall * my_get_test_property (NihDBusProxy * proxy, MyGetTestPropertyReply handler, NihDBusErrorHandler error_handler, void * data, int timeout) { DBusMessage * method_call; DBusMessageIter iter; DBusPendingCall * pending_call; NihDBusPendingData *pending_data; const char * interface; const char * property; nih_assert (proxy != NULL); nih_assert ((handler != NULL) && (error_handler != NULL)); /* Construct the method call message. */ method_call = dbus_message_new_method_call (proxy->name, proxy->path, "org.freedesktop.DBus.Properties", "Get"); if (! method_call) nih_return_no_memory_error (NULL); dbus_message_set_auto_start (method_call, proxy->auto_start); dbus_message_iter_init_append (method_call, &iter); interface = "com.netsplit.Nih.Test"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } property = "test_property"; if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property)) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } /* Send the message and set up the reply notification. */ pending_data = nih_dbus_pending_data_new (NULL, proxy->connection, (NihDBusReplyHandler)handler, error_handler, data); if (! pending_data) { dbus_message_unref (method_call); nih_return_no_memory_error (NULL); } pending_call = NULL; if (! dbus_connection_send_with_reply (proxy->connection, method_call, &pending_call, timeout)) { dbus_message_unref (method_call); nih_free (pending_data); nih_return_no_memory_error (NULL); } dbus_message_unref (method_call); if (! pending_call) { nih_dbus_error_raise (DBUS_ERROR_DISCONNECTED, "Connection is closed"); nih_free (pending_data); return NULL; } NIH_MUST (dbus_pending_call_set_notify (pending_call, (DBusPendingCallNotifyFunction)my_com_netsplit_Nih_Test_test_property_get_notify, pending_data, (DBusFreeFunction)nih_discard)); return pending_call; } libnih-1.0.3/nih-dbus-tool/tests/expected/test_method_object_function_deprecated.c0000644000175000017500000000641311445765555025453 00000000000000DBusHandlerResult my_com_netsplit_Nih_Test_Method_method (NihDBusObject * object, NihDBusMessage *message) { DBusMessageIter iter; DBusMessage * reply; char * str; const char * str_dbus; nih_assert (object != NULL); nih_assert (message != NULL); /* Iterate the arguments to the message and demarshal into arguments * for our own function call. */ dbus_message_iter_init (message->message, &iter); /* Demarshal a char * from the message */ if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_get_basic (&iter, &str_dbus); str = nih_strdup (message, str_dbus); if (! str) { return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_iter_next (&iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) { reply = dbus_message_new_error (message->message, DBUS_ERROR_INVALID_ARGS, "Invalid arguments to Method method"); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (message->connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /* Call the handler function */ nih_error_push_context (); if (my_method (object->data, message, str) < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error (message->message, dbus_err->name, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } else { reply = NIH_MUST (dbus_message_new_error (message->message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } nih_error_pop_context (); /* If the sender doesn't care about a reply, don't bother wasting * effort constructing and sending one. */ if (dbus_message_get_no_reply (message->message)) return DBUS_HANDLER_RESULT_HANDLED; do { __label__ enomem; /* Construct the reply message. */ reply = dbus_message_new_method_return (message->message); if (! reply) goto enomem; dbus_message_iter_init_append (reply, &iter); enomem: __attribute__ ((unused)); } while (! reply); /* Send the reply, appending it to the outgoing queue. */ NIH_MUST (dbus_connection_send (message->connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } libnih-1.0.3/nih-dbus-tool/tests/property_code.h0000644000175000017500000000555611445765555016612 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_TESTS_PROPERTY_CODE_H #define NIH_DBUS_TOOL_TESTS_PROPERTY_CODE_H #include #include #include #include #include #include typedef void (*MyGetPropertyReply) (void *data, NihDBusMessage *message, const char *value); typedef void (*MySetPropertyReply) (void *data, NihDBusMessage *message); typedef void (*MyGetTestPropertyReply) (void *data, NihDBusMessage *message, const char *value); typedef void (*MySetTestPropertyReply) (void *data, NihDBusMessage *message); NIH_BEGIN_EXTERN int my_com_netsplit_Nih_Test_property_get (NihDBusObject *object, NihDBusMessage *message, DBusMessageIter *iter) __attribute__ ((warn_unused_result)); int my_com_netsplit_Nih_Test_property_set (NihDBusObject *object, NihDBusMessage *message, DBusMessageIter *iter) __attribute__ ((warn_unused_result)); DBusPendingCall *my_get_test_property (NihDBusProxy *proxy, MyGetTestPropertyReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); void my_com_netsplit_Nih_Test_property_get_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); DBusPendingCall *my_set_test_property (NihDBusProxy *proxy, const char *value, MySetTestPropertyReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); void my_com_netsplit_Nih_Test_property_set_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); int my_get_property_sync (const void *parent, NihDBusProxy *proxy, char **value) __attribute__ ((warn_unused_result)); int my_set_property_sync (const void *parent, NihDBusProxy *proxy, const char *value) __attribute__ ((warn_unused_result)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_TESTS_PROPERTY_CODE_H */ libnih-1.0.3/nih-dbus-tool/tests/test_output.c0000644000175000017500000003255411445765555016324 00000000000000/* nih-dbus-tool * * test_output.c - test suite for nih-dbus-tool/output.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include "method.h" #include "signal.h" #include "property.h" #include "node.h" #include "output.h" void test_output (void) { FILE * source; FILE * header; Node * node = NULL; Interface * interface = NULL; Method * method = NULL; Signal * signal = NULL; Argument * argument = NULL; Property * property = NULL; int ret; NihError * err; TEST_FUNCTION ("output"); source = tmpfile (); header = tmpfile (); /* Check that we can generate a valid source file and accompanying * header file for a node in proxy mode. */ TEST_FEATURE ("with proxy"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); argument = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); argument->symbol = "height"; nih_list_add (&signal->arguments, &argument->entry); argument = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); argument->symbol = "velocity"; nih_list_add (&signal->arguments, &argument->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Bing"); method->symbol = "bing"; nih_list_add (&interface->methods, &method->entry); signal = signal_new (interface, "NewResult"); signal->symbol = "new_result"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "preferences", "(us)", NIH_DBUS_READWRITE); property->symbol = "preferences"; nih_list_add (&interface->properties, &property->entry); } ret = output ("test.c", fileno (source), "test.h", fileno (header), "my", node, FALSE); rewind (source); rewind (header); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (source); TEST_FILE_RESET (header); nih_free (node); continue; } TEST_EQ (ret, 0); TEST_EXPECTED_FILE (source, "test_output_proxy_standard.c"); TEST_EXPECTED_FILE (header, "test_output_proxy_standard.h"); nih_free (node); } /* Check that when there are no interfaces, a valid empty source * and header file are generated. */ TEST_FEATURE ("with proxy but no interfaces"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); } ret = output ("test.c", fileno (source), "test.h", fileno (header), "my", node, FALSE); rewind (source); rewind (header); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (source); TEST_FILE_RESET (header); nih_free (node); continue; } TEST_EQ (ret, 0); TEST_EXPECTED_FILE (source, "test_output_proxy_no_interfaces.c"); TEST_EXPECTED_FILE (header, "test_output_proxy_no_interfaces.h"); nih_free (node); } /* Check that we can generate a valid source file and accompanying * header file for a node in object mode. */ TEST_FEATURE ("with object"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; method->async = TRUE; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "is_valid", "b", NIH_DBUS_ARG_OUT); argument->symbol = "is_valid"; nih_list_add (&method->arguments, &argument->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); argument = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); argument->symbol = "height"; nih_list_add (&signal->arguments, &argument->entry); argument = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); argument->symbol = "velocity"; nih_list_add (&signal->arguments, &argument->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Bing"); method->symbol = "bing"; nih_list_add (&interface->methods, &method->entry); signal = signal_new (interface, "NewResult"); signal->symbol = "new_result"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "preferences", "(us)", NIH_DBUS_READWRITE); property->symbol = "preferences"; nih_list_add (&interface->properties, &property->entry); } ret = output ("test.c", fileno (source), "test.h", fileno (header), "my", node, TRUE); rewind (source); rewind (header); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (source); TEST_FILE_RESET (header); nih_free (node); continue; } TEST_EQ (ret, 0); TEST_EXPECTED_FILE (source, "test_output_object_standard.c"); TEST_EXPECTED_FILE (header, "test_output_object_standard.h"); nih_free (node); } /* Check that when there are no interfaces, a valid empty source * and header file are generated. */ TEST_FEATURE ("with object but no interfaces"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); } ret = output ("test.c", fileno (source), "test.h", fileno (header), "my", node, TRUE); rewind (source); rewind (header); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (source); TEST_FILE_RESET (header); nih_free (node); continue; } TEST_EQ (ret, 0); TEST_EXPECTED_FILE (source, "test_output_object_no_interfaces.c"); TEST_EXPECTED_FILE (header, "test_output_object_no_interfaces.h"); nih_free (node); } fclose (source); fclose (header); } void test_preamble (void) { char *str; TEST_FUNCTION ("output_preamble"); /* Check that a preamble for a source file is correctly generated, * with the package name, source file path and copyright all * present. */ TEST_FEATURE ("with path"); TEST_ALLOC_FAIL { str = output_preamble (NULL, "path.c"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, ("/* test\n" " *\n" " * path.c - auto-generated D-Bus bindings\n" " *\n" " * Copyright (C) 2009 Joe Bloggs.\n" " *\n" " * This file was automatically generated; see the source for copying\n" " * conditions.\n" " */\n" "\n")); nih_free (str); } /* Check that a preamble for a header file (NULL path) is correctly * generated with the package name and copyright present. */ TEST_FEATURE ("with no path"); TEST_ALLOC_FAIL { str = output_preamble (NULL, NULL); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, ("/* test\n" " *\n" " * Copyright (C) 2009 Joe Bloggs.\n" " *\n" " * This file was automatically generated; see the source for copying\n" " * conditions.\n" " */\n" "\n")); nih_free (str); } } void test_sentinel (void) { char *str; TEST_FUNCTION ("output_sentinel"); /* Check that a header file sentinel is correctly generated for a * local path. */ TEST_FEATURE ("with local path"); TEST_ALLOC_FAIL { str = output_sentinel (NULL, "foo.h"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "TEST_FOO_H"); nih_free (str); } /* Check that a header file sentinel is correctly generated for a * sub-directory path. */ TEST_FEATURE ("with sub-directory path"); TEST_ALLOC_FAIL { str = output_sentinel (NULL, "path/to/foo.h"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "TEST_PATH_TO_FOO_H"); nih_free (str); } /* Check that a header file sentinel is generated for an absolute * path; we might want to change the format of this later, but it's * ok for now. */ TEST_FEATURE ("with absolute path"); TEST_ALLOC_FAIL { str = output_sentinel (NULL, "/path/to/foo.h"); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, "TEST__PATH_TO_FOO_H"); nih_free (str); } } int main (int argc, char *argv[]) { package_name = "test"; package_copyright = "Copyright (C) 2009 Joe Bloggs."; program_name = "test"; nih_error_init (); test_output (); test_preamble (); test_sentinel (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/signal_code.h0000644000175000017500000000267711445765555016204 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_TESTS_SIGNAL_CODE_H #define NIH_DBUS_TOOL_TESTS_SIGNAL_CODE_H #include #include #include #include typedef void (*MySignalHandler) (void *data, NihDBusMessage *message, const char *msg); NIH_BEGIN_EXTERN int my_emit_signal (DBusConnection *connection, const char *origin_path, const char *msg) __attribute__ ((warn_unused_result)); DBusHandlerResult my_com_netsplit_Nih_Test_Signal_signal (DBusConnection *connection, DBusMessage *signal, NihDBusProxySignal *proxied); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_TESTS_SIGNAL_CODE_H */ libnih-1.0.3/nih-dbus-tool/tests/test_interface.c0000644000175000017500000056430611445765555016731 00000000000000/* nih-dbus-tool * * test_interface.c - test suite for nih-dbus-tool/interface.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "type.h" #include "node.h" #include "interface.h" #include "method.h" #include "signal.h" #include "property.h" #include "parse.h" #include "errors.h" #include "tests/interface_code.h" void test_name_valid (void) { TEST_FUNCTION ("interface_name_valid"); /* Check that a typical interface name is valid. */ TEST_FEATURE ("with typical interface name"); TEST_TRUE (interface_name_valid ("com.netsplit.Nih.Test")); /* Check that an interface name is not valid if it is has an * initial period. */ TEST_FEATURE ("with initial period"); TEST_FALSE (interface_name_valid (".com.netsplit.Nih.Test")); /* Check that an interface name is not valid if it has multiple * consecutive periods. */ TEST_FEATURE ("with consecutive periods"); TEST_FALSE (interface_name_valid ("com..netsplit.Nih.Test")); /* Check that an interface name is not valid if it ends in a period */ TEST_FEATURE ("with final period"); TEST_FALSE (interface_name_valid ("com.netsplit.Nih.Test.")); /* Check that an interface name is not valid if it only has one * component */ TEST_FEATURE ("with only one component"); TEST_FALSE (interface_name_valid ("com")); /* Check that an interface name is valid if it has two components. */ TEST_FEATURE ("with two components"); TEST_TRUE (interface_name_valid ("com.netsplit")); /* Check that a interface name elements may contain numbers */ TEST_FEATURE ("with numbers in interface name"); TEST_TRUE (interface_name_valid ("com.netsplit.a43b.Test")); /* Check that a interface name elements may not begin with numbers */ TEST_FEATURE ("with numbers starting interface name element"); TEST_FALSE (interface_name_valid ("com.netsplit.43b.Test")); /* Check that the first interface name element may not begin * with numbers */ TEST_FEATURE ("with numbers starting first interface name element"); TEST_FALSE (interface_name_valid ("32com.netsplit.Nih.Test")); /* Check that a interface name elements may contain underscores */ TEST_FEATURE ("with underscore in interface name"); TEST_TRUE (interface_name_valid ("com.netsplit.Nih_Test")); /* Check that a interface name elements may begin with underscores */ TEST_FEATURE ("with underscore starting interface name element"); TEST_TRUE (interface_name_valid ("com.netsplit._Nih.Test")); /* Check that other characters are not permitted */ TEST_FEATURE ("with non-permitted characters"); TEST_FALSE (interface_name_valid ("com.netsplit/Nih.Test-Thing")); /* Check that an empty interface name is invalid */ TEST_FEATURE ("with empty string"); TEST_FALSE (interface_name_valid ("")); /* Check that an interface name may not exceed 255 characters */ TEST_FEATURE ("with overly long name"); TEST_FALSE (interface_name_valid ("com.netsplit.Nih.ReallyLongInt" "erfaceNameThatNobodyInTheirRig" "htMindWouldEverUseButStillWeNe" "edToTestThisKindOfShitSeriousl" "yLookHowLongThisIs.IMeanYoureJ" "ustNeverGoingToGetAnywhereNear" "ThisLimitInFactIfTheLimitIsThi" "sLongWhyHaveOneAtAllStupidSoft" "ware.YayThereNow")); } void test_new (void) { Interface *interface; /* Check that an Interface object is allocated with the structure * filled in properly, but not placed in a list. */ TEST_FUNCTION ("interface_new"); TEST_ALLOC_FAIL { interface = interface_new (NULL, "com.netsplit.Nih.Test"); if (test_alloc_failed) { TEST_EQ_P (interface, NULL); continue; } TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_LIST_EMPTY (&interface->entry); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_P (interface->symbol, NULL); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); nih_free (interface); } } void test_start_tag (void) { ParseContext context; ParseStack * parent = NULL; ParseStack * entry = NULL; XML_Parser xmlp; Node * node = NULL; Interface * interface; Method * method = NULL; char * attr[5]; int ret = 0; NihError * err; FILE * output; TEST_FUNCTION ("interface_start_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); output = tmpfile (); /* Check that an interface tag for an node with the usual name * attribute results in an Interface member being created and pushed * onto the stack with that attribute filled in correctly. */ TEST_FEATURE ("with interface"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, "/com/netsplit/Nih/Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); } attr[0] = "name"; attr[1] = "com.netsplit.Nih.Test"; attr[2] = NULL; ret = interface_start_tag (xmlp, "interface", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&node->interfaces); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_INTERFACE); interface = entry->interface; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, entry); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_P (interface->symbol, NULL); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); TEST_LIST_EMPTY (&node->interfaces); nih_free (entry); nih_free (parent); } /* Check that a interface with a missing name attribute results * in an error being raised. */ TEST_FEATURE ("with missing name"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, "/com/netsplit/Nih/Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); attr[0] = NULL; } ret = interface_start_tag (xmlp, "interface", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&node->interfaces); err = nih_error_get (); TEST_EQ (err->number, INTERFACE_MISSING_NAME); nih_free (err); nih_free (parent); } /* Check that a interface with an invalid name results in an * error being raised. */ TEST_FEATURE ("with invalid name"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, "/com/netsplit/Nih/Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); attr[0] = "name"; attr[1] = "Test Interface"; attr[2] = NULL; } ret = interface_start_tag (xmlp, "interface", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&node->interfaces); err = nih_error_get (); TEST_EQ (err->number, INTERFACE_INVALID_NAME); nih_free (err); nih_free (parent); } /* Check that an unknown interface attribute results in a warning * being printed to standard error, but is otherwise ignored * and the normal processing finished. */ TEST_FEATURE ("with unknown attribute"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, "/com/netsplit/Nih/Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); attr[0] = "name"; attr[1] = "com.netsplit.Nih.Test"; attr[2] = "frodo"; attr[3] = "baggins"; attr[4] = NULL; } TEST_DIVERT_STDERR (output) { ret = interface_start_tag (xmlp, "interface", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_INTERFACE); interface = entry->interface; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, entry); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_P (interface->symbol, NULL); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); TEST_LIST_EMPTY (&node->interfaces); TEST_FILE_EQ (output, ("test:foo:1:0: Ignored unknown attribute: " "frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } /* Check that a interface on an empty stack (ie. a top-level * interface element) results in a warning being printed on * standard error and an ignored element being pushed onto the * stack. */ TEST_FEATURE ("with empty stack"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { attr[0] = "name"; attr[1] = "com.netsplit.Nih.Test"; attr[2] = NULL; } TEST_DIVERT_STDERR (output) { ret = interface_start_tag (xmlp, "interface", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), NULL); TEST_FILE_RESET (output); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unexpected tag\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); } /* Check that a interface on top of a stack entry that's not an * node results in a warning being printed on * standard error and an ignored element being pushed onto the * stack. */ TEST_FEATURE ("with non-node on stack"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); attr[0] = "name"; attr[1] = "com.netsplit.Nih.Test"; attr[2] = NULL; } TEST_DIVERT_STDERR (output) { ret = interface_start_tag (xmlp, "interface", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unexpected tag\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } XML_ParserFree (xmlp); fclose (output); } void test_end_tag (void) { ParseContext context; ParseStack * parent = NULL; ParseStack * entry = NULL; XML_Parser xmlp; Node * node = NULL; Interface * interface = NULL; Interface * other = NULL; int ret; NihError * err; TEST_FUNCTION ("interface_end_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); /* Check that when we parse the end tag for a interface, we pop * the Interface object off the stack (freeing and removing it) * and append it to the parent node's interfaces list, adding a * reference to the node as well. A symbol should be generated * for the interface by taking the last part of the Interface * name and convering it to C style. */ TEST_FEATURE ("with no assigned symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, "/com/netsplit/Nih/Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); interface = interface_new (NULL, "com.netsplit.Nih.TestInterface"); entry = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } TEST_FREE_TAG (entry); ret = interface_end_tag (xmlp, "interface"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&node->interfaces); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (interface, node); TEST_LIST_NOT_EMPTY (&node->interfaces); TEST_EQ_P (node->interfaces.next, &interface->entry); TEST_EQ_STR (interface->symbol, "test_interface"); TEST_ALLOC_PARENT (interface->symbol, interface); nih_free (parent); } /* Check that when the symbol has been pre-assigned by the data, * it's not overriden and is used even if different. */ TEST_FEATURE ("with assigned symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, "/com/netsplit/Nih/Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = nih_strdup (interface, "foo"); entry = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } TEST_FREE_TAG (entry); ret = interface_end_tag (xmlp, "interface"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&node->interfaces); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (interface, node); TEST_LIST_NOT_EMPTY (&node->interfaces); TEST_EQ_P (node->interfaces.next, &interface->entry); TEST_EQ_STR (interface->symbol, "foo"); TEST_ALLOC_PARENT (interface->symbol, interface); nih_free (parent); } /* Check that we don't generate a duplicate symbol, and instead * raise an error and allow the user to deal with it using * the Symbol annotation. The reason we don't work around this * with a counter or similar is that the function names then * become unpredictable (introspection data isn't ordered). */ TEST_FEATURE ("with conflicting symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, "/com/netsplit/Nih/Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); other = interface_new (node, "com.netsplit.Foo.Test"); other->symbol = nih_strdup (other, "test"); nih_list_add (&node->interfaces, &other->entry); interface = interface_new (NULL, "com.netsplit.Nih.Test"); entry = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } ret = interface_end_tag (xmlp, "interface"); TEST_LT (ret, 0); err = nih_error_get (); if ((! test_alloc_failed) || (err->number != ENOMEM)) TEST_EQ (err->number, INTERFACE_DUPLICATE_SYMBOL); nih_free (err); nih_free (entry); nih_free (parent); } XML_ParserFree (xmlp); } void test_annotation (void) { Interface *interface = NULL; char * symbol; int ret; NihError * err; TEST_FUNCTION ("interface_annotation"); /* Check that the annotation to mark a interface as deprecated is * handled, and the Interface is marked deprecated. */ TEST_FEATURE ("with deprecated annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); } ret = interface_annotation (interface, "org.freedesktop.DBus.Deprecated", "true"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_FALSE (interface->deprecated); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (interface); continue; } TEST_EQ (ret, 0); TEST_TRUE (interface->deprecated); nih_free (interface); } /* Check that the annotation to mark a interface as deprecated can be * given a false value to explicitly mark the Interface non-deprecated. */ TEST_FEATURE ("with explicitly non-deprecated annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->deprecated = TRUE; } ret = interface_annotation (interface, "org.freedesktop.DBus.Deprecated", "false"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_TRUE (interface->deprecated); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (interface); continue; } TEST_EQ (ret, 0); TEST_FALSE (interface->deprecated); nih_free (interface); } /* Check that an annotation to add a symbol to the interface is * handled, and the new symbol is stored in the interface. */ TEST_FEATURE ("with symbol annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); } ret = interface_annotation (interface, "com.netsplit.Nih.Symbol", "foo"); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (interface); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (interface->symbol, "foo"); TEST_ALLOC_PARENT (interface->symbol, interface); nih_free (interface); } /* Check that an annotation to add a symbol to the interface * replaces any previous symbol applied (e.g. by a previous * annotation). */ TEST_FEATURE ("with symbol annotation and existing symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = nih_strdup (interface, "test_arg"); } symbol = interface->symbol; TEST_FREE_TAG (symbol); ret = interface_annotation (interface, "com.netsplit.Nih.Symbol", "foo"); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (interface); continue; } TEST_EQ (ret, 0); TEST_FREE (symbol); TEST_EQ_STR (interface->symbol, "foo"); TEST_ALLOC_PARENT (interface->symbol, interface); nih_free (interface); } /* Check that an invalid value for the deprecated annotation results * in an error being raised. */ TEST_FEATURE ("with invalid value for deprecated annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); } ret = interface_annotation (interface, "org.freedesktop.DBus.Deprecated", "foo"); TEST_LT (ret, 0); TEST_EQ_P (interface->symbol, NULL); err = nih_error_get (); TEST_EQ (err->number, INTERFACE_ILLEGAL_DEPRECATED); nih_free (err); nih_free (interface); } /* Check that an invalid symbol in an annotation results in an * error being raised. */ TEST_FEATURE ("with invalid symbol in annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); } ret = interface_annotation (interface, "com.netsplit.Nih.Symbol", "foo bar"); TEST_LT (ret, 0); TEST_EQ_P (interface->symbol, NULL); err = nih_error_get (); TEST_EQ (err->number, INTERFACE_INVALID_SYMBOL); nih_free (err); nih_free (interface); } /* Check that an unknown annotation results in an error being * raised. */ TEST_FEATURE ("with unknown annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); } ret = interface_annotation (interface, "com.netsplit.Nih.Unknown", "true"); TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, INTERFACE_UNKNOWN_ANNOTATION); nih_free (err); nih_free (interface); } } void test_methods_array (void) { NihList prototypes; Interface *interface = NULL; Method * method = NULL; Argument * arg = NULL; char * str; TypeVar * var; TEST_FUNCTION ("interface_methods_array"); /* Check that we can generate an array of interface methods with * their handler functions. The C code returned should be lined up * nicely and include the argument variable definitions as well. */ TEST_FEATURE ("with handlers"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); } str = interface_methods_array (NULL, "my", interface, TRUE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "static const NihDBusArg my_com_netsplit_Nih_Test_Poke_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ \"value\", \"s\", NIH_DBUS_ARG_IN },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Peek_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ \"value\", \"s\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_IsValidAddress_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ NULL }\n" "};\n" "\n" "const NihDBusMethod my_com_netsplit_Nih_Test_methods[] = {\n" "\t{ \"Poke\", my_com_netsplit_Nih_Test_Poke_method_args, my_com_netsplit_Nih_Test_Poke_method },\n" "\t{ \"Peek\", my_com_netsplit_Nih_Test_Peek_method_args, my_com_netsplit_Nih_Test_Peek_method },\n" "\t{ \"IsValidAddress\", my_com_netsplit_Nih_Test_IsValidAddress_method_args, my_com_netsplit_Nih_Test_IsValidAddress_method },\n" "\t{ NULL }\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusMethod"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test_methods"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } /* Check that we can generate an array of interface methods without * their handler functions. The C code returned should be lined up * nicely, but should include NULL in the place of the handler * function. */ TEST_FEATURE ("without handlers"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); } str = interface_methods_array (NULL, "my", interface, FALSE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "static const NihDBusArg my_com_netsplit_Nih_Test_Poke_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ \"value\", \"s\", NIH_DBUS_ARG_IN },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Peek_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ \"value\", \"s\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_IsValidAddress_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ NULL }\n" "};\n" "\n" "const NihDBusMethod my_com_netsplit_Nih_Test_methods[] = {\n" "\t{ \"Poke\", my_com_netsplit_Nih_Test_Poke_method_args, NULL },\n" "\t{ \"Peek\", my_com_netsplit_Nih_Test_Peek_method_args, NULL },\n" "\t{ \"IsValidAddress\", my_com_netsplit_Nih_Test_IsValidAddress_method_args, NULL },\n" "\t{ NULL }\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusMethod"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test_methods"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } /* Check that the array is returned empty if the interface has * no methods. */ TEST_FEATURE ("with no methods"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; } str = interface_methods_array (NULL, "my", interface, FALSE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "const NihDBusMethod my_com_netsplit_Nih_Test_methods[] = {\n" "\t{ NULL }\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusMethod"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test_methods"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } } void test_signals_array (void) { NihList prototypes; Interface *interface = NULL; Signal * signal = NULL; Argument * arg = NULL; char * str; TypeVar * var; TEST_FUNCTION ("interface_signals_array"); /* Check that we can generate an array of interface signals with * their filter functions. The C code returned should be lined up * nicely and include the argument variable definitions as well. */ TEST_FEATURE ("with filters"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); arg = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); arg->symbol = "height"; nih_list_add (&signal->arguments, &arg->entry); arg = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); arg->symbol = "velocity"; nih_list_add (&signal->arguments, &arg->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); } str = interface_signals_array (NULL, "my", interface, TRUE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "static const NihDBusArg my_com_netsplit_Nih_Test_Bounce_signal_args[] = {\n" "\t{ \"height\", \"u\", NIH_DBUS_ARG_OUT },\n" "\t{ \"velocity\", \"i\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Exploded_signal_args[] = {\n" "\t{ NULL }\n" "};\n" "\n" "const NihDBusSignal my_com_netsplit_Nih_Test_signals[] = {\n" "\t{ \"Bounce\", my_com_netsplit_Nih_Test_Bounce_signal_args, my_com_netsplit_Nih_Test_Bounce_signal },\n" "\t{ \"Exploded\", my_com_netsplit_Nih_Test_Exploded_signal_args, my_com_netsplit_Nih_Test_Exploded_signal },\n" "\t{ NULL }\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusSignal"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test_signals"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } /* Check that we can generate an array of interface signals without * their filter functions. The C code returned should be lined up * nicely, but should include NULL in the place of the filter * function. */ TEST_FEATURE ("without filters"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); arg = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); arg->symbol = "height"; nih_list_add (&signal->arguments, &arg->entry); arg = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); arg->symbol = "velocity"; nih_list_add (&signal->arguments, &arg->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); } str = interface_signals_array (NULL, "my", interface, FALSE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "static const NihDBusArg my_com_netsplit_Nih_Test_Bounce_signal_args[] = {\n" "\t{ \"height\", \"u\", NIH_DBUS_ARG_OUT },\n" "\t{ \"velocity\", \"i\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Exploded_signal_args[] = {\n" "\t{ NULL }\n" "};\n" "\n" "const NihDBusSignal my_com_netsplit_Nih_Test_signals[] = {\n" "\t{ \"Bounce\", my_com_netsplit_Nih_Test_Bounce_signal_args, NULL },\n" "\t{ \"Exploded\", my_com_netsplit_Nih_Test_Exploded_signal_args, NULL },\n" "\t{ NULL }\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusSignal"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test_signals"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } /* Check that the array is returned empty if the interface has * no signals. */ TEST_FEATURE ("with no signals"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; } str = interface_signals_array (NULL, "my", interface, FALSE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "const NihDBusSignal my_com_netsplit_Nih_Test_signals[] = {\n" "\t{ NULL }\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusSignal"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test_signals"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } } void test_properties_array (void) { NihList prototypes; Interface *interface = NULL; Property * property = NULL; char * str; TypeVar * var; TEST_FUNCTION ("interface_properties_array"); /* Check that we can create an array of an interface's properties, * with getter and setter functions filled in where appropriate. * Each of the columns should be lined up nicely. */ TEST_FEATURE ("with handler functions"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); } str = interface_properties_array (NULL, "my", interface, TRUE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "const NihDBusProperty my_com_netsplit_Nih_Test_properties[] = {\n" "\t{ \"colour\", \"s\", NIH_DBUS_READWRITE, my_com_netsplit_Nih_Test_colour_get, my_com_netsplit_Nih_Test_colour_set },\n" "\t{ \"size\", \"u\", NIH_DBUS_READ, my_com_netsplit_Nih_Test_size_get, NULL },\n" "\t{ \"touch\", \"b\", NIH_DBUS_WRITE, NULL, my_com_netsplit_Nih_Test_touch_set },\n" "\t{ NULL }\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusProperty"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test_properties"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } /* Check that we can create an array of an interface's properties * without getter and setter functions filled in. Each of the * columns should still be lined up. */ TEST_FEATURE ("without handler functions"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); } str = interface_properties_array (NULL, "my", interface, FALSE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "const NihDBusProperty my_com_netsplit_Nih_Test_properties[] = {\n" "\t{ \"colour\", \"s\", NIH_DBUS_READWRITE, NULL, NULL },\n" "\t{ \"size\", \"u\", NIH_DBUS_READ, NULL, NULL },\n" "\t{ \"touch\", \"b\", NIH_DBUS_WRITE, NULL, NULL },\n" "\t{ NULL }\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusProperty"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test_properties"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } /* Check that we return an empty array when the interface has no * properties. */ TEST_FEATURE ("with no properties"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; } str = interface_properties_array (NULL, "my", interface, FALSE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "const NihDBusProperty my_com_netsplit_Nih_Test_properties[] = {\n" "\t{ NULL }\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusProperty"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test_properties"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } } void test_struct (void) { NihList prototypes; Interface *interface = NULL; Method * method = NULL; Signal * signal = NULL; Argument * arg = NULL; Property * property = NULL; char * str; TypeVar * var; TEST_FUNCTION ("interface_struct"); /* Check that we can generate the structure variable code for an * interface with many methods, signals and properties. We want * the members set up for an object implementation, so the method * and property function pointers should be set and not the signal * filter pointer. */ TEST_FEATURE ("with object"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); arg = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); arg->symbol = "height"; nih_list_add (&signal->arguments, &arg->entry); arg = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); arg->symbol = "velocity"; nih_list_add (&signal->arguments, &arg->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); } str = interface_struct (NULL, "my", interface, TRUE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "static const NihDBusArg my_com_netsplit_Nih_Test_Poke_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ \"value\", \"s\", NIH_DBUS_ARG_IN },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Peek_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ \"value\", \"s\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_IsValidAddress_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusMethod my_com_netsplit_Nih_Test_methods[] = {\n" "\t{ \"Poke\", my_com_netsplit_Nih_Test_Poke_method_args, my_com_netsplit_Nih_Test_Poke_method },\n" "\t{ \"Peek\", my_com_netsplit_Nih_Test_Peek_method_args, my_com_netsplit_Nih_Test_Peek_method },\n" "\t{ \"IsValidAddress\", my_com_netsplit_Nih_Test_IsValidAddress_method_args, my_com_netsplit_Nih_Test_IsValidAddress_method },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Bounce_signal_args[] = {\n" "\t{ \"height\", \"u\", NIH_DBUS_ARG_OUT },\n" "\t{ \"velocity\", \"i\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Exploded_signal_args[] = {\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusSignal my_com_netsplit_Nih_Test_signals[] = {\n" "\t{ \"Bounce\", my_com_netsplit_Nih_Test_Bounce_signal_args, NULL },\n" "\t{ \"Exploded\", my_com_netsplit_Nih_Test_Exploded_signal_args, NULL },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusProperty my_com_netsplit_Nih_Test_properties[] = {\n" "\t{ \"colour\", \"s\", NIH_DBUS_READWRITE, my_com_netsplit_Nih_Test_colour_get, my_com_netsplit_Nih_Test_colour_set },\n" "\t{ \"size\", \"u\", NIH_DBUS_READ, my_com_netsplit_Nih_Test_size_get, NULL },\n" "\t{ \"touch\", \"b\", NIH_DBUS_WRITE, NULL, my_com_netsplit_Nih_Test_touch_set },\n" "\t{ NULL }\n" "};\n" "\n" "const NihDBusInterface my_com_netsplit_Nih_Test = {\n" "\t\"com.netsplit.Nih.Test\",\n" "\tmy_com_netsplit_Nih_Test_methods,\n" "\tmy_com_netsplit_Nih_Test_signals,\n" "\tmy_com_netsplit_Nih_Test_properties\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusInterface"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test"); TEST_ALLOC_PARENT (var->name, var); TEST_FALSE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } /* Check that we can generate the structure variable code for an * interface with many methods, signals and properties. We want * the members set up for a proxy implementation, so the signal * filter pointer should be set but not the method or property * function pointers. */ TEST_FEATURE ("with proxy"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); arg = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); arg->symbol = "height"; nih_list_add (&signal->arguments, &arg->entry); arg = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); arg->symbol = "velocity"; nih_list_add (&signal->arguments, &arg->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); } str = interface_struct (NULL, "my", interface, FALSE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "static const NihDBusArg my_com_netsplit_Nih_Test_Poke_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ \"value\", \"s\", NIH_DBUS_ARG_IN },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Peek_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ \"value\", \"s\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_IsValidAddress_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusMethod my_com_netsplit_Nih_Test_methods[] = {\n" "\t{ \"Poke\", my_com_netsplit_Nih_Test_Poke_method_args, NULL },\n" "\t{ \"Peek\", my_com_netsplit_Nih_Test_Peek_method_args, NULL },\n" "\t{ \"IsValidAddress\", my_com_netsplit_Nih_Test_IsValidAddress_method_args, NULL },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Bounce_signal_args[] = {\n" "\t{ \"height\", \"u\", NIH_DBUS_ARG_OUT },\n" "\t{ \"velocity\", \"i\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Exploded_signal_args[] = {\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusSignal my_com_netsplit_Nih_Test_signals[] = {\n" "\t{ \"Bounce\", my_com_netsplit_Nih_Test_Bounce_signal_args, my_com_netsplit_Nih_Test_Bounce_signal },\n" "\t{ \"Exploded\", my_com_netsplit_Nih_Test_Exploded_signal_args, my_com_netsplit_Nih_Test_Exploded_signal },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusProperty my_com_netsplit_Nih_Test_properties[] = {\n" "\t{ \"colour\", \"s\", NIH_DBUS_READWRITE, NULL, NULL },\n" "\t{ \"size\", \"u\", NIH_DBUS_READ, NULL, NULL },\n" "\t{ \"touch\", \"b\", NIH_DBUS_WRITE, NULL, NULL },\n" "\t{ NULL }\n" "};\n" "\n" "const NihDBusInterface my_com_netsplit_Nih_Test = {\n" "\t\"com.netsplit.Nih.Test\",\n" "\tmy_com_netsplit_Nih_Test_methods,\n" "\tmy_com_netsplit_Nih_Test_signals,\n" "\tmy_com_netsplit_Nih_Test_properties\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusInterface"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test"); TEST_ALLOC_PARENT (var->name, var); TEST_FALSE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } /* Check that valid code is still returned when there are no * methods. */ TEST_FEATURE ("with no methods"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); arg = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); arg->symbol = "height"; nih_list_add (&signal->arguments, &arg->entry); arg = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); arg->symbol = "velocity"; nih_list_add (&signal->arguments, &arg->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); } str = interface_struct (NULL, "my", interface, TRUE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "static const NihDBusMethod my_com_netsplit_Nih_Test_methods[] = {\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Bounce_signal_args[] = {\n" "\t{ \"height\", \"u\", NIH_DBUS_ARG_OUT },\n" "\t{ \"velocity\", \"i\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Exploded_signal_args[] = {\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusSignal my_com_netsplit_Nih_Test_signals[] = {\n" "\t{ \"Bounce\", my_com_netsplit_Nih_Test_Bounce_signal_args, NULL },\n" "\t{ \"Exploded\", my_com_netsplit_Nih_Test_Exploded_signal_args, NULL },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusProperty my_com_netsplit_Nih_Test_properties[] = {\n" "\t{ \"colour\", \"s\", NIH_DBUS_READWRITE, my_com_netsplit_Nih_Test_colour_get, my_com_netsplit_Nih_Test_colour_set },\n" "\t{ \"size\", \"u\", NIH_DBUS_READ, my_com_netsplit_Nih_Test_size_get, NULL },\n" "\t{ \"touch\", \"b\", NIH_DBUS_WRITE, NULL, my_com_netsplit_Nih_Test_touch_set },\n" "\t{ NULL }\n" "};\n" "\n" "const NihDBusInterface my_com_netsplit_Nih_Test = {\n" "\t\"com.netsplit.Nih.Test\",\n" "\tmy_com_netsplit_Nih_Test_methods,\n" "\tmy_com_netsplit_Nih_Test_signals,\n" "\tmy_com_netsplit_Nih_Test_properties\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusInterface"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test"); TEST_ALLOC_PARENT (var->name, var); TEST_FALSE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } /* Check that valid code is still returned when there are no * signals. */ TEST_FEATURE ("with no signals"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); } str = interface_struct (NULL, "my", interface, TRUE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "static const NihDBusArg my_com_netsplit_Nih_Test_Poke_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ \"value\", \"s\", NIH_DBUS_ARG_IN },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Peek_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ \"value\", \"s\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_IsValidAddress_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusMethod my_com_netsplit_Nih_Test_methods[] = {\n" "\t{ \"Poke\", my_com_netsplit_Nih_Test_Poke_method_args, my_com_netsplit_Nih_Test_Poke_method },\n" "\t{ \"Peek\", my_com_netsplit_Nih_Test_Peek_method_args, my_com_netsplit_Nih_Test_Peek_method },\n" "\t{ \"IsValidAddress\", my_com_netsplit_Nih_Test_IsValidAddress_method_args, my_com_netsplit_Nih_Test_IsValidAddress_method },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusSignal my_com_netsplit_Nih_Test_signals[] = {\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusProperty my_com_netsplit_Nih_Test_properties[] = {\n" "\t{ \"colour\", \"s\", NIH_DBUS_READWRITE, my_com_netsplit_Nih_Test_colour_get, my_com_netsplit_Nih_Test_colour_set },\n" "\t{ \"size\", \"u\", NIH_DBUS_READ, my_com_netsplit_Nih_Test_size_get, NULL },\n" "\t{ \"touch\", \"b\", NIH_DBUS_WRITE, NULL, my_com_netsplit_Nih_Test_touch_set },\n" "\t{ NULL }\n" "};\n" "\n" "const NihDBusInterface my_com_netsplit_Nih_Test = {\n" "\t\"com.netsplit.Nih.Test\",\n" "\tmy_com_netsplit_Nih_Test_methods,\n" "\tmy_com_netsplit_Nih_Test_signals,\n" "\tmy_com_netsplit_Nih_Test_properties\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusInterface"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test"); TEST_ALLOC_PARENT (var->name, var); TEST_FALSE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } /* Check that valid code is still returned when there are no * properties. */ TEST_FEATURE ("with no properties"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); arg = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); arg->symbol = "height"; nih_list_add (&signal->arguments, &arg->entry); arg = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); arg->symbol = "velocity"; nih_list_add (&signal->arguments, &arg->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); } str = interface_struct (NULL, "my", interface, TRUE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "static const NihDBusArg my_com_netsplit_Nih_Test_Poke_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ \"value\", \"s\", NIH_DBUS_ARG_IN },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Peek_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ \"value\", \"s\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_IsValidAddress_method_args[] = {\n" "\t{ \"address\", \"u\", NIH_DBUS_ARG_IN },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusMethod my_com_netsplit_Nih_Test_methods[] = {\n" "\t{ \"Poke\", my_com_netsplit_Nih_Test_Poke_method_args, my_com_netsplit_Nih_Test_Poke_method },\n" "\t{ \"Peek\", my_com_netsplit_Nih_Test_Peek_method_args, my_com_netsplit_Nih_Test_Peek_method },\n" "\t{ \"IsValidAddress\", my_com_netsplit_Nih_Test_IsValidAddress_method_args, my_com_netsplit_Nih_Test_IsValidAddress_method },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Bounce_signal_args[] = {\n" "\t{ \"height\", \"u\", NIH_DBUS_ARG_OUT },\n" "\t{ \"velocity\", \"i\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusArg my_com_netsplit_Nih_Test_Exploded_signal_args[] = {\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusSignal my_com_netsplit_Nih_Test_signals[] = {\n" "\t{ \"Bounce\", my_com_netsplit_Nih_Test_Bounce_signal_args, NULL },\n" "\t{ \"Exploded\", my_com_netsplit_Nih_Test_Exploded_signal_args, NULL },\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusProperty my_com_netsplit_Nih_Test_properties[] = {\n" "\t{ NULL }\n" "};\n" "\n" "const NihDBusInterface my_com_netsplit_Nih_Test = {\n" "\t\"com.netsplit.Nih.Test\",\n" "\tmy_com_netsplit_Nih_Test_methods,\n" "\tmy_com_netsplit_Nih_Test_signals,\n" "\tmy_com_netsplit_Nih_Test_properties\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusInterface"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test"); TEST_ALLOC_PARENT (var->name, var); TEST_FALSE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } /* Check that valid code is still returned when there are no * methods, signals or properties. */ TEST_FEATURE ("with no members"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; } str = interface_struct (NULL, "my", interface, TRUE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "static const NihDBusMethod my_com_netsplit_Nih_Test_methods[] = {\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusSignal my_com_netsplit_Nih_Test_signals[] = {\n" "\t{ NULL }\n" "};\n" "\n" "static const NihDBusProperty my_com_netsplit_Nih_Test_properties[] = {\n" "\t{ NULL }\n" "};\n" "\n" "const NihDBusInterface my_com_netsplit_Nih_Test = {\n" "\t\"com.netsplit.Nih.Test\",\n" "\tmy_com_netsplit_Nih_Test_methods,\n" "\tmy_com_netsplit_Nih_Test_signals,\n" "\tmy_com_netsplit_Nih_Test_properties\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusInterface"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test"); TEST_ALLOC_PARENT (var->name, var); TEST_FALSE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } } int my_com_netsplit_Nih_TestA_get_all_notify_called = FALSE; static DBusPendingCall * last_pending_call = NULL; static NihDBusPendingData *last_pending_data = NULL; void my_com_netsplit_Nih_TestA_get_all_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { my_com_netsplit_Nih_TestA_get_all_notify_called = TRUE; last_pending_call = pending_call; last_pending_data = pending_data; } static void my_blank_get_handler (void * data, NihDBusMessage * message, const MyProperties *value) { } static void my_blank_error_handler (void * data, NihDBusMessage *message) { } void test_proxy_get_all_function (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihList prototypes; NihList structs; Interface * interface = NULL; Property * property = NULL; char * str; TypeFunc * func; TypeVar * arg; NihListEntry * attrib; DBusConnection * flakey_conn; NihDBusProxy * proxy = NULL; DBusPendingCall * pending_call; DBusMessage * method_call; DBusMessage * reply; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; char * str_value; uint32_t uint32_value; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("interface_proxy_get_all_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that makes a method call * to obtain the value of all readable D-Bus properties for the given * interface, returning the pending call structure. */ TEST_FEATURE ("with interface"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (interface, "name", "s", NIH_DBUS_READWRITE); property->symbol = "name"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); } str = interface_proxy_get_all_function ( NULL, "my", interface, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_interface_proxy_get_all_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_get_all"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyGetAllReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (interface); } /* Check that we can use the generated code to make a method call * to obtain the values of the properties. The function should * return a DBusPendingCall object and we should receive the method * call on the other side. Returning the reply and blocking the call * should result in our notify function being called with the * pending call that was returned and the pending data with the * expected information. */ TEST_FEATURE ("with interface (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_TestA_get_all_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_get_all (proxy, my_blank_get_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.TestA"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "name"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variter); str_value = "Joe Bloggs"; dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "size"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &variter); uint32_value = 34; dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Block the pending call until we receive the reply */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_com_netsplit_Nih_TestA_get_all_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_get_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the notify function is still called when the server * returns an error; strictly speaking we're testing D-Bus here, * but let's be complete about the whole thing - besides, it's * good documentation for how things should behave */ TEST_FEATURE ("with error reply (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_TestA_get_all_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_get_all (proxy, my_blank_get_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.TestA"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_error (method_call, "com.netsplit.Nih.Fail", "Things didn't work out"); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Block the pending call until we receive the reply */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Fail")); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_com_netsplit_Nih_TestA_get_all_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_get_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the pending call will fail if the timeout is reached, * with the notify function being called for the timeout error. */ TEST_FEATURE ("with timeout (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_TestA_get_all_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_get_all (proxy, my_blank_get_handler, my_blank_error_handler, &proxy, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.TestA"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (method_call); /* Block the pending call until timeout */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_NO_REPLY)); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_com_netsplit_Nih_TestA_get_all_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_get_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the pending call will fail if the remote end * disconnects. The notify function will be called with the no * reply error. */ TEST_FEATURE ("with server disconnection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_TestA_get_all_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_get_all (proxy, my_blank_get_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (flakey_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.TestA"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (method_call); /* Close the server connection */ TEST_DBUS_CLOSE (flakey_conn); /* Block the pending call until timeout */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_NO_REPLY)); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_com_netsplit_Nih_TestA_get_all_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_get_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the pending call can be cancelled by the user. * The notify function should not be called, but the data it * contains should be freed (check valgrind). */ TEST_FEATURE ("with cancelled call (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_TestA_get_all_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_get_all (proxy, my_blank_get_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.TestA"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send a reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Cancel the pending call */ dbus_pending_call_cancel (pending_call); dbus_pending_call_unref (pending_call); /* Dispatch until we receive a message */ TEST_DBUS_DISPATCH (client_conn); /* Check the notify function was not called. */ TEST_FALSE (my_com_netsplit_Nih_TestA_get_all_notify_called); nih_free (proxy); } /* Check that when the remote end is not connected, the function * returns NULL and raises the disconnected D-Bus error. */ TEST_FEATURE ("with unconnected connection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } TEST_DBUS_CLOSE (flakey_conn); my_com_netsplit_Nih_TestA_get_all_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_get_all (proxy, my_blank_get_handler, my_blank_error_handler, &proxy, -1); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (my_com_netsplit_Nih_TestA_get_all_notify_called); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static void my_error_handler (void *data, NihDBusMessage *message); static int my_get_all_handler_called = FALSE; static int my_error_handler_called = FALSE; static NihDBusMessage *last_message = NULL; static DBusConnection *last_conn = NULL; static DBusMessage *last_msg = NULL; static NihError *last_error = NULL; static void __attribute__ ((unused)) my_get_all_handler (void * data, NihDBusMessage * message, const MyProperties *properties) { my_get_all_handler_called++; TEST_EQ_P (data, (void *)my_error_handler); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_message = message; TEST_FREE_TAG (last_message); last_conn = message->connection; dbus_connection_ref (last_conn); last_msg = message->message; dbus_message_ref (last_msg); TEST_NE_P (properties, NULL); TEST_ALLOC_SIZE (properties, sizeof (MyProperties)); TEST_ALLOC_PARENT (properties, message); TEST_EQ_STR (properties->name, "Joe Bloggs"); TEST_ALLOC_PARENT (properties->name, properties); TEST_EQ (properties->size, 34); } static void my_error_handler (void * data, NihDBusMessage *message) { my_error_handler_called++; TEST_EQ_P (data, (void *)my_error_handler); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_message = message; TEST_FREE_TAG (last_message); last_conn = message->connection; dbus_connection_ref (last_conn); last_msg = message->message; dbus_message_ref (last_msg); last_error = nih_error_steal (); TEST_NE_P (last_error, NULL); } void test_proxy_get_all_notify_function (void) { pid_t dbus_pid; NihList prototypes; NihList typedefs; NihList structs; Interface * interface = NULL; Property * property = NULL; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; DBusConnection * server_conn; DBusConnection * client_conn; DBusConnection * flakey_conn; dbus_uint32_t serial; DBusPendingCall * pending_call; NihDBusPendingData *pending_data = NULL; DBusMessage * method_call; DBusMessage * reply; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; char * str_value; uint32_t uint32_value; double double_value; NihDBusError * dbus_err; TEST_FUNCTION ("interface_proxy_get_all_notify_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that takes a pending call * and pending data structure, stealing the D-Bus message and * demarshalling the property values from the array of name and * variants argument before making a call to either the handler * for a valid reply or error handler for an invalid reply. * The typedef for the handler function is returned in addition * to the prototype. */ TEST_FEATURE ("with interface"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (interface, "name", "s", NIH_DBUS_READWRITE); property->symbol = "name"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); } str = interface_proxy_get_all_notify_function ( NULL, "my", interface, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_interface_proxy_get_all_notify_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_get_all_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyGetAllReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyProperties *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyProperties"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "name"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can generate a notify function for an interface * that has a structure property, with the structure type passed * back in the structs array before the struct definition for * the return value. */ TEST_FEATURE ("with structure property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (interface, "name", "s", NIH_DBUS_READWRITE); property->symbol = "name"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); property = property_new (NULL, "birthday", "(iii)", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "birthday"); nih_list_add (&interface->properties, &property->entry); } str = interface_proxy_get_all_notify_function ( NULL, "my", interface, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_interface_proxy_get_all_notify_function_structure.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_get_all_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyGetAllReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyProperties *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyBirthday"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "int32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "int32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "int32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item2"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyProperties"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "name"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "MyBirthday *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "birthday"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can use the generated code to handle a completed * pending call, demarshalling the property values from the array * of name and variants in the reply and passing them in a single * structure to our handler. */ TEST_FEATURE ("with reply (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "name"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variter); str_value = "Joe Bloggs"; dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "size"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &variter); uint32_value = 34; dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_all_handler, my_error_handler, (void *)my_error_handler); } my_get_all_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_get_all_notify (pending_call, pending_data); TEST_TRUE (my_get_all_handler_called); TEST_FALSE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that we can use the generated code to handle an error * reply, passing it to the error handler as a raised error * instead of calling the usual handler. */ TEST_FEATURE ("with error reply (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_error (method_call, "com.netsplit.Nih.Fail", "Things didn't work out"); dbus_message_unref (method_call); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_all_handler, my_error_handler, (void *)my_error_handler); } my_get_all_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_get_all_notify (pending_call, pending_data); TEST_FALSE (my_get_all_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Fail"); TEST_EQ_STR (last_error->message, "Things didn't work out"); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches a timeout of the pending * call and runs the error handler with the D-Bus timeout error * raised. */ TEST_FEATURE ("with timeout (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); dbus_message_unref (method_call); /* Wait for timeout */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_all_handler, my_error_handler, (void *)my_error_handler); } my_get_all_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_get_all_notify (pending_call, pending_data); TEST_FALSE (my_get_all_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches disconnection of the * remote end during a pending call call and runs the error handler * with the D-Bus timeout error raised. */ TEST_FEATURE ("with disconnection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (flakey_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); dbus_message_unref (method_call); TEST_DBUS_CLOSE (flakey_conn); /* Wait for error */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_all_handler, my_error_handler, (void *)my_error_handler); } my_get_all_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_get_all_notify (pending_call, pending_data); TEST_FALSE (my_get_all_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code doesn't mind if there's an * extra property in the reply, it simply ignores it; this is to * allow for future extension without breaking the API. */ TEST_FEATURE ("with extra property (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "name"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variter); str_value = "Joe Bloggs"; dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "size"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &variter); uint32_value = 34; dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "body_mass"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &variter); double_value = 25.5; dbus_message_iter_append_basic (&variter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_all_handler, my_error_handler, (void *)my_error_handler); } my_get_all_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_get_all_notify (pending_call, pending_data); TEST_TRUE (my_get_all_handler_called); TEST_FALSE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches a missing property in * the reply and calls the error handler with the invalid arguments * error raised. */ TEST_FEATURE ("with missing property (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "size"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &variter); uint32_value = 34; dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_all_handler, my_error_handler, (void *)my_error_handler); } my_get_all_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_get_all_notify (pending_call, pending_data); TEST_FALSE (my_get_all_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches an invalid argument type in * the variant and calls the error handler with the invalid arguments * error raised. */ TEST_FEATURE ("with incorrect variant member type (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "name"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variter); str_value = "Joe Bloggs"; dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "size"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &variter); double_value = 3.14; dbus_message_iter_append_basic (&variter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_all_handler, my_error_handler, (void *)my_error_handler); } my_get_all_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_get_all_notify (pending_call, pending_data); TEST_FALSE (my_get_all_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches an invalid key type in * the dictionary and calls the error handler with the invalid * arguments error raised. */ TEST_FEATURE ("with incorrect dict key type (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_DOUBLE_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); double_value = 3.14; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variter); str_value = "Joe Bloggs"; dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); double_value = 4.86; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &variter); uint32_value = 34; dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_all_handler, my_error_handler, (void *)my_error_handler); } my_get_all_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_get_all_notify (pending_call, pending_data); TEST_FALSE (my_get_all_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches an invalid argument type in * the dictionary and calls the error handler with the invalid * arguments error raised. */ TEST_FEATURE ("with incorrect dict member type (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "name"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); str_value = "Joe Bloggs"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "size"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); str_value = "34"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_all_handler, my_error_handler, (void *)my_error_handler); } my_get_all_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_get_all_notify (pending_call, pending_data); TEST_FALSE (my_get_all_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches an invalid argument type in * the array and calls the error handler with the invalid * arguments error raised. */ TEST_FEATURE ("with incorrect array member type (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &arrayiter); str_value = "name"; dbus_message_iter_append_basic (&arrayiter, DBUS_TYPE_STRING, &str_value); str_value = "size"; dbus_message_iter_append_basic (&arrayiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &arrayiter); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_all_handler, my_error_handler, (void *)my_error_handler); } my_get_all_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_get_all_notify (pending_call, pending_data); TEST_FALSE (my_get_all_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches an invalid argument type in * the reply and calls the error handler with the invalid * arguments error raised. */ TEST_FEATURE ("with incorrect type (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_all_handler, my_error_handler, (void *)my_error_handler); } my_get_all_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_get_all_notify (pending_call, pending_data); TEST_FALSE (my_get_all_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches a missing argument in * the reply and calls the error handler with the invalid arguments * error raised. */ TEST_FEATURE ("with missing argument (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_all_handler, my_error_handler, (void *)my_error_handler); } my_get_all_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_get_all_notify (pending_call, pending_data); TEST_FALSE (my_get_all_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches an extra argument in * the reply and calls the error handler with the invalid arguments * error raised. */ TEST_FEATURE ("with extra argument (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "name"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variter); str_value = "Joe Bloggs"; dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "size"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &variter); uint32_value = 34; dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_all_handler, my_error_handler, (void *)my_error_handler); } my_get_all_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_get_all_notify (pending_call, pending_data); TEST_FALSE (my_get_all_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_proxy_get_all_sync_function (void) { pid_t dbus_pid; DBusConnection *server_conn; DBusConnection *client_conn; DBusConnection *flakey_conn; NihList prototypes; NihList structs; Interface * interface = NULL; Property * property = NULL; char * str; TypeFunc * func; TypeVar * arg; NihListEntry * attrib; TypeStruct * structure; TypeVar * var; NihDBusProxy * proxy = NULL; void * parent = NULL; pid_t pid; int status; DBusMessage * method_call; DBusMessage * reply; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter variter; char * str_value; uint32_t uint32_value; double double_value; MyProperties * properties; int ret; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("interface_proxy_get_all_sync_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that will make a method * call to obtain the value of all properties and return a struct * containing them in the pointer argument supplied. The function * returns an integer to indicate success. */ TEST_FEATURE ("with interface"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (interface, "name", "s", NIH_DBUS_READWRITE); property->symbol = "name"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); } str = interface_proxy_get_all_sync_function ( NULL, "my", interface, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_interface_proxy_get_all_sync_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_get_all_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyProperties **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyProperties"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "name"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can generate a function for an interface that * has a structure property, with the structure type passed * back in the structs array before the struct definition for * the return value. */ TEST_FEATURE ("with structure property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (interface, "name", "s", NIH_DBUS_READWRITE); property->symbol = "name"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "birthday", "(iii)", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "birthday"); nih_list_add (&interface->properties, &property->entry); } str = interface_proxy_get_all_sync_function ( NULL, "my", interface, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_interface_proxy_get_all_sync_function_structure.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_get_all_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyProperties **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyBirthday"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "int32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "int32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "int32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item2"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyProperties"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "name"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "MyBirthday *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "birthday"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can use the generated code to make a method call * and obtain the value of the properties. */ TEST_FEATURE ("with method call (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "name"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variter); str_value = "Joe Bloggs"; dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "size"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &variter); uint32_value = 34; dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } properties = NULL; ret = my_get_all_sync (parent, proxy, &properties); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (properties, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (ret, 0); TEST_NE_P (properties, NULL); TEST_ALLOC_SIZE (properties, sizeof (MyProperties)); TEST_ALLOC_PARENT (properties, parent); TEST_EQ_STR (properties->name, "Joe Bloggs"); TEST_ALLOC_PARENT (properties->name, properties); TEST_EQ (properties->size, 34); nih_free (proxy); } /* Check that the generated code handles an error returned from * the property get function, returning a raised error. */ TEST_FEATURE ("with error returned (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_error (method_call, "com.netsplit.Nih.Failed", "Didn't work out"); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } properties = NULL; ret = my_get_all_sync (parent, proxy, &properties); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (properties, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Failed"); TEST_EQ_STR (err->message, "Didn't work out"); nih_free (err); TEST_EQ_P (properties, NULL); nih_free (proxy); } /* Check that the generated code returns a raised disconnected * error when called on a disconnected connection. */ TEST_FEATURE ("with error returned (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } TEST_DBUS_CLOSE (flakey_conn); properties = NULL; ret = my_get_all_sync (parent, proxy, &properties); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); TEST_EQ_P (properties, NULL); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_EQ_P (properties, NULL); nih_free (proxy); } /* Check that the generated code doesn't mind if there's an * extra property in the reply, it simply ignores it; this is to * allow for future extension without breaking the API. */ TEST_FEATURE ("with extra property (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "name"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variter); str_value = "Joe Bloggs"; dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "size"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &variter); uint32_value = 34; dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "body_mass"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &variter); double_value = 25.5; dbus_message_iter_append_basic (&variter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } properties = NULL; ret = my_get_all_sync (parent, proxy, &properties); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (properties, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (ret, 0); TEST_NE_P (properties, NULL); TEST_ALLOC_SIZE (properties, sizeof (MyProperties)); TEST_ALLOC_PARENT (properties, parent); TEST_EQ_STR (properties->name, "Joe Bloggs"); TEST_ALLOC_PARENT (properties->name, properties); TEST_EQ (properties->size, 34); nih_free (proxy); } /* Check that the generated code catches a missing property in * the reply and results in the function returning a raised error. */ TEST_FEATURE ("with missing property (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "size"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &variter); uint32_value = 34; dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } properties = NULL; ret = my_get_all_sync (parent, proxy, &properties); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (properties, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); TEST_EQ_P (properties, NULL); nih_free (proxy); } /* Check that an incorrect member type in the variant results in * the function returning a raised error. */ TEST_FEATURE ("with incorrect variant member type (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "name"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variter); str_value = "Joe Bloggs"; dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "size"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &variter); double_value = 3.14; dbus_message_iter_append_basic (&variter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } properties = NULL; ret = my_get_all_sync (parent, proxy, &properties); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (properties, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); TEST_EQ_P (properties, NULL); nih_free (proxy); } /* Check that an incorrect key type in the dictionary results in * the function returning a raised error. */ TEST_FEATURE ("with incorrect dict key type (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_DOUBLE_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); double_value = 3.14; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variter); str_value = "Joe Bloggs"; dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); double_value = 4.86; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &variter); uint32_value = 34; dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } properties = NULL; ret = my_get_all_sync (parent, proxy, &properties); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (properties, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); TEST_EQ_P (properties, NULL); nih_free (proxy); } /* Check that an incorrect member type in the dictionary results in * the function returning a raised error. */ TEST_FEATURE ("with incorrect dict member type (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_DOUBLE_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "name"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); double_value = 3.14; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "size"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); double_value = 4.86; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } properties = NULL; ret = my_get_all_sync (parent, proxy, &properties); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (properties, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); TEST_EQ_P (properties, NULL); nih_free (proxy); } /* Check that an incorrect member type in the array results in * the function returning a raised error. */ TEST_FEATURE ("with incorrect array member type (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &arrayiter); str_value = "name"; dbus_message_iter_append_basic (&arrayiter, DBUS_TYPE_STRING, &str_value); str_value = "size"; dbus_message_iter_append_basic (&arrayiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } properties = NULL; ret = my_get_all_sync (parent, proxy, &properties); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (properties, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); TEST_EQ_P (properties, NULL); nih_free (proxy); } /* Check that an incorrect type in the arguments results in the * function returning a raised error. */ TEST_FEATURE ("with incorrect type (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } properties = NULL; ret = my_get_all_sync (parent, proxy, &properties); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (properties, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); TEST_EQ_P (properties, NULL); nih_free (proxy); } /* Check that a missing argument results in the function * returning a raised error. */ TEST_FEATURE ("with missing argument (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } properties = NULL; ret = my_get_all_sync (parent, proxy, &properties); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (properties, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); TEST_EQ_P (properties, NULL); nih_free (proxy); } /* Check that an extra arguments results in the function * returning a raised error. */ TEST_FEATURE ("with extra argument (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "GetAll")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "name"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variter); str_value = "Joe Bloggs"; dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter); str_value = "size"; dbus_message_iter_append_basic (&dictiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&dictiter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &variter); uint32_value = 34; dbus_message_iter_append_basic (&variter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&dictiter, &variter); dbus_message_iter_close_container (&arrayiter, &dictiter); dbus_message_iter_close_container (&iter, &arrayiter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } properties = NULL; ret = my_get_all_sync (parent, proxy, &properties); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (properties, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); TEST_EQ_P (properties, NULL); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } int main (int argc, char *argv[]) { program_name = "test"; nih_error_init (); test_name_valid (); test_new (); test_start_tag (); test_end_tag (); test_annotation (); test_methods_array (); test_signals_array (); test_properties_array (); test_struct (); test_proxy_get_all_function (); test_proxy_get_all_notify_function (); test_proxy_get_all_sync_function (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/signal_factory.c0000644000175000017500000000500611445765555016721 00000000000000/* nih-dbus-tool * * tests/signal_factory.c - generate tests/signal_code.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include "type.h" #include "interface.h" #include "signal.h" #include "argument.h" int main (int argc, char *argv[]) { NihList prototypes; NihList typedefs; NihList structs; nih_local Interface *interface = NULL; nih_local Signal * signal = NULL; Argument * arg; nih_local char * code = NULL; printf ("#include \n" "\n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "\n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "\n" "#include \"tests/signal_code.h\"\n" "\n"); interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; signal = signal_new (NULL, "Signal"); signal->symbol = nih_strdup (signal, "signal"); arg = argument_new (signal, "Msg", "s", NIH_DBUS_ARG_OUT); arg->symbol = nih_strdup (arg, "msg"); nih_list_add (&signal->arguments, &arg->entry); nih_list_init (&prototypes); nih_list_init (&structs); code = signal_object_function (NULL, "my", interface, signal, &prototypes, &structs); printf ("%s" "\n", code); nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); code = signal_proxy_function (NULL, "my", interface, signal, &prototypes, &typedefs, &structs); printf ("%s", code); return 0; } libnih-1.0.3/nih-dbus-tool/tests/method_code.h0000644000175000017500000000441311445765555016175 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_TESTS_METHOD_CODE_H #define NIH_DBUS_TOOL_TESTS_METHOD_CODE_H #include #include #include #include #include typedef void (*MyMethodReply) (void *data, NihDBusMessage *message, char * const *output, int32_t length); typedef void (*MyTestMethodReply) (void *data, NihDBusMessage *message, char * const *output, int32_t length); NIH_BEGIN_EXTERN DBusHandlerResult my_com_netsplit_Nih_Test_Method_method (NihDBusObject *object, NihDBusMessage *message); DBusHandlerResult my_com_netsplit_Nih_Test_AsyncMethod_method (NihDBusObject *object, NihDBusMessage *message); int my_async_method_reply (NihDBusMessage *message, char * const *output) __attribute__ ((warn_unused_result)); DBusPendingCall * my_test_method (NihDBusProxy *proxy, const char *str, int32_t flags, MyTestMethodReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); void my_com_netsplit_Nih_Test_Method_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); int my_method_sync (const void *parent, NihDBusProxy *proxy, const char *str, int32_t flags, char ***output, int32_t *length) __attribute__ ((warn_unused_result)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_TESTS_METHOD_CODE_H */ libnih-1.0.3/nih-dbus-tool/tests/test_property.c0000644000175000017500000076336411445765555016662 00000000000000/* nih-dbus-tool * * test_property.c - test suite for nih-dbus-tool/property.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "type.h" #include "node.h" #include "property.h" #include "parse.h" #include "errors.h" #include "tests/property_code.h" void test_name_valid (void) { TEST_FUNCTION ("property_name_valid"); /* Check that a typical property name is valid. */ TEST_FEATURE ("with typical property name"); TEST_TRUE (property_name_valid ("Wibble")); /* Check that an property name is not valid if it is has an * initial period. */ TEST_FEATURE ("with initial period"); TEST_FALSE (property_name_valid (".Wibble")); /* Check that an property name is not valid if it ends with a period */ TEST_FEATURE ("with final period"); TEST_FALSE (property_name_valid ("Wibble.")); /* Check that an property name is not valid if it contains a period */ TEST_FEATURE ("with period"); TEST_FALSE (property_name_valid ("Wib.ble")); /* Check that a property name may contain numbers */ TEST_FEATURE ("with numbers"); TEST_TRUE (property_name_valid ("Wib43ble")); /* Check that a property name may not begin with numbers */ TEST_FEATURE ("with leading digits"); TEST_FALSE (property_name_valid ("43Wibble")); /* Check that a property name may end with numbers */ TEST_FEATURE ("with trailing digits"); TEST_TRUE (property_name_valid ("Wibble43")); /* Check that a property name may contain underscores */ TEST_FEATURE ("with underscore"); TEST_TRUE (property_name_valid ("Wib_ble")); /* Check that a property name may begin with underscores */ TEST_FEATURE ("with initial underscore"); TEST_TRUE (property_name_valid ("_Wibble")); /* Check that a property name may end with underscores */ TEST_FEATURE ("with final underscore"); TEST_TRUE (property_name_valid ("Wibble_")); /* Check that other characters are not permitted */ TEST_FEATURE ("with non-permitted characters"); TEST_FALSE (property_name_valid ("Wib-ble")); /* Check that an empty property name is invalid */ TEST_FEATURE ("with empty string"); TEST_FALSE (property_name_valid ("")); /* Check that an property name may not exceed 255 characters */ TEST_FEATURE ("with overly long name"); TEST_FALSE (property_name_valid ("ReallyLongPropertyNameThatNobo" "dyInTheirRightMindWouldEverUse" "NotInTheLeastBecauseThenYoudEn" "dUpWithAnEvenLongerInterfaceNa" "meAndThatJustWontWorkWhenCombi" "nedButStillWeTestThisShitJustI" "ncaseSomeoneTriesItBecauseThat" "sWhatTestDrivenDevelopmentIsAl" "lAboutYayDoneNow")); } void test_new (void) { Property *property; /* Check that an Property object is allocated with the structure * filled in properly, but not placed in a list. */ TEST_FUNCTION ("property_new"); TEST_ALLOC_FAIL { property = property_new (NULL, "Size", "i", NIH_DBUS_READ); if (test_alloc_failed) { TEST_EQ_P (property, NULL); continue; } TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_LIST_EMPTY (&property->entry); TEST_EQ_STR (property->name, "Size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_EQ_P (property->symbol, NULL); TEST_EQ (property->access, NIH_DBUS_READ); TEST_FALSE (property->deprecated); nih_free (property); } } void test_start_tag (void) { ParseContext context; ParseStack * parent = NULL; ParseStack * entry; XML_Parser xmlp; Node * node = NULL; Interface * interface = NULL; Property * property; char * attr[9]; int ret; NihError * err; FILE * output; TEST_FUNCTION ("property_start_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); output = tmpfile (); /* Check that an property tag for an interface with the usual name, * and type attributes and with an access attribute of read results * in an Property member being created and pushed onto the stack * with the attributes filled in correctly for a read-only property. */ TEST_FEATURE ("with read-only property"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } attr[0] = "name"; attr[1] = "TestProperty"; attr[2] = "type"; attr[3] = "s"; attr[4] = "access"; attr[5] = "read"; attr[6] = NULL; ret = property_start_tag (xmlp, "property", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->properties); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_PROPERTY); property = entry->property; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, entry); TEST_EQ_STR (property->name, "TestProperty"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_P (property->symbol, NULL); TEST_EQ_STR (property->type, "s"); TEST_ALLOC_PARENT (property->type, property); TEST_EQ (property->access, NIH_DBUS_READ); TEST_LIST_EMPTY (&interface->properties); nih_free (entry); nih_free (parent); } /* Check that an property tag for an interface with the usual name, * and type attributes and with an access attribute of write results * in an Property member being created and pushed onto the stack * with the attributes filled in correctly for a write-only property. */ TEST_FEATURE ("with write-only property"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } attr[0] = "name"; attr[1] = "TestProperty"; attr[2] = "type"; attr[3] = "s"; attr[4] = "access"; attr[5] = "write"; attr[6] = NULL; ret = property_start_tag (xmlp, "property", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->properties); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_PROPERTY); property = entry->property; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, entry); TEST_EQ_STR (property->name, "TestProperty"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_P (property->symbol, NULL); TEST_EQ_STR (property->type, "s"); TEST_ALLOC_PARENT (property->type, property); TEST_EQ (property->access, NIH_DBUS_WRITE); TEST_LIST_EMPTY (&interface->properties); nih_free (entry); nih_free (parent); } /* Check that an property tag for an interface with the usual name, * and type attributes and with an access attribute of readwrite * results in an Property member being created and pushed onto the * stack with the attributes filled in correctly for a read/write * property. */ TEST_FEATURE ("with read/write property"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } attr[0] = "name"; attr[1] = "TestProperty"; attr[2] = "type"; attr[3] = "s"; attr[4] = "access"; attr[5] = "readwrite"; attr[6] = NULL; ret = property_start_tag (xmlp, "property", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->properties); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_PROPERTY); property = entry->property; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, entry); TEST_EQ_STR (property->name, "TestProperty"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_P (property->symbol, NULL); TEST_EQ_STR (property->type, "s"); TEST_ALLOC_PARENT (property->type, property); TEST_EQ (property->access, NIH_DBUS_READWRITE); TEST_LIST_EMPTY (&interface->properties); nih_free (entry); nih_free (parent); } /* Check that a property with a missing name attribute results * in an error being raised. */ TEST_FEATURE ("with missing name"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "type"; attr[1] = "s"; attr[2] = "access"; attr[3] = "read"; attr[4] = NULL; } ret = property_start_tag (xmlp, "property", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->properties); err = nih_error_get (); TEST_EQ (err->number, PROPERTY_MISSING_NAME); nih_free (err); nih_free (parent); } /* Check that a property with an invalid name results in an * error being raised. */ TEST_FEATURE ("with invalid name"); interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "Test Property"; attr[2] = "type"; attr[3] = "s"; attr[4] = "access"; attr[5] = "readwrite"; attr[6] = NULL; ret = property_start_tag (xmlp, "property", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->properties); err = nih_error_get (); TEST_EQ (err->number, PROPERTY_INVALID_NAME); nih_free (err); nih_free (parent); /* Check that a property with a missing type attribute results * in an error being raised. */ TEST_FEATURE ("with missing type"); interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "TestProperty"; attr[2] = "access"; attr[3] = "read"; attr[4] = NULL; ret = property_start_tag (xmlp, "property", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->properties); err = nih_error_get (); TEST_EQ (err->number, PROPERTY_MISSING_TYPE); nih_free (err); nih_free (parent); /* Check that a property with an invalid type results in an * error being raised. */ TEST_FEATURE ("with invalid type"); interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "TestProperty"; attr[2] = "type"; attr[3] = "si"; attr[4] = "access"; attr[5] = "readwrite"; attr[6] = NULL; ret = property_start_tag (xmlp, "property", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->properties); err = nih_error_get (); TEST_EQ (err->number, PROPERTY_INVALID_TYPE); nih_free (err); nih_free (parent); /* Check that a property with a missing access attribute results * in an error being raised. */ TEST_FEATURE ("with missing access"); interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "TestProperty"; attr[2] = "type"; attr[3] = "s"; attr[4] = NULL; ret = property_start_tag (xmlp, "property", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->properties); err = nih_error_get (); TEST_EQ (err->number, PROPERTY_MISSING_ACCESS); nih_free (err); nih_free (parent); /* Check that a property with an invalid access results in an * error being raised. */ TEST_FEATURE ("with invalid access"); interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "TestProperty"; attr[2] = "type"; attr[3] = "s"; attr[4] = "access"; attr[5] = "sideways"; attr[6] = NULL; ret = property_start_tag (xmlp, "property", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->properties); err = nih_error_get (); TEST_EQ (err->number, PROPERTY_ILLEGAL_ACCESS); nih_free (err); nih_free (parent); /* Check that an unknown property attribute results in a warning * being printed to standard error, but is otherwise ignored * and the normal processing finished. */ TEST_FEATURE ("with unknown attribute"); interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "TestProperty"; attr[2] = "type"; attr[3] = "s"; attr[4] = "access"; attr[5] = "read"; attr[6] = "frodo"; attr[7] = "baggins"; attr[8] = NULL; TEST_DIVERT_STDERR (output) { ret = property_start_tag (xmlp, "property", attr); } rewind (output); TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_PROPERTY); property = entry->property; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, entry); TEST_EQ_STR (property->name, "TestProperty"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_P (property->symbol, NULL); TEST_LIST_EMPTY (&interface->properties); TEST_FILE_EQ (output, ("test:foo:1:0: Ignored unknown attribute: " "frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); /* Check that a property on an empty stack (ie. a top-level * property element) results in a warning being printed on * standard error and an ignored element being pushed onto the * stack. */ TEST_FEATURE ("with empty stack"); attr[0] = "name"; attr[1] = "TestProperty"; attr[2] = "type"; attr[3] = "s"; attr[4] = "access"; attr[5] = "read"; attr[6] = NULL; TEST_DIVERT_STDERR (output) { ret = property_start_tag (xmlp, "property", attr); } rewind (output); TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unexpected tag\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); /* Check that a property on top of a stack entry that's not an * interface results in a warning being printed on * standard error and an ignored element being pushed onto the * stack. */ TEST_FEATURE ("with non-interface on stack"); node = node_new (NULL, NULL); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); attr[0] = "name"; attr[1] = "TestProperty"; attr[2] = "type"; attr[3] = "s"; attr[4] = "access"; attr[5] = "read"; attr[6] = NULL; TEST_DIVERT_STDERR (output) { ret = property_start_tag (xmlp, "property", attr); } rewind (output); TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unexpected tag\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); XML_ParserFree (xmlp); fclose (output); } void test_end_tag (void) { ParseContext context; ParseStack * parent = NULL; ParseStack * entry = NULL; XML_Parser xmlp; Interface * interface = NULL; Property * property = NULL; Property * other = NULL; int ret; NihError * err; TEST_FUNCTION ("property_end_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); /* Check that when we parse the end tag for a property, we pop * the Property object off the stack (freeing and removing it) * and append it to the parent interface's properties list, adding a * reference to the interface as well. A symbol should be generated * for the property by convering its name to C style. */ TEST_FEATURE ("with no assigned symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); entry = parse_stack_push (NULL, &context.stack, PARSE_PROPERTY, property); nih_discard (property); } TEST_FREE_TAG (entry); ret = property_end_tag (xmlp, "property"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->properties); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (property, interface); TEST_LIST_NOT_EMPTY (&interface->properties); TEST_EQ_P (interface->properties.next, &property->entry); TEST_EQ_STR (property->symbol, "test_property"); TEST_ALLOC_PARENT (property->symbol, property); nih_free (parent); } /* Check that when the symbol has been pre-assigned by the data, * it's not overridden and is used even if different. */ TEST_FEATURE ("with assigned symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); property->symbol = nih_strdup (property, "foo"); entry = parse_stack_push (NULL, &context.stack, PARSE_PROPERTY, property); nih_discard (property); } TEST_FREE_TAG (entry); ret = property_end_tag (xmlp, "property"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->properties); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (property, interface); TEST_LIST_NOT_EMPTY (&interface->properties); TEST_EQ_P (interface->properties.next, &property->entry); TEST_EQ_STR (property->symbol, "foo"); TEST_ALLOC_PARENT (property->symbol, property); nih_free (parent); } /* Check that we don't generate a duplicate symbol, and instead * raise an error and allow the user to deal with it using * the Symbol annotation. The reason we don't work around this * with a counter or similar is that the function names then * become unpredicatable (introspection data isn't ordered). */ TEST_FEATURE ("with conflicting symbol"); interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); other = property_new (interface, "Test", "s", NIH_DBUS_READ); other->symbol = nih_strdup (other, "test_property"); nih_list_add (&interface->properties, &other->entry); property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); entry = parse_stack_push (NULL, &context.stack, PARSE_PROPERTY, property); nih_discard (property); ret = property_end_tag (xmlp, "property"); TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, PROPERTY_DUPLICATE_SYMBOL); nih_free (err); nih_free (entry); nih_free (parent); XML_ParserFree (xmlp); } void test_annotation (void) { Property *property = NULL; char * symbol; int ret; NihError *err; TEST_FUNCTION ("property_annotation"); /* Check that the annotation to mark a property as deprecated is * handled, and the Property is marked deprecated. */ TEST_FEATURE ("with deprecated annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); } ret = property_annotation (property, "org.freedesktop.DBus.Deprecated", "true"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_FALSE (property->deprecated); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (property); continue; } TEST_EQ (ret, 0); TEST_TRUE (property->deprecated); nih_free (property); } /* Check that the annotation to mark a property as deprecated can be * given a false value to explicitly mark the Property non-deprecated. */ TEST_FEATURE ("with explicitly non-deprecated annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); property->deprecated = TRUE; } ret = property_annotation (property, "org.freedesktop.DBus.Deprecated", "false"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_TRUE (property->deprecated); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (property); continue; } TEST_EQ (ret, 0); TEST_FALSE (property->deprecated); nih_free (property); } /* Check that an annotation to add a symbol to the property is * handled, and the new symbol is stored in the property. */ TEST_FEATURE ("with symbol annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); } ret = property_annotation (property, "com.netsplit.Nih.Symbol", "foo"); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (property); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (property->symbol, "foo"); TEST_ALLOC_PARENT (property->symbol, property); nih_free (property); } /* Check that an annotation to add a symbol to the property * replaces any previous symbol applied (e.g. by a previous * annotation). */ TEST_FEATURE ("with symbol annotation and existing symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); property->symbol = nih_strdup (property, "test_arg"); } symbol = property->symbol; TEST_FREE_TAG (symbol); ret = property_annotation (property, "com.netsplit.Nih.Symbol", "foo"); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (property); continue; } TEST_EQ (ret, 0); TEST_FREE (symbol); TEST_EQ_STR (property->symbol, "foo"); TEST_ALLOC_PARENT (property->symbol, property); nih_free (property); } /* Check that an invalid value for the deprecated annotation results * in an error being raised. */ TEST_FEATURE ("with invalid value for deprecated annotation"); property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); ret = property_annotation (property, "org.freedesktop.DBus.Deprecated", "foo"); TEST_LT (ret, 0); TEST_EQ_P (property->symbol, NULL); err = nih_error_get (); TEST_EQ (err->number, PROPERTY_ILLEGAL_DEPRECATED); nih_free (err); nih_free (property); /* Check that an invalid symbol in an annotation results in an * error being raised. */ TEST_FEATURE ("with invalid symbol in annotation"); property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); ret = property_annotation (property, "com.netsplit.Nih.Symbol", "foo bar"); TEST_LT (ret, 0); TEST_EQ_P (property->symbol, NULL); err = nih_error_get (); TEST_EQ (err->number, PROPERTY_INVALID_SYMBOL); nih_free (err); nih_free (property); /* Check that an unknown annotation results in an error being * raised. */ TEST_FEATURE ("with unknown annotation"); property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); ret = property_annotation (property, "com.netsplit.Nih.Unknown", "true"); TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, PROPERTY_UNKNOWN_ANNOTATION); nih_free (err); nih_free (property); } void test_lookup (void) { Interface *interface = NULL; Property * property1 = NULL; Property * property2 = NULL; Property * property3 = NULL; Property * ret; TEST_FUNCTION ("property_lookup"); /* Check that the function returns the property if there is one * with the given symbol. */ TEST_FEATURE ("with matching symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); property1 = property_new (interface, "Test", "s", NIH_DBUS_READ); property1->symbol = nih_strdup (property1, "test"); nih_list_add (&interface->properties, &property1->entry); property2 = property_new (interface, "Foo", "s", NIH_DBUS_READ); nih_list_add (&interface->properties, &property2->entry); property3 = property_new (interface, "Bar", "s", NIH_DBUS_READ); property3->symbol = nih_strdup (property3, "bar"); nih_list_add (&interface->properties, &property3->entry); } ret = property_lookup (interface, "bar"); TEST_EQ_P (ret, property3); nih_free (interface); } /* Check that the function returns NULL if there is no property * with the given symbol. */ TEST_FEATURE ("with non-matching symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); property1 = property_new (interface, "Test", "s", NIH_DBUS_READ); property1->symbol = nih_strdup (property1, "test"); nih_list_add (&interface->properties, &property1->entry); property2 = property_new (interface, "Foo", "s", NIH_DBUS_READ); nih_list_add (&interface->properties, &property2->entry); property3 = property_new (interface, "Bar", "s", NIH_DBUS_READ); property3->symbol = nih_strdup (property3, "bar"); nih_list_add (&interface->properties, &property3->entry); } ret = property_lookup (interface, "baz"); TEST_EQ_P (ret, NULL); nih_free (interface); } } static int my_get_property_called = 0; static const char *property_value; int my_get_property (void * data, NihDBusMessage *message, char ** str) { my_get_property_called++; TEST_EQ_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (str, NULL); if (! strcmp (property_value, "felch and firkin")) { nih_dbus_error_raise ("com.netsplit.Nih.MyProperty.Fail", "Bad value for property"); return -1; } else if (! strcmp (property_value, "fruitbat and ball")) { nih_error_raise (EBADF, strerror (EBADF)); return -1; } else { *str = nih_strdup (message, property_value); if (! *str) nih_return_no_memory_error (-1); } return 0; } void test_object_get_function (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihList prototypes; NihList handlers; NihList structs; Interface * interface = NULL; Property * property = NULL; char * iface; char * name; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; NihListEntry * attrib; DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter subiter; DBusMessage * reply; NihDBusMessage * message = NULL; NihDBusObject * object = NULL; dbus_uint32_t serial; int ret; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("property_object_get_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that marshals a value * obtained by calling a property handler function into a variant * appended to the message iterator passed. */ TEST_FEATURE ("with property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); } str = property_object_get_function (NULL, "my", interface, property, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_object_get_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_property_get"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_get_property"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can generate a function that marshals a structure * value obtained by calling a property handler function, with * the structure type passed back in the structs array. */ TEST_FEATURE ("with structure property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "(su)", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); } str = property_object_get_function (NULL, "my", interface, property, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_object_get_function_structure.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_property_get"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_get_property"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyProperty **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyProperty"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can use the generated code to get the value of a * property for a reply we're generating. The handler function * should be called and the value appended to our message inside * a variant. */ TEST_FEATURE ("with property (generated code)"); TEST_ALLOC_FAIL { property_value = "dog and doughnut"; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "org.freedesktop.DBus.Properties", "Get"); dbus_message_iter_init_append (method_call, &iter); iface = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface); name = "property"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } reply = dbus_message_new_method_return (method_call); dbus_message_iter_init_append (reply, &iter); my_get_property_called = 0; ret = my_com_netsplit_Nih_Test_property_get (object, message, &iter); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); dbus_message_unref (reply); nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_get_property_called); TEST_EQ (ret, 0); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str); TEST_EQ_STR (str, "dog and doughnut"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that our function can return a D-Bus error and the * generated code simply returns that upwards. */ TEST_FEATURE ("with D-Bus error from handler (generated code)"); TEST_ALLOC_FAIL { property_value = "felch and firkin"; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "org.freedesktop.DBus.Properties", "Get"); dbus_message_iter_init_append (method_call, &iter); iface = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface); name = "property"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } reply = dbus_message_new_method_return (method_call); dbus_message_iter_init_append (reply, &iter); my_get_property_called = 0; ret = my_com_netsplit_Nih_Test_property_get (object, message, &iter); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); dbus_message_unref (reply); nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_get_property_called); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.MyProperty.Fail"); TEST_EQ_STR (err->message, "Bad value for property"); nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that our function can return a generic error and the * generated code simply returns that upwards. */ TEST_FEATURE ("with generic error from handler (generated code)"); TEST_ALLOC_FAIL { property_value = "fruitbat and ball"; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "org.freedesktop.DBus.Properties", "Get"); dbus_message_iter_init_append (method_call, &iter); iface = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface); name = "property"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } reply = dbus_message_new_method_return (method_call); dbus_message_iter_init_append (reply, &iter); my_get_property_called = 0; ret = my_com_netsplit_Nih_Test_property_get (object, message, &iter); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); dbus_message_unref (reply); nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_get_property_called); TEST_EQ (err->number, EBADF); TEST_EQ_STR (err->message, strerror (EBADF)); nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that when we generate a function for a deprecated * property, we don't include the attribute since we don't * want gcc warnings when implementing an object. */ TEST_FEATURE ("with deprecated property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); property->deprecated = TRUE; } str = property_object_get_function (NULL, "my", interface, property, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_object_get_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_property_get"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_get_property"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int my_set_property_called = 0; int my_set_property (void * data, NihDBusMessage *message, const char * str) { nih_local char *dup = NULL; my_set_property_called++; TEST_EQ_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_ALLOC_PARENT (str, message); if (! strcmp (str, "dog and doughnut")) { dup = nih_strdup (NULL, str); if (! dup) nih_return_no_memory_error (-1); return 0; } else if (! strcmp (str, "felch and firkin")) { nih_dbus_error_raise ("com.netsplit.Nih.MyProperty.Fail", "Bad value for property"); return -1; } else if (! strcmp (str, "fruitbat and ball")) { nih_error_raise (EBADF, strerror (EBADF)); return -1; } return 0; } void test_object_set_function (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihList prototypes; NihList handlers; NihList structs; Interface * interface = NULL; Property * property = NULL; char * iface; char * name; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; NihListEntry * attrib; double double_arg; DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter subiter; NihDBusMessage * message = NULL; NihDBusObject * object = NULL; dbus_uint32_t serial; int ret; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("property_object_set_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that demarshals a value * from a variant in the passed message iterator, calls a handler * function to set that property and returns to indicate success * or error. */ TEST_FEATURE ("with property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); } str = property_object_set_function (NULL, "my", interface, property, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_object_set_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_property_set"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_set_property"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can use the generated code to demarshal the * property value from inside the variant in the method call, * passing it to the handler function. */ TEST_FEATURE ("with property (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "org.freedesktop.DBus.Properties", "Set"); dbus_message_iter_init_append (method_call, &iter); iface = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface); name = "property"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str = "dog and doughnut"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } dbus_message_iter_init (method_call, &iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_VARIANT); my_set_property_called = 0; ret = my_com_netsplit_Nih_Test_property_set (object, message, &iter); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_set_property_called); TEST_EQ (ret, 0); nih_free (object); nih_free (message); dbus_message_unref (method_call); } /* Check that we can generate a function that demarshals a * structure value from a variant in the passed message iterator, * calling a handler function to set that property, with the * structure type passed back in the structs array. */ TEST_FEATURE ("with structure property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "(su)", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); } str = property_object_set_function (NULL, "my", interface, property, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_object_set_function_structure.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_property_set"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_set_property"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyProperty *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyProperty"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that if the handler raises a D-Bus error, it is returned * to the caller. */ TEST_FEATURE ("with D-Bus error from handler (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "org.freedesktop.DBus.Properties", "Set"); dbus_message_iter_init_append (method_call, &iter); iface = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface); name = "property"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str = "felch and firkin"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } dbus_message_iter_init (method_call, &iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_VARIANT); my_set_property_called = 0; ret = my_com_netsplit_Nih_Test_property_set (object, message, &iter); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_set_property_called); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.MyProperty.Fail"); nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (method_call); } /* Check that if the handler raises a generic error, it is returned * to the caller. */ TEST_FEATURE ("with generic error from handler (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "org.freedesktop.DBus.Properties", "Set"); dbus_message_iter_init_append (method_call, &iter); iface = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface); name = "property"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str = "fruitbat and ball"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } dbus_message_iter_init (method_call, &iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_VARIANT); my_set_property_called = 0; ret = my_com_netsplit_Nih_Test_property_set (object, message, &iter); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_set_property_called); TEST_EQ (err->number, EBADF); nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (method_call); } /* Check that a missing argument to the property method call * results in an invalid args error message being returned * without the handler being called. */ TEST_FEATURE ("with missing argument to method (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "org.freedesktop.DBus.Properties", "Set"); dbus_message_iter_init_append (method_call, &iter); iface = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface); name = "property"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } dbus_message_iter_init (method_call, &iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); my_set_property_called = 0; ret = my_com_netsplit_Nih_Test_property_set (object, message, &iter); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_FALSE (my_set_property_called); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_INVALID_ARGS); nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (method_call); } /* Check that a non-variant type in the property method call * results in an invalid args error message being returned * without the handler being called. */ TEST_FEATURE ("with invalid argument in method (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "org.freedesktop.DBus.Properties", "Set"); dbus_message_iter_init_append (method_call, &iter); iface = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface); name = "property"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name); double_arg = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_arg); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } dbus_message_iter_init (method_call, &iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); my_set_property_called = 0; ret = my_com_netsplit_Nih_Test_property_set (object, message, &iter); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_FALSE (my_set_property_called); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_INVALID_ARGS); nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (method_call); } /* Check that the wrong type in the variant in the property method call * results in an invalid args error message being returned without * the handler being called. */ TEST_FEATURE ("with invalid variant item in method (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "org.freedesktop.DBus.Properties", "Set"); dbus_message_iter_init_append (method_call, &iter); iface = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface); name = "property"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_arg = 3.14; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_arg); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } dbus_message_iter_init (method_call, &iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); my_set_property_called = 0; ret = my_com_netsplit_Nih_Test_property_set (object, message, &iter); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_FALSE (my_set_property_called); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_INVALID_ARGS); nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (method_call); } /* Check that an extra argument to the property method call * results in an invalid args error message being returned * without the handler being called. */ TEST_FEATURE ("with extra argument to method (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "org.freedesktop.DBus.Properties", "Set"); dbus_message_iter_init_append (method_call, &iter); iface = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface); name = "property"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str = "dog and doughnut"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str); dbus_message_iter_close_container (&iter, &subiter); double_arg = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_arg); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } dbus_message_iter_init (method_call, &iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING); dbus_message_iter_next (&iter); my_set_property_called = 0; ret = my_com_netsplit_Nih_Test_property_set (object, message, &iter); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_FALSE (my_set_property_called); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_INVALID_ARGS); nih_free (err); nih_free (object); nih_free (message); dbus_message_unref (method_call); } /* Check that a deprecated property does not have the attribute * added, since we don't want gcc warnings when implementing * objects. */ TEST_FEATURE ("with deprecated property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); property->deprecated = TRUE; } str = property_object_set_function (NULL, "my", interface, property, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_object_set_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_property_set"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_set_property"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } int my_com_netsplit_Nih_Test_test_property_get_notify_called = FALSE; static DBusPendingCall * last_pending_call = NULL; static NihDBusPendingData *last_pending_data = NULL; void my_com_netsplit_Nih_Test_test_property_get_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { my_com_netsplit_Nih_Test_test_property_get_notify_called = TRUE; last_pending_call = pending_call; last_pending_data = pending_data; } static void my_blank_get_handler (void * data, NihDBusMessage *message, const char * value) { } static void my_blank_error_handler (void * data, NihDBusMessage *message) { } void test_proxy_get_function (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihList prototypes; NihList structs; Interface * interface = NULL; Property * property = NULL; char * str; TypeFunc * func; TypeVar * arg; NihListEntry * attrib; DBusConnection * flakey_conn; NihDBusProxy * proxy = NULL; DBusPendingCall * pending_call; DBusMessage * method_call; DBusMessage * reply; DBusMessageIter iter; DBusMessageIter subiter; char * str_value; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("property_proxy_get_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that makes a method call * to obtain the value of a D-Bus property and returns the pending * call structure. */ TEST_FEATURE ("with property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "test_property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "test_property"); } str = property_proxy_get_function (NULL, "my", interface, property, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_get_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_get_test_property"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyGetTestPropertyReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can use the generated code to make a method call * to obtain the value of a property. The function should return * a DBusPendingCall object and we should receive the method call * on the other side. Returning the reply and blocking the call * should result in our notify function being called with the * pending call that was returned and the pending data with the * expected information. */ TEST_FEATURE ("with property (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_Test_test_property_get_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_get_test_property (proxy, my_blank_get_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Get")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test_property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "wibble"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Block the pending call until we receive the reply */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_com_netsplit_Nih_Test_test_property_get_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_get_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the notify function is still called when the server * returns an error; strictly speaking we're testing D-Bus here, * but let's be complete about the whole thing - besides, it's * good documentation for how things should behave */ TEST_FEATURE ("with error reply (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_Test_test_property_get_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_get_test_property (proxy, my_blank_get_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Get")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test_property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_error (method_call, "com.netsplit.Nih.MyProperty.Fail", "Things didn't work out"); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Block the pending call until we receive the reply */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.MyProperty.Fail")); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_com_netsplit_Nih_Test_test_property_get_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_get_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the pending call will fail if the timeout is reached, * with the notify function being called for the timeout error. */ TEST_FEATURE ("with timeout (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_Test_test_property_get_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_get_test_property (proxy, my_blank_get_handler, my_blank_error_handler, &proxy, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Get")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test_property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (method_call); /* Block the pending call until timeout */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_NO_REPLY)); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_com_netsplit_Nih_Test_test_property_get_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_get_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the pending call will fail if the remote end * disconnects. The notify function will be called with the no * reply error. */ TEST_FEATURE ("with server disconnection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_Test_test_property_get_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_get_test_property (proxy, my_blank_get_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (flakey_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Get")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test_property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (method_call); /* Close the server connection */ TEST_DBUS_CLOSE (flakey_conn); /* Block the pending call until timeout */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_NO_REPLY)); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_com_netsplit_Nih_Test_test_property_get_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_get_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the pending call can be cancelled by the user. * The notify function should not be called, but the data it * contains should be freed (check valgrind). */ TEST_FEATURE ("with cancelled call (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_Test_test_property_get_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_get_test_property (proxy, my_blank_get_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Get")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test_property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send a reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Cancel the pending call */ dbus_pending_call_cancel (pending_call); dbus_pending_call_unref (pending_call); /* Dispatch until we receive a message */ TEST_DBUS_DISPATCH (client_conn); /* Check the notify function was not called. */ TEST_FALSE (my_com_netsplit_Nih_Test_test_property_get_notify_called); nih_free (proxy); } /* Check that when the remote end is not connected, the function * returns NULL and raises the disconnected D-Bus error. */ TEST_FEATURE ("with unconnected connection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } TEST_DBUS_CLOSE (flakey_conn); my_com_netsplit_Nih_Test_test_property_get_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_get_test_property (proxy, my_blank_get_handler, my_blank_error_handler, &proxy, -1); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (my_com_netsplit_Nih_Test_test_property_get_notify_called); nih_free (proxy); } /* Check that a deprecated property has its get function annotated * with the deprecated attribute so that the client gets a gcc * warning if they use it. */ TEST_FEATURE ("with deprecated property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "test_property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "test_property"); property->deprecated = TRUE; } str = property_proxy_get_function (NULL, "my", interface, property, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_get_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_get_test_property"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyGetTestPropertyReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "deprecated"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static void my_error_handler (void *data, NihDBusMessage *message); static int my_get_property_handler_called = FALSE; static int my_error_handler_called = FALSE; static NihDBusMessage *last_message = NULL; static DBusConnection *last_conn = NULL; static DBusMessage *last_msg = NULL; static NihError *last_error = NULL; static void my_get_property_handler (void * data, NihDBusMessage *message, const char * value) { my_get_property_handler_called++; TEST_EQ_P (data, (void *)my_error_handler); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_message = message; TEST_FREE_TAG (last_message); last_conn = message->connection; dbus_connection_ref (last_conn); last_msg = message->message; dbus_message_ref (last_msg); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); TEST_EQ_STR (value, "wibble"); } static void my_error_handler (void * data, NihDBusMessage *message) { my_error_handler_called++; TEST_EQ_P (data, (void *)my_error_handler); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_message = message; TEST_FREE_TAG (last_message); last_conn = message->connection; dbus_connection_ref (last_conn); last_msg = message->message; dbus_message_ref (last_msg); last_error = nih_error_steal (); TEST_NE_P (last_error, NULL); } void test_proxy_get_notify_function (void) { pid_t dbus_pid; NihList prototypes; NihList typedefs; NihList structs; Interface * interface = NULL; Property * property = NULL; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; DBusConnection * server_conn; DBusConnection * client_conn; DBusConnection * flakey_conn; dbus_uint32_t serial; DBusPendingCall * pending_call; NihDBusPendingData *pending_data = NULL; DBusMessage * method_call; DBusMessage * reply; DBusMessageIter iter; DBusMessageIter subiter; char * str_value; double double_value; NihDBusError * dbus_err; TEST_FUNCTION ("property_proxy_get_notify_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that takes a pending call * and pending data structure, stealing the D-Bus message and * demarshalling the property value from the variant argument * before making a call to either the handler for a valid reply * or error handler for an invalid reply. The typedef for the * handler function is returned in addition to the prototype. */ TEST_FEATURE ("with property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); } str = property_proxy_get_notify_function (NULL, "my", interface, property, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_get_notify_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_property_get_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyGetPropertyReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can generate a notify function for a structure * property, with the structure type passed back in the structs * array. */ TEST_FEATURE ("with structure property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "(su)", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); } str = property_proxy_get_notify_function (NULL, "my", interface, property, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_get_notify_function_structure.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_property_get_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyGetPropertyReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyProperty *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyProperty"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can use the generated code to handle a completed * pending call, demarshalling the property value from the variant in * the reply and passing it to our handler. */ TEST_FEATURE ("with reply (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "wibble"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_property_handler, my_error_handler, (void *)my_error_handler); } my_get_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_get_notify (pending_call, pending_data); TEST_TRUE (my_get_property_handler_called); TEST_FALSE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that we can use the generated code to handle an error * reply, passing it to the error handler as a raised error * instead of calling the usual handler. */ TEST_FEATURE ("with error reply (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_error (method_call, "com.netsplit.Nih.MyProperty.Fail", "Things didn't work out"); dbus_message_unref (method_call); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_property_handler, my_error_handler, (void *)my_error_handler); } my_get_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_get_notify (pending_call, pending_data); TEST_FALSE (my_get_property_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.MyProperty.Fail"); TEST_EQ_STR (last_error->message, "Things didn't work out"); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches a timeout of the pending * call and runs the error handler with the D-Bus timeout error * raised. */ TEST_FEATURE ("with timeout (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); dbus_message_unref (method_call); /* Wait for timeout */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_property_handler, my_error_handler, (void *)my_error_handler); } my_get_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_get_notify (pending_call, pending_data); TEST_FALSE (my_get_property_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches disconnection of the * remote end during a pending call call and runs the error handler * with the D-Bus timeout error raised. */ TEST_FEATURE ("with disconnection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (flakey_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); dbus_message_unref (method_call); TEST_DBUS_CLOSE (flakey_conn); /* Wait for error */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_property_handler, my_error_handler, (void *)my_error_handler); } my_get_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_get_notify (pending_call, pending_data); TEST_FALSE (my_get_property_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches an invalid argument type in * the variant and calls the error handler with the invalid arguments * error raised. */ TEST_FEATURE ("with incorrect variant member type (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_value = 3.14; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_property_handler, my_error_handler, (void *)my_error_handler); } my_get_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_get_notify (pending_call, pending_data); TEST_FALSE (my_get_property_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches an invalid argument type in * the reply and calls the error handler with the invalid arguments * error raised. */ TEST_FEATURE ("with incorrect argument type (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); str_value = "wibble"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_property_handler, my_error_handler, (void *)my_error_handler); } my_get_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_get_notify (pending_call, pending_data); TEST_FALSE (my_get_property_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches a missing argument in * the reply and calls the error handler with the invalid arguments * error raised. */ TEST_FEATURE ("with missing argument (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_property_handler, my_error_handler, (void *)my_error_handler); } my_get_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_get_notify (pending_call, pending_data); TEST_FALSE (my_get_property_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches an extra argument in * the reply and calls the error handler with the invalid arguments * error raised. */ TEST_FEATURE ("with extra argument (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "wibble"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_get_property_handler, my_error_handler, (void *)my_error_handler); } my_get_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_get_notify (pending_call, pending_data); TEST_FALSE (my_get_property_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated function for a deprecated property is * not marked deprecated, since it's implementation. */ TEST_FEATURE ("with deprecated property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); property->deprecated = TRUE; } str = property_proxy_get_notify_function (NULL, "my", interface, property, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_get_notify_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_property_get_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyGetPropertyReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } int my_com_netsplit_Nih_Test_test_property_set_notify_called = FALSE; void my_com_netsplit_Nih_Test_test_property_set_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { my_com_netsplit_Nih_Test_test_property_set_notify_called = TRUE; last_pending_call = pending_call; last_pending_data = pending_data; } static void my_blank_set_handler (void * data, NihDBusMessage *message) { } void test_proxy_set_function (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihList prototypes; NihList structs; Interface * interface = NULL; Property * property = NULL; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; NihListEntry * attrib; DBusConnection * flakey_conn; NihDBusProxy * proxy = NULL; DBusPendingCall * pending_call; DBusMessage * method_call; DBusMessage * reply; DBusMessageIter iter; DBusMessageIter subiter; char * str_value; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("property_proxy_set_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that makes a method call * to set the value of a D-Bus property and returns the pending * call structure. */ TEST_FEATURE ("with property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "test_property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "test_property"); } str = property_proxy_set_function (NULL, "my", interface, property, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_set_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_set_test_property"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MySetTestPropertyReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can generate a function for a structure property, * with the structure type passed back in the structs array. */ TEST_FEATURE ("with structure property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "test_property", "(su)", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "test_property"); } str = property_proxy_set_function (NULL, "my", interface, property, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_set_function_structure.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_set_test_property"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestProperty *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MySetTestPropertyReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestProperty"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that an array argument may be NULL if the length argument * is zero. */ TEST_FEATURE ("with array property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "test_property", "ai", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "test_property"); } str = property_proxy_set_function (NULL, "my", interface, property, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_set_function_array.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_set_test_property"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const int32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "size_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value_len"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MySetTestPropertyReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can use the generated code to make a method call * to set the value of a property. The function should return * a DBusPendingCall object and we should receive the method call * on the other side. Returning the reply and blocking the call * should result in our notify function being called with the * pending call that was returned and the pending data with the * expected information. */ TEST_FEATURE ("with property (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_Test_test_property_set_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_set_test_property (proxy, "wibble", my_blank_set_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Set")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test_property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "wibble"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Block the pending call until we receive the reply */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_com_netsplit_Nih_Test_test_property_set_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_set_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the handler argument to the generated function * may be NULL, since there's no useful information in there that * isn't conveyed by a separate error reply (other than the success). * The pending call should still be generated, and the message still * expecting a reply, just the handler missing from the data (which * tells the notify function to do everything but call it). */ TEST_FEATURE ("with no handler (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_Test_test_property_set_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_set_test_property (proxy, "wibble", NULL, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Set")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test_property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "wibble"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Block the pending call until we receive the reply */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_com_netsplit_Nih_Test_test_property_set_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, NULL); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that both the handler and error handler arguments may * be set to NULL for a fire-and-forget method call in which * we don't care about the success or failure of setting the * property. The method call is flagged to expect no reply, * and we don't ever call the notify function. */ TEST_FEATURE ("with no reply expected (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_Test_test_property_set_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_set_test_property (proxy, "wibble", NULL, NULL, NULL, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_EQ_P (pending_call, (void *)TRUE); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Set")); TEST_TRUE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test_property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "wibble"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send a reply anyway */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Dispatch until we receive a message */ TEST_DBUS_DISPATCH (client_conn); /* Check the notify function was not called. */ TEST_FALSE (my_com_netsplit_Nih_Test_test_property_set_notify_called); nih_free (proxy); } /* Check that the notify function is still called when the server * returns an error; strictly speaking we're testing D-Bus here, * but let's be complete about the whole thing - besides, it's * good documentation for how things should behave */ TEST_FEATURE ("with error reply (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_Test_test_property_set_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_set_test_property (proxy, "wibble", my_blank_set_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Set")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test_property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "wibble"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_error (method_call, "com.netsplit.Nih.MyProperty.Fail", "Things didn't work out"); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Block the pending call until we receive the reply */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.MyProperty.Fail")); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_com_netsplit_Nih_Test_test_property_set_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_set_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the pending call will fail if the timeout is reached, * with the notify function being called for the timeout error. */ TEST_FEATURE ("with timeout (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_Test_test_property_set_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_set_test_property (proxy, "wibble", my_blank_set_handler, my_blank_error_handler, &proxy, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Set")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test_property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "wibble"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (method_call); /* Block the pending call until timeout */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_NO_REPLY)); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_com_netsplit_Nih_Test_test_property_set_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_set_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the pending call will fail if the remote end * disconnects. The notify function will be called with the no * reply error. */ TEST_FEATURE ("with server disconnection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_Test_test_property_set_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_set_test_property (proxy, "wibble", my_blank_set_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (flakey_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Set")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test_property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "wibble"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (method_call); /* Close the server connection */ TEST_DBUS_CLOSE (flakey_conn); /* Block the pending call until timeout */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_NO_REPLY)); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_com_netsplit_Nih_Test_test_property_set_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_set_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the pending call can be cancelled by the user. * The notify function should not be called, but the data it * contains should be freed (check valgrind). */ TEST_FEATURE ("with cancelled call (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_com_netsplit_Nih_Test_test_property_set_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_set_test_property (proxy, "wibble", my_blank_set_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Set")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test_property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "wibble"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send a reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Cancel the pending call */ dbus_pending_call_cancel (pending_call); dbus_pending_call_unref (pending_call); /* Dispatch until we receive a message */ TEST_DBUS_DISPATCH (client_conn); /* Check the notify function was not called. */ TEST_FALSE (my_com_netsplit_Nih_Test_test_property_set_notify_called); nih_free (proxy); } /* Check that when the remote end is not connected, the function * returns NULL and raises the disconnected D-Bus error. */ TEST_FEATURE ("with unconnected connection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } TEST_DBUS_CLOSE (flakey_conn); my_com_netsplit_Nih_Test_test_property_set_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_set_test_property (proxy, "wibble", my_blank_set_handler, my_blank_error_handler, &proxy, -1); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (my_com_netsplit_Nih_Test_test_property_set_notify_called); nih_free (proxy); } /* Check that a deprecated property has its get function annotated * with the deprecated attribute so that the client gets a gcc * warning if they use it. */ TEST_FEATURE ("with deprecated property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "test_property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "test_property"); property->deprecated = TRUE; } str = property_proxy_set_function (NULL, "my", interface, property, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_set_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_set_test_property"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MySetTestPropertyReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "deprecated"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int my_set_property_handler_called = FALSE; static void my_set_property_handler (void * data, NihDBusMessage *message) { my_set_property_handler_called++; TEST_EQ_P (data, (void *)my_error_handler); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_message = message; TEST_FREE_TAG (last_message); last_conn = message->connection; dbus_connection_ref (last_conn); last_msg = message->message; dbus_message_ref (last_msg); } void test_proxy_set_notify_function (void) { pid_t dbus_pid; NihList prototypes; NihList typedefs; NihList structs; Interface * interface = NULL; Property * property = NULL; char * str; TypeFunc * func; TypeVar * arg; DBusConnection * server_conn; DBusConnection * client_conn; DBusConnection * flakey_conn; dbus_uint32_t serial; DBusPendingCall * pending_call; NihDBusPendingData *pending_data = NULL; DBusMessage * method_call; DBusMessage * reply; DBusMessageIter iter; double double_value; NihDBusError * dbus_err; TEST_FUNCTION ("property_proxy_set_notify_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that takes a pending call * and pending data structure, stealing the D-Bus message and * before making a call to either the handler for a valid reply * or error handler for an invalid reply. The typedef for the * handler function is returned in addition to the prototype. */ TEST_FEATURE ("with property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); } str = property_proxy_set_notify_function (NULL, "my", interface, property, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_set_notify_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_property_set_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MySetPropertyReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can use the generated code to handle a completed * pending call, checking the reply has no arguments before passing * it to our handler. */ TEST_FEATURE ("with reply (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_set_property_handler, my_error_handler, (void *)my_error_handler); } my_set_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_set_notify (pending_call, pending_data); TEST_TRUE (my_set_property_handler_called); TEST_FALSE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Since there's no useful information in the reply, we allow * it to be omitted (thus only requiring the error handler), * check that in this case the function is not called. */ TEST_FEATURE ("with no handler (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, NULL, my_error_handler, (void *)my_error_handler); } my_set_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_set_notify (pending_call, pending_data); TEST_FALSE (my_set_property_handler_called); TEST_FALSE (my_error_handler_called); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that we can use the generated code to handle an error * reply, passing it to the error handler as a raised error * instead of calling the usual handler. */ TEST_FEATURE ("with error reply (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_error (method_call, "com.netsplit.Nih.MyProperty.Fail", "Things didn't work out"); dbus_message_unref (method_call); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_set_property_handler, my_error_handler, (void *)my_error_handler); } my_set_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_set_notify (pending_call, pending_data); TEST_FALSE (my_set_property_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.MyProperty.Fail"); TEST_EQ_STR (last_error->message, "Things didn't work out"); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches a timeout of the pending * call and runs the error handler with the D-Bus timeout error * raised. */ TEST_FEATURE ("with timeout (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); dbus_message_unref (method_call); /* Wait for timeout */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_set_property_handler, my_error_handler, (void *)my_error_handler); } my_set_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_set_notify (pending_call, pending_data); TEST_FALSE (my_set_property_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches disconnection of the * remote end during a pending call call and runs the error handler * with the D-Bus timeout error raised. */ TEST_FEATURE ("with disconnection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (flakey_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); dbus_message_unref (method_call); TEST_DBUS_CLOSE (flakey_conn); /* Wait for error */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_set_property_handler, my_error_handler, (void *)my_error_handler); } my_set_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_set_notify (pending_call, pending_data); TEST_FALSE (my_set_property_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches an unexpected argument in * the reply and calls the error handler with the invalid arguments * error raised. */ TEST_FEATURE ("with unexpected argument (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_set_property_handler, my_error_handler, (void *)my_error_handler); } my_set_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_set_notify (pending_call, pending_data); TEST_FALSE (my_set_property_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that an unexpected argument is still caught even if no * reply handler has been specified. */ TEST_FEATURE ("with unexpected argument and no handler (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, NULL, my_error_handler, (void *)my_error_handler); } my_set_property_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_property_set_notify (pending_call, pending_data); TEST_FALSE (my_set_property_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated function for a deprecated property is * not marked deprecated, since it's implementation. */ TEST_FEATURE ("with deprecated property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); property->deprecated = TRUE; } str = property_proxy_set_notify_function (NULL, "my", interface, property, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_set_notify_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_property_set_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MySetPropertyReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_proxy_get_sync_function (void) { pid_t dbus_pid; DBusConnection *server_conn; DBusConnection *client_conn; DBusConnection *flakey_conn; NihList prototypes; NihList structs; Interface * interface = NULL; Property * property = NULL; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; NihListEntry * attrib; NihDBusProxy * proxy = NULL; void * parent = NULL; pid_t pid; int status; DBusMessage * method_call; DBusMessage * reply; DBusMessageIter iter; DBusMessageIter subiter; char * str_value; double double_value; int ret; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("property_proxy_get_sync_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that will make a method * call to obtain the value of a property and return it in the * pointer argument supplied. The function returns an integer * to indicate success. */ TEST_FEATURE ("with property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); } str = property_proxy_get_sync_function (NULL, "my", interface, property, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_get_sync_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_get_property_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can generate a function that will make a method * call to obtain the value of a property and return it in the * pointer argument supplied. The function returns an integer * to indicate success. */ TEST_FEATURE ("with structure property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "(su)", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); } str = property_proxy_get_sync_function (NULL, "my", interface, property, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_get_sync_function_structure.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_get_property_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyProperty **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyProperty"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can use the generated code to make a method call * and obtain the value of the property. */ TEST_FEATURE ("with method call (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Get")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "wibble"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } str_value = NULL; ret = my_get_property_sync (parent, proxy, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (str_value, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (ret, 0); TEST_NE_P (str_value, NULL); TEST_ALLOC_PARENT (str_value, parent); TEST_EQ_STR (str_value, "wibble"); nih_free (proxy); } /* Check that the generated code handles an error returned from * the property get function, returning a raised error. */ TEST_FEATURE ("with error returned (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Get")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_error (method_call, "com.netsplit.Nih.Failed", "Didn't work out"); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } str_value = NULL; ret = my_get_property_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (str_value, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Failed"); TEST_EQ_STR (err->message, "Didn't work out"); nih_free (err); TEST_EQ_P (str_value, NULL); nih_free (proxy); } /* Check that the generated code returns a raised disconnected * error when called on a disconnected connection. */ TEST_FEATURE ("with disconnected connection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } TEST_DBUS_CLOSE (flakey_conn); str_value = NULL; ret = my_get_property_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); TEST_EQ_P (str_value, NULL); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_EQ_P (str_value, NULL); nih_free (proxy); } /* Check that an incorrect type in the variant results in the * function returning a raised error. */ TEST_FEATURE ("with incorrect type in variant (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Get")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_value = 3.14; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } str_value = NULL; ret = my_get_property_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (str_value, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); TEST_EQ_P (str_value, NULL); nih_free (proxy); } /* Check that an incorrect type in the arguments results in the * function returning a raised error. */ TEST_FEATURE ("with incorrect type (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Get")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } str_value = NULL; ret = my_get_property_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (str_value, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); TEST_EQ_P (str_value, NULL); nih_free (proxy); } /* Check that a missing argument results in the function * returning a raised error. */ TEST_FEATURE ("with missing argument (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Get")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } str_value = NULL; ret = my_get_property_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (str_value, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); TEST_EQ_P (str_value, NULL); nih_free (proxy); } /* Check that an extra arguments results in the function * returning a raised error. */ TEST_FEATURE ("with extra argument (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Get")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "wibble"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } str_value = NULL; ret = my_get_property_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (str_value, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); TEST_EQ_P (str_value, NULL); nih_free (proxy); } /* Check that a deprecated property has the deprecated attribute * added to its function prototype, since we want to warn about * client code using them. */ TEST_FEATURE ("with deprecated property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); property->deprecated = TRUE; } str = property_proxy_get_sync_function (NULL, "my", interface, property, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_get_sync_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_get_property_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "deprecated"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_proxy_set_sync_function (void) { pid_t dbus_pid; DBusConnection *server_conn; DBusConnection *client_conn; DBusConnection *flakey_conn; NihList prototypes; NihList structs; Interface * interface = NULL; Property * property = NULL; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; NihListEntry * attrib; NihDBusProxy * proxy = NULL; void * parent = NULL; pid_t pid = -1; int status; DBusMessage * method_call; DBusMessage * reply; DBusMessageIter iter; DBusMessageIter subiter; char * str_value; double double_value; int ret; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("property_proxy_set_sync_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that will make a method * call to set the value of a property, returning an integer to * indicate success. */ TEST_FEATURE ("with property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); } str = property_proxy_set_sync_function (NULL, "my", interface, property, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_set_sync_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_set_property_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can generate a function for a structure property, * with the structure type passed back in the structs array. */ TEST_FEATURE ("with structure property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "(su)", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); } str = property_proxy_set_sync_function (NULL, "my", interface, property, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_set_sync_function_structure.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_set_property_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyProperty *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyProperty"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that an array property argument may be NULL if the length * of the array is zero. */ TEST_FEATURE ("with array property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "ai", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); } str = property_proxy_set_sync_function (NULL, "my", interface, property, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_set_sync_function_array.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_set_property_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const int32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "size_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value_len"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } /* Check that we can use the generated code to make a method call * and set the value of the property. */ TEST_FEATURE ("with method call (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Set")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "wibble"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } ret = my_set_property_sync (NULL, proxy, "wibble"); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (str_value, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (ret, 0); nih_free (proxy); } /* Check that the generated code handles an error returned from * the property get function, returning a raised error. */ TEST_FEATURE ("with error returned (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Set")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "wibble"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_error (method_call, "com.netsplit.Nih.Failed", "Didn't work out"); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } ret = my_set_property_sync (NULL, proxy, "wibble"); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (str_value, NULL); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Failed"); TEST_EQ_STR (err->message, "Didn't work out"); nih_free (err); nih_free (proxy); } /* Check that the generated code returns a raised disconnected * error when called on a disconnected connection. */ TEST_FEATURE ("with disconnected connection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = my_set_property_sync (NULL, proxy, "wibble"); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (proxy); } /* Check that an extra arguments results in the function * returning a raised error. */ TEST_FEATURE ("with extra argument (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, DBUS_INTERFACE_PROPERTIES, "Set")); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "com.netsplit.Nih.Test"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "property"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "wibble"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } ret = my_set_property_sync (NULL, proxy, "wibble"); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); nih_free (proxy); } /* Check that a deprecated property has the deprecated attribute * added to its function prototype, since we want to warn against * client code using this. */ TEST_FEATURE ("with deprecated property"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (NULL, "property", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "property"); property->deprecated = TRUE; } str = property_proxy_set_sync_function (NULL, "my", interface, property, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (property); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_property_proxy_set_sync_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_set_property_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "deprecated"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (property); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } int main (int argc, char *argv[]) { program_name = "test"; nih_error_init (); test_name_valid (); test_new (); test_start_tag (); test_end_tag (); test_annotation (); test_lookup (); test_object_get_function (); test_object_set_function (); test_proxy_get_function (); test_proxy_get_notify_function (); test_proxy_set_function (); test_proxy_set_notify_function (); test_proxy_get_sync_function (); test_proxy_set_sync_function (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/test_node.c0000644000175000017500000166173611445765555015724 00000000000000/* nih-dbus-tool * * test_node.c - test suite for nih-dbus-tool/node.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include "type.h" #include "node.h" #include "interface.h" #include "parse.h" #include "errors.h" void test_path_valid (void) { TEST_FUNCTION ("node_path_valid"); /* Check that a typical node path is valid. */ TEST_FEATURE ("with typical node path"); TEST_TRUE (node_path_valid ("/com/netsplit/Nih/Test")); /* Check that an node path is not valid if it is missing the first * slash. */ TEST_FEATURE ("without first slash"); TEST_FALSE (node_path_valid ("com/netsplit/Nih/Test")); /* Check that an node path is not valid if it has multiple * consecutive slashes. */ TEST_FEATURE ("with consecutive slashes"); TEST_FALSE (node_path_valid ("/com//netsplit/Nih/Test")); /* Check that an node path is not valid if it ends in a slash. */ TEST_FEATURE ("with final slash"); TEST_FALSE (node_path_valid ("/com/netsplit/Nih/Test/")); /* Check that the root node path is valid */ TEST_FEATURE ("with root node path"); TEST_TRUE (node_path_valid ("/")); /* Check that a node path elements may contain numbers */ TEST_FEATURE ("with numbers in node path"); TEST_TRUE (node_path_valid ("/com/netsplit/a43b/Test")); /* Check that a node path elements may begin with numbers */ TEST_FEATURE ("with numbers starting node path element"); TEST_TRUE (node_path_valid ("/com/netsplit/43/Test")); /* Check that a node path elements may contain underscores */ TEST_FEATURE ("with underscore in node path"); TEST_TRUE (node_path_valid ("/com/netsplit/Nih_Test")); /* Check that a node path elements may begin with underscores */ TEST_FEATURE ("with underscore starting node path element"); TEST_TRUE (node_path_valid ("/com/netsplit/_Nih/Test")); /* Check that other characters are not permitted */ TEST_FEATURE ("with non-permitted characters"); TEST_FALSE (node_path_valid ("/com/netsplit/Nih.Test-Thing")); /* Check that an empty node path is invalid */ TEST_FEATURE ("with empty string"); TEST_FALSE (node_path_valid ("")); } void test_new (void) { Node *node; TEST_FUNCTION ("node_new"); /* Check that when given a name, the node structure is allocated, * the defaults filled in and the name copied into the structure. */ TEST_FEATURE ("with name"); TEST_ALLOC_FAIL { node = node_new (NULL, "test"); if (test_alloc_failed) { TEST_EQ_P (node, NULL); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_STR (node->path, "test"); TEST_ALLOC_PARENT (node->path, node); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); } /* Check that when a name is not given, NULL is stored instead. */ TEST_FEATURE ("without name"); TEST_ALLOC_FAIL { node = node_new (NULL, NULL); if (test_alloc_failed) { TEST_EQ_P (node, NULL); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); } } void test_start_tag (void) { ParseContext context; ParseStack * parent = NULL; ParseStack * entry; XML_Parser xmlp; Node * node = NULL; Interface * interface = NULL; char * attr[5]; int ret = 0; NihError * err; FILE * output; TEST_FUNCTION ("node_start_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); output = tmpfile (); /* Check that an node tag for an node with the usual name * attribute results in an Node member being created and pushed * onto the stack with that attribute filled in correctly. */ TEST_FEATURE ("with node and name"); TEST_ALLOC_FAIL { attr[0] = "name"; attr[1] = "/com/netsplit/Nih/Test"; attr[2] = NULL; ret = node_start_tag (xmlp, "node", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, NULL); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_NODE); node = entry->node; TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_ALLOC_PARENT (node, entry); TEST_EQ_STR (node->path, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (node->path, node); TEST_LIST_EMPTY (&node->interfaces); nih_free (entry); } /* Check that a node tag may be missing the name attribute, and * that still results in a Node member being created and pushed * onto the stack with that attribute filled in correctly. */ TEST_FEATURE ("with node but no name"); TEST_ALLOC_FAIL { attr[0] = NULL; ret = node_start_tag (xmlp, "node", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, NULL); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_NODE); node = entry->node; TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_ALLOC_PARENT (node, entry); TEST_EQ_P (node->path, NULL); TEST_LIST_EMPTY (&node->interfaces); nih_free (entry); } /* Check that a node may appear inside another node tag, but that * an ignored tag is pushed since we don't want to process children. */ TEST_FEATURE ("with child node"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); } attr[0] = "name"; attr[1] = "/com/netsplit/Nih/Test"; attr[2] = NULL; ret = node_start_tag (xmlp, "node", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, NULL); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); nih_free (entry); nih_free (parent); } /* Check that a node with an invalid name results in an * error being raised. */ TEST_FEATURE ("with invalid name"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { attr[0] = "name"; attr[1] = "Test Node"; attr[2] = NULL; } ret = node_start_tag (xmlp, "node", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), NULL); err = nih_error_get (); TEST_EQ (err->number, NODE_INVALID_PATH); nih_free (err); } /* Check that an unknown node attribute results in a warning * being printed to standard error, but is otherwise ignored * and the normal processing finished. */ TEST_FEATURE ("with unknown attribute"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { attr[0] = "name"; attr[1] = "/com/netsplit/Nih/Test"; attr[2] = "frodo"; attr[3] = "baggins"; attr[4] = NULL; } TEST_DIVERT_STDERR (output) { ret = node_start_tag (xmlp, "node", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), NULL); TEST_FILE_RESET (output); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, NULL); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_NODE); node = entry->node; TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_ALLOC_PARENT (node, entry); TEST_EQ_STR (node->path, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (node->path, node); TEST_LIST_EMPTY (&node->interfaces); TEST_FILE_EQ (output, ("test:foo:1:0: Ignored unknown attribute: " "frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); } /* Check that a node on top of a stack entry results in a warning * being printed on standard error and an ignored element being * pushed onto the stack. */ TEST_FEATURE ("with non-node on stack"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "/com/netsplit/Nih/Test"; attr[2] = NULL; } TEST_DIVERT_STDERR (output) { ret = node_start_tag (xmlp, "node", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unexpected tag\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } XML_ParserFree (xmlp); fclose (output); } void test_end_tag (void) { ParseContext context; ParseStack * entry = NULL; XML_Parser xmlp; Node * node = NULL; int ret; NihError * err; void * parent; TEST_FUNCTION ("node_end_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); /* Check that when we parse the end tag for a node, we pop * the Node object off the stack and place it in the context's * node member. The stack entry should be freed and removed from * the stack. */ TEST_FEATURE ("with no parent"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, "/com/netsplit/Nih/Test"); entry = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); } TEST_FREE_TAG (entry); ret = node_end_tag (xmlp, "node"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (node, NULL); TEST_EQ_P (context.node, node); nih_free (node); context.node = NULL; } /* Check that when the context has a parent, the new node is * referenced by it. */ TEST_FEATURE ("with parent"); context.parent = parent = nih_alloc (NULL, 1); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, "/com/netsplit/Nih/Test"); entry = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); } TEST_FREE_TAG (entry); ret = node_end_tag (xmlp, "node"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (node, context.parent); TEST_EQ_P (context.node, node); nih_free (node); context.node = NULL; } nih_free (parent); XML_ParserFree (xmlp); } void test_lookup_interface (void) { Node * node = NULL; Interface *interface1 = NULL; Interface *interface2 = NULL; Interface *interface3 = NULL; Interface *ret; TEST_FUNCTION ("node_lookup_interface"); /* Check that the function returns the interface if there is one * with the given symbol. */ TEST_FEATURE ("with matching symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface1 = interface_new (node, "com.netsplit.Nih.Test"); interface1->symbol = nih_strdup (interface1, "test"); nih_list_add (&node->interfaces, &interface1->entry); interface2 = interface_new (node, "com.netsplit.Nih.Foo"); nih_list_add (&node->interfaces, &interface2->entry); interface3 = interface_new (node, "com.netsplit.Nih.Bar"); interface3->symbol = nih_strdup (interface3, "bar"); nih_list_add (&node->interfaces, &interface3->entry); } ret = node_lookup_interface (node, "bar"); TEST_EQ_P (ret, interface3); nih_free (node); } /* Check that the function returns the interface if there is one * with no symbol and NULL is given. */ TEST_FEATURE ("with no specified symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface1 = interface_new (node, "com.netsplit.Nih.Test"); interface1->symbol = nih_strdup (interface1, "test"); nih_list_add (&node->interfaces, &interface1->entry); interface2 = interface_new (node, "com.netsplit.Nih.Foo"); nih_list_add (&node->interfaces, &interface2->entry); interface3 = interface_new (node, "com.netsplit.Nih.Bar"); interface3->symbol = nih_strdup (interface3, "bar"); nih_list_add (&node->interfaces, &interface3->entry); } ret = node_lookup_interface (node, NULL); TEST_EQ_P (ret, interface2); nih_free (node); } /* Check that the function returns NULL if there is no interface * with the given symbol. */ TEST_FEATURE ("with non-matching symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface1 = interface_new (node, "com.netsplit.Nih.Test"); interface1->symbol = nih_strdup (interface1, "test"); nih_list_add (&node->interfaces, &interface1->entry); interface2 = interface_new (node, "com.netsplit.Nih.Foo"); nih_list_add (&node->interfaces, &interface2->entry); interface3 = interface_new (node, "com.netsplit.Nih.Bar"); interface3->symbol = nih_strdup (interface3, "bar"); nih_list_add (&node->interfaces, &interface3->entry); } ret = node_lookup_interface (node, "baz"); TEST_EQ_P (ret, NULL); nih_free (node); } } void test_interfaces_array (void) { NihList prototypes; Node * node = NULL; Interface *interface = NULL; Method * method = NULL; Signal * signal = NULL; Argument * arg = NULL; Property * property = NULL; char * str; TypeVar * var; TEST_FUNCTION ("node_interfaces_array"); /* Check that we can generate the interfaces array code for a * node with multiple interfaces. We want the members set up for * an object implementation, so the method and property function * pointers should be set and not the signal filter pointer. * Since the interface structures themselves are not made static, * the prototypes should contain those as well. */ TEST_FEATURE ("with object"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); arg = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); arg->symbol = "height"; nih_list_add (&signal->arguments, &arg->entry); arg = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); arg->symbol = "velocity"; nih_list_add (&signal->arguments, &arg->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); } str = node_interfaces_array (NULL, "my", node, TRUE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_interfaces_array_object.c"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "extern const NihDBusInterface"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test"); TEST_ALLOC_PARENT (var->name, var); TEST_FALSE (var->array); nih_free (var); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "extern const NihDBusInterface"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Foo"); TEST_ALLOC_PARENT (var->name, var); TEST_FALSE (var->array); nih_free (var); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "extern const NihDBusInterface *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_interfaces"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (node); } /* Check that we can generate the interfaces array code for a * node with multiple interfaces. We want the members set up for * a proxy implementation, so the signal filter pointer should be * set but not the method or property function pointers. * Since the interface structures themselves are not made static, * the prototypes should contain those as well. */ TEST_FEATURE ("with proxy"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); arg->symbol = "value"; nih_list_add (&method->arguments, &arg->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); arg = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); arg->symbol = "address"; nih_list_add (&method->arguments, &arg->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); arg = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); arg->symbol = "height"; nih_list_add (&signal->arguments, &arg->entry); arg = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); arg->symbol = "velocity"; nih_list_add (&signal->arguments, &arg->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); } str = node_interfaces_array (NULL, "my", node, FALSE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_interfaces_array_proxy.c"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "extern const NihDBusInterface"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test"); TEST_ALLOC_PARENT (var->name, var); TEST_FALSE (var->array); nih_free (var); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "extern const NihDBusInterface"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Foo"); TEST_ALLOC_PARENT (var->name, var); TEST_FALSE (var->array); nih_free (var); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "extern const NihDBusInterface *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_interfaces"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (node); } /* Check that we can still generate an interfaces array even when * there are no interfaces. */ TEST_FEATURE ("with no interfaces"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); } str = node_interfaces_array (NULL, "my", node, TRUE, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_interfaces_array_none.c"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "extern const NihDBusInterface *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_interfaces"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (node); } } void test_object_functions (void) { NihList prototypes; NihList handlers; NihList structs; NihList externs; Node * node = NULL; Interface * interface = NULL; Method * method = NULL; Signal * signal = NULL; Argument * argument = NULL; Property * property = NULL; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; NihListEntry *attrib; TEST_FUNCTION ("node_object_functions"); /* Check that we can generate all of the functions needed for a Node's * object implementation, wrapping externally defined functions. Each * static function should have its prototype returned, each externally * defined function should have the extern prototype returned and * each API function its prototype returned. Property functions * should only be generated as access allows. */ TEST_FEATURE ("with node"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; method->async = TRUE; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "is_valid", "b", NIH_DBUS_ARG_OUT); argument->symbol = "is_valid"; nih_list_add (&method->arguments, &argument->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); argument = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); argument->symbol = "height"; nih_list_add (&signal->arguments, &argument->entry); argument = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); argument->symbol = "velocity"; nih_list_add (&signal->arguments, &argument->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Bing"); method->symbol = "bing"; nih_list_add (&interface->methods, &method->entry); signal = signal_new (interface, "NewResult"); signal->symbol = "new_result"; nih_list_add (&interface->signals, &signal->entry); } str = node_object_functions (NULL, "my", node, &prototypes, &handlers, &structs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_object_functions_standard.c"); /* Poke */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Poke_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_poke"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Peek */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Peek_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_peek"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_peek_reply"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* IsValidAddress */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_IsValidAddress_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_is_valid_address"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "is_valid"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* bounce */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_emit_bounce"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "height"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "velocity"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* exploded */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_emit_exploded"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (get) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_get"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (set) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_set"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* size (get) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_size_get"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_size"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* touch (set) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_touch_set"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_touch"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Bing */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Foo_Bing_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_foo_bing"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* NewResult */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_foo_emit_new_result"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that we can still generate all of the functions even if * there are no methods in the object implementation. */ TEST_FEATURE ("with no methods"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); argument = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); argument->symbol = "height"; nih_list_add (&signal->arguments, &argument->entry); argument = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); argument->symbol = "velocity"; nih_list_add (&signal->arguments, &argument->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); signal = signal_new (interface, "NewResult"); signal->symbol = "new_result"; nih_list_add (&interface->signals, &signal->entry); } str = node_object_functions (NULL, "my", node, &prototypes, &handlers, &structs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_object_functions_no_methods.c"); /* bounce */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_emit_bounce"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "height"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "velocity"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* exploded */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_emit_exploded"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (get) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_get"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (set) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_set"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* size (get) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_size_get"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_size"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* touch (set) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_touch_set"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_touch"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* NewResult */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_foo_emit_new_result"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that we can still generate all of the functions even if * there are no signals in the object implementation. */ TEST_FEATURE ("with no signals"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; method->async = TRUE; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "is_valid", "b", NIH_DBUS_ARG_OUT); argument->symbol = "is_valid"; nih_list_add (&method->arguments, &argument->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Bing"); method->symbol = "bing"; nih_list_add (&interface->methods, &method->entry); } str = node_object_functions (NULL, "my", node, &prototypes, &handlers, &structs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_object_functions_no_signals.c"); /* Poke */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Poke_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_poke"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Peek */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Peek_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_peek"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_peek_reply"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* IsValidAddress */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_IsValidAddress_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_is_valid_address"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "is_valid"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (get) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_get"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (set) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_set"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* size (get) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_size_get"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_size"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* touch (set) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_touch_set"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_touch"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Bing */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Foo_Bing_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_foo_bing"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that we can still generate all of the functions even if * there are no properties in the object implementation. */ TEST_FEATURE ("with no properties"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; method->async = TRUE; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "is_valid", "b", NIH_DBUS_ARG_OUT); argument->symbol = "is_valid"; nih_list_add (&method->arguments, &argument->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); argument = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); argument->symbol = "height"; nih_list_add (&signal->arguments, &argument->entry); argument = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); argument->symbol = "velocity"; nih_list_add (&signal->arguments, &argument->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Bing"); method->symbol = "bing"; nih_list_add (&interface->methods, &method->entry); signal = signal_new (interface, "NewResult"); signal->symbol = "new_result"; nih_list_add (&interface->signals, &signal->entry); } str = node_object_functions (NULL, "my", node, &prototypes, &handlers, &structs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_object_functions_no_properties.c"); /* Poke */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Poke_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_poke"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Peek */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Peek_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_peek"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_peek_reply"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* IsValidAddress */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_IsValidAddress_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_is_valid_address"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "is_valid"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* bounce */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_emit_bounce"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "height"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "velocity"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* exploded */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_emit_exploded"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Bing */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Foo_Bing_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_foo_bing"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* NewResult */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_foo_emit_new_result"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that we can still generate all of the functions even if * there are no methods or signals in the object implementation. */ TEST_FEATURE ("with no methods or signals"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); } str = node_object_functions (NULL, "my", node, &prototypes, &handlers, &structs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_object_functions_only_properties.c"); /* colour (get) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_get"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (set) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_set"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* size (get) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_size_get"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_size"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* touch (set) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_touch_set"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_touch"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that methods, signals and properties with structure * arguments all pass the struct definitions back in the structs * list. Make sure that output arguments from an async method * call aren't duplicated and make sure those from readwrite * properties aren't duplicated while read and write only are * still returned. */ TEST_FEATURE ("with structure arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Search"); method->async = TRUE; method->symbol = "search"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "item", "(su)", NIH_DBUS_ARG_IN); argument->symbol = "item"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "result", "(ss)", NIH_DBUS_ARG_OUT); argument->symbol = "result"; nih_list_add (&method->arguments, &argument->entry); signal = signal_new (interface, "NewSearch"); signal->symbol = "new_search"; nih_list_add (&interface->signals, &signal->entry); argument = argument_new (signal, "query", "(ssu)", NIH_DBUS_ARG_OUT); argument->symbol = "query"; nih_list_add (&signal->arguments, &argument->entry); property = property_new (interface, "last_search", "(su)", NIH_DBUS_READ); property->symbol = "last_search"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "annotation", "(ss)", NIH_DBUS_WRITE); property->symbol = "annotation"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "preferences", "(us)", NIH_DBUS_READWRITE); property->symbol = "preferences"; nih_list_add (&interface->properties, &property->entry); } str = node_object_functions (NULL, "my", node, &prototypes, &handlers, &structs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_object_functions_structure.c"); /* Search */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Search_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_search"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestSearchItem *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "item"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_search_reply"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestSearchResult *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "result"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestSearchItem"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestSearchResult"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); /* NewSearch */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_emit_new_search"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "origin_path"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestNewSearchQuery *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "query"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestNewSearchQuery"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item2"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); /* last_search (get) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_last_search_get"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_last_search"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestLastSearch **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestLastSearch"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); /* annotation (set) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_annotation_set"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_annotation"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestAnnotation *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestAnnotation"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); /* preferences (get) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_preferences_get"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_preferences"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestPreferences **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* preferences (set) */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_preferences_set"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessageIter *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "iter"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "extern int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_preferences"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestPreferences *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestPreferences"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that when there are no interface members, an empty string * is returned. */ TEST_FEATURE ("with no members"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); } str = node_object_functions (NULL, "my", node, &prototypes, &handlers, &structs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EQ_STR (str, ""); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that when there are no interfaces, an empty string * is returned. */ TEST_FEATURE ("with no interfaces"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); } str = node_object_functions (NULL, "my", node, &prototypes, &handlers, &structs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EQ_STR (str, ""); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } } void test_proxy_functions (void) { NihList prototypes; NihList structs; NihList typedefs; NihList externs; Node * node = NULL; Interface * interface = NULL; Method * method = NULL; Signal * signal = NULL; Argument * argument = NULL; Property * property = NULL; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; NihListEntry *attrib; TEST_FUNCTION ("node_proxy_functions"); /* Check that we can generate all of the functions needed for a remote * Node's proxy implementation. Each static function should have its * prototype returned, each callback or handler function should have * its typedef returned and each API function its prototype returned. * Property functions should only be generated as access allows. */ TEST_FEATURE ("with node"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); nih_list_init (&typedefs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); argument = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); argument->symbol = "height"; nih_list_add (&signal->arguments, &argument->entry); argument = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); argument->symbol = "velocity"; nih_list_add (&signal->arguments, &argument->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Bing"); method->symbol = "bing"; nih_list_add (&interface->methods, &method->entry); signal = signal_new (interface, "NewResult"); signal->symbol = "new_result"; nih_list_add (&interface->signals, &signal->entry); } str = node_proxy_functions (NULL, "my", node, &prototypes, &structs, &typedefs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_proxy_functions_standard.c"); /* Poke */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_poke"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestPokeReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Poke_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestPokeReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_poke_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Peek */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_peek"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestPeekReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Peek_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestPeekReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_peek_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* IsValidAddress */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_is_valid_address"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestIsValidAddressReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_IsValidAddress_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestIsValidAddressReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_is_valid_address_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Bounce */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Bounce_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestBounceHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "height"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "velocity"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Exploded */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Exploded_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestExplodedHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (get) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetColourReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_get_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetColourReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_colour_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (set) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestSetColourReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_set_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestSetColourReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_colour_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* size (get) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_size"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetSizeReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_size_get_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetSizeReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_size_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* touch (set) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_touch"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestSetTouchReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_touch_set_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestSetTouchReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_touch_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Get All */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_all"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetAllReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_get_all_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetAllReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestProperties *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_all_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestProperties **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestProperties"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "colour"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); /* Bing */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_foo_bing"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyFooBingReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Foo_Bing_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyFooBingReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_foo_bing_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* NewResult */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Foo_NewResult_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyFooNewResultHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that we can still generate all of the functions even if * there are no methods in the object implementation. */ TEST_FEATURE ("with no methods"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); nih_list_init (&typedefs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); argument = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); argument->symbol = "height"; nih_list_add (&signal->arguments, &argument->entry); argument = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); argument->symbol = "velocity"; nih_list_add (&signal->arguments, &argument->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); signal = signal_new (interface, "NewResult"); signal->symbol = "new_result"; nih_list_add (&interface->signals, &signal->entry); } str = node_proxy_functions (NULL, "my", node, &prototypes, &structs, &typedefs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_proxy_functions_no_methods.c"); /* Bounce */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Bounce_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestBounceHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "height"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "velocity"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Exploded */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Exploded_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestExplodedHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (get) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetColourReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_get_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetColourReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_colour_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (set) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestSetColourReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_set_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestSetColourReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_colour_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* size (get) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_size"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetSizeReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_size_get_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetSizeReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_size_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* touch (set) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_touch"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestSetTouchReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_touch_set_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestSetTouchReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_touch_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Get All */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_all"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetAllReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_get_all_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetAllReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestProperties *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_all_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestProperties **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestProperties"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "colour"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); /* NewResult */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Foo_NewResult_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyFooNewResultHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that we can still generate all of the functions even if * there are no signals in the object implementation. */ TEST_FEATURE ("with no signals"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); nih_list_init (&typedefs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Bing"); method->symbol = "bing"; nih_list_add (&interface->methods, &method->entry); } str = node_proxy_functions (NULL, "my", node, &prototypes, &structs, &typedefs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_proxy_functions_no_signals.c"); /* Poke */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_poke"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestPokeReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Poke_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestPokeReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_poke_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Peek */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_peek"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestPeekReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Peek_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestPeekReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_peek_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* IsValidAddress */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_is_valid_address"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestIsValidAddressReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_IsValidAddress_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestIsValidAddressReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_is_valid_address_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (get) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetColourReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_get_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetColourReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_colour_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (set) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestSetColourReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_set_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestSetColourReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_colour_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* size (get) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_size"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetSizeReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_size_get_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetSizeReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_size_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* touch (set) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_touch"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestSetTouchReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_touch_set_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestSetTouchReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_touch_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Get All */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_all"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetAllReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_get_all_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetAllReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestProperties *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_all_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestProperties **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestProperties"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "colour"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); /* Bing */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_foo_bing"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyFooBingReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Foo_Bing_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyFooBingReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_foo_bing_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that we can still generate all of the functions even if * there are no prototypes in the object implementation. */ TEST_FEATURE ("with no properties"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); nih_list_init (&typedefs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Poke"); method->symbol = "poke"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_IN); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "Peek"); method->symbol = "peek"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "value", "s", NIH_DBUS_ARG_OUT); argument->symbol = "value"; nih_list_add (&method->arguments, &argument->entry); method = method_new (interface, "IsValidAddress"); method->symbol = "is_valid_address"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "address", "u", NIH_DBUS_ARG_IN); argument->symbol = "address"; nih_list_add (&method->arguments, &argument->entry); signal = signal_new (interface, "Bounce"); signal->symbol = "bounce"; nih_list_add (&interface->signals, &signal->entry); argument = argument_new (signal, "height", "u", NIH_DBUS_ARG_OUT); argument->symbol = "height"; nih_list_add (&signal->arguments, &argument->entry); argument = argument_new (signal, "velocity", "i", NIH_DBUS_ARG_OUT); argument->symbol = "velocity"; nih_list_add (&signal->arguments, &argument->entry); signal = signal_new (interface, "Exploded"); signal->symbol = "exploded"; nih_list_add (&interface->signals, &signal->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Bing"); method->symbol = "bing"; nih_list_add (&interface->methods, &method->entry); signal = signal_new (interface, "NewResult"); signal->symbol = "new_result"; nih_list_add (&interface->signals, &signal->entry); } str = node_proxy_functions (NULL, "my", node, &prototypes, &structs, &typedefs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_proxy_functions_no_properties.c"); /* Poke */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_poke"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestPokeReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Poke_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestPokeReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_poke_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Peek */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_peek"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestPeekReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Peek_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestPeekReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_peek_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* IsValidAddress */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_is_valid_address"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestIsValidAddressReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_IsValidAddress_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestIsValidAddressReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_is_valid_address_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "address"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Bounce */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Bounce_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestBounceHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "height"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "velocity"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Exploded */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Exploded_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestExplodedHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Bing */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_foo_bing"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyFooBingReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Foo_Bing_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyFooBingReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_foo_bing_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* NewResult */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Foo_NewResult_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyFooNewResultHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that we can still generate all of the functions even if * there are no methods or signals in the object implementation. */ TEST_FEATURE ("with no methods or signals"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); nih_list_init (&typedefs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); property = property_new (interface, "colour", "s", NIH_DBUS_READWRITE); property->symbol = "colour"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READ); property->symbol = "size"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "touch", "b", NIH_DBUS_WRITE); property->symbol = "touch"; nih_list_add (&interface->properties, &property->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); } str = node_proxy_functions (NULL, "my", node, &prototypes, &structs, &typedefs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_proxy_functions_only_properties.c"); /* colour (get) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetColourReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_get_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetColourReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_colour_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* colour (set) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_colour"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestSetColourReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_colour_set_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestSetColourReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_colour_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* size (get) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_size"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetSizeReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_size_get_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetSizeReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_size_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "uint32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* touch (set) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_touch"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestSetTouchReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_touch_set_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestSetTouchReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_touch_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Get All */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_all"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetAllReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_get_all_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetAllReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestProperties *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_all_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestProperties **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestProperties"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "colour"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that methods, signals and properties with structure * arguments all pass the struct definitions back in the structs * list. Make sure that output arguments from an async method * call aren't duplicated and make sure those from readwrite * properties aren't duplicated while read and write only are * still returned. */ TEST_FEATURE ("with structure arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); nih_list_init (&typedefs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); method = method_new (interface, "Search"); method->async = TRUE; method->symbol = "search"; nih_list_add (&interface->methods, &method->entry); argument = argument_new (method, "item", "(su)", NIH_DBUS_ARG_IN); argument->symbol = "item"; nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, "result", "(ss)", NIH_DBUS_ARG_OUT); argument->symbol = "result"; nih_list_add (&method->arguments, &argument->entry); signal = signal_new (interface, "NewSearch"); signal->symbol = "new_search"; nih_list_add (&interface->signals, &signal->entry); argument = argument_new (signal, "query", "(ssu)", NIH_DBUS_ARG_OUT); argument->symbol = "query"; nih_list_add (&signal->arguments, &argument->entry); property = property_new (interface, "last_search", "(su)", NIH_DBUS_READ); property->symbol = "last_search"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "annotation", "(ss)", NIH_DBUS_WRITE); property->symbol = "annotation"; nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "preferences", "(us)", NIH_DBUS_READWRITE); property->symbol = "preferences"; nih_list_add (&interface->properties, &property->entry); } str = node_proxy_functions (NULL, "my", node, &prototypes, &structs, &typedefs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EXPECTED_STR (str, "test_node_proxy_functions_structure.c"); /* Search */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_search"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestSearchItem *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "item"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestSearchReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Search_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestSearchReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestSearchResult *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "result"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_search_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestSearchItem *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "item"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestSearchResult **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "result"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestSearchItem"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestSearchResult"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); /* NewSearch */ TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_NewSearch_signal"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusConnection *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "connection"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "signal"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxySignal *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxied"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestNewSearchHandler)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestNewSearchQuery *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "query"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestNewSearchQuery"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item2"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); /* last_search (get) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_last_search"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetLastSearchReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_last_search_get_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetLastSearchReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestLastSearch *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_last_search_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestLastSearch **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* annotation (set) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_annotation"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestAnnotation *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestSetAnnotationReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_annotation_set_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestSetAnnotationReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_annotation_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestAnnotation *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestAnnotation"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); /* preferences (get) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_preferences"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetPreferencesReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_preferences_get_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetPreferencesReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestPreferences *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_preferences_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestPreferences **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* preferences (set) */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_preferences"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestPreferences *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestSetPreferencesReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_preferences_set_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestSetPreferencesReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_set_preferences_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestPreferences *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); /* Get All */ TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_all"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestGetAllReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "static void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_get_all_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyTestGetAllReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestProperties *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&externs); func = (TypeFunc *)externs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_get_all_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestProperties **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "properties"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestLastSearch"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestPreferences"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestProperties"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "MyTestLastSearch *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "last_search"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "MyTestPreferences *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "preferences"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that when there are no interface members, an empty string * is returned. */ TEST_FEATURE ("with no members"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); nih_list_init (&typedefs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); interface = interface_new (node, "com.netsplit.Nih.Test"); interface->symbol = "test"; nih_list_add (&node->interfaces, &interface->entry); interface = interface_new (node, "com.netsplit.Nih.Foo"); interface->symbol = "foo"; nih_list_add (&node->interfaces, &interface->entry); } str = node_proxy_functions (NULL, "my", node, &prototypes, &structs, &typedefs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EQ_STR (str, ""); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } /* Check that when there are no interfaces, an empty string * is returned. */ TEST_FEATURE ("with no interfaces"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); nih_list_init (&typedefs); nih_list_init (&externs); TEST_ALLOC_SAFE { node = node_new (NULL, NULL); } str = node_proxy_functions (NULL, "my", node, &prototypes, &structs, &typedefs, &externs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (node); continue; } TEST_EQ_STR (str, ""); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&externs); nih_free (str); nih_free (node); } } int main (int argc, char *argv[]) { program_name = "test"; nih_error_init (); test_path_valid (); test_new (); test_start_tag (); test_end_tag (); test_lookup_interface (); test_interfaces_array (); test_object_functions (); test_proxy_functions (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/interface_code.h0000644000175000017500000000342211445765555016654 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_TESTS_INTERFACE_CODE_H #define NIH_DBUS_TOOL_TESTS_INTERFACE_CODE_H #include #include #include #include #include #include typedef struct my_properties { char * name; uint32_t size; } MyProperties; typedef void (*MyGetAllReply) (void *data, NihDBusMessage *message, const MyProperties *value); NIH_BEGIN_EXTERN DBusPendingCall *my_get_all (NihDBusProxy *proxy, MyGetAllReply handler, NihDBusErrorHandler error_handler, void *data, int timeout) __attribute__ ((warn_unused_result)); void my_com_netsplit_Nih_Test_get_all_notify (DBusPendingCall *pending_call, NihDBusPendingData *pending_data); int my_get_all_sync (const void *parent, NihDBusProxy *proxy, MyProperties **value) __attribute__ ((warn_unused_result)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_TESTS_INTERFACE_CODE_H */ libnih-1.0.3/nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c0000644000175000017500000301126611504715212022341 00000000000000/* libnih * * test_com.netsplit.Nih.Test_object.c - test suite for auto-generated * object bindings. * * Copyright © 2010 Scott James Remnant . * Copyright © 2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include "tests/com.netsplit.Nih.Test_object.h" #include "tests/com.netsplit.Nih.Test_impl.h" void test_ordinary_method (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_OrdinaryMethod_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "OrdinaryMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "she needs more of ze punishment"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "OrdinaryMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.OrdinaryMethod.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "OrdinaryMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "OrdinaryMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = "/she/needs/more/of/ze/punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "OrdinaryMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "OrdinaryMethod"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_nameless_method (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_NamelessMethod_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "NamelessMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "she needs more of ze punishment"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "NamelessMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.NamelessMethod.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "NamelessMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "NamelessMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = "/she/needs/more/of/ze/punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "NamelessMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "NamelessMethod"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_async_method (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; int ret; TEST_FUNCTION ("my_com_netsplit_Nih_Test_AsyncMethod_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } async_method_input = NULL; async_method_message = NULL; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); TEST_EQ_STR (async_method_input, "she needs more of ze punishment"); TEST_ALLOC_SIZE (async_method_message, sizeof (NihDBusMessage)); TEST_ALLOC_PARENT (async_method_message, async_method_input); ret = my_test_async_method_reply (async_method_message, async_method_input); if (test_alloc_failed && (ret < 0)) { nih_free (async_method_message); nih_free (async_method_input); nih_free (object); continue; } TEST_EQ (ret, 0); nih_free (async_method_message); nih_free (async_method_input); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "she needs more of ze punishment"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.AsyncMethod.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error may be sent after the function returns * using nih_dbus_message_error(). */ TEST_FEATURE ("with error after function return"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } async_method_input = NULL; async_method_message = NULL; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); TEST_EQ_STR (async_method_input, "she needs more of ze punishment"); TEST_ALLOC_SIZE (async_method_message, sizeof (NihDBusMessage)); TEST_ALLOC_PARENT (async_method_message, async_method_input); TEST_ALLOC_SAFE { assert0 (nih_dbus_message_error (async_method_message, "com.netsplit.Nih.Test.AsyncMethod.Fail", "The method failed in some way")); } nih_free (async_method_message); nih_free (async_method_input); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.AsyncMethod.Fail")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = "/she/needs/more/of/ze/punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_byte_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; uint8_t byte_value; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_ByteToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "ByteToStr"); dbus_message_iter_init_append (method_call, &iter); byte_value = 97; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BYTE, &byte_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "97"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "ByteToStr"); dbus_message_iter_init_append (method_call, &iter); byte_value = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BYTE, &byte_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.ByteToStr.ZeroInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "ByteToStr"); dbus_message_iter_init_append (method_call, &iter); byte_value = 4; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BYTE, &byte_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "ByteToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "97"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "ByteToStr"); dbus_message_iter_init_append (method_call, &iter); byte_value = 97; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BYTE, &byte_value); str_value = "97"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "ByteToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_byte (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; uint8_t byte_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToByte_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToByte"); dbus_message_iter_init_append (method_call, &iter); str_value = "97"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_BYTE_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &byte_value); TEST_EQ (byte_value, 97); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToByte"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToByte.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToByte"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToByte"); dbus_message_iter_init_append (method_call, &iter); byte_value = 97; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BYTE, &byte_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToByte"); dbus_message_iter_init_append (method_call, &iter); str_value = "97"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); byte_value = 97; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BYTE, &byte_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToByte"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_boolean_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; int boolean_value; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; TEST_FUNCTION ("my_com_netsplit_Nih_Test_BooleanToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "BooleanToStr"); dbus_message_iter_init_append (method_call, &iter); boolean_value = TRUE; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &boolean_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "True"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "BooleanToStr"); dbus_message_iter_init_append (method_call, &iter); boolean_value = FALSE; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &boolean_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.BooleanToStr.ZeroInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "BooleanToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "True"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "BooleanToStr"); dbus_message_iter_init_append (method_call, &iter); boolean_value = TRUE; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &boolean_value); str_value = "True"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "BooleanToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_boolean (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; int boolean_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToBoolean_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToBoolean"); dbus_message_iter_init_append (method_call, &iter); str_value = "True"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_BOOLEAN_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &boolean_value); TEST_EQ (boolean_value, TRUE); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToBoolean"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToBoolean.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToBoolean"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToBoolean"); dbus_message_iter_init_append (method_call, &iter); boolean_value = TRUE; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &boolean_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToBoolean"); dbus_message_iter_init_append (method_call, &iter); str_value = "97"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); boolean_value = TRUE; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &boolean_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToBoolean"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_int16_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; int16_t int16_value; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_Int16ToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int16ToStr"); dbus_message_iter_init_append (method_call, &iter); int16_value = -42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT16, &int16_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "-42"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int16ToStr"); dbus_message_iter_init_append (method_call, &iter); int16_value = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT16, &int16_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int16ToStr.ZeroInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int16ToStr"); dbus_message_iter_init_append (method_call, &iter); int16_value = 4; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT16, &int16_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int16ToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "-42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int16ToStr"); dbus_message_iter_init_append (method_call, &iter); int16_value = -42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT16, &int16_value); str_value = "-42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int16ToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_int16 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; int16_t int16_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToInt16_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt16"); dbus_message_iter_init_append (method_call, &iter); str_value = "-42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_INT16_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &int16_value); TEST_EQ (int16_value, -42); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt16"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToInt16.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt16"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt16"); dbus_message_iter_init_append (method_call, &iter); int16_value = -42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT16, &int16_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt16"); dbus_message_iter_init_append (method_call, &iter); str_value = "-42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); int16_value = -42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT16, &int16_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt16"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_uint16_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; uint16_t uint16_value; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_UInt16ToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt16ToStr"); dbus_message_iter_init_append (method_call, &iter); uint16_value = 42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT16, &uint16_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "42"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt16ToStr"); dbus_message_iter_init_append (method_call, &iter); uint16_value = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT16, &uint16_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.UInt16ToStr.ZeroInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt16ToStr"); dbus_message_iter_init_append (method_call, &iter); uint16_value = 4; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT16, &uint16_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt16ToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt16ToStr"); dbus_message_iter_init_append (method_call, &iter); uint16_value = 42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT16, &uint16_value); str_value = "42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt16ToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_uint16 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; uint16_t uint16_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToUInt16_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt16"); dbus_message_iter_init_append (method_call, &iter); str_value = "42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_UINT16_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &uint16_value); TEST_EQ (uint16_value, 42); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt16"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToUInt16.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt16"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt16"); dbus_message_iter_init_append (method_call, &iter); uint16_value = 42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT16, &uint16_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt16"); dbus_message_iter_init_append (method_call, &iter); str_value = "42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); uint16_value = 42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT16, &uint16_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt16"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_int32_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; int32_t int32_value; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_Int32ToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ToStr"); dbus_message_iter_init_append (method_call, &iter); int32_value = -1048576; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "-1048576"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ToStr"); dbus_message_iter_init_append (method_call, &iter); int32_value = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int32ToStr.ZeroInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ToStr"); dbus_message_iter_init_append (method_call, &iter); int32_value = 4; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "-1048576"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ToStr"); dbus_message_iter_init_append (method_call, &iter); int32_value = -1048576; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); str_value = "-1048576"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_int32 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; int32_t int32_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToInt32_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32"); dbus_message_iter_init_append (method_call, &iter); str_value = "-1048576"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_INT32_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, -1048576); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToInt32.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32"); dbus_message_iter_init_append (method_call, &iter); int32_value = -1048576; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32"); dbus_message_iter_init_append (method_call, &iter); str_value = "-1048576"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); int32_value = -1048576; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_uint32_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; uint32_t uint32_value; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_UInt32ToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt32ToStr"); dbus_message_iter_init_append (method_call, &iter); uint32_value = 1048576; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "1048576"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt32ToStr"); dbus_message_iter_init_append (method_call, &iter); uint32_value = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.UInt32ToStr.ZeroInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt32ToStr"); dbus_message_iter_init_append (method_call, &iter); uint32_value = 4; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt32ToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "1048576"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt32ToStr"); dbus_message_iter_init_append (method_call, &iter); uint32_value = 1048576; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value); str_value = "1048576"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt32ToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_uint32 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; uint32_t uint32_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToUInt32_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt32"); dbus_message_iter_init_append (method_call, &iter); str_value = "1048576"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_UINT32_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &uint32_value); TEST_EQ (uint32_value, 1048576); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt32"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToUInt32.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt32"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt32"); dbus_message_iter_init_append (method_call, &iter); uint32_value = 1048576; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt32"); dbus_message_iter_init_append (method_call, &iter); str_value = "1048576"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); uint32_value = 1048576; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt32"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_int64_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; int64_t int64_value; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_Int64ToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int64ToStr"); dbus_message_iter_init_append (method_call, &iter); int64_value = -4815162342L; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT64, &int64_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "-4815162342"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int64ToStr"); dbus_message_iter_init_append (method_call, &iter); int64_value = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT64, &int64_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int64ToStr.ZeroInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int64ToStr"); dbus_message_iter_init_append (method_call, &iter); int64_value = 4; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT64, &int64_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int64ToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "-4815162342"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int64ToStr"); dbus_message_iter_init_append (method_call, &iter); int64_value = -4815162342L; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT64, &int64_value); str_value = "-4815162342"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int64ToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_int64 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; int64_t int64_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToInt64_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt64"); dbus_message_iter_init_append (method_call, &iter); str_value = "-4815162342"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_INT64_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &int64_value); TEST_EQ (int64_value, -4815162342L); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt64"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToInt64.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt64"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt64"); dbus_message_iter_init_append (method_call, &iter); int64_value = -4815162342L; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT64, &int64_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt64"); dbus_message_iter_init_append (method_call, &iter); str_value = "-4815162342"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); int64_value = -4815162342L; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT64, &int64_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt64"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_uint64_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; uint64_t uint64_value; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_UInt64ToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt64ToStr"); dbus_message_iter_init_append (method_call, &iter); uint64_value = 4815162342L; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT64, &uint64_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "4815162342"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt64ToStr"); dbus_message_iter_init_append (method_call, &iter); uint64_value = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT64, &uint64_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.UInt64ToStr.ZeroInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt64ToStr"); dbus_message_iter_init_append (method_call, &iter); uint64_value = 4; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT64, &uint64_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt64ToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "4815162342"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt64ToStr"); dbus_message_iter_init_append (method_call, &iter); uint64_value = 4815162342; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT64, &uint64_value); str_value = "4815162342"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UInt64ToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_uint64 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; uint64_t uint64_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToUInt64_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt64"); dbus_message_iter_init_append (method_call, &iter); str_value = "4815162342"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_UINT64_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &uint64_value); TEST_EQ (uint64_value, 4815162342); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt64"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToUInt64.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt64"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt64"); dbus_message_iter_init_append (method_call, &iter); uint64_value = 4815162342; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT64, &uint64_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt64"); dbus_message_iter_init_append (method_call, &iter); str_value = "4815162342"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); uint64_value = 4815162342L; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT64, &uint64_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUInt64"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_double_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; double double_value; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_DoubleToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DoubleToStr"); dbus_message_iter_init_append (method_call, &iter); double_value = 3.141597; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "3.141597"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DoubleToStr"); dbus_message_iter_init_append (method_call, &iter); double_value = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.DoubleToStr.ZeroInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DoubleToStr"); dbus_message_iter_init_append (method_call, &iter); double_value = 4; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DoubleToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "3.141597"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DoubleToStr"); dbus_message_iter_init_append (method_call, &iter); double_value = 3.141597; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); str_value = "3.141597"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DoubleToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_double (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; double double_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToDouble_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToDouble"); dbus_message_iter_init_append (method_call, &iter); str_value = "3.141597"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_DOUBLE_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &double_value); TEST_EQ (double_value, 3.141597); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToDouble"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToDouble.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToDouble"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToDouble"); dbus_message_iter_init_append (method_call, &iter); double_value = 3.141597; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToDouble"); dbus_message_iter_init_append (method_call, &iter); str_value = "3.141597"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); double_value = 3.141597; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToDouble"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_object_path_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_ObjectPathToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "ObjectPathToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "/com/netsplit/Nih/Test"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "ObjectPathToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "/"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.ObjectPathToStr.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "ObjectPathToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "/invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "ObjectPathToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "ObjectPathToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "ObjectPathToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_object_path (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToObjectPath_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToObjectPath"); dbus_message_iter_init_append (method_call, &iter); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_OBJECT_PATH_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "/com/netsplit/Nih/Test"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToObjectPath"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToObjectPath.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToObjectPath"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToObjectPath"); dbus_message_iter_init_append (method_call, &iter); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToObjectPath"); dbus_message_iter_init_append (method_call, &iter); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToObjectPath"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_signature_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_SignatureToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "SignatureToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "a(ib)"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_SIGNATURE, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "a(ib)"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "SignatureToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_SIGNATURE, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.SignatureToStr.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "SignatureToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "inva(x)id"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_SIGNATURE, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "SignatureToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "a(ib)"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "SignatureToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "a(ib)"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_SIGNATURE, &str_value); str_value = "a(ib)"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "SignatureToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_signature (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToSignature_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToSignature"); dbus_message_iter_init_append (method_call, &iter); str_value = "a(ib)"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_SIGNATURE_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "a(ib)"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToSignature"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToSignature.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToSignature"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToSignature"); dbus_message_iter_init_append (method_call, &iter); str_value = "a(ib)"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_SIGNATURE, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToSignature"); dbus_message_iter_init_append (method_call, &iter); str_value = "a(ib)"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "a(ib)"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_SIGNATURE, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToSignature"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_struct_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter subiter; const char * str_value; uint32_t uint32_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StructToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "Joe 34"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = ""; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StructToStr.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "invalid"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "Joe"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a structure member of the wrong type is given. */ TEST_FEATURE ("with wrong member type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "34"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra structure entry is given. */ TEST_FEATURE ("with extra member"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); str_value = "Male"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_struct (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter subiter; char * str_value; uint32_t uint32_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToStruct_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStruct"); dbus_message_iter_init_append (method_call, &iter); str_value = "Joe 34"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING)); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &subiter); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Joe"); dbus_message_iter_next (&subiter); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 34); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStruct"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToStruct.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStruct"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStruct"); dbus_message_iter_init_append (method_call, &iter); uint32_value = 34; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStruct"); dbus_message_iter_init_append (method_call, &iter); str_value = "Joe 34"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStruct"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_int32_array_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter subiter; int32_t int32_value; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_Int32ArrayToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subiter); int32_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "4 8 15 16 23 42"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int32ArrayToStr.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subiter); int32_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if array elements of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "4"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "8"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "15"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "16"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "23"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "42"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "4 8 15 16 23 42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subiter); int32_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "4 8 15 16 23 42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_int32_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; int32_t int32_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToInt32Array_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32Array"); dbus_message_iter_init_append (method_call, &iter); str_value = "4 8 15 16 23 42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING)); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subiter, &int32_value); TEST_EQ (int32_value, 4); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subiter, &int32_value); TEST_EQ (int32_value, 8); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subiter, &int32_value); TEST_EQ (int32_value, 15); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subiter, &int32_value); TEST_EQ (int32_value, 16); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subiter, &int32_value); TEST_EQ (int32_value, 23); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subiter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32Array"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToInt32Array.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32Array"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32Array"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subiter); int32_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32Array"); dbus_message_iter_init_append (method_call, &iter); str_value = "4 8 15 16 23 42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subiter); int32_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32Array"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_array_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter subiter; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrArrayToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "she"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "needs"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "more"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "ze"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "punishment"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "she needs more of ze punishment"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrArrayToStr.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "this"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "is"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "a"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "test"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if array elements of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH_AS_STRING, &subiter); str_value = "/she"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &str_value); str_value = "/needs"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &str_value); str_value = "/more"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &str_value); str_value = "/of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &str_value); str_value = "/ze"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &str_value); str_value = "/punishment"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrArrayToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "she"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "needs"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "more"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "ze"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "punishment"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_str_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToStrArray_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStrArray"); dbus_message_iter_init_append (method_call, &iter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "she"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "needs"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "more"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "of"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "ze"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "punishment"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStrArray"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToStrArray.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStrArray"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStrArray"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "she"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "needs"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "more"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "ze"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "punishment"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStrArray"); dbus_message_iter_init_append (method_call, &iter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "she"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "needs"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "more"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "ze"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "punishment"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStrArray"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_int32_array_array_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter subiter; DBusMessageIter subsubiter; int32_t int32_value; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_Int32ArrayArrayToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); int32_value = 4; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); int32_value = 1; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 1; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 2; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 3; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 5; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "4 8 15 16 23 42\n1 1 2 3 5 8"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int32ArrayArrayToStr.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); int32_value = 4; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if first-level array elements of the wrong type is given. */ TEST_FEATURE ("with wrong first-level element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "4"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "8"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "15"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "16"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "23"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "42"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if second-level array elements of the wrong type is given. */ TEST_FEATURE ("with wrong second-level element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subsubiter); str_value = "4"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "8"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "15"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "16"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "23"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "42"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayArrayToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "4 8 15 16 23 42\n1 1 2 3 5 8"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); int32_value = 4; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); int32_value = 1; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 1; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 2; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 3; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 5; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); str_value = "4 8 15 16 23 42\n1 1 2 3 5 8"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "Int32ArrayArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_int32_array_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; DBusMessageIter subsubiter; int32_t int32_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToInt32ArrayArray_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32ArrayArray"); dbus_message_iter_init_append (method_call, &iter); str_value = "4 8 15 16 23 42\n1 1 2 3 5 8"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING)); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &subiter); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 4); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 8); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 15); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 16); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 23); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 1); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 1); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 2); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 3); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 5); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 8); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32ArrayArray"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToInt32ArrayArray.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32ArrayArray"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32ArrayArray"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); int32_value = 4; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); int32_value = 1; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 1; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 2; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 3; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 5; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32ArrayArray"); dbus_message_iter_init_append (method_call, &iter); str_value = "4 8 15 16 23 42\n1 1 2 3 5 8"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); int32_value = 4; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); int32_value = 1; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 1; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 2; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 3; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 5; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToInt32ArrayArray"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_struct_array_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter subiter; const char * str_value; uint32_t uint32_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StructArrayToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 27; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "Joe 34\nPaul 27"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StructArrayToStr.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructArrayToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "Joe"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an array member of the wrong type is given. */ TEST_FEATURE ("with wrong array member type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &arrayiter); str_value = "Joe"; dbus_message_iter_append_basic (&arrayiter, DBUS_TYPE_STRING, &str_value); str_value = "Paul"; dbus_message_iter_append_basic (&arrayiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a structure member of the wrong type is given. */ TEST_FEATURE ("with wrong struct member type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "34"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "27"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra structure entry is given. */ TEST_FEATURE ("with extra member"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); str_value = "Male"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 27; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); str_value = "Male"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 27; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&iter, &arrayiter); str_value = "Jane"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StructArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_struct_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter subiter; char * str_value; uint32_t uint32_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToStructArray_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStructArray"); dbus_message_iter_init_append (method_call, &iter); str_value = "Joe 34\nPaul 27"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), (DBUS_TYPE_ARRAY_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING)); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_STRUCT); dbus_message_iter_recurse (&arrayiter, &subiter); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Joe"); dbus_message_iter_next (&subiter); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 34); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_STRUCT); dbus_message_iter_recurse (&arrayiter, &subiter); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Paul"); dbus_message_iter_next (&subiter); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 27); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_INVALID); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStructArray"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToStructArray.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStructArray"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStructArray"); dbus_message_iter_init_append (method_call, &iter); uint32_value = 34; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStructArray"); dbus_message_iter_init_append (method_call, &iter); str_value = "Joe 34\nPaul 27"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToStructArray"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_dict_entry_array_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter subiter; const char * str_value; uint32_t uint32_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_DictEntryArrayToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DictEntryArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 27; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "Joe 34\nPaul 27"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DictEntryArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.DictEntryArrayToStr.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DictEntryArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DictEntryArrayToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "Joe"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an array member of the wrong type is given. */ TEST_FEATURE ("with wrong array member type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DictEntryArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &arrayiter); str_value = "Joe"; dbus_message_iter_append_basic (&arrayiter, DBUS_TYPE_STRING, &str_value); str_value = "Paul"; dbus_message_iter_append_basic (&arrayiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a dictionary member of the wrong type is given. */ TEST_FEATURE ("with wrong dict entry member type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DictEntryArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "34"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "27"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&iter, &arrayiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DictEntryArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 27; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&iter, &arrayiter); str_value = "Jane"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "DictEntryArrayToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_dict_entry_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter subiter; char * str_value; uint32_t uint32_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToDictEntryArray_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToDictEntryArray"); dbus_message_iter_init_append (method_call, &iter); str_value = "Joe 34\nPaul 27"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), (DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING)); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_DICT_ENTRY); dbus_message_iter_recurse (&arrayiter, &subiter); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Joe"); dbus_message_iter_next (&subiter); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 34); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_DICT_ENTRY); dbus_message_iter_recurse (&arrayiter, &subiter); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Paul"); dbus_message_iter_next (&subiter); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 27); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_INVALID); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToDictEntryArray"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToDictEntryArray.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToDictEntryArray"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToDictEntryArray"); dbus_message_iter_init_append (method_call, &iter); uint32_value = 34; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToDictEntryArray"); dbus_message_iter_init_append (method_call, &iter); str_value = "Joe 34\nPaul 27"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToDictEntryArray"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_unix_fd_to_str (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; int unix_fd_value; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; TEST_FUNCTION ("my_com_netsplit_Nih_Test_UnixFdToStr_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UnixFdToStr"); dbus_message_iter_init_append (method_call, &iter); unix_fd_value = 1; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UNIX_FD, &unix_fd_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_TRUE (strchr ("0123456789", str_value[0])); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UnixFdToStr"); dbus_message_iter_init_append (method_call, &iter); str_value = "True"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UnixFdToStr"); dbus_message_iter_init_append (method_call, &iter); unix_fd_value = 1; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UNIX_FD, &unix_fd_value); str_value = "True"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "UnixFdToStr"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_unix_fd (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; char * str_value; dbus_uint32_t serial; DBusMessage * reply; int unix_fd_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_StrToUnixFd_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the function works as we expect when we give the * expected argument type. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUnixFd"); dbus_message_iter_init_append (method_call, &iter); str_value = "1"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), DBUS_TYPE_UNIX_FD_AS_STRING); dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &unix_fd_value); TEST_GT (unix_fd_value, 2); // duplicated by dbus dbus_message_unref (reply); close (unix_fd_value); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUnixFd"); dbus_message_iter_init_append (method_call, &iter); str_value = ""; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrToUnixFd.EmptyInput")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUnixFd"); dbus_message_iter_init_append (method_call, &iter); str_value = "invalid"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUnixFd"); dbus_message_iter_init_append (method_call, &iter); unix_fd_value = 1; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UNIX_FD, &unix_fd_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUnixFd"); dbus_message_iter_init_append (method_call, &iter); str_value = "1"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); unix_fd_value = 1; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UNIX_FD, &unix_fd_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "StrToUnixFd"); dbus_message_iter_init_append (method_call, &iter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_byte (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; uint8_t byte_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_byte"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_byte (server_conn, "/com/netsplit/Nih/Test", 97); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewByte")); TEST_EQ_STR (dbus_message_get_signature (signal), DBUS_TYPE_BYTE_AS_STRING); dbus_message_iter_init (signal, &iter); dbus_message_iter_get_basic (&iter, &byte_value); TEST_EQ (byte_value, 97); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_boolean (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; int boolean_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_boolean"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_boolean (server_conn, "/com/netsplit/Nih/Test", TRUE); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewBoolean")); TEST_EQ_STR (dbus_message_get_signature (signal), DBUS_TYPE_BOOLEAN_AS_STRING); dbus_message_iter_init (signal, &iter); dbus_message_iter_get_basic (&iter, &boolean_value); TEST_EQ (boolean_value, TRUE); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_int16 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; int16_t int16_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_int16"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_int16 (server_conn, "/com/netsplit/Nih/Test", -42); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewInt16")); TEST_EQ_STR (dbus_message_get_signature (signal), DBUS_TYPE_INT16_AS_STRING); dbus_message_iter_init (signal, &iter); dbus_message_iter_get_basic (&iter, &int16_value); TEST_EQ (int16_value, -42); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_uint16 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; uint16_t uint16_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_uint16"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_uint16 (server_conn, "/com/netsplit/Nih/Test", 42); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewUInt16")); TEST_EQ_STR (dbus_message_get_signature (signal), DBUS_TYPE_UINT16_AS_STRING); dbus_message_iter_init (signal, &iter); dbus_message_iter_get_basic (&iter, &uint16_value); TEST_EQ (uint16_value, 42); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_int32 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; int32_t int32_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_int32"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_int32 (server_conn, "/com/netsplit/Nih/Test", -1048576); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewInt32")); TEST_EQ_STR (dbus_message_get_signature (signal), DBUS_TYPE_INT32_AS_STRING); dbus_message_iter_init (signal, &iter); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, -1048576); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_uint32 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; uint32_t uint32_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_uint32"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_uint32 (server_conn, "/com/netsplit/Nih/Test", 1048576); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewUInt32")); TEST_EQ_STR (dbus_message_get_signature (signal), DBUS_TYPE_UINT32_AS_STRING); dbus_message_iter_init (signal, &iter); dbus_message_iter_get_basic (&iter, &uint32_value); TEST_EQ (uint32_value, 1048576); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_int64 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; int64_t int64_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_int64"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_int64 (server_conn, "/com/netsplit/Nih/Test", -4815162342L); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewInt64")); TEST_EQ_STR (dbus_message_get_signature (signal), DBUS_TYPE_INT64_AS_STRING); dbus_message_iter_init (signal, &iter); dbus_message_iter_get_basic (&iter, &int64_value); TEST_EQ (int64_value, -4815162342L); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_uint64 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; uint64_t uint64_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_uint64"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_uint64 (server_conn, "/com/netsplit/Nih/Test", 4815162342L); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewUInt64")); TEST_EQ_STR (dbus_message_get_signature (signal), DBUS_TYPE_UINT64_AS_STRING); dbus_message_iter_init (signal, &iter); dbus_message_iter_get_basic (&iter, &uint64_value); TEST_EQ (uint64_value, 4815162342L); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_double (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; double double_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_double"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_double (server_conn, "/com/netsplit/Nih/Test", 3.141597); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewDouble")); TEST_EQ_STR (dbus_message_get_signature (signal), DBUS_TYPE_DOUBLE_AS_STRING); dbus_message_iter_init (signal, &iter); dbus_message_iter_get_basic (&iter, &double_value); TEST_EQ (double_value, 3.141597); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_string (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; const char * str_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_string"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_string (server_conn, "/com/netsplit/Nih/Test", "she needs more of ze punishment"); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewString")); TEST_EQ_STR (dbus_message_get_signature (signal), DBUS_TYPE_STRING_AS_STRING); dbus_message_iter_init (signal, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "she needs more of ze punishment"); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_object_path (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; const char * str_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_object_path"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_object_path (server_conn, "/com/netsplit/Nih/Test", "/com/netsplit/Nih/Test"); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewObjectPath")); TEST_EQ_STR (dbus_message_get_signature (signal), DBUS_TYPE_OBJECT_PATH_AS_STRING); dbus_message_iter_init (signal, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "/com/netsplit/Nih/Test"); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_signature (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; const char * str_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_signature"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_signature (server_conn, "/com/netsplit/Nih/Test", "a(ib)"); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewSignature")); TEST_EQ_STR (dbus_message_get_signature (signal), DBUS_TYPE_SIGNATURE_AS_STRING); dbus_message_iter_init (signal, &iter); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "a(ib)"); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_struct (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; DBusMessageIter subiter; MyTestNewStructValue struct_value; const char * str_value; uint32_t uint32_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_struct"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); struct_value.item0 = "Joe"; struct_value.item1 = 34; ret = my_test_emit_new_struct (server_conn, "/com/netsplit/Nih/Test", &struct_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewStruct")); TEST_EQ_STR (dbus_message_get_signature (signal), (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING)); dbus_message_iter_init (signal, &iter); dbus_message_iter_recurse (&iter, &subiter); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Joe"); dbus_message_iter_next (&subiter); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 34); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_int32_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; int32_t * int32_array = NULL; size_t int32_array_len; DBusMessageIter subiter; int32_t int32_value; TEST_FUNCTION ("my_test_emit_new_int32_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FEATURE ("with array"); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); TEST_ALLOC_SAFE { int32_array = nih_alloc (NULL, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; int32_array_len = 6; } ret = my_test_emit_new_int32_array (server_conn, "/com/netsplit/Nih/Test", int32_array, int32_array_len); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); nih_free (int32_array); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewInt32Array")); TEST_EQ_STR (dbus_message_get_signature (signal), (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING)); dbus_message_iter_init (signal, &iter); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subiter, &int32_value); TEST_EQ (int32_value, 4); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subiter, &int32_value); TEST_EQ (int32_value, 8); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subiter, &int32_value); TEST_EQ (int32_value, 15); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subiter, &int32_value); TEST_EQ (int32_value, 16); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subiter, &int32_value); TEST_EQ (int32_value, 23); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subiter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); nih_free (int32_array); } /* Check that we can also given an empty array, which is actually * the NULL pointer. */ TEST_FEATURE ("with empty array"); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_int32_array (server_conn, "/com/netsplit/Nih/Test", NULL, 0); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); nih_free (int32_array); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewInt32Array")); TEST_EQ_STR (dbus_message_get_signature (signal), (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING)); dbus_message_iter_init (signal, &iter); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_str_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; char ** str_array = NULL; DBusMessageIter subiter; const char * str_value; TEST_FUNCTION ("my_test_emit_new_str_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FEATURE ("with array"); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); TEST_ALLOC_SAFE { str_array = nih_alloc (NULL, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; } ret = my_test_emit_new_str_array (server_conn, "/com/netsplit/Nih/Test", str_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); nih_free (str_array); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewStrArray")); TEST_EQ_STR (dbus_message_get_signature (signal), (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)); dbus_message_iter_init (signal, &iter); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "she"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "needs"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "more"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "of"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "ze"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "punishment"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); nih_free (str_array); } /* Check that we can give an empty array consisting of just the * NULL pointer. */ TEST_FEATURE ("with empty array"); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); TEST_ALLOC_SAFE { str_array = nih_alloc (NULL, sizeof (char *) * 1); str_array[0] = NULL; } ret = my_test_emit_new_str_array (server_conn, "/com/netsplit/Nih/Test", str_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); nih_free (str_array); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewStrArray")); TEST_EQ_STR (dbus_message_get_signature (signal), (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)); dbus_message_iter_init (signal, &iter); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); nih_free (str_array); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_int32_array_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; int32_t ** int32_array_array = NULL; size_t * int32_array_array_len = NULL; DBusMessageIter subiter; DBusMessageIter subsubiter; int32_t int32_value; TEST_FUNCTION ("my_test_emit_new_int32_array_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FEATURE ("with array"); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); TEST_ALLOC_SAFE { int32_array_array = nih_alloc (NULL, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (NULL, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; } ret = my_test_emit_new_int32_array_array (server_conn, "/com/netsplit/Nih/Test", int32_array_array, int32_array_array_len); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); nih_free (int32_array_array); nih_free (int32_array_array_len); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewInt32ArrayArray")); TEST_EQ_STR (dbus_message_get_signature (signal), (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING)); dbus_message_iter_init (signal, &iter); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 4); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 8); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 15); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 16); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 23); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 1); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 1); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 2); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 3); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 5); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 8); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); nih_free (int32_array_array); nih_free (int32_array_array_len); } /* Check that we can also give an empty array, which actually has * NULL for its size array. */ TEST_FEATURE ("with empty array"); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); TEST_ALLOC_SAFE { int32_array_array = nih_alloc (NULL, sizeof (int32_t *) * 1); int32_array_array_len = NULL; int32_array_array[0] = NULL; } ret = my_test_emit_new_int32_array_array (server_conn, "/com/netsplit/Nih/Test", int32_array_array, int32_array_array_len); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); nih_free (int32_array_array); nih_free (int32_array_array_len); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewInt32ArrayArray")); TEST_EQ_STR (dbus_message_get_signature (signal), (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING)); dbus_message_iter_init (signal, &iter); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (signal); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); nih_free (int32_array_array); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_struct_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter subiter; MyTestNewStructArrayValueElement **struct_array = NULL; const char * str_value; uint32_t uint32_value; TEST_FUNCTION ("my_test_emit_new_struct_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FEATURE ("with array"); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); TEST_ALLOC_SAFE { struct_array = nih_alloc (NULL, sizeof (MyTestNewStructArrayValueElement *) * 3); struct_array[0] = nih_new (struct_array, MyTestNewStructArrayValueElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, MyTestNewStructArrayValueElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; } ret = my_test_emit_new_struct_array (server_conn, "/com/netsplit/Nih/Test", struct_array); if (test_alloc_failed) { TEST_LT (ret, 0); nih_free (struct_array); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewStructArray")); TEST_EQ_STR (dbus_message_get_signature (signal), (DBUS_TYPE_ARRAY_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING)); dbus_message_iter_init (signal, &iter); dbus_message_iter_recurse (&iter, &arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_STRUCT); dbus_message_iter_recurse (&arrayiter, &subiter); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Joe"); dbus_message_iter_next (&subiter); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 34); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_STRUCT); dbus_message_iter_recurse (&arrayiter, &subiter); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Paul"); dbus_message_iter_next (&subiter); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 27); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_INVALID); dbus_message_unref (signal); nih_free (struct_array); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } /* Check that we can pass an empty array, which has NULL as the * only element. */ TEST_FEATURE ("with empty array"); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); TEST_ALLOC_SAFE { struct_array = nih_alloc (NULL, sizeof (MyTestNewStructArrayValueElement *) * 1); struct_array[0] = NULL; } ret = my_test_emit_new_struct_array (server_conn, "/com/netsplit/Nih/Test", struct_array); if (test_alloc_failed) { TEST_LT (ret, 0); nih_free (struct_array); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewStructArray")); TEST_EQ_STR (dbus_message_get_signature (signal), (DBUS_TYPE_ARRAY_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING)); dbus_message_iter_init (signal, &iter); dbus_message_iter_recurse (&iter, &arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_INVALID); dbus_message_unref (signal); nih_free (struct_array); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_dict_entry_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter subiter; MyTestNewDictEntryArrayValueElement **dict_entry_array = NULL; const char * str_value; uint32_t uint32_value; TEST_FUNCTION ("my_test_emit_new_dict_entry_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FEATURE ("with array"); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); TEST_ALLOC_SAFE { dict_entry_array = nih_alloc (NULL, sizeof (MyTestNewDictEntryArrayValueElement *) * 3); dict_entry_array[0] = nih_new (dict_entry_array, MyTestNewDictEntryArrayValueElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, MyTestNewDictEntryArrayValueElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; } ret = my_test_emit_new_dict_entry_array (server_conn, "/com/netsplit/Nih/Test", dict_entry_array); if (test_alloc_failed) { TEST_LT (ret, 0); nih_free (dict_entry_array); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewDictEntryArray")); TEST_EQ_STR (dbus_message_get_signature (signal), (DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING)); dbus_message_iter_init (signal, &iter); dbus_message_iter_recurse (&iter, &arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_DICT_ENTRY); dbus_message_iter_recurse (&arrayiter, &subiter); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Joe"); dbus_message_iter_next (&subiter); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 34); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_DICT_ENTRY); dbus_message_iter_recurse (&arrayiter, &subiter); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Paul"); dbus_message_iter_next (&subiter); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 27); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_INVALID); dbus_message_unref (signal); nih_free (dict_entry_array); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } /* Check that we can pass an empty array, which has NULL as the * only element. */ TEST_FEATURE ("with empty array"); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); TEST_ALLOC_SAFE { dict_entry_array = nih_alloc (NULL, sizeof (MyTestNewDictEntryArrayValueElement *) * 1); dict_entry_array[0] = NULL; } ret = my_test_emit_new_dict_entry_array (server_conn, "/com/netsplit/Nih/Test", dict_entry_array); if (test_alloc_failed) { TEST_LT (ret, 0); nih_free (dict_entry_array); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewDictEntryArray")); TEST_EQ_STR (dbus_message_get_signature (signal), (DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING)); dbus_message_iter_init (signal, &iter); dbus_message_iter_recurse (&iter, &arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_INVALID); dbus_message_unref (signal); nih_free (dict_entry_array); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_new_unix_fd (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusError dbus_error; int ret; DBusMessage * signal; DBusMessageIter iter; int unix_fd_value; /* Check that the generated function emits the expected signal, * with the arguments we give. */ TEST_FUNCTION ("my_test_emit_new_unix_fd"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); ret = my_test_emit_new_unix_fd (server_conn, "/com/netsplit/Nih/Test", 1); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); continue; } dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, signal); TEST_TRUE (dbus_message_is_signal ( signal, "com.netsplit.Nih.Test", "NewUnixFd")); TEST_EQ_STR (dbus_message_get_signature (signal), DBUS_TYPE_UNIX_FD_AS_STRING); dbus_message_iter_init (signal, &iter); dbus_message_iter_get_basic (&iter, &unix_fd_value); TEST_GT (unix_fd_value, 2); // dbus dups this dbus_message_unref (signal); close (unix_fd_value); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); assert (! dbus_error_is_set (&dbus_error)); dbus_error_free (&dbus_error); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_byte (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; uint8_t byte_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_byte_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } byte_property = 97; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "byte"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_BYTE); dbus_message_iter_get_basic (&subiter, &byte_value); TEST_EQ (byte_value, 97); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } byte_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "byte"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Byte.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } byte_property = 4; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "byte"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "byte"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_BYTE_AS_STRING, &subiter); byte_value = 97; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_BYTE, &byte_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_byte (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; uint8_t byte_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_byte_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } byte_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "byte"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_BYTE_AS_STRING, &subiter); byte_value = 97; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_BYTE, &byte_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_EQ (byte_property, 97); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "byte"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_BYTE_AS_STRING, &subiter); byte_value = 0; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_BYTE, &byte_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Byte.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "byte"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_BYTE_AS_STRING, &subiter); byte_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_BYTE, &byte_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "byte"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "97"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "byte"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "97"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "byte"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_BYTE_AS_STRING, &subiter); byte_value = 97; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_BYTE, &byte_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "97"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "byte"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_boolean (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; int boolean_value; TEST_FUNCTION ("my_com_netsplit_Nih_Test_boolean_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } boolean_property = TRUE; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "boolean"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_BOOLEAN); dbus_message_iter_get_basic (&subiter, &boolean_value); TEST_EQ (boolean_value, TRUE); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } boolean_property = FALSE; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "boolean"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Boolean.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "boolean"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_BOOLEAN_AS_STRING, &subiter); boolean_value = TRUE; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_BOOLEAN, &boolean_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_boolean (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; int boolean_value; dbus_uint32_t serial; DBusMessage * reply; TEST_FUNCTION ("my_com_netsplit_Nih_Test_boolean_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } boolean_property = FALSE; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "boolean"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_BOOLEAN_AS_STRING, &subiter); boolean_value = TRUE; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_BOOLEAN, &boolean_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_EQ (boolean_property, TRUE); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "boolean"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_BOOLEAN_AS_STRING, &subiter); boolean_value = FALSE; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_BOOLEAN, &boolean_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Boolean.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "boolean"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "True"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "boolean"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "True"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "boolean"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_BOOLEAN_AS_STRING, &subiter); boolean_value = TRUE; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_BOOLEAN, &boolean_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "True"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "boolean"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_int16 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; int16_t int16_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_int16_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int16_property = -42; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT16); dbus_message_iter_get_basic (&subiter, &int16_value); TEST_EQ (int16_value, -42); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int16_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int16.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int16_property = 4; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT16_AS_STRING, &subiter); int16_value = -42; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT16, &int16_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_int16 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; int16_t int16_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_int16_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int16_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT16_AS_STRING, &subiter); int16_value = -42; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT16, &int16_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_EQ (int16_property, -42); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT16_AS_STRING, &subiter); int16_value = 0; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT16, &int16_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int16.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT16_AS_STRING, &subiter); int16_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT16, &int16_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "-42"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "-42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT16_AS_STRING, &subiter); int16_value = -42; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT16, &int16_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "-42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_uint16 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; uint16_t uint16_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_uint16_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } uint16_property = 42; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UINT16); dbus_message_iter_get_basic (&subiter, &uint16_value); TEST_EQ (uint16_value, 42); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } uint16_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.UInt16.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } uint16_property = 4; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT16_AS_STRING, &subiter); uint16_value = 42; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT16, &uint16_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_uint16 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; uint16_t uint16_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_uint16_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } uint16_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT16_AS_STRING, &subiter); uint16_value = 42; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT16, &uint16_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_EQ (uint16_property, 42); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT16_AS_STRING, &subiter); uint16_value = 0; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT16, &uint16_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.UInt16.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT16_AS_STRING, &subiter); uint16_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT16, &uint16_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "42"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT16_AS_STRING, &subiter); uint16_value = 42; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT16, &uint16_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint16"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_int32 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; int32_t int32_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_int32_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int32_property = -1048576; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subiter, &int32_value); TEST_EQ (int32_value, -1048576); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int32_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int32.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int32_property = 4; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT32_AS_STRING, &subiter); int32_value = -1048576; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_int32 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; int32_t int32_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_int32_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int32_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT32_AS_STRING, &subiter); int32_value = -1048576; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_EQ (int32_property, -1048576); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT32_AS_STRING, &subiter); int32_value = 0; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int32.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT32_AS_STRING, &subiter); int32_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "-1048576"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "-1048576"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT32_AS_STRING, &subiter); int32_value = -1048576; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "-1048576"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_uint32 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; uint32_t uint32_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_uint32_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } uint32_property = 1048576; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UINT32); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 1048576); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } uint32_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.UInt32.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } uint32_property = 4; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &subiter); uint32_value = 1048576; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_uint32 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; uint32_t uint32_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_uint32_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } uint32_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &subiter); uint32_value = 1048576; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_EQ (uint32_property, 1048576); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &subiter); uint32_value = 0; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.UInt32.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &subiter); uint32_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "1048576"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "1048576"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &subiter); uint32_value = 1048576; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "1048576"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint32"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_int64 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; int64_t int64_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_int16_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int64_property = -4815162342L; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT64); dbus_message_iter_get_basic (&subiter, &int64_value); TEST_EQ (int64_value, -4815162342L); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int64_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int64.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int64_property = 4; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT64_AS_STRING, &subiter); int64_value = -4815162342L; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT64, &int64_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_int64 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; int64_t int64_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_int64_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int64_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT64_AS_STRING, &subiter); int64_value = -4815162342L; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT64, &int64_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_EQ (int64_property, -4815162342L); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT64_AS_STRING, &subiter); int64_value = 0; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT64, &int64_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int64.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT64_AS_STRING, &subiter); int64_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT64, &int64_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "-4815162342"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "-4815162342"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT64_AS_STRING, &subiter); int64_value = -4815162342L; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT64, &int64_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "-4815162342"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_uint64 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; uint64_t uint64_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_uint64_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } uint64_property = 4815162342L; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UINT64); dbus_message_iter_get_basic (&subiter, &uint64_value); TEST_EQ (uint64_value, 4815162342L); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } uint64_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.UInt64.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } uint64_property = 4; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT64_AS_STRING, &subiter); uint64_value = 4815162342L; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT64, &uint64_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_uint64 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; uint64_t uint64_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_uint64_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } uint64_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT64_AS_STRING, &subiter); uint64_value = 4815162342L; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT64, &uint64_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_EQ (uint64_property, 4815162342L); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT64_AS_STRING, &subiter); uint64_value = 0; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT64, &uint64_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.UInt64.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT64_AS_STRING, &subiter); uint64_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT64, &uint64_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "4815162342"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "4815162342"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT64_AS_STRING, &subiter); uint64_value = 4815162342L; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT64, &uint64_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "4815162342"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "uint64"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_double (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; double double_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_double_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } double_property = 3.141597; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "double"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_DOUBLE); dbus_message_iter_get_basic (&subiter, &double_value); TEST_EQ (double_value, 3.141597); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } double_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "double"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Double.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } double_property = 4; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "double"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "double"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_value = 3.141597; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_double (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; double double_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_double_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } double_property = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "double"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_value = 3.141597; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_EQ (double_property, 3.141597); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "double"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_value = 0; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Double.Zero")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "double"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "double"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "97"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "boolean"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "3.141597"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "double"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_value = 3.141597; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "3.141597"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "double"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_string (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_string_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } str_property = "she needs more of ze punishment"; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "string"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "she needs more of ze punishment"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } str_property = ""; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "string"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.String.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } str_property = "invalid"; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "string"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "string"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_string (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_string_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } str_property = NULL; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "string"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_EQ_STR (str_property, "she needs more of ze punishment"); nih_free (str_property); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "string"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = ""; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.String.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "string"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "invalid"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "string"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_OBJECT_PATH_AS_STRING, &subiter); str_value = "/she/needs/more/of/ze/punishment"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "string"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "string"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "/she/needs/more/of/ze/punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "string"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_object_path (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_object_path_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } object_path_property = "/com/netsplit/Nih/Test"; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "object_path"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_OBJECT_PATH); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "/com/netsplit/Nih/Test"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } object_path_property = "/"; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "object_path"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.ObjectPath.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } object_path_property = "/invalid"; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "object_path"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "object_path"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_OBJECT_PATH_AS_STRING, &subiter); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_object_path (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_object_path_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } object_path_property = NULL; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "object_path"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_OBJECT_PATH_AS_STRING, &subiter); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_EQ_STR (object_path_property, "/com/netsplit/Nih/Test"); nih_free (object_path_property); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "object_path"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_OBJECT_PATH_AS_STRING, &subiter); str_value = "/"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.ObjectPath.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "object_path"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_OBJECT_PATH_AS_STRING, &subiter); str_value = "/invalid"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "object_path"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "object_path"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "object_path"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_OBJECT_PATH_AS_STRING, &subiter); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "object_path"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_signature (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_signature_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } signature_property = "a(ib)"; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "signature"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_SIGNATURE); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "a(ib)"); dbus_message_unref (reply); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } signature_property = ""; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "signature"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Signature.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } signature_property = "inva(x)id"; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "signature"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "signature"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_SIGNATURE_AS_STRING, &subiter); str_value = "a(ib)"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_SIGNATURE, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_signature (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_signature_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } signature_property = NULL; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "signature"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_SIGNATURE_AS_STRING, &subiter); str_value = "a(ib)"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_SIGNATURE, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_EQ_STR (signature_property, "a(ib)"); nih_free (signature_property); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "signature"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_SIGNATURE_AS_STRING, &subiter); str_value = ""; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_SIGNATURE, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Signature.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "signature"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_SIGNATURE_AS_STRING, &subiter); str_value = "inva(x)id"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_SIGNATURE, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "signature"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "a(ib)"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "signature"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "a(ib)"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "signature"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_SIGNATURE_AS_STRING, &subiter); str_value = "a(ib)"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_SIGNATURE, &str_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "signature"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_structure (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; uint32_t uint32_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter variter; DBusMessageIter subiter; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_structure_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); struct_property = nih_new (NULL, MyStruct); struct_property->item0 = "Joe"; struct_property->item1 = 34; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "structure"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &variter); TEST_EQ (dbus_message_iter_get_arg_type (&variter), DBUS_TYPE_STRUCT); dbus_message_iter_recurse (&variter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Joe"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UINT32); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 34); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (reply); nih_free (struct_property); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); struct_property = nih_new (NULL, MyStruct); struct_property->item0 = ""; struct_property->item1 = 34; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "structure"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Structure.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (struct_property); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); struct_property = nih_new (NULL, MyStruct); struct_property->item0 = "invalid"; struct_property->item1 = 34; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "structure"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (struct_property); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "structure"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_structure (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; uint32_t uint32_value; DBusMessageIter variter; DBusMessageIter subiter; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_structure_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } struct_property = NULL; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "structure"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&variter, &subiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_NE_P (struct_property, NULL); TEST_ALLOC_SIZE (struct_property, sizeof (MyStruct)); TEST_EQ_STR (struct_property->item0, "Joe"); TEST_EQ (struct_property->item1, 34); nih_free (struct_property); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "structure"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = ""; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&variter, &subiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Structure.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "structure"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "invalid"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&variter, &subiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a structure member of the wrong type is given. */ TEST_FEATURE ("with wrong member type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "structure"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "34"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&variter, &subiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "structure"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "structure"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "Joe"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "structure"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&variter, &subiter); dbus_message_iter_close_container (&iter, &variter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "structure"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_int32_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; DBusMessageIter subsubiter; int32_t int32_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_int32_array_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); int32_array_property = nih_alloc (NULL, sizeof (int32_t) * 6); int32_array_property[0] = 4; int32_array_property[1] = 8; int32_array_property[2] = 15; int32_array_property[3] = 16; int32_array_property[4] = 23; int32_array_property[5] = 42; int32_array_property_len = 6; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 4); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 8); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 15); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 16); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 23); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubiter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (reply); nih_free (object); nih_free (int32_array_property); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int32_array_property = NULL; int32_array_property_len = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int32Array.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); int32_array_property = nih_alloc (NULL, sizeof (int32_t) * 4); int32_array_property[0] = 4; int32_array_property[1] = 8; int32_array_property[2] = 15; int32_array_property[3] = 16; int32_array_property_len = 4; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); nih_free (int32_array_property); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); int32_value = 4; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_int32_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; DBusMessageIter subsubiter; int32_t int32_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_int32_array_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int32_array_property = NULL; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); int32_value = 4; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_EQ (int32_array_property_len, 6); TEST_ALLOC_SIZE (int32_array_property, sizeof (int32_t) * 6); TEST_EQ (int32_array_property[0], 4); TEST_EQ (int32_array_property[1], 8); TEST_EQ (int32_array_property[2], 15); TEST_EQ (int32_array_property[3], 16); TEST_EQ (int32_array_property[4], 23); TEST_EQ (int32_array_property[5], 42); nih_free (int32_array_property); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int32Array.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); int32_value = 4; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an array element of the wrong type is given. */ TEST_FEATURE ("with wrong array element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subsubiter); str_value = "4"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "8"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "15"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "16"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "23"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "42"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong variant element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "4 8 15 16 32 42"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "4 8 15 16 23 42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); int32_value = 4; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); str_value = "4 8 15 16 23 42"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_str_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; DBusMessageIter subsubiter; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_str_array_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); str_array_property = nih_alloc (NULL, sizeof (char *) * 7); str_array_property[0] = "she"; str_array_property[1] = "needs"; str_array_property[2] = "more"; str_array_property[3] = "of"; str_array_property[4] = "ze"; str_array_property[5] = "punishment"; str_array_property[6] = NULL; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "str_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "she"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "needs"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "more"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "of"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "ze"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "punishment"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (reply); nih_free (object); nih_free (str_array_property); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); str_array_property = nih_alloc (NULL, sizeof (char *) * 1); str_array_property[0] = NULL; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "str_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrArray.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); nih_free (str_array_property); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); str_array_property = nih_alloc (NULL, sizeof (char *) * 5); str_array_property[0] = "this"; str_array_property[1] = "is"; str_array_property[2] = "a"; str_array_property[3] = "test"; str_array_property[4] = NULL; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "str_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); nih_free (str_array_property); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "str_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subsubiter); str_value = "she"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "needs"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "more"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "the"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "punishment"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_str_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; DBusMessageIter subsubiter; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_str_array_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } str_array_property = NULL; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "str_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); str_value = "she"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "needs"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "more"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "ze"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "punishment"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_ALLOC_SIZE (str_array_property, sizeof (char *) * 7); TEST_EQ_STR (str_array_property[0], "she"); TEST_EQ_STR (str_array_property[1], "needs"); TEST_EQ_STR (str_array_property[2], "more"); TEST_EQ_STR (str_array_property[3], "of"); TEST_EQ_STR (str_array_property[4], "ze"); TEST_EQ_STR (str_array_property[5], "punishment"); TEST_EQ_P (str_array_property[6], NULL); nih_free (str_array_property); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "str_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subsubiter); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StrArray.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "str_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subsubiter); str_value = "this"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "is"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "a"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "test"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an array element of the wrong type is given. */ TEST_FEATURE ("with wrong array element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "str_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH_AS_STRING, &subsubiter); str_value = "/she"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_OBJECT_PATH, &str_value); str_value = "/needs"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_OBJECT_PATH, &str_value); str_value = "/more"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_OBJECT_PATH, &str_value); str_value = "/of"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_OBJECT_PATH, &str_value); str_value = "/ze"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_OBJECT_PATH, &str_value); str_value = "/punishment"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_OBJECT_PATH, &str_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong variant element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "str_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "str_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "str_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubiter); str_value = "she"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "needs"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "more"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "ze"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "punishment"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "str_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_int32_array_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; DBusMessageIter subsubiter; DBusMessageIter subsubsubiter; int32_t int32_value; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_int32_array_array_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); int32_array_array_property = nih_alloc ( NULL, sizeof (int32_t *) * 3); int32_array_array_property_len = nih_alloc ( NULL, sizeof (size_t) * 2); int32_array_array_property[0] = nih_alloc ( int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[0][0] = 4; int32_array_array_property[0][1] = 8; int32_array_array_property[0][2] = 15; int32_array_array_property[0][3] = 16; int32_array_array_property[0][4] = 23; int32_array_array_property[0][5] = 42; int32_array_array_property_len[0] = 6; int32_array_array_property[1] = nih_alloc ( int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[1][0] = 1; int32_array_array_property[1][1] = 1; int32_array_array_property[1][2] = 2; int32_array_array_property[1][3] = 3; int32_array_array_property[1][4] = 5; int32_array_array_property[1][5] = 8; int32_array_array_property_len[1] = 6; int32_array_array_property[2] = NULL; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&subsubiter, &subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubsubiter, &int32_value); TEST_EQ (int32_value, 4); dbus_message_iter_next (&subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubsubiter, &int32_value); TEST_EQ (int32_value, 8); dbus_message_iter_next (&subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubsubiter, &int32_value); TEST_EQ (int32_value, 15); dbus_message_iter_next (&subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubsubiter, &int32_value); TEST_EQ (int32_value, 16); dbus_message_iter_next (&subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubsubiter, &int32_value); TEST_EQ (int32_value, 23); dbus_message_iter_next (&subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubsubiter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&subsubiter, &subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubsubiter, &int32_value); TEST_EQ (int32_value, 1); dbus_message_iter_next (&subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubsubiter, &int32_value); TEST_EQ (int32_value, 1); dbus_message_iter_next (&subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubsubiter, &int32_value); TEST_EQ (int32_value, 2); dbus_message_iter_next (&subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubsubiter, &int32_value); TEST_EQ (int32_value, 3); dbus_message_iter_next (&subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubsubiter, &int32_value); TEST_EQ (int32_value, 5); dbus_message_iter_next (&subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&subsubsubiter, &int32_value); TEST_EQ (int32_value, 8); dbus_message_iter_next (&subsubsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (reply); nih_free (object); nih_free (int32_array_array_property); nih_free (int32_array_array_property_len); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); int32_array_array_property = nih_alloc ( NULL, sizeof (int32_t *) * 1); int32_array_array_property_len = NULL; int32_array_array_property[0] = NULL; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int32ArrayArray.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); nih_free (int32_array_array_property); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); int32_array_array_property = nih_alloc ( NULL, sizeof (int32_t *) * 2); int32_array_array_property_len = nih_alloc ( NULL, sizeof (size_t) * 1); int32_array_array_property[0] = nih_alloc ( int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[0][0] = 4; int32_array_array_property[0][1] = 8; int32_array_array_property[0][2] = 15; int32_array_array_property[0][3] = 16; int32_array_array_property[0][4] = 23; int32_array_array_property[0][5] = 42; int32_array_array_property_len[0] = 6; int32_array_array_property[1] = NULL; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); nih_free (int32_array_array_property); nih_free (int32_array_array_property_len); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subsubiter); dbus_message_iter_open_container (&subsubiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubsubiter); int32_value = 4; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subsubiter, &subsubsubiter); dbus_message_iter_open_container (&subsubiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubsubiter); int32_value = 1; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 1; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 2; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 3; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 5; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subsubiter, &subsubsubiter); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_int32_array_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; DBusMessageIter subsubiter; DBusMessageIter subsubsubiter; int32_t int32_value; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_int32_array_array_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } int32_array_array_property = NULL; int32_array_array_property_len = 0; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subsubiter); dbus_message_iter_open_container (&subsubiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubsubiter); int32_value = 4; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subsubiter, &subsubsubiter); dbus_message_iter_open_container (&subsubiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubsubiter); int32_value = 1; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 1; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 2; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 3; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 5; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subsubiter, &subsubsubiter); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_ALLOC_SIZE (int32_array_array_property_len, sizeof (size_t) * 2); TEST_ALLOC_SIZE (int32_array_array_property, sizeof (int32_t *) * 3); TEST_EQ (int32_array_array_property_len[0], 6); TEST_ALLOC_SIZE (int32_array_array_property[0], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (int32_array_array_property[0], int32_array_array_property); TEST_EQ (int32_array_array_property[0][0], 4); TEST_EQ (int32_array_array_property[0][1], 8); TEST_EQ (int32_array_array_property[0][2], 15); TEST_EQ (int32_array_array_property[0][3], 16); TEST_EQ (int32_array_array_property[0][4], 23); TEST_EQ (int32_array_array_property[0][5], 42); TEST_EQ (int32_array_array_property_len[1], 6); TEST_ALLOC_SIZE (int32_array_array_property[1], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (int32_array_array_property[0], int32_array_array_property); TEST_EQ (int32_array_array_property[1][0], 1); TEST_EQ (int32_array_array_property[1][1], 1); TEST_EQ (int32_array_array_property[1][2], 2); TEST_EQ (int32_array_array_property[1][3], 3); TEST_EQ (int32_array_array_property[1][4], 5); TEST_EQ (int32_array_array_property[1][5], 8); TEST_EQ_P (int32_array_array_property[2], NULL); nih_free (int32_array_array_property); nih_free (int32_array_array_property_len); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subsubiter); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Int32ArrayArray.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subsubiter); dbus_message_iter_open_container (&subsubiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubsubiter); int32_value = 4; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subsubiter, &subsubsubiter); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a nested array element of the wrong type is given. */ TEST_FEATURE ("with wrong nested array element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING), &subsubiter); dbus_message_iter_open_container (&subsubiter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subsubsubiter); str_value = "4"; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_STRING, &str_value); str_value = "8"; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_STRING, &str_value); str_value = "15"; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_STRING, &str_value); str_value = "16"; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_STRING, &str_value); str_value = "23"; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_STRING, &str_value); str_value = "42"; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&subsubiter, &subsubsubiter); dbus_message_iter_open_container (&subsubiter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subsubsubiter); str_value = "1"; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_STRING, &str_value); str_value = "1"; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_STRING, &str_value); str_value = "2"; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_STRING, &str_value); str_value = "3"; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_STRING, &str_value); str_value = "5"; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_STRING, &str_value); str_value = "6"; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&subsubiter, &subsubsubiter); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a top array element of the wrong type is given. */ TEST_FEATURE ("with wrong top array element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subsubiter); str_value = "4"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "8"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "15"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "16"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "23"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "42"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong variant element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "4 8 15 16 32 42\n1 1 2 3 5 8"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "4 8 15 16 23 42\n1 1 2 3 5 8"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING), &subsubiter); dbus_message_iter_open_container (&subsubiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubsubiter); int32_value = 4; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 15; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 16; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 23; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 42; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subsubiter, &subsubsubiter); dbus_message_iter_open_container (&subsubiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &subsubsubiter); int32_value = 1; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 1; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 2; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 3; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 5; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); int32_value = 8; dbus_message_iter_append_basic (&subsubsubiter, DBUS_TYPE_INT32, &int32_value); dbus_message_iter_close_container (&subsubiter, &subsubsubiter); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); str_value = "4 8 15 16 23 42\n1 1 2 3 5 8"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "int32_array_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_struct_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; uint32_t uint32_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter variter; DBusMessageIter arrayiter; DBusMessageIter subiter; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_struct_array_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); struct_array_property = nih_alloc (NULL, sizeof (MyStruct *) * 3); struct_array_property[0] = nih_new (struct_array_property, MyStruct); struct_array_property[0]->item0 = "Joe"; struct_array_property[0]->item1 = 34; struct_array_property[1] = nih_new (struct_array_property, MyStruct); struct_array_property[1]->item0 = "Paul"; struct_array_property[1]->item1 = 27; struct_array_property[2] = NULL; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "struct_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &variter); TEST_EQ (dbus_message_iter_get_arg_type (&variter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&variter, &arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_STRUCT); dbus_message_iter_recurse (&arrayiter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Joe"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UINT32); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 34); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_STRUCT); dbus_message_iter_recurse (&arrayiter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Paul"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UINT32); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 27); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_INVALID); dbus_message_unref (reply); nih_free (struct_array_property); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); struct_array_property = nih_alloc (NULL, sizeof (MyStruct *) * 1); struct_array_property[0] = NULL; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "struct_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StructArray.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (struct_array_property); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); struct_array_property = nih_alloc (NULL, sizeof (MyStruct *) * 2); struct_array_property[0] = nih_new (struct_array_property, MyStruct); struct_array_property[0]->item0 = "Joe"; struct_array_property[0]->item1 = 34; struct_array_property[1] = NULL; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "struct_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (struct_array_property); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "struct_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_struct_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; uint32_t uint32_value; DBusMessageIter variter; DBusMessageIter arrayiter; DBusMessageIter subiter; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_struct_array_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } struct_array_property = NULL; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "struct_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 27; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&variter, &arrayiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_NE_P (struct_array_property, NULL); TEST_ALLOC_SIZE (struct_array_property, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (struct_array_property[0], struct_array_property); TEST_ALLOC_SIZE (struct_array_property[0], sizeof (MyStruct)); TEST_EQ_STR (struct_array_property[0]->item0, "Joe"); TEST_EQ (struct_array_property[0]->item1, 34); TEST_ALLOC_PARENT (struct_array_property[1], struct_array_property); TEST_ALLOC_SIZE (struct_array_property[1], sizeof (MyStruct)); TEST_EQ_STR (struct_array_property[1]->item0, "Paul"); TEST_EQ (struct_array_property[1]->item1, 27); TEST_EQ_P (struct_array_property[2], NULL); nih_free (struct_array_property); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "struct_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_close_container (&variter, &arrayiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.StructArray.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "struct_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&variter, &arrayiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a structure member of the wrong type is given. */ TEST_FEATURE ("with wrong member type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "struct_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "34"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "27"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&variter, &arrayiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an array element of the wrong type is given. */ TEST_FEATURE ("with wrong array element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "struct_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &arrayiter); str_value = "Joe"; dbus_message_iter_append_basic (&arrayiter, DBUS_TYPE_STRING, &str_value); str_value = "Paul"; dbus_message_iter_append_basic (&arrayiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&variter, &arrayiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong variant element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "struct_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variter); str_value = "Joe"; dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "struct_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "Joe"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "struct_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 27; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&variter, &arrayiter); dbus_message_iter_close_container (&iter, &variter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "struct_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_dict_entry_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; uint32_t uint32_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter variter; DBusMessageIter arrayiter; DBusMessageIter subiter; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_dict_entry_array_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); dict_entry_array_property = nih_alloc (NULL, sizeof (MyStruct *) * 3); dict_entry_array_property[0] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[0]->item0 = "Joe"; dict_entry_array_property[0]->item1 = 34; dict_entry_array_property[1] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[1]->item0 = "Paul"; dict_entry_array_property[1]->item1 = 27; dict_entry_array_property[2] = NULL; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "dict_entry_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &variter); TEST_EQ (dbus_message_iter_get_arg_type (&variter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&variter, &arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_DICT_ENTRY); dbus_message_iter_recurse (&arrayiter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Joe"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UINT32); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 34); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_DICT_ENTRY); dbus_message_iter_recurse (&arrayiter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "Paul"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UINT32); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 27); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_INVALID); dbus_message_unref (reply); nih_free (dict_entry_array_property); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); dict_entry_array_property = nih_alloc (NULL, sizeof (MyStruct *) * 1); dict_entry_array_property[0] = NULL; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "dict_entry_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.DictEntryArray.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (dict_entry_array_property); nih_free (object); } /* Check that a generic error may be returned from the property * handler, and is returned as a D-Bus "failed" error reply to * the message. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); dict_entry_array_property = nih_alloc (NULL, sizeof (MyStruct *) * 2); dict_entry_array_property[0] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[0]->item0 = "Joe"; dict_entry_array_property[0]->item1 = 34; dict_entry_array_property[1] = NULL; } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "dict_entry_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (dict_entry_array_property); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "dict_entry_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_dict_entry_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; uint32_t uint32_value; DBusMessageIter variter; DBusMessageIter arrayiter; DBusMessageIter subiter; dbus_uint32_t serial; DBusMessage * reply; DBusError dbus_error; TEST_FUNCTION ("my_com_netsplit_Nih_Test_dict_entry_array_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } dict_entry_array_property = NULL; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "dict_entry_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 27; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&variter, &arrayiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_NE_P (dict_entry_array_property, NULL); TEST_ALLOC_SIZE (dict_entry_array_property, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (dict_entry_array_property[0], dict_entry_array_property); TEST_ALLOC_SIZE (dict_entry_array_property[0], sizeof (MyStruct)); TEST_EQ_STR (dict_entry_array_property[0]->item0, "Joe"); TEST_EQ (dict_entry_array_property[0]->item1, 34); TEST_ALLOC_PARENT (dict_entry_array_property[1], dict_entry_array_property); TEST_ALLOC_SIZE (dict_entry_array_property[1], sizeof (MyStruct)); TEST_EQ_STR (dict_entry_array_property[1]->item0, "Paul"); TEST_EQ (dict_entry_array_property[1]->item1, 27); TEST_EQ_P (dict_entry_array_property[2], NULL); nih_free (dict_entry_array_property); nih_free (object); } /* Check that a D-Bus error raised from the function is returned * as an error return of the same name and message. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "dict_entry_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_close_container (&variter, &arrayiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.DictEntryArray.Empty")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that a non-D-Bus error raised from the function is * returned as the generic D-Bus "failed" error to the user, * with the message copied across. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "dict_entry_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&variter, &arrayiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, "Invalid argument"); dbus_error_free (&dbus_error); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a structure member of the wrong type is given. */ TEST_FEATURE ("with wrong member type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "dict_entry_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "34"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "27"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&variter, &arrayiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an array element of the wrong type is given. */ TEST_FEATURE ("with wrong array element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "dict_entry_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &arrayiter); str_value = "Joe"; dbus_message_iter_append_basic (&arrayiter, DBUS_TYPE_STRING, &str_value); str_value = "Paul"; dbus_message_iter_append_basic (&arrayiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&variter, &arrayiter); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong variant element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "dict_entry_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &variter); str_value = "Joe"; dbus_message_iter_append_basic (&variter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &variter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "dict_entry_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "Joe"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "dict_entry_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, (DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &variter); dbus_message_iter_open_container (&variter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Joe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 34; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_open_container (&arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &subiter); str_value = "Paul"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 27; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&arrayiter, &subiter); dbus_message_iter_close_container (&variter, &arrayiter); dbus_message_iter_close_container (&iter, &variter); str_value = "she needs more of ze punishment"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "dict_entry_array"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_unix_fd (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; dbus_uint32_t serial; DBusMessage * reply; DBusMessageIter subiter; int unix_fd_value; TEST_FUNCTION ("my_com_netsplit_Nih_Test_unix_fd_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can obtain the current value of a property, * marshalled through the Get call, and that it's returned inside * a variant. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } unix_fd_property = 1; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "unix_fd"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UNIX_FD); dbus_message_iter_get_basic (&subiter, &unix_fd_value); TEST_GT (unix_fd_value, 2); // dbus dups it dbus_message_unref (reply); close (unix_fd_value); nih_free (object); } /* Check that a D-Bus error may be returned from the property * handler, and is returned as a D-Bus error reply to the message. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } unix_fd_property = -1; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "unix_fd"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.UnixFd.Invalid")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Get"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "unix_fd"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UNIX_FD_AS_STRING, &subiter); unix_fd_value = 1; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UNIX_FD, &unix_fd_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_unix_fd (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusObject * object = NULL; DBusMessage * method_call; DBusMessageIter iter; const char * str_value; DBusMessageIter subiter; int unix_fd_value; dbus_uint32_t serial; DBusMessage * reply; TEST_FUNCTION ("my_com_netsplit_Nih_Test_unix_fd_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can set a new value of a property, marshalled * through the Set call, and that an empty reply is returned. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } unix_fd_property = -1; method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "unix_fd"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UNIX_FD_AS_STRING, &subiter); unix_fd_value = 1; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UNIX_FD, &unix_fd_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_signature (reply), ""); dbus_message_unref (reply); TEST_GT (unix_fd_property, 2); // dbus dups it close (unix_fd_property); nih_free (object); } /* Check that the function returns an invalid arguments error * if a variant element of the wrong type is given. */ TEST_FEATURE ("with wrong element type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "unix_fd"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "True"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an argument of the wrong type is given. */ TEST_FEATURE ("with wrong argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "unix_fd"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "True"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if an extra argument is given. */ TEST_FEATURE ("with extra argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "unix_fd"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UNIX_FD_AS_STRING, &subiter); unix_fd_value = 1; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UNIX_FD, &unix_fd_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "True"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } /* Check that the function returns an invalid arguments error * if no arguments are given. */ TEST_FEATURE ("with missing arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); } method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", DBUS_INTERFACE_PROPERTIES, "Set"); dbus_message_iter_init_append (method_call, &iter); str_value = "com.netsplit.Nih.Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); str_value = "unix_fd"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } int main (int argc, char *argv[]) { nih_error_init (); test_ordinary_method (); test_nameless_method (); test_async_method (); test_byte_to_str (); test_str_to_byte (); test_boolean_to_str (); test_str_to_boolean (); test_int16_to_str (); test_str_to_int16 (); test_uint16_to_str (); test_str_to_uint16 (); test_int32_to_str (); test_str_to_int32 (); test_uint32_to_str (); test_str_to_uint32 (); test_int64_to_str (); test_str_to_int64 (); test_uint64_to_str (); test_str_to_uint64 (); test_double_to_str (); test_str_to_double (); test_object_path_to_str (); test_str_to_object_path (); test_signature_to_str (); test_str_to_signature (); test_struct_to_str (); test_str_to_struct (); test_int32_array_to_str (); test_str_to_int32_array (); test_str_array_to_str (); test_str_to_str_array (); test_int32_array_array_to_str (); test_str_to_int32_array_array (); test_struct_array_to_str (); test_str_to_struct_array (); test_dict_entry_array_to_str (); test_str_to_dict_entry_array (); test_unix_fd_to_str (); test_str_to_unix_fd (); test_new_byte (); test_new_boolean (); test_new_int16 (); test_new_uint16 (); test_new_int32 (); test_new_uint32 (); test_new_int64 (); test_new_uint64 (); test_new_double (); test_new_string (); test_new_object_path (); test_new_signature (); test_new_struct (); test_new_int32_array (); test_new_str_array (); test_new_int32_array_array (); test_new_struct_array (); test_new_dict_entry_array (); test_new_unix_fd (); test_get_byte (); test_set_byte (); test_get_boolean (); test_set_boolean (); test_get_int16 (); test_set_int16 (); test_get_uint16 (); test_set_uint16 (); test_get_int32 (); test_set_int32 (); test_get_uint32 (); test_set_uint32 (); test_get_int64 (); test_set_int64 (); test_get_uint64 (); test_set_uint64 (); test_get_double (); test_set_double (); test_get_string (); test_set_string (); test_get_object_path (); test_set_object_path (); test_get_signature (); test_set_signature (); test_get_structure (); test_set_structure (); test_get_int32_array (); test_set_int32_array (); test_get_str_array (); test_set_str_array (); test_get_int32_array_array (); test_set_int32_array_array (); test_get_struct_array (); test_set_struct_array (); test_get_dict_entry_array (); test_set_dict_entry_array (); test_get_unix_fd (); test_set_unix_fd (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/marshal_code.h0000644000175000017500000000600111504706003016312 00000000000000/* nih-dbus-tool * * Copyright © 2010 Scott James Remnant . * Copyright © 2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_TESTS_MARSHAL_CODE_H #define NIH_DBUS_TOOL_TESTS_MARSHAL_CODE_H #include #include #include typedef struct my_struct_value { char * item0; uint32_t item1; char ** item2; int16_t * item3; size_t item3_len; } MyStructValue; typedef struct my_struct_array_value_element { char * item0; uint32_t item1; } MyStructArrayValueElement; typedef struct my_dict_entry_array_value_element { char * item0; uint32_t item1; } MyDictEntryArrayValueElement; NIH_BEGIN_EXTERN int my_byte_marshal (DBusMessage *message, uint8_t value); int my_boolean_marshal (DBusMessage *message, int value); int my_int16_marshal (DBusMessage *message, int16_t value); int my_uint16_marshal (DBusMessage *message, uint16_t value); int my_int32_marshal (DBusMessage *message, int32_t value); int my_uint32_marshal (DBusMessage *message, uint32_t value); int my_int64_marshal (DBusMessage *message, int64_t value); int my_uint64_marshal (DBusMessage *message, uint64_t value); int my_double_marshal (DBusMessage *message, double value); int my_string_marshal (DBusMessage *message, const char *value); int my_object_path_marshal (DBusMessage *message, const char * value); int my_signature_marshal (DBusMessage *message, const char * value); int my_int16_array_marshal (DBusMessage *message, const int16_t * value, size_t value_len); int my_int16_array_array_marshal (DBusMessage *message, int16_t * const * value, const size_t * value_len); int my_string_array_marshal (DBusMessage *message, char * const * value); int my_string_array_array_marshal (DBusMessage *message, char ** const * value); int my_struct_marshal (DBusMessage *message, const MyStructValue * value); int my_struct_array_marshal (DBusMessage *message, MyStructArrayValueElement * const * value); int my_dict_entry_array_marshal (DBusMessage *message, MyDictEntryArrayValueElement * const * value); int my_unix_fd_marshal (DBusMessage *message, int value); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_TESTS_MARSHAL_CODE_H */ libnih-1.0.3/nih-dbus-tool/tests/test_annotation.c0000644000175000017500000005251411445765555017134 00000000000000/* nih-dbus-tool * * test_annotation.c - test suite for nih-dbus-tool/annotation.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include "interface.h" #include "method.h" #include "signal.h" #include "property.h" #include "argument.h" #include "parse.h" #include "errors.h" #include "annotation.h" void test_start_tag (void) { ParseContext context; ParseStack * parent = NULL; ParseStack * entry; XML_Parser xmlp; Node * node = NULL; Interface * interface = NULL; Method * method = NULL; Signal * signal = NULL; Property * property = NULL; Argument * argument = NULL; char * attr[7]; int ret = 0; NihError * err; FILE * output; TEST_FUNCTION ("annotation_start_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); output = tmpfile (); /* Check that an annotation for an interface with the usual name and * value attributes is passed to the interface_annotation() function * and results in it being handled with an empty annotation stack * object being pushed onto the stack. */ TEST_FEATURE ("with interface annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } attr[0] = "name"; attr[1] = "org.freedesktop.DBus.Deprecated"; attr[2] = "value"; attr[3] = "true"; attr[4] = NULL; ret = annotation_start_tag (xmlp, "annotation", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ANNOTATION); TEST_EQ_P (entry->data, NULL); TEST_TRUE (interface->deprecated); nih_free (entry); nih_free (parent); } /* Check that an annotation for a method with the usual name and * value attributes is passed to the method_annotation() function * and results in it being handled with an empty annotation stack * object being pushed onto the stack. */ TEST_FEATURE ("with method annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); } attr[0] = "name"; attr[1] = "org.freedesktop.DBus.Deprecated"; attr[2] = "value"; attr[3] = "true"; attr[4] = NULL; ret = annotation_start_tag (xmlp, "annotation", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ANNOTATION); TEST_EQ_P (entry->data, NULL); TEST_TRUE (method->deprecated); nih_free (entry); nih_free (parent); } /* Check that an annotation for a signal with the usual name and * value attributes is passed to the signal_annotation() function * and results in it being handled with an empty annotation stack * object being pushed onto the stack. */ TEST_FEATURE ("with signal annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); parent = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); } attr[0] = "name"; attr[1] = "org.freedesktop.DBus.Deprecated"; attr[2] = "value"; attr[3] = "true"; attr[4] = NULL; ret = annotation_start_tag (xmlp, "annotation", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ANNOTATION); TEST_EQ_P (entry->data, NULL); TEST_TRUE (signal->deprecated); nih_free (entry); nih_free (parent); } /* Check that an annotation for a property with the usual name and * value attributes is passed to the property_annotation() function * and results in it being handled with an empty annotation stack * object being pushed onto the stack. */ TEST_FEATURE ("with property annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); parent = parse_stack_push (NULL, &context.stack, PARSE_PROPERTY, property); nih_discard (property); } attr[0] = "name"; attr[1] = "org.freedesktop.DBus.Deprecated"; attr[2] = "value"; attr[3] = "true"; attr[4] = NULL; ret = annotation_start_tag (xmlp, "annotation", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ANNOTATION); TEST_EQ_P (entry->data, NULL); TEST_TRUE (property->deprecated); nih_free (entry); nih_free (parent); } /* Check that an annotation for an argument with the usual name and * value attributes is passed to the argument_annotation() function * and results in it being handled with an empty annotation stack * object being pushed onto the stack. */ TEST_FEATURE ("with argument annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { argument = argument_new (NULL, "test_arg", "s", NIH_DBUS_ARG_IN); parent = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); } attr[0] = "name"; attr[1] = "com.netsplit.Nih.Symbol"; attr[2] = "value"; attr[3] = "test"; attr[4] = NULL; ret = annotation_start_tag (xmlp, "annotation", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ANNOTATION); TEST_EQ_P (entry->data, NULL); TEST_EQ_STR (argument->symbol, "test"); TEST_ALLOC_PARENT (argument->symbol, argument); nih_free (entry); nih_free (parent); } /* Check that an annotation with a missing name attribute results * in an error being raised. */ TEST_FEATURE ("with missing name"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "value"; attr[1] = "true"; attr[2] = NULL; } ret = annotation_start_tag (xmlp, "annotation", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->methods); err = nih_error_get (); TEST_EQ (err->number, ANNOTATION_MISSING_NAME); nih_free (err); nih_free (parent); } /* Check that an annotation with a missing value attribute results * in an error being raised. */ TEST_FEATURE ("with missing value"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "org.freedesktop.DBus.Deprecated"; attr[2] = NULL; } ret = annotation_start_tag (xmlp, "annotation", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->methods); err = nih_error_get (); TEST_EQ (err->number, ANNOTATION_MISSING_VALUE); nih_free (err); nih_free (parent); } /* Check that an unknown annotation attribute results in a warning * being printed to standard error, but is otherwise ignored * and the normal processing finished. */ TEST_FEATURE ("with unknown attribute"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "org.freedesktop.DBus.Deprecated"; attr[2] = "value"; attr[3] = "true"; attr[4] = "frodo"; attr[5] = "baggins"; attr[6] = NULL; } TEST_DIVERT_STDERR (output) { ret = annotation_start_tag (xmlp, "annotation", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ANNOTATION); TEST_EQ_P (entry->data, NULL); TEST_TRUE (interface->deprecated); TEST_FILE_EQ (output, ("test:foo:1:0: Ignored unknown attribute: " "frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } /* Check that an annotation on an empty stack (ie. a top-level * annotation element) results in a warning being printed on * standard error and an ignored element being pushed onto the * stack. */ TEST_FEATURE ("with empty stack"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { attr[0] = "name"; attr[1] = "org.freedesktop.DBus.Deprecated"; attr[2] = "value"; attr[3] = "true"; attr[4] = NULL; } TEST_DIVERT_STDERR (output) { ret = annotation_start_tag (xmlp, "annotation", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), NULL); TEST_FILE_RESET (output); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unexpected tag\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); } /* Check that an annotation on top of a stack entry that's not an * interface, method, signal, property or argument results in a * warning being printed on standard error and an ignored element * being pushed onto the stack. */ TEST_FEATURE ("with non-annotated element on stack"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); attr[0] = "name"; attr[1] = "org.freedesktop.DBus.Deprecated"; attr[2] = "value"; attr[3] = "true"; attr[4] = NULL; } TEST_DIVERT_STDERR (output) { ret = annotation_start_tag (xmlp, "annotation", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unexpected tag\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } /* Check that an unknown interface annotation error is converted * into a warning and printed to standard error, and results in * an ignored element being pushed onto the stack. */ TEST_FEATURE ("with unknown interface annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "com.netsplit.Nih.Unknown"; attr[2] = "value"; attr[3] = "true"; attr[4] = NULL; } TEST_DIVERT_STDERR (output) { ret = annotation_start_tag (xmlp, "annotation", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, ("test:foo:1:0: Ignored unknown interface annotation: " "com.netsplit.Nih.Unknown\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } /* Check that an unknown method annotation error is converted * into a warning and printed to standard error, and results in * an ignored element being pushed onto the stack. */ TEST_FEATURE ("with unknown method annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); attr[0] = "name"; attr[1] = "com.netsplit.Nih.Unknown"; attr[2] = "value"; attr[3] = "true"; attr[4] = NULL; } TEST_DIVERT_STDERR (output) { ret = annotation_start_tag (xmlp, "annotation", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, ("test:foo:1:0: Ignored unknown method annotation: " "com.netsplit.Nih.Unknown\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } /* Check that an unknown signal annotation error is converted * into a warning and printed to standard error, and results in * an ignored element being pushed onto the stack. */ TEST_FEATURE ("with unknown signal annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); parent = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); attr[0] = "name"; attr[1] = "com.netsplit.Nih.Unknown"; attr[2] = "value"; attr[3] = "true"; attr[4] = NULL; } TEST_DIVERT_STDERR (output) { ret = annotation_start_tag (xmlp, "annotation", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, ("test:foo:1:0: Ignored unknown signal annotation: " "com.netsplit.Nih.Unknown\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } /* Check that an unknown property annotation error is converted * into a warning and printed to standard error, and results in * an ignored element being pushed onto the stack. */ TEST_FEATURE ("with unknown property annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); parent = parse_stack_push (NULL, &context.stack, PARSE_PROPERTY, property); nih_discard (property); attr[0] = "name"; attr[1] = "com.netsplit.Nih.Unknown"; attr[2] = "value"; attr[3] = "true"; attr[4] = NULL; } TEST_DIVERT_STDERR (output) { ret = annotation_start_tag (xmlp, "annotation", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, ("test:foo:1:0: Ignored unknown property annotation: " "com.netsplit.Nih.Unknown\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } /* Check that an unknown argument annotation error is converted * into a warning and printed to standard error, and results in * an ignored element being pushed onto the stack. */ TEST_FEATURE ("with unknown argument annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { argument = argument_new (NULL, "test_arg", "s", NIH_DBUS_ARG_IN); parent = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); attr[0] = "name"; attr[1] = "com.netsplit.Nih.Unknown"; attr[2] = "value"; attr[3] = "true"; attr[4] = NULL; } TEST_DIVERT_STDERR (output) { ret = annotation_start_tag (xmlp, "annotation", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, ("test:foo:1:0: Ignored unknown argument annotation: " "com.netsplit.Nih.Unknown\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } XML_ParserFree (xmlp); fclose (output); } void test_end_tag (void) { ParseContext context; ParseStack * parent = NULL; ParseStack * entry = NULL; XML_Parser xmlp; Method * method = NULL; int ret; NihError * err; /* Check that when we parse the end tag for an annotation, we pop * the top of the stack off and free it. */ TEST_FUNCTION ("annotation_end_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); entry = parse_stack_push (NULL, &context.stack, PARSE_ANNOTATION, NULL); } TEST_FREE_TAG (entry); ret = annotation_end_tag (xmlp, "annotation"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); nih_free (parent); } XML_ParserFree (xmlp); } int main (int argc, char *argv[]) { program_name = "test"; nih_error_init (); test_start_tag (); test_end_tag (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/demarshal_code.h0000644000175000017500000000702211504707164016640 00000000000000/* nih-dbus-tool * * Copyright © 2010 Scott James Remnant . * Copyright © 2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_TESTS_DEMARSHAL_CODE_H #define NIH_DBUS_TOOL_TESTS_DEMARSHAL_CODE_H #include #include #include typedef struct my_struct_value { char * item0; uint32_t item1; char ** item2; int16_t * item3; size_t item3_len; } MyStructValue; typedef struct my_struct_array_value_element { char * item0; uint32_t item1; } MyStructArrayValueElement; typedef struct my_dict_entry_array_value_element { char * item0; uint32_t item1; } MyDictEntryArrayValueElement; NIH_BEGIN_EXTERN int my_byte_demarshal (const void *parent, DBusMessage *message, uint8_t *value); int my_boolean_demarshal (const void *parent, DBusMessage *message, int *value); int my_int16_demarshal (const void *parent, DBusMessage *message, int16_t *value); int my_uint16_demarshal (const void *parent, DBusMessage *message, uint16_t *value); int my_int32_demarshal (const void *parent, DBusMessage *message, int32_t *value); int my_uint32_demarshal (const void *parent, DBusMessage *message, uint32_t *value); int my_int64_demarshal (const void *parent, DBusMessage *message, int64_t *value); int my_uint64_demarshal (const void *parent, DBusMessage *message, uint64_t *value); int my_double_demarshal (const void *parent, DBusMessage *message, double *value); int my_string_demarshal (const void *parent, DBusMessage *message, char **value); int my_object_path_demarshal (const void *parent, DBusMessage *message, char **value); int my_signature_demarshal (const void *parent, DBusMessage *message, char **value); int my_int16_array_demarshal (const void *parent, DBusMessage *message, int16_t **value, size_t *value_len); int my_int16_array_array_demarshal (const void *parent, DBusMessage *message, int16_t ***value, size_t **value_len); int my_string_array_demarshal (const void *parent, DBusMessage *message, char ***value); int my_string_array_array_demarshal (const void *parent, DBusMessage *message, char ****value); int my_struct_demarshal (const void *parent, DBusMessage *message, MyStructValue **value); int my_struct_array_demarshal (const void *parent, DBusMessage *message, MyStructArrayValueElement ***value); int my_dict_entry_array_demarshal (const void *parent, DBusMessage *message, MyDictEntryArrayValueElement ***value); int my_unix_fd_demarshal (const void *parent, DBusMessage *message, int *value); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_TESTS_DEMARSHAL_CODE_H */ libnih-1.0.3/nih-dbus-tool/tests/interface_factory.c0000644000175000017500000000622311445765555017406 00000000000000/* nih-dbus-tool * * tests/interface_factory.c - generate tests/interface_code.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include "type.h" #include "interface.h" #include "property.h" int main (int argc, char *argv[]) { NihList prototypes; NihList typedefs; NihList structs; nih_local Interface *interface = NULL; nih_local Property * property = NULL; nih_local char * code = NULL; nih_local char * block = NULL; printf ("#include \n" "\n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "\n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "\n" "#include \"tests/interface_code.h\"\n" "\n" "\n"); interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; property = property_new (interface, "name", "s", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "name"); nih_list_add (&interface->properties, &property->entry); property = property_new (interface, "size", "u", NIH_DBUS_READWRITE); property->symbol = nih_strdup (property, "size"); nih_list_add (&interface->properties, &property->entry); nih_list_init (&prototypes); nih_list_init (&structs); interface->name = "com.netsplit.Nih.TestA"; code = interface_proxy_get_all_function (NULL, "my", interface, &prototypes, &structs); printf ("extern void my_com_netsplit_Nih_TestA_get_all_notify (DBusPendingCall *pending_call, " "NihDBusPendingData *pending_data);\n"); printf ("\n"); printf ("%s" "\n", code); nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); interface->name = "com.netsplit.Nih.Test"; code = interface_proxy_get_all_notify_function (NULL, "my", interface, &prototypes, &typedefs, &structs); printf ("%s", code); printf ("\n" "\n"); nih_list_init (&prototypes); nih_list_init (&structs); code = interface_proxy_get_all_sync_function (NULL, "my", interface, &prototypes, &structs); printf ("%s" "\n", code); return 0; } libnih-1.0.3/nih-dbus-tool/tests/method_factory.c0000644000175000017500000001143111445765555016723 00000000000000/* nih-dbus-tool * * tests/method_factory.c - generate tests/method_code.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include "type.h" #include "interface.h" #include "method.h" #include "argument.h" int main (int argc, char *argv[]) { NihList prototypes; NihList handlers; NihList typedefs; NihList structs; nih_local Interface *interface = NULL; nih_local Method * method = NULL; Argument * arg; nih_local char * code = NULL; nih_local char * block = NULL; printf ("#include \n" "\n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "\n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "\n" "#include \"tests/method_code.h\"\n" "\n" "\n"); interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); arg = argument_new (method, "Str", "s", NIH_DBUS_ARG_IN); arg->symbol = nih_strdup (arg, "str"); nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "Flags", "i", NIH_DBUS_ARG_IN); arg->symbol = nih_strdup (arg, "flags"); nih_list_add (&method->arguments, &arg->entry); arg = argument_new (method, "Output", "as", NIH_DBUS_ARG_OUT); arg->symbol = nih_strdup (arg, "output"); nih_list_add (&method->arguments, &arg->entry); nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); code = method_object_function (NULL, "my", interface, method, &prototypes, &handlers, &structs); NIH_LIST_FOREACH (&handlers, iter) { TypeFunc *func = (TypeFunc *)iter; NIH_MUST (type_to_extern (&func->type, func)); } block = type_func_layout (NULL, &handlers); printf ("%s\n", block); printf ("%s", code); printf ("\n" "\n"); nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); method->name = "AsyncMethod"; method->symbol = "async_method"; method->async = TRUE; code = method_object_function (NULL, "my", interface, method, &prototypes, &handlers, &structs); NIH_LIST_FOREACH (&handlers, iter) { TypeFunc *func = (TypeFunc *)iter; NIH_MUST (type_to_extern (&func->type, func)); } block = type_func_layout (NULL, &handlers); printf ("%s\n", block); printf ("%s", code); printf ("\n"); nih_list_init (&prototypes); nih_list_init (&structs); code = method_reply_function (NULL, "my", interface, method, &prototypes, &structs); printf ("%s", code); printf ("\n" "\n"); nih_list_init (&prototypes); nih_list_init (&structs); method->name = "TestMethod"; method->symbol = "test_method"; method->async = FALSE; arg = argument_new (method, "Length", "i", NIH_DBUS_ARG_OUT); arg->symbol = nih_strdup (arg, "length"); nih_list_add (&method->arguments, &arg->entry); code = method_proxy_function (NULL, "my", interface, method, &prototypes, &structs); printf ("extern void my_com_netsplit_Nih_Test_TestMethod_notify (DBusPendingCall *pending_call, " "NihDBusPendingData *pending_data);\n"); printf ("\n"); printf ("%s", code); printf ("\n"); nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); method->name = "Method"; method->symbol = "method"; code = method_proxy_notify_function (NULL, "my", interface, method, &prototypes, &typedefs, &structs); printf ("%s", code); printf ("\n" "\n"); nih_list_init (&prototypes); nih_list_init (&structs); code = method_proxy_sync_function (NULL, "my", interface, method, &prototypes, &structs); printf ("%s", code); printf ("\n"); return 0; } libnih-1.0.3/nih-dbus-tool/tests/test_marshal.c0000644000175000017500000025613011504706714016375 00000000000000/* nih-dbus-tool * * test_marshal.c - test suite for nih-dbus-tool/marshal.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include "type.h" #include "marshal.h" #include "tests/marshal_code.h" void test_marshal (void) { NihList inputs; NihList locals; NihList structs; TypeVar * var; TypeStruct * structure; DBusSignatureIter signature; DBusMessage * message = NULL; DBusMessageIter iter; DBusMessageIter subiter; DBusMessageIter subsubiter; char * str; int ret; uint8_t byte_value; int boolean_value; int16_t int16_value; uint16_t uint16_value; int32_t int32_value; uint32_t uint32_value; int64_t int64_value; uint64_t uint64_value; double double_value; char * str_value; int16_t * int16_array = NULL; size_t int16_array_len; int16_t ** int16_array_array = NULL; size_t * int16_array_array_len = NULL; char ** str_array = NULL; char *** str_array_array = NULL; MyStructValue * struct_value = NULL; MyStructArrayValueElement **struct_array = NULL; MyDictEntryArrayValueElement **dict_entry_array = NULL; int unix_fd_value; TEST_FUNCTION ("marshal"); /* Check that the code to marshal a uint8_t into a D-Bus Byte is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with byte"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_BYTE_AS_STRING); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "byte", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a uint8_t onto the message */\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_BYTE, &value)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "uint8_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the uint8_t and * appends it as a D-Bus Byte to the message we pass. We check the * message signature is correct, then iterate the message to check * the types are correct, and extract the values to check that they * are correct too. */ TEST_FEATURE ("with byte (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); } byte_value = 42; ret = my_byte_marshal (message, byte_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_BYTE_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_BYTE); byte_value = 0; dbus_message_iter_get_basic (&iter, &byte_value); TEST_EQ (byte_value, 42); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to marshal an int into a D-Bus Boolean is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with boolean"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_BOOLEAN_AS_STRING); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "boolean", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a int onto the message */\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &value)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the int and * appends it as a D-Bus Boolean to the message we pass. We check the * message signature is correct, then iterate the message to check * the types are correct, and extract the values to check that they * are correct too. */ TEST_FEATURE ("with boolean (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); } boolean_value = TRUE; ret = my_boolean_marshal (message, boolean_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_BOOLEAN_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_BOOLEAN); boolean_value = FALSE; dbus_message_iter_get_basic (&iter, &boolean_value); TEST_EQ (boolean_value, TRUE); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to marshal an int16_t into a D-Bus Int16 is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with int16"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_INT16_AS_STRING); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "int16", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a int16_t onto the message */\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT16, &value)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int16_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the int16_t and * appends it as a D-Bus Int16 to the message we pass. We check the * message signature is correct, then iterate the message to check * the types are correct, and extract the values to check that they * are correct too. */ TEST_FEATURE ("with int16 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); } int16_value = -42; ret = my_int16_marshal (message, int16_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_INT16_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&iter, &int16_value); TEST_EQ (int16_value, -42); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to marshal an uint16_t into a D-Bus UInt16 is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with uint16"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_UINT16_AS_STRING); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "uint16", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a uint16_t onto the message */\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT16, &value)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "uint16_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the uint16_t and * appends it as a D-Bus UInt16 to the message we pass. We check the * message signature is correct, then iterate the message to check * the types are correct, and extract the values to check that they * are correct too. */ TEST_FEATURE ("with uint16 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); } uint16_value = 42; ret = my_uint16_marshal (message, uint16_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_UINT16_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_UINT16); uint16_value = 0; dbus_message_iter_get_basic (&iter, &uint16_value); TEST_EQ (uint16_value, 42); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to marshal an int32_t into a D-Bus Int32 is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with int32"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_INT32_AS_STRING); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "int32", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a int32_t onto the message */\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &value)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the int32_t and * appends it as a D-Bus Int32 to the message we pass. We check the * message signature is correct, then iterate the message to check * the types are correct, and extract the values to check that they * are correct too. */ TEST_FEATURE ("with int32 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); } int32_value = -42; ret = my_int32_marshal (message, int32_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_INT32_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); int32_value = 0; dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, -42); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to marshal an uint32_t into a D-Bus UInt32 is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with uint32"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_UINT32_AS_STRING); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "uint32", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a uint32_t onto the message */\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &value)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the uint32_t and * appends it as a D-Bus UInt32 to the message we pass. We check the * message signature is correct, then iterate the message to check * the types are correct, and extract the values to check that they * are correct too. */ TEST_FEATURE ("with uint32 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); } uint32_value = 42; ret = my_uint32_marshal (message, uint32_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_UINT32_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_UINT32); uint32_value = 0; dbus_message_iter_get_basic (&iter, &uint32_value); TEST_EQ (uint32_value, 42); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to marshal an int64_t into a D-Bus Int64 is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with int64"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_INT64_AS_STRING); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "int64", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a int64_t onto the message */\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT64, &value)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int64_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the int64_t and * appends it as a D-Bus Int64 to the message we pass. We check the * message signature is correct, then iterate the message to check * the types are correct, and extract the values to check that they * are correct too. */ TEST_FEATURE ("with int64 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); } int64_value = -42; ret = my_int64_marshal (message, int64_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_INT64_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT64); int64_value = 0; dbus_message_iter_get_basic (&iter, &int64_value); TEST_EQ (int64_value, -42); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to marshal an uint64_t into a D-Bus UInt64 is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with uint64"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_UINT64_AS_STRING); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "uint64", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a uint64_t onto the message */\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT64, &value)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "uint64_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the uint64_t and * appends it as a D-Bus UInt64 to the message we pass. We check the * message signature is correct, then iterate the message to check * the types are correct, and extract the values to check that they * are correct too. */ TEST_FEATURE ("with uint64 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); } uint64_value = 42; ret = my_uint64_marshal (message, uint64_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_UINT64_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_UINT64); uint64_value = 0; dbus_message_iter_get_basic (&iter, &uint64_value); TEST_EQ (uint64_value, 42); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to marshal an double into a D-Bus Double is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with double"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_DOUBLE_AS_STRING); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "double", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a double onto the message */\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &value)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "double"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the double and * appends it as a D-Bus Double to the message we pass. We check the * message signature is correct, then iterate the message to check * the types are correct, and extract the values to check that they * are correct too. */ TEST_FEATURE ("with double (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); } double_value = 3.14; ret = my_double_marshal (message, double_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_DOUBLE_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_DOUBLE); double_value = 0; dbus_message_iter_get_basic (&iter, &double_value); TEST_EQ (double_value, 3.14); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to marshal a char * into a D-Bus String is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with string"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_STRING_AS_STRING); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "string", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a char * onto the message */\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &value)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the char * and * appends it as a D-Bus String to the message we pass. We check the * message signature is correct, then iterate the message to check * the types are correct, and extract the values to check that they * are correct too. */ TEST_FEATURE ("with string (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); } str_value = "hello there"; ret = my_string_marshal (message, str_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_STRING_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "hello there"); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to marshal a char * into a D-Bus Object Path is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with object path"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_OBJECT_PATH_AS_STRING); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "object_path", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a char * onto the message */\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &value)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the char * and * appends it as a D-Bus Object Path to the message we pass. We check * the message signature is correct, then iterate the message to check * the types are correct, and extract the values to check that they * are correct too. */ TEST_FEATURE ("with object path (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); } str_value = "/com/netsplit/Nih/Test"; ret = my_object_path_marshal (message, str_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_OBJECT_PATH_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_OBJECT_PATH); str_value = NULL; dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "/com/netsplit/Nih/Test"); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to marshal a char * into a D-Bus Signature is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with signature"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_SIGNATURE_AS_STRING); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "signature", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a char * onto the message */\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_SIGNATURE, &value)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the char * and * appends it as a D-Bus Signature to the message we pass. We check * the message signature is correct, then iterate the message to check * the types are correct, and extract the values to check that they * are correct too. */ TEST_FEATURE ("with signature (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); } str_value = "a(ii)"; ret = my_signature_marshal (message, str_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_SIGNATURE_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_SIGNATURE); str_value = NULL; dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "a(ii)"); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to marshal an array of int16_t into a D-Bus * Int16 Array is correctly generated and returned as an allocated * string. This will a local variable to track the iteration. */ TEST_FEATURE ("with int16 array"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING)); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "int16_array", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal an array onto the message */\n" "if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, \"n\", &value_iter)) {\n" "\treturn -1;\n" "}\n" "\n" "for (size_t value_i = 0; value_i < value_len; value_i++) {\n" "\tint16_t value_element;\n" "\n" "\tvalue_element = value[value_i];\n" "\n" "\t/* Marshal a int16_t onto the message */\n" "\tif (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_INT16, &value_element)) {\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "}\n" "\n" "if (! dbus_message_iter_close_container (&iter, &value_iter)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int16_t *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "size_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_len"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the values from the array of * int16_t and appends them as a D-Bus Int16 Array to the message * we pass. We check the message signature is correct, then iterate * the message to check the types are correct, and extract the values * to check that they are correct too. */ TEST_FEATURE ("with int16 array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); int16_array = nih_alloc (NULL, sizeof (int16_t) * 6); } int16_array_len = 0; int16_array[int16_array_len++] = 4; int16_array[int16_array_len++] = 8; int16_array[int16_array_len++] = 15; int16_array[int16_array_len++] = 16; int16_array[int16_array_len++] = 23; int16_array[int16_array_len++] = 42; ret = my_int16_array_marshal (message, int16_array, int16_array_len); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); nih_free (int16_array); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING)); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subiter, &int16_value); TEST_EQ (int16_value, 4); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subiter, &int16_value); TEST_EQ (int16_value, 8); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subiter, &int16_value); TEST_EQ (int16_value, 15); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subiter, &int16_value); TEST_EQ (int16_value, 16); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subiter, &int16_value); TEST_EQ (int16_value, 23); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subiter, &int16_value); TEST_EQ (int16_value, 42); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (message); dbus_shutdown (); nih_free (int16_array); } /* Check that the code to marshal an array of arrays of int16_t * into a D-Bus Int16 Array Array is correctly generated and * returned as an allocated string. This will require a local * variable to track the iteration, and iterates over both the * int16_t array and a size_t length array. */ TEST_FEATURE ("with int16 array array"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING)); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "int16_array_array", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal an array onto the message */\n" "if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, \"an\", &value_iter)) {\n" "\treturn -1;\n" "}\n" "\n" "for (size_t value_i = 0; value[value_i]; value_i++) {\n" "\tDBusMessageIter value_element_iter;\n" "\tconst int16_t * value_element;\n" "\tsize_t value_element_len;\n" "\n" "\tvalue_element = value[value_i];\n" "\tvalue_element_len = value_len[value_i];\n" "\n" "\t/* Marshal an array onto the message */\n" "\tif (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_ARRAY, \"n\", &value_element_iter)) {\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tfor (size_t value_element_i = 0; value_element_i < value_element_len; value_element_i++) {\n" "\t\tint16_t value_element_element;\n" "\n" "\t\tvalue_element_element = value_element[value_element_i];\n" "\n" "\t\t/* Marshal a int16_t onto the message */\n" "\t\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_INT16, &value_element_element)) {\n" "\t\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n" "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\t\treturn -1;\n" "\t\t}\n" "\t}\n" "\n" "\tif (! dbus_message_iter_close_container (&value_iter, &value_element_iter)) {\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "}\n" "\n" "if (! dbus_message_iter_close_container (&iter, &value_iter)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int16_t **"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "size_t *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_len"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the values from the array of * int16_t arrays and appends them as a D-Bus Int16 Array Array to * the message we pass. We check the message signature is correct, * then iterate the message to check the types are correct, and * extract the values to check that they are correct too. */ TEST_FEATURE ("with int16 array array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); int16_array_array = nih_alloc (NULL, sizeof (int16_t *) * 3); int16_array_array_len = nih_alloc (int16_array_array, sizeof (size_t) * 2); int16_array_array[0] = nih_alloc (int16_array_array, sizeof (int16_t) * 6); int16_array_array[1] = nih_alloc (int16_array_array, sizeof (int16_t) * 3); int16_array_array[2] = NULL; } int16_array_array_len[0] = 6; int16_array_array[0][0] = 4; int16_array_array[0][1] = 8; int16_array_array[0][2] = 15; int16_array_array[0][3] = 16; int16_array_array[0][4] = 23; int16_array_array[0][5] = 42; int16_array_array_len[1] = 3; int16_array_array[1][0] = 999; int16_array_array[1][1] = 911; int16_array_array[1][2] = 112; ret = my_int16_array_array_marshal (message, int16_array_array, int16_array_array_len); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); nih_free (int16_array_array); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING)); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 4); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 8); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 15); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 16); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 23); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 42); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 999); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 911); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 112); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (message); dbus_shutdown (); nih_free (int16_array_array); } /* Check that the code to marshal an array of char * into a D-Bus * String Array is correctly generated and returned as an allocated * string. Alocal variable to track the iteration is required. */ TEST_FEATURE ("with string array"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "string_array", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal an array onto the message */\n" "if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, \"s\", &value_iter)) {\n" "\treturn -1;\n" "}\n" "\n" "for (size_t value_i = 0; value[value_i]; value_i++) {\n" "\tconst char *value_element;\n" "\n" "\tvalue_element = value[value_i];\n" "\n" "\t/* Marshal a char * onto the message */\n" "\tif (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_element)) {\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "}\n" "\n" "if (! dbus_message_iter_close_container (&iter, &value_iter)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "char **"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the values from the array of * char * up to the NULL and appends them as a D-Bus String Array to * the message we pass. The NULL pointer itself should not be * appended. We check the message signature is correct, then iterate * the message to check the types are correct, and extract the values * to check that they are correct too. */ TEST_FEATURE ("with string array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); str_array = nih_alloc (NULL, sizeof (char *) * 4); } str_array[0] = "hello"; str_array[1] = "cruel"; str_array[2] = "world"; str_array[3] = NULL; ret = my_string_array_marshal (message, str_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); nih_free (str_array); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "hello"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "cruel"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "world"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (message); dbus_shutdown (); nih_free (str_array); } /* Check that the code to marshal an array of arrays of char * into * a D-Bus String Array Array is correctly generated and returned * as an allocated string. We have a local variable to track the * iteration, but there should be no other leak from inside. */ TEST_FEATURE ("with string array array"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "string_array_array", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal an array onto the message */\n" "if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, \"as\", &value_iter)) {\n" "\treturn -1;\n" "}\n" "\n" "for (size_t value_i = 0; value[value_i]; value_i++) {\n" "\tDBusMessageIter value_element_iter;\n" "\tchar * const * value_element;\n" "\n" "\tvalue_element = value[value_i];\n" "\n" "\t/* Marshal an array onto the message */\n" "\tif (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_ARRAY, \"s\", &value_element_iter)) {\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tfor (size_t value_element_i = 0; value_element[value_element_i]; value_element_i++) {\n" "\t\tconst char *value_element_element;\n" "\n" "\t\tvalue_element_element = value_element[value_element_i];\n" "\n" "\t\t/* Marshal a char * onto the message */\n" "\t\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_STRING, &value_element_element)) {\n" "\t\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n" "\t\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\t\treturn -1;\n" "\t\t}\n" "\t}\n" "\n" "\tif (! dbus_message_iter_close_container (&value_iter, &value_element_iter)) {\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "}\n" "\n" "if (! dbus_message_iter_close_container (&iter, &value_iter)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "char ***"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the values from the array of * arrays of char * up to each of the NULLs and appends them as * D-Bus String Arrays to a D-Bus String Array Array for the message * we pass. The NULL pointers themselves should not be appended. * We check the message signature is correct, then iterate * the message to check the types are correct, and extract the values * to check that they are correct too. */ TEST_FEATURE ("with string array array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); str_array_array = nih_alloc (NULL, sizeof (char **) * 3); str_array_array[0] = nih_alloc (str_array_array, sizeof (char *) * 4); str_array_array[1] = nih_alloc (str_array_array, sizeof (char *) * 3); str_array_array[2] = NULL; } str_array_array[0][0] = "hello"; str_array_array[0][1] = "cruel"; str_array_array[0][2] = "world"; str_array_array[0][3] = NULL; str_array_array[1][0] = "frodo"; str_array_array[1][1] = "baggins"; str_array_array[1][2] = NULL; ret = my_string_array_array_marshal (message, str_array_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); nih_free (str_array_array); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "hello"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "cruel"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "world"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "frodo"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "baggins"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_unref (message); dbus_shutdown (); nih_free (str_array_array); } /* Check that the code to marshal a structure into a D-Bus Struct is * correctly generated and returned as an allocated string, containing * the marshalling code for each of the structure's members. */ TEST_FEATURE ("with structure"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING)); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "struct", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a structure onto the message */\n" "if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &value_iter)) {\n" "\treturn -1;\n" "}\n" "\n" "value_item0 = value->item0;\n" "\n" "/* Marshal a char * onto the message */\n" "if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_STRING, &value_item0)) {\n" "\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\treturn -1;\n" "}\n" "\n" "value_item1 = value->item1;\n" "\n" "/* Marshal a uint32_t onto the message */\n" "if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_UINT32, &value_item1)) {\n" "\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\treturn -1;\n" "}\n" "\n" "value_item2 = value->item2;\n" "\n" "/* Marshal an array onto the message */\n" "if (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_ARRAY, \"s\", &value_item2_iter)) {\n" "\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\treturn -1;\n" "}\n" "\n" "for (size_t value_item2_i = 0; value_item2[value_item2_i]; value_item2_i++) {\n" "\tconst char *value_item2_element;\n" "\n" "\tvalue_item2_element = value_item2[value_item2_i];\n" "\n" "\t/* Marshal a char * onto the message */\n" "\tif (! dbus_message_iter_append_basic (&value_item2_iter, DBUS_TYPE_STRING, &value_item2_element)) {\n" "\t\tdbus_message_iter_abandon_container (&value_iter, &value_item2_iter);\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "}\n" "\n" "if (! dbus_message_iter_close_container (&value_iter, &value_item2_iter)) {\n" "\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\treturn -1;\n" "}\n" "\n" "value_item3 = value->item3;\n" "value_item3_len = value->item3_len;\n" "\n" "/* Marshal an array onto the message */\n" "if (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_ARRAY, \"n\", &value_item3_iter)) {\n" "\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\treturn -1;\n" "}\n" "\n" "for (size_t value_item3_i = 0; value_item3_i < value_item3_len; value_item3_i++) {\n" "\tint16_t value_item3_element;\n" "\n" "\tvalue_item3_element = value_item3[value_item3_i];\n" "\n" "\t/* Marshal a int16_t onto the message */\n" "\tif (! dbus_message_iter_append_basic (&value_item3_iter, DBUS_TYPE_INT16, &value_item3_element)) {\n" "\t\tdbus_message_iter_abandon_container (&value_iter, &value_item3_iter);\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "}\n" "\n" "if (! dbus_message_iter_close_container (&value_iter, &value_item3_iter)) {\n" "\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\treturn -1;\n" "}\n" "\n" "if (! dbus_message_iter_close_container (&iter, &value_iter)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "MyStructValue *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item2_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "char * const *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item2"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item3_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const int16_t *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item3"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "size_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item3_len"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyStructValue"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char **"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item2"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "int16_t *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item3"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "size_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item3_len"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes each of the values from a * structure and appends them into a D-Bus Structure to the message * we pass. We check the message signature is correct, then iterate * the message to check the types are correct, and extract the values * to check that they* are correct too. */ TEST_FEATURE ("with structure (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); struct_value = nih_new (NULL, MyStructValue); struct_value->item0 = "hello there"; struct_value->item1 = 1818118181; struct_value->item2 = nih_alloc (struct_value, sizeof (char *) * 3); struct_value->item2[0] = "welcome"; struct_value->item2[1] = "aboard"; struct_value->item2[2] = NULL; struct_value->item3 = nih_alloc (struct_value, sizeof (int16_t) * 6); struct_value->item3[0] = 4; struct_value->item3[1] = 8; struct_value->item3[2] = 15; struct_value->item3[3] = 16; struct_value->item3[4] = 23; struct_value->item3[5] = 42; struct_value->item3_len = 6; } ret = my_struct_marshal (message, struct_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); nih_free (struct_value); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRUCT); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "hello there"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UINT32); uint32_value = 0; dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 1818118181); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "welcome"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "aboard"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 4); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 8); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 15); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 16); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 23); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INT16); int16_value = 0; dbus_message_iter_get_basic (&subsubiter, &int16_value); TEST_EQ (int16_value, 42); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (message); dbus_shutdown (); nih_free (struct_value); } /* Check that the code to marshal an array of structures into a * D-Bus Struct Array is correctly generated and returned as an * allocated string, containing the marshalling code for each of * the structures. */ TEST_FEATURE ("with structure array"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_TYPE_ARRAY_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING)); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "struct_array", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal an array onto the message */\n" "if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, \"(su)\", &value_iter)) {\n" "\treturn -1;\n" "}\n" "\n" "for (size_t value_i = 0; value[value_i]; value_i++) {\n" "\tDBusMessageIter value_element_iter;\n" "\tconst char * value_element_item0;\n" "\tuint32_t value_element_item1;\n" "\tconst MyStructArrayValueElement *value_element;\n" "\n" "\tvalue_element = value[value_i];\n" "\n" "\t/* Marshal a structure onto the message */\n" "\tif (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_STRUCT, NULL, &value_element_iter)) {\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue_element_item0 = value_element->item0;\n" "\n" "\t/* Marshal a char * onto the message */\n" "\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_STRING, &value_element_item0)) {\n" "\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue_element_item1 = value_element->item1;\n" "\n" "\t/* Marshal a uint32_t onto the message */\n" "\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_UINT32, &value_element_item1)) {\n" "\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tif (! dbus_message_iter_close_container (&value_iter, &value_element_iter)) {\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "}\n" "\n" "if (! dbus_message_iter_close_container (&iter, &value_iter)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "MyStructArrayValueElement **"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyStructArrayValueElement"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes each of the values from an * array of structures and appends them into a D-Bus Structure Array * to the message we pass. We check the message signature is correct, * then iterate the message to check the types are correct, and * extract the values to check that they* are correct too. */ TEST_FEATURE ("with structure array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); struct_array = nih_alloc (NULL, sizeof (MyStructArrayValueElement *) * 3); struct_array[0] = nih_new (struct_array, MyStructArrayValueElement); struct_array[0]->item0 = "hello there"; struct_array[0]->item1 = 1818118181; struct_array[1] = nih_new (struct_array, MyStructArrayValueElement); struct_array[1]->item0 = "goodbye world"; struct_array[1]->item1 = 12345; struct_array[2] = NULL; } ret = my_struct_array_marshal (message, struct_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); nih_free (struct_array); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_ARRAY_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRUCT); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "hello there"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_UINT32); uint32_value = 0; dbus_message_iter_get_basic (&subsubiter, &uint32_value); TEST_EQ (uint32_value, 1818118181); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRUCT); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "goodbye world"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_UINT32); uint32_value = 0; dbus_message_iter_get_basic (&subsubiter, &uint32_value); TEST_EQ (uint32_value, 12345); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (message); dbus_shutdown (); nih_free (struct_array); } /* Check that the code to marshal an array of key/value structures * into a D-Bus DictEntry Array is correctly generated and returned * as an allocated string, containing the marshalling code for each of * the structures. */ TEST_FEATURE ("with dict entry array"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING)); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "dict_entry_array", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal an array onto the message */\n" "if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, \"{su}\", &value_iter)) {\n" "\treturn -1;\n" "}\n" "\n" "for (size_t value_i = 0; value[value_i]; value_i++) {\n" "\tDBusMessageIter value_element_iter;\n" "\tconst char * value_element_item0;\n" "\tuint32_t value_element_item1;\n" "\tconst MyDictEntryArrayValueElement *value_element;\n" "\n" "\tvalue_element = value[value_i];\n" "\n" "\t/* Marshal a structure onto the message */\n" "\tif (! dbus_message_iter_open_container (&value_iter, DBUS_TYPE_DICT_ENTRY, NULL, &value_element_iter)) {\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue_element_item0 = value_element->item0;\n" "\n" "\t/* Marshal a char * onto the message */\n" "\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_STRING, &value_element_item0)) {\n" "\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue_element_item1 = value_element->item1;\n" "\n" "\t/* Marshal a uint32_t onto the message */\n" "\tif (! dbus_message_iter_append_basic (&value_element_iter, DBUS_TYPE_UINT32, &value_element_item1)) {\n" "\t\tdbus_message_iter_abandon_container (&value_iter, &value_element_iter);\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tif (! dbus_message_iter_close_container (&value_iter, &value_element_iter)) {\n" "\t\tdbus_message_iter_abandon_container (&iter, &value_iter);\n" "\t\treturn -1;\n" "\t}\n" "}\n" "\n" "if (! dbus_message_iter_close_container (&iter, &value_iter)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "MyDictEntryArrayValueElement **"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyDictEntryArrayValueElement"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes each of the values from an * array of dict entries and appends them into a D-Bus DictEntry Array * to the message we pass. We check the message signature is correct, * then iterate the message to check the types are correct, and * extract the values to check that they* are correct too. */ TEST_FEATURE ("with dict entry array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dict_entry_array = nih_alloc (NULL, sizeof (MyDictEntryArrayValueElement *) * 3); dict_entry_array[0] = nih_new (dict_entry_array, MyDictEntryArrayValueElement); dict_entry_array[0]->item0 = "hello there"; dict_entry_array[0]->item1 = 1818118181; dict_entry_array[1] = nih_new (dict_entry_array, MyDictEntryArrayValueElement); dict_entry_array[1]->item0 = "goodbye world"; dict_entry_array[1]->item1 = 12345; dict_entry_array[2] = NULL; } ret = my_dict_entry_array_marshal (message, dict_entry_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); nih_free (dict_entry_array); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_ARRAY); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_DICT_ENTRY); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "hello there"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_UINT32); uint32_value = 0; dbus_message_iter_get_basic (&subsubiter, &uint32_value); TEST_EQ (uint32_value, 1818118181); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_DICT_ENTRY); dbus_message_iter_recurse (&subiter, &subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_STRING); str_value = NULL; dbus_message_iter_get_basic (&subsubiter, &str_value); TEST_EQ_STR (str_value, "goodbye world"); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_UINT32); uint32_value = 0; dbus_message_iter_get_basic (&subsubiter, &uint32_value); TEST_EQ (uint32_value, 12345); dbus_message_iter_next (&subsubiter); TEST_EQ (dbus_message_iter_get_arg_type (&subsubiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (message); dbus_shutdown (); nih_free (dict_entry_array); } /* Check that the code to marshal an int into a D-Bus file descriptor * is correctly generated and returned as an allocated string. */ TEST_FEATURE ("with file descriptor"); TEST_ALLOC_FAIL { nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_UNIX_FD_AS_STRING); str = marshal (NULL, &signature, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, "unix_fd", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Marshal a int onto the message */\n" "if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_UNIX_FD, &value)) {\n" "\treturn -1;\n" "}\n")); TEST_LIST_NOT_EMPTY (&inputs); var = (TypeVar *)inputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&inputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the int and * appends it as a D-Bus file descriptor to the message we pass. We * check the message signature is correct, then iterate the message to * check the types are correct, and extract the values to check that they * are correct too. */ TEST_FEATURE ("with file descriptor (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); } unix_fd_value = 1; ret = my_unix_fd_marshal (message, unix_fd_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (dbus_message_get_signature (message), DBUS_TYPE_UNIX_FD_AS_STRING); assert (dbus_message_iter_init (message, &iter)); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_UNIX_FD); unix_fd_value = -1; dbus_message_iter_get_basic (&iter, &unix_fd_value); TEST_GT (unix_fd_value, 2); // file descriptor is duplicated dbus_message_unref (message); close (unix_fd_value); dbus_shutdown (); } } int main (int argc, char *argv[]) { test_marshal (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/test_method.c0000644000175000017500000100652011445765555016237 00000000000000/* nih-dbus-tool * * test_method.c - test suite for nih-dbus-tool/method.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "type.h" #include "node.h" #include "method.h" #include "argument.h" #include "parse.h" #include "errors.h" #include "tests/method_code.h" void test_name_valid (void) { TEST_FUNCTION ("method_name_valid"); /* Check that a typical method name is valid. */ TEST_FEATURE ("with typical method name"); TEST_TRUE (method_name_valid ("Wibble")); /* Check that an method name is not valid if it is has an * initial period. */ TEST_FEATURE ("with initial period"); TEST_FALSE (method_name_valid (".Wibble")); /* Check that an method name is not valid if it ends with a period */ TEST_FEATURE ("with final period"); TEST_FALSE (method_name_valid ("Wibble.")); /* Check that an method name is not valid if it contains a period */ TEST_FEATURE ("with period"); TEST_FALSE (method_name_valid ("Wib.ble")); /* Check that a method name may contain numbers */ TEST_FEATURE ("with numbers"); TEST_TRUE (method_name_valid ("Wib43ble")); /* Check that a method name may not begin with numbers */ TEST_FEATURE ("with leading digits"); TEST_FALSE (method_name_valid ("43Wibble")); /* Check that a method name may end with numbers */ TEST_FEATURE ("with trailing digits"); TEST_TRUE (method_name_valid ("Wibble43")); /* Check that a method name may contain underscores */ TEST_FEATURE ("with underscore"); TEST_TRUE (method_name_valid ("Wib_ble")); /* Check that a method name may begin with underscores */ TEST_FEATURE ("with initial underscore"); TEST_TRUE (method_name_valid ("_Wibble")); /* Check that a method name may end with underscores */ TEST_FEATURE ("with final underscore"); TEST_TRUE (method_name_valid ("Wibble_")); /* Check that other characters are not permitted */ TEST_FEATURE ("with non-permitted characters"); TEST_FALSE (method_name_valid ("Wib-ble")); /* Check that an empty method name is invalid */ TEST_FEATURE ("with empty string"); TEST_FALSE (method_name_valid ("")); /* Check that an method name may not exceed 255 characters */ TEST_FEATURE ("with overly long name"); TEST_FALSE (method_name_valid ("ReallyLongMethodNameThatNobody" "InTheirRightMindWouldEverUseNo" "tInTheLeastBecauseThenYoudEndU" "pWithAnEvenLongerInterfaceName" "AndThatJustWontWorkWhenCombine" "dButStillWeTestThisShitJustInc" "aseSomeoneTriesItBecauseThatsW" "hatTestDrivenDevelopmentIsAllA" "bout.YayThereNow")); } void test_new (void) { Method *method; /* Check that an Method object is allocated with the structure * filled in properly, but not placed in a list. */ TEST_FUNCTION ("method_new"); TEST_ALLOC_FAIL { method = method_new (NULL, "Wibble"); if (test_alloc_failed) { TEST_EQ_P (method, NULL); continue; } TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_LIST_EMPTY (&method->entry); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_P (method->symbol, NULL); TEST_FALSE (method->deprecated); TEST_FALSE (method->async); TEST_FALSE (method->no_reply); TEST_LIST_EMPTY (&method->arguments); nih_free (method); } } void test_start_tag (void) { ParseContext context; ParseStack * parent = NULL; ParseStack * entry; XML_Parser xmlp; Node * node = NULL; Interface * interface = NULL; Method * method; char * attr[5]; int ret = 0; NihError * err; FILE * output; TEST_FUNCTION ("method_start_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); output = tmpfile (); /* Check that an method tag for an interface with the usual name * attribute results in an Method member being created and pushed * onto the stack with that attribute filled in correctly. */ TEST_FEATURE ("with method"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } attr[0] = "name"; attr[1] = "TestMethod"; attr[2] = NULL; ret = method_start_tag (xmlp, "method", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->methods); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_METHOD); method = entry->method; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, entry); TEST_EQ_STR (method->name, "TestMethod"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_P (method->symbol, NULL); TEST_LIST_EMPTY (&method->arguments); TEST_LIST_EMPTY (&interface->methods); nih_free (entry); nih_free (parent); } /* Check that a method with a missing name attribute results * in an error being raised. */ TEST_FEATURE ("with missing name"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = NULL; } ret = method_start_tag (xmlp, "method", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->methods); err = nih_error_get (); TEST_EQ (err->number, METHOD_MISSING_NAME); nih_free (err); nih_free (parent); } /* Check that a method with an invalid name results in an * error being raised. */ TEST_FEATURE ("with invalid name"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "Test Method"; attr[2] = NULL; } ret = method_start_tag (xmlp, "method", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&interface->methods); err = nih_error_get (); TEST_EQ (err->number, METHOD_INVALID_NAME); nih_free (err); nih_free (parent); } /* Check that an unknown method attribute results in a warning * being printed to standard error, but is otherwise ignored * and the normal processing finished. */ TEST_FEATURE ("with unknown attribute"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); attr[0] = "name"; attr[1] = "TestMethod"; attr[2] = "frodo"; attr[3] = "baggins"; attr[4] = NULL; } TEST_DIVERT_STDERR (output) { ret = method_start_tag (xmlp, "method", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_METHOD); method = entry->method; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, entry); TEST_EQ_STR (method->name, "TestMethod"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_P (method->symbol, NULL); TEST_LIST_EMPTY (&method->arguments); TEST_LIST_EMPTY (&interface->methods); TEST_FILE_EQ (output, ("test:foo:1:0: Ignored unknown attribute: " "frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } /* Check that a method on an empty stack (ie. a top-level * method element) results in a warning being printed on * standard error and an ignored element being pushed onto the * stack. */ TEST_FEATURE ("with empty stack"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { attr[0] = "name"; attr[1] = "TestMethod"; attr[2] = NULL; } TEST_DIVERT_STDERR (output) { ret = method_start_tag (xmlp, "method", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), NULL); TEST_FILE_RESET (output); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unexpected tag\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); } /* Check that a method on top of a stack entry that's not an * interface results in a warning being printed on * standard error and an ignored element being pushed onto the * stack. */ TEST_FEATURE ("with non-interface on stack"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); attr[0] = "name"; attr[1] = "TestMethod"; attr[2] = NULL; } TEST_DIVERT_STDERR (output) { ret = method_start_tag (xmlp, "method", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unexpected tag\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } XML_ParserFree (xmlp); fclose (output); } void test_end_tag (void) { ParseContext context; ParseStack * parent = NULL; ParseStack * entry = NULL; XML_Parser xmlp; Interface * interface = NULL; Method * method = NULL; Method * other = NULL; Argument * argument = NULL; int ret = 0; NihError * err; FILE * output; TEST_FUNCTION ("method_end_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); output = tmpfile (); /* Check that when we parse the end tag for a method, we pop * the Method object off the stack (freeing and removing it) * and append it to the parent interface's methods list, adding a * reference to the interface as well. A symbol should be generated * for the method by convering its name to C style. */ TEST_FEATURE ("with no assigned symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); method = method_new (NULL, "TestMethod"); entry = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); } TEST_FREE_TAG (entry); ret = method_end_tag (xmlp, "method"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->methods); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (method, interface); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_EQ_P (interface->methods.next, &method->entry); TEST_EQ_STR (method->symbol, "test_method"); TEST_ALLOC_PARENT (method->symbol, method); nih_free (parent); } /* Check that when the symbol has been pre-assigned by the data, * it's not overridden and is used even if different. */ TEST_FEATURE ("with assigned symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); method = method_new (NULL, "TestMethod"); method->symbol = nih_strdup (method, "foo"); entry = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); } TEST_FREE_TAG (entry); ret = method_end_tag (xmlp, "method"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->methods); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (method, interface); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_EQ_P (interface->methods.next, &method->entry); TEST_EQ_STR (method->symbol, "foo"); TEST_ALLOC_PARENT (method->symbol, method); nih_free (parent); } /* Check that we don't generate a duplicate symbol, and instead * raise an error and allow the user to deal with it using * the Symbol annotation. The reason we don't work around this * with a counter or similar is that the function names then * become unpredicatable (introspection data isn't ordered). */ TEST_FEATURE ("with conflicting symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); other = method_new (interface, "Test"); other->symbol = nih_strdup (other, "test_method"); nih_list_add (&interface->methods, &other->entry); method = method_new (NULL, "TestMethod"); entry = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); } ret = method_end_tag (xmlp, "method"); TEST_LT (ret, 0); err = nih_error_get (); if ((! test_alloc_failed) || (err->number != ENOMEM)) TEST_EQ (err->number, METHOD_DUPLICATE_SYMBOL); nih_free (err); nih_free (entry); nih_free (parent); } /* Check that a method with the NoReply annotation and only * input arguments is accepted. */ TEST_FEATURE ("with no reply expected"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); method = method_new (NULL, "TestMethod"); method->no_reply = TRUE; entry = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); argument = argument_new (method, NULL, "i", NIH_DBUS_ARG_IN); nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, NULL, "i", NIH_DBUS_ARG_IN); nih_list_add (&method->arguments, &argument->entry); } TEST_FREE_TAG (entry); TEST_DIVERT_STDERR (output) { ret = method_end_tag (xmlp, "method"); } rewind (output); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->methods); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (method, interface); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_EQ_P (interface->methods.next, &method->entry); TEST_EQ_STR (method->symbol, "test_method"); TEST_ALLOC_PARENT (method->symbol, method); TEST_TRUE (method->no_reply); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (parent); } /* Check that a method with the NoReply annotation and output * arguments has the annotation removed and a warning emitted. */ TEST_FEATURE ("with no reply expected and output arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); method = method_new (NULL, "TestMethod"); method->no_reply = TRUE; entry = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); argument = argument_new (method, NULL, "i", NIH_DBUS_ARG_OUT); nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, NULL, "i", NIH_DBUS_ARG_OUT); nih_list_add (&method->arguments, &argument->entry); } TEST_FREE_TAG (entry); TEST_DIVERT_STDERR (output) { ret = method_end_tag (xmlp, "method"); } rewind (output); if (test_alloc_failed && (ret < 0)) { TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->methods); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (method, interface); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_EQ_P (interface->methods.next, &method->entry); TEST_EQ_STR (method->symbol, "test_method"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->no_reply); TEST_FILE_EQ (output, "test:foo:1:0: Ignored NoReply annotation for method with output arguments\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (parent); } /* Check that a method with the Async annotation is accepted. */ TEST_FEATURE ("with async implementation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); method = method_new (NULL, "TestMethod"); method->async = TRUE; entry = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); } TEST_FREE_TAG (entry); TEST_DIVERT_STDERR (output) { ret = method_end_tag (xmlp, "method"); } rewind (output); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->methods); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (method, interface); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_EQ_P (interface->methods.next, &method->entry); TEST_EQ_STR (method->symbol, "test_method"); TEST_ALLOC_PARENT (method->symbol, method); TEST_TRUE (method->async); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (parent); } /* Check that a method that is both Async and NoReply has the * async annotation removed and a warning emitted. */ TEST_FEATURE ("with async but no reply expected"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); method = method_new (NULL, "TestMethod"); method->async = TRUE; method->no_reply = TRUE; entry = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); } TEST_FREE_TAG (entry); TEST_DIVERT_STDERR (output) { ret = method_end_tag (xmlp, "method"); } rewind (output); if (test_alloc_failed && (ret < 0)) { TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->methods); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (method, interface); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_EQ_P (interface->methods.next, &method->entry); TEST_EQ_STR (method->symbol, "test_method"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->async); TEST_TRUE (method->no_reply); TEST_FILE_EQ (output, "test:foo:1:0: Ignored Async annotation for NoReply method\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (parent); } /* Check that an Async method with the NoReply annotation but * output arguments only has the NoReply annotation removed and * a warning emitted about that, but remains async. */ TEST_FEATURE ("with async, no reply expected and output arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); method = method_new (NULL, "TestMethod"); method->async = TRUE; method->no_reply = TRUE; entry = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); argument = argument_new (method, NULL, "i", NIH_DBUS_ARG_OUT); nih_list_add (&method->arguments, &argument->entry); argument = argument_new (method, NULL, "i", NIH_DBUS_ARG_OUT); nih_list_add (&method->arguments, &argument->entry); } TEST_FREE_TAG (entry); TEST_DIVERT_STDERR (output) { ret = method_end_tag (xmlp, "method"); } rewind (output); if (test_alloc_failed && (ret < 0)) { TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->methods); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (method, interface); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_EQ_P (interface->methods.next, &method->entry); TEST_EQ_STR (method->symbol, "test_method"); TEST_ALLOC_PARENT (method->symbol, method); TEST_TRUE (method->async); TEST_FALSE (method->no_reply); TEST_FILE_EQ (output, "test:foo:1:0: Ignored NoReply annotation for method with output arguments\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (parent); } XML_ParserFree (xmlp); fclose (output); } void test_annotation (void) { Method * method = NULL; char * symbol; int ret = 0; NihError *err; TEST_FUNCTION ("method_annotation"); /* Check that the annotation to mark a method as deprecated is * handled, and the Method is marked deprecated. */ TEST_FEATURE ("with deprecated annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); } ret = method_annotation (method, "org.freedesktop.DBus.Deprecated", "true"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_FALSE (method->deprecated); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (method); continue; } TEST_EQ (ret, 0); TEST_TRUE (method->deprecated); nih_free (method); } /* Check that the annotation to mark a method as deprecated can be * given a false value to explicitly mark the Method non-deprecated. */ TEST_FEATURE ("with explicitly non-deprecated annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); method->deprecated = TRUE; } ret = method_annotation (method, "org.freedesktop.DBus.Deprecated", "false"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_TRUE (method->deprecated); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (method); continue; } TEST_EQ (ret, 0); TEST_FALSE (method->deprecated); nih_free (method); } /* Check that the annotation to mark a method caller to expect no * reply is handled, and the Method is marked. */ TEST_FEATURE ("with no reply annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); } ret = method_annotation (method, "org.freedesktop.DBus.Method.NoReply", "true"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_FALSE (method->no_reply); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (method); continue; } TEST_EQ (ret, 0); TEST_TRUE (method->no_reply); nih_free (method); } /* Check that the annotation to mark a method caller to expect * no reply can be given a false value to explicitly mark the * Method caller to expect one. */ TEST_FEATURE ("with explicitly replies annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); method->no_reply = TRUE; } ret = method_annotation (method, "org.freedesktop.DBus.Method.NoReply", "false"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_TRUE (method->no_reply); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (method); continue; } TEST_EQ (ret, 0); TEST_FALSE (method->no_reply); nih_free (method); } /* Check that an annotation to add a symbol to the method is * handled, and the new symbol is stored in the method. */ TEST_FEATURE ("with symbol annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); } ret = method_annotation (method, "com.netsplit.Nih.Symbol", "foo"); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (method); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (method->symbol, "foo"); TEST_ALLOC_PARENT (method->symbol, method); nih_free (method); } /* Check that an annotation to add a symbol to the method * replaces any previous symbol applied (e.g. by a previous * annotation). */ TEST_FEATURE ("with symbol annotation and existing symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); method->symbol = nih_strdup (method, "test_method"); } symbol = method->symbol; TEST_FREE_TAG (symbol); ret = method_annotation (method, "com.netsplit.Nih.Symbol", "foo"); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (method); continue; } TEST_EQ (ret, 0); TEST_FREE (symbol); TEST_EQ_STR (method->symbol, "foo"); TEST_ALLOC_PARENT (method->symbol, method); nih_free (method); } /* Check that the annotation to mark a method implementation as * asynchronous is handled, and the Method is marked async. */ TEST_FEATURE ("with async annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); } ret = method_annotation (method, "com.netsplit.Nih.Method.Async", "true"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_FALSE (method->async); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (method); continue; } TEST_EQ (ret, 0); TEST_TRUE (method->async); nih_free (method); } /* Check that the annotation to mark a method implementation as * asynchronous can be given a false value to explicitly mark the * Method synchronous. */ TEST_FEATURE ("with explicitly non-async annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); method->async = TRUE; } ret = method_annotation (method, "com.netsplit.Nih.Method.Async", "false"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_TRUE (method->async); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (method); continue; } TEST_EQ (ret, 0); TEST_FALSE (method->async); nih_free (method); } /* Check that an invalid value for the deprecated annotation results * in an error being raised. */ TEST_FEATURE ("with invalid value for deprecated annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); } ret = method_annotation (method, "org.freedesktop.DBus.Deprecated", "foo"); TEST_LT (ret, 0); TEST_EQ_P (method->symbol, NULL); err = nih_error_get (); TEST_EQ (err->number, METHOD_ILLEGAL_DEPRECATED); nih_free (err); nih_free (method); } /* Check that an invalid value for the no reply annotation results * in an error being raised. */ TEST_FEATURE ("with invalid value for no reply annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); ret = method_annotation (method, "org.freedesktop.DBus.Method.NoReply", "foo"); } TEST_LT (ret, 0); TEST_EQ_P (method->symbol, NULL); err = nih_error_get (); TEST_EQ (err->number, METHOD_ILLEGAL_NO_REPLY); nih_free (err); nih_free (method); } /* Check that an invalid symbol in an annotation results in an * error being raised. */ TEST_FEATURE ("with invalid symbol in annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); } ret = method_annotation (method, "com.netsplit.Nih.Symbol", "foo bar"); TEST_LT (ret, 0); TEST_EQ_P (method->symbol, NULL); err = nih_error_get (); TEST_EQ (err->number, METHOD_INVALID_SYMBOL); nih_free (err); nih_free (method); } /* Check that an invalid value for the async annotation results * in an error being raised. */ TEST_FEATURE ("with invalid value for async annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); } ret = method_annotation (method, "com.netsplit.Nih.Method.Async", "foo"); TEST_LT (ret, 0); TEST_EQ_P (method->symbol, NULL); err = nih_error_get (); TEST_EQ (err->number, METHOD_ILLEGAL_ASYNC); nih_free (err); nih_free (method); } /* Check that an unknown annotation results in an error being * raised. */ TEST_FEATURE ("with unknown annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); } ret = method_annotation (method, "com.netsplit.Nih.Unknown", "true"); TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, METHOD_UNKNOWN_ANNOTATION); nih_free (err); nih_free (method); } } void test_lookup (void) { Interface *interface = NULL; Method * method1 = NULL; Method * method2 = NULL; Method * method3 = NULL; Method * ret; TEST_FUNCTION ("method_lookup"); /* Check that the function returns the method if there is one * with the given symbol. */ TEST_FEATURE ("with matching symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); method1 = method_new (interface, "Test"); method1->symbol = nih_strdup (method1, "test"); nih_list_add (&interface->methods, &method1->entry); method2 = method_new (interface, "Foo"); nih_list_add (&interface->methods, &method2->entry); method3 = method_new (interface, "Bar"); method3->symbol = nih_strdup (method3, "bar"); nih_list_add (&interface->methods, &method3->entry); } ret = method_lookup (interface, "bar"); TEST_EQ_P (ret, method3); nih_free (interface); } /* Check that the function returns NULL if there is no method * with the given symbol. */ TEST_FEATURE ("with non-matching symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); method1 = method_new (interface, "Test"); method1->symbol = nih_strdup (method1, "test"); nih_list_add (&interface->methods, &method1->entry); method2 = method_new (interface, "Foo"); nih_list_add (&interface->methods, &method2->entry); method3 = method_new (interface, "Bar"); method3->symbol = nih_strdup (method3, "bar"); nih_list_add (&interface->methods, &method3->entry); } ret = method_lookup (interface, "baz"); TEST_EQ_P (ret, NULL); nih_free (interface); } } void test_lookup_argument (void) { Method * method = NULL; Argument *argument1 = NULL; Argument *argument2 = NULL; Argument *argument3 = NULL; Argument *ret; TEST_FUNCTION ("method_lookup_argument"); /* Check that the function returns the argument if there is one * with the given symbol. */ TEST_FEATURE ("with matching symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "com.netsplit.Nih.Test"); argument1 = argument_new (method, "Test", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "test"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Foo", "s", NIH_DBUS_ARG_IN); nih_list_add (&method->arguments, &argument2->entry); argument3 = argument_new (method, "Bar", "s", NIH_DBUS_ARG_IN); argument3->symbol = nih_strdup (argument3, "bar"); nih_list_add (&method->arguments, &argument3->entry); } ret = method_lookup_argument (method, "bar"); TEST_EQ_P (ret, argument3); nih_free (method); } /* Check that the function returns NULL if there is no argument * with the given symbol. */ TEST_FEATURE ("with non-matching symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "com.netsplit.Nih.Test"); argument1 = argument_new (method, "Test", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "test"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Foo", "s", NIH_DBUS_ARG_IN); nih_list_add (&method->arguments, &argument2->entry); argument3 = argument_new (method, "Bar", "s", NIH_DBUS_ARG_IN); argument3->symbol = nih_strdup (argument3, "bar"); nih_list_add (&method->arguments, &argument3->entry); } ret = method_lookup_argument (method, "baz"); TEST_EQ_P (ret, NULL); nih_free (method); } } static int my_method_called = 0; int my_method (void * data, NihDBusMessage *message, const char * str, int32_t flags, char *** output) { my_method_called++; TEST_EQ_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_EQ_STR (str, "this is a test"); TEST_ALLOC_PARENT (str, message); TEST_NE_P (output, NULL); switch (flags) { case 0: *output = nih_str_split (message, str, " ", TRUE); if (! *output) nih_return_no_memory_error (-1); break; case 1: nih_dbus_error_raise ("com.netsplit.Nih.Test.Method.Fail", "Method failed"); return -1; case 2: nih_error_raise (EBADF, strerror (EBADF)); return -1; } return 0; } static int my_async_method_called = 0; int my_async_method (void * data, NihDBusMessage *message, const char * str, int32_t flags) { my_async_method_called++; TEST_EQ_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_EQ_STR (str, "this is a test"); TEST_ALLOC_PARENT (str, message); switch (flags) { case 0: break; case 1: nih_dbus_error_raise ("com.netsplit.Nih.Test.AsyncMethod.Fail", "Method failed"); return -1; case 2: nih_error_raise (EBADF, strerror (EBADF)); return -1; } return 0; } void test_object_function (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihList prototypes; NihList handlers; NihList structs; Interface * interface = NULL; Method * method = NULL; Argument * argument1 = NULL; Argument * argument2 = NULL; Argument * argument3 = NULL; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; NihListEntry * attrib; int32_t flags; double double_arg; DBusMessage * method_call; DBusMessage * next_call; DBusMessageIter iter; DBusMessageIter subiter; DBusMessage * reply; NihDBusMessage * message = NULL; NihDBusObject * object = NULL; dbus_uint32_t serial; dbus_uint32_t next_serial; DBusHandlerResult result; DBusError dbus_error; TEST_FUNCTION ("method_object_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a method call that demarshals a * D-Bus message, calls a handler function with the demarshalled * arguments and pointers to output arguments, then marshals those * back into a reply message or an error as appropriate. */ TEST_FEATURE ("with standard method"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); argument1 = argument_new (method, "Str", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "str"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Flags", "i", NIH_DBUS_ARG_IN); argument2->symbol = nih_strdup (argument2, "flags"); nih_list_add (&method->arguments, &argument2->entry); argument3 = argument_new (method, "Output", "as", NIH_DBUS_ARG_OUT); argument3->symbol = nih_strdup (argument3, "output"); nih_list_add (&method->arguments, &argument3->entry); } str = method_object_function (NULL, "my", interface, method, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_object_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Method_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "str"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "flags"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char ***"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "output"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a method call with no input arguments still results in * a correctly generated function. */ TEST_FEATURE ("with no input arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); argument1 = argument_new (method, "Output", "as", NIH_DBUS_ARG_OUT); argument1->symbol = nih_strdup (argument1, "output"); nih_list_add (&method->arguments, &argument1->entry); } str = method_object_function (NULL, "my", interface, method, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_object_function_no_input.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Method_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char ***"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "output"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a method call with no output arguments still results in * a correctly generated function. */ TEST_FEATURE ("with no output arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); argument1 = argument_new (method, "Str", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "str"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Flags", "i", NIH_DBUS_ARG_IN); argument2->symbol = nih_strdup (argument2, "flags"); nih_list_add (&method->arguments, &argument2->entry); } str = method_object_function (NULL, "my", interface, method, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_object_function_no_output.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Method_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "str"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "flags"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a method call with a structure as an input argument * is correctly generated, with the structure type passed back * in the structs array. */ TEST_FEATURE ("with structure input argument"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); argument1 = argument_new (method, "structure", "(su)", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "structure"); nih_list_add (&method->arguments, &argument1->entry); } str = method_object_function (NULL, "my", interface, method, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_object_function_structure_input.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Method_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyMethodStructure *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "structure"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyMethodStructure"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a method call with a structure as an output argument * is correctly generated, with the structure type passed back * in the structs array. */ TEST_FEATURE ("with structure output argument"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); argument1 = argument_new (method, "structure", "(su)", NIH_DBUS_ARG_OUT); argument1->symbol = nih_strdup (argument1, "structure"); nih_list_add (&method->arguments, &argument1->entry); } str = method_object_function (NULL, "my", interface, method, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_object_function_structure_output.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Method_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyMethodStructure **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "structure"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyMethodStructure"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a method call with no arguments still results in * a correctly generated function. */ TEST_FEATURE ("with no arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); } str = method_object_function (NULL, "my", interface, method, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_object_function_no_args.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Method_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that we can use the generated code to convert a message we * send to a function call which on return causes a reply message * to be sent back to us. */ TEST_FEATURE ("with normal return (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); flags = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_method_called = 0; result = my_com_netsplit_Nih_Test_Method_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_ARRAY); TEST_EQ (dbus_message_iter_get_element_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str); TEST_EQ_STR (str, "this"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str); TEST_EQ_STR (str, "is"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str); TEST_EQ_STR (str, "a"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str); TEST_EQ_STR (str, "test"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that when no reply is expected, none is sent but the * function returns success. */ TEST_FEATURE ("with no reply expected (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); flags = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); dbus_message_set_no_reply (method_call, TRUE); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_method_called = 0; result = my_com_netsplit_Nih_Test_Method_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); next_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "NextMethod"); dbus_connection_send (server_conn, next_call, &next_serial); dbus_connection_flush (server_conn); dbus_message_unref (next_call); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_CALL); TEST_EQ (dbus_message_get_serial (reply), next_serial); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that when the handler function raises a D-Bus error, we * receive the error reply as an equivalent D-Bus error reply. */ TEST_FEATURE ("with D-Bus error from handler (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); flags = 1; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_method_called = 0; result = my_com_netsplit_Nih_Test_Method_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_ERROR); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_error_name (reply), "com.netsplit.Nih.Test.Method.Fail"); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that when the handler function raises a non-D-Bus error, * we receive an error reply with the generic D-Bus failed error * but the same message. */ TEST_FEATURE ("with generic error from handler (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); flags = 2; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_method_called = 0; result = my_com_netsplit_Nih_Test_Method_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_ERROR); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_error_name (reply), DBUS_ERROR_FAILED); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, strerror (EBADF)); dbus_error_free (&dbus_error); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that an incorrect type in the method we send results in * an error reply being received and the function not being called. */ TEST_FEATURE ("with incorrect type in method (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); dbus_message_iter_init_append (method_call, &iter); flags = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_method_called = 0; result = my_com_netsplit_Nih_Test_Method_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_FALSE (my_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_ERROR); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_error_name (reply), DBUS_ERROR_INVALID_ARGS); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that a missing argument in the method we send results in * an error reply being received and the function not being called. */ TEST_FEATURE ("with missing argument in method (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_method_called = 0; result = my_com_netsplit_Nih_Test_Method_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_FALSE (my_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_ERROR); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_error_name (reply), DBUS_ERROR_INVALID_ARGS); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that an extra argument to the method also results in an * error reply being received and the function not being called. */ TEST_FEATURE ("with too many arguments in method (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); flags = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); double_arg = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_arg); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_method_called = 0; result = my_com_netsplit_Nih_Test_Method_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_FALSE (my_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_ERROR); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_error_name (reply), DBUS_ERROR_INVALID_ARGS); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that we can generate an asynchronous method call that * demarshals a D-Bus message, calls a handler function with the * demarshalled arguments and then returns. Errors should still * be handled. */ TEST_FEATURE ("with asynchronous method"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "AsyncMethod"); method->symbol = nih_strdup (method, "async_method"); method->async = TRUE; argument1 = argument_new (method, "Str", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "str"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Flags", "i", NIH_DBUS_ARG_IN); argument2->symbol = nih_strdup (argument2, "flags"); nih_list_add (&method->arguments, &argument2->entry); argument3 = argument_new (method, "Output", "as", NIH_DBUS_ARG_OUT); argument3->symbol = nih_strdup (argument3, "output"); nih_list_add (&method->arguments, &argument3->entry); } str = method_object_function (NULL, "my", interface, method, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_object_function_async.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_AsyncMethod_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_async_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "str"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "flags"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that we can use the generated asynchronous method code * to convert a message we send to a function call which returns. */ TEST_FEATURE ("with asynchronous method return (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); flags = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_async_method_called = 0; result = my_com_netsplit_Nih_Test_AsyncMethod_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_async_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); nih_free (object); nih_free (message); dbus_message_unref (method_call); } /* Check that when no reply is expected, the asynchronous call * is still left pending since the reply function will ignore it. */ TEST_FEATURE ("with no reply expected to async (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); flags = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); dbus_message_set_no_reply (method_call, TRUE); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_async_method_called = 0; result = my_com_netsplit_Nih_Test_AsyncMethod_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_async_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); nih_free (object); nih_free (message); dbus_message_unref (method_call); } /* Check that when the handler function raises a D-Bus error, we * receive the error reply as an equivalent D-Bus error reply; * since this constitutes handling, it should return handled. */ TEST_FEATURE ("with D-Bus error from async handler (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); flags = 1; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_async_method_called = 0; result = my_com_netsplit_Nih_Test_AsyncMethod_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_async_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_ERROR); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_error_name (reply), "com.netsplit.Nih.Test.AsyncMethod.Fail"); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that when the handler function raises a non-D-Bus error, * we receive an error reply with the generic D-Bus failed error * but the same message, this also constitutes being handled. */ TEST_FEATURE ("with generic error from async handler (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); flags = 2; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_async_method_called = 0; result = my_com_netsplit_Nih_Test_AsyncMethod_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_TRUE (my_async_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_ERROR); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_error_name (reply), DBUS_ERROR_FAILED); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, strerror (EBADF)); dbus_error_free (&dbus_error); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that an incorrect type in the method we send results in * an error reply being received and the function not being called, * this constitutes being handled. */ TEST_FEATURE ("with incorrect type in async method (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); flags = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_async_method_called = 0; result = my_com_netsplit_Nih_Test_AsyncMethod_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_FALSE (my_async_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_ERROR); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_error_name (reply), DBUS_ERROR_INVALID_ARGS); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that a missing argument in the method we send results in * an error reply being received and the function not being called, * again this is being handled. */ TEST_FEATURE ("with missing argument in async method (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_async_method_called = 0; result = my_com_netsplit_Nih_Test_AsyncMethod_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_FALSE (my_async_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_ERROR); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_error_name (reply), DBUS_ERROR_INVALID_ARGS); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that an extra argument to the method also results in an * error reply being received and the function not being called, * again this counts as being handled. */ TEST_FEATURE ("with too many arguments in async method (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "AsyncMethod"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); flags = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); double_arg = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_arg); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; } my_async_method_called = 0; result = my_com_netsplit_Nih_Test_AsyncMethod_method (object, message); if (test_alloc_failed && (result == DBUS_HANDLER_RESULT_NEED_MEMORY)) { nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_FALSE (my_async_method_called); TEST_EQ (result, DBUS_HANDLER_RESULT_HANDLED); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_ERROR); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_EQ_STR (dbus_message_get_error_name (reply), DBUS_ERROR_INVALID_ARGS); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that a method call function for a deprecated method is * identical to the standard one, and does not have the deprecated * attribute since it would always result in a compiler warning/error * and we generally always want to implement it. */ TEST_FEATURE ("with deprecated method"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&handlers); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); method->deprecated = TRUE; argument1 = argument_new (method, "Str", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "str"); nih_list_add (&method->arguments, &argument1->entry); } str = method_object_function (NULL, "my", interface, method, &prototypes, &handlers, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_object_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusHandlerResult"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Method_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusObject *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "object"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&handlers); func = (TypeFunc *)handlers.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "str"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&handlers); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_reply_function (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihList prototypes; NihList structs; Interface * interface = NULL; Method * method = NULL; Argument * argument1 = NULL; Argument * argument2 = NULL; Argument * argument3 = NULL; char * str; int32_t flags; char ** output = NULL; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; NihListEntry * attrib; DBusMessage * method_call; DBusMessage * next_call; DBusMessageIter iter; DBusMessageIter subiter; DBusMessage * reply; NihDBusMessage * message = NULL; NihDBusObject * object = NULL; dbus_uint32_t serial; dbus_uint32_t next_serial; int ret; TEST_FUNCTION ("method_reply_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that marhals its arguments * into a D-Bus message and sends them as a reply to a previous * D-Bus method call. */ TEST_FEATURE ("with reply"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "AsyncMethod"); method->symbol = nih_strdup (method, "async_method"); argument1 = argument_new (method, "Str", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "str"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Flags", "i", NIH_DBUS_ARG_IN); argument2->symbol = nih_strdup (argument2, "flags"); nih_list_add (&method->arguments, &argument2->entry); argument3 = argument_new (method, "Output", "as", NIH_DBUS_ARG_OUT); argument3->symbol = nih_strdup (argument3, "output"); nih_list_add (&method->arguments, &argument3->entry); } str = method_reply_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_reply_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_async_method_reply"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char * const *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "output"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a method call without output arguments still has * a reply function generated for it. */ TEST_FEATURE ("with no arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "AsyncMethod"); method->symbol = nih_strdup (method, "async_method"); } str = method_reply_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_reply_function_no_args.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_async_method_reply"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a reply function for a method with a structure as * an output argument is correctly generated, with the structure * type passed back in the structs array. */ TEST_FEATURE ("with structure argument"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "AsyncMethod"); method->symbol = nih_strdup (method, "async_method"); argument1 = argument_new (method, "structure", "(su)", NIH_DBUS_ARG_OUT); argument1->symbol = nih_strdup (argument1, "structure"); nih_list_add (&method->arguments, &argument1->entry); } str = method_reply_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_reply_function_structure.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_async_method_reply"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyAsyncMethodStructure *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "structure"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyAsyncMethodStructure"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that an array argument may be NULL when the size is non-zero */ TEST_FEATURE ("with array argument"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "AsyncMethod"); method->symbol = nih_strdup (method, "async_method"); argument1 = argument_new (method, "Output", "ai", NIH_DBUS_ARG_OUT); argument1->symbol = nih_strdup (argument1, "output"); nih_list_add (&method->arguments, &argument1->entry); } str = method_reply_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_reply_function_array.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_async_method_reply"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const int32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "output"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "size_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "output_len"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that we can use the generated code to reply to a method * call we created, and that we can receive the reply. */ TEST_FEATURE ("with reply (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); flags = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; output = nih_str_split (NULL, "this is a test", " ", TRUE); } ret = my_async_method_reply (message, output); if (test_alloc_failed && (ret < 0)) { nih_free (output); nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_EQ (ret, 0); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_ARRAY); TEST_EQ (dbus_message_iter_get_element_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str); TEST_EQ_STR (str, "this"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str); TEST_EQ_STR (str, "is"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str); TEST_EQ_STR (str, "a"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str); TEST_EQ_STR (str, "test"); dbus_message_iter_next (&subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); nih_free (output); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that when no reply is expected, none is sent but the * function returns success. */ TEST_FEATURE ("with no reply expected (generated code)"); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (client_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); dbus_message_iter_init_append (method_call, &iter); str = "this is a test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str); flags = 0; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags); dbus_message_set_no_reply (method_call, TRUE); dbus_connection_send (server_conn, method_call, &serial); dbus_connection_flush (server_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; object = nih_new (NULL, NihDBusObject); object->path = "/com/netsplit/Nih"; object->connection = client_conn; object->data = NULL; object->interfaces = NULL; object->registered = TRUE; output = nih_str_split (NULL, "this is a test", " ", TRUE); } ret = my_async_method_reply (message, output); if (test_alloc_failed && (ret < 0)) { nih_free (output); nih_free (object); nih_free (message); dbus_message_unref (method_call); continue; } TEST_EQ (ret, 0); next_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "NextMethod"); dbus_connection_send (server_conn, next_call, &next_serial); dbus_connection_flush (server_conn); dbus_message_unref (next_call); TEST_DBUS_MESSAGE (server_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_CALL); TEST_EQ (dbus_message_get_serial (reply), next_serial); nih_free (output); nih_free (object); nih_free (message); dbus_message_unref (reply); dbus_message_unref (method_call); } /* Check that the code for a deprecated method is the same as * a non-deprecated one, since we don't want to penalise implementing * the object - just using it remotely. */ TEST_FEATURE ("with deprecated method"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "AsyncMethod"); method->symbol = nih_strdup (method, "async_method"); method->deprecated = TRUE; argument1 = argument_new (method, "Str", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "str"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Flags", "i", NIH_DBUS_ARG_IN); argument2->symbol = nih_strdup (argument2, "flags"); nih_list_add (&method->arguments, &argument2->entry); argument3 = argument_new (method, "Output", "as", NIH_DBUS_ARG_OUT); argument3->symbol = nih_strdup (argument3, "output"); nih_list_add (&method->arguments, &argument3->entry); } str = method_reply_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_reply_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_async_method_reply"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char * const *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "output"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } int my_test_method_notify_called = FALSE; static DBusPendingCall * last_pending_call = NULL; static NihDBusPendingData *last_pending_data = NULL; void my_com_netsplit_Nih_Test_TestMethod_notify (DBusPendingCall * pending_call, NihDBusPendingData *pending_data) { my_test_method_notify_called = TRUE; last_pending_call = pending_call; last_pending_data = pending_data; } static void my_blank_handler (void * data, NihDBusMessage *message, char * const * output, int32_t length) { } static void my_blank_error_handler (void * data, NihDBusMessage *message) { } void test_proxy_function (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihList prototypes; NihList structs; Interface * interface = NULL; Method * method = NULL; Argument * argument1 = NULL; Argument * argument2 = NULL; Argument * argument3 = NULL; Argument * argument4 = NULL; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; NihListEntry * attrib; DBusConnection * flakey_conn = NULL; NihDBusProxy * proxy = NULL; DBusPendingCall * pending_call; DBusMessage * method_call; DBusMessage * reply; DBusMessageIter iter; DBusMessageIter subiter; char * str_value; int32_t int32_value; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("method_proxy_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that marshals its * arguments into a D-Bus message, makes a method call and returns * the pending call structure. */ TEST_FEATURE ("with method call"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "TestMethod"); method->symbol = nih_strdup (method, "test_method"); argument1 = argument_new (method, "Str", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "str"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Flags", "i", NIH_DBUS_ARG_IN); argument2->symbol = nih_strdup (argument2, "flags"); nih_list_add (&method->arguments, &argument2->entry); argument3 = argument_new (method, "Output", "as", NIH_DBUS_ARG_OUT); argument3->symbol = nih_strdup (argument3, "output"); nih_list_add (&method->arguments, &argument3->entry); argument4 = argument_new (method, "Length", "i", NIH_DBUS_ARG_OUT); argument4->symbol = nih_strdup (argument4, "length"); nih_list_add (&method->arguments, &argument4->entry); } str = method_proxy_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "str"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "flags"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestMethodReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that we can generate a function for a method call with * no arguments, and that it's all still proper. */ TEST_FEATURE ("with no arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "TestMethod"); method->symbol = nih_strdup (method, "test_method"); } str = method_proxy_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_function_no_args.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestMethodReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a method call with a structure as an input argument * is correctly generated, with the structure type passed back * in the structs array. */ TEST_FEATURE ("with structure argument"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "TestMethod"); method->symbol = nih_strdup (method, "test_method"); argument1 = argument_new (method, "structure", "(su)", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "structure"); nih_list_add (&method->arguments, &argument1->entry); } str = method_proxy_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_function_structure.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyTestMethodStructure *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "structure"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestMethodReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyTestMethodStructure"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that when the function has an array argument, it does not * assert that the pointer is not NULL unless the length pointer * is non-zero. */ TEST_FEATURE ("with array argument"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "TestMethod"); method->symbol = nih_strdup (method, "test_method"); argument1 = argument_new (method, "Value", "ai", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "value"); nih_list_add (&method->arguments, &argument1->entry); } str = method_proxy_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_function_array.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const int32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "size_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value_len"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestMethodReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that we can use the generated code to make a method call, * it should return a DBusPendingCall object and we should receive * the method call on the other side. Returning the reply and * blocking the call should result in our notify function being * called with the pending call that was returned and the pending * data with the expected information. */ TEST_FEATURE ("with method call (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_test_method_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_test_method (proxy, "test string", 42, my_blank_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, "com.netsplit.Nih.Test", "TestMethod")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test string"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "land"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "make"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "believe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); int32_value = 1234; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Block the pending call until we receive the reply */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_test_method_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the reply handler may be omitted if we only want to * check for errors (assumedly we have no return arguments that * we're interested in). The function should still return a * DBusPendingCall object and we should still receive the method * call on the other side, and the notify function should still * be called, just with a NULL handler. */ TEST_FEATURE ("with no handler (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_test_method_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_test_method (proxy, "test string", 42, NULL, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, "com.netsplit.Nih.Test", "TestMethod")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test string"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "land"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "make"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "believe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); int32_value = 1234; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Block the pending call until we receive the reply */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_test_method_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, NULL); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the notify function is still called when the server * returns an error; strictly speaking we're testing D-Bus here, * but let's be complete about the whole thing - besides, it's * good documentation for how things should behave */ TEST_FEATURE ("with error reply (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_test_method_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_test_method (proxy, "test string", 42, my_blank_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, "com.netsplit.Nih.Test", "TestMethod")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test string"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_error (method_call, "com.netsplit.Nih.Test.Method.Fail", "Things didn't work out"); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Block the pending call until we receive the reply */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.Test.Method.Fail")); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_test_method_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the pending call will fail if the timeout is reached, * we'll set a really short one for this. The notify function * should be called with the timeout error. */ TEST_FEATURE ("with timeout (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_test_method_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_test_method (proxy, "test string", 42, my_blank_handler, my_blank_error_handler, &proxy, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, "com.netsplit.Nih.Test", "TestMethod")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test string"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (method_call); /* Block the pending call until timeout */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_NO_REPLY)); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_test_method_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the pending call will fail if the remote end * disconnects. The notify function should be called with the * timeout error. */ TEST_FEATURE ("with server disconnection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih", NULL, NULL); } my_test_method_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_test_method (proxy, "test string", 42, my_blank_handler, my_blank_error_handler, &proxy, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (flakey_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, "com.netsplit.Nih.Test", "TestMethod")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test string"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (method_call); /* Close the server connection */ TEST_DBUS_CLOSE (flakey_conn); /* Block the pending call until error */ dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_NO_REPLY)); dbus_message_unref (reply); /* Check the notify function was called with all the right * things. */ TEST_TRUE (my_test_method_notify_called); TEST_EQ_P (last_pending_call, pending_call); TEST_ALLOC_SIZE (last_pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (last_pending_data->connection, client_conn); TEST_EQ_P (last_pending_data->handler, (NihDBusReplyHandler)my_blank_handler); TEST_EQ_P (last_pending_data->error_handler, my_blank_error_handler); TEST_EQ_P (last_pending_data->data, &proxy); /* Make sure the pending data is freed along with the * pending call. */ TEST_FREE_TAG (last_pending_data); dbus_pending_call_unref (pending_call); TEST_FREE (last_pending_data); nih_free (proxy); } /* Check that the pending call can be cancelled by the user. The * notify function should not be called, but the data it contains * freed (valgrind will reveal this). */ TEST_FEATURE ("with cancelled call (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_test_method_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_test_method (proxy, "test string", 42, my_blank_handler, my_blank_error_handler, &proxy, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); continue; } TEST_NE_P (pending_call, NULL); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, "com.netsplit.Nih.Test", "TestMethod")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test string"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send a reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Cancel the pending call */ dbus_pending_call_cancel (pending_call); dbus_pending_call_unref (pending_call); /* Dispatch until we receive a message */ TEST_DBUS_DISPATCH (client_conn); /* Check the notify function was not called. */ TEST_FALSE (my_test_method_notify_called); nih_free (proxy); } /* Check that when the remote end is not connected, the function * returns NULL and raises the disconnected D-Bus error. */ TEST_FEATURE ("with unconnected connection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } TEST_DBUS_CLOSE (flakey_conn); my_test_method_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_test_method (proxy, "test string", 42, my_blank_handler, my_blank_error_handler, &proxy, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (my_test_method_notify_called); nih_free (proxy); } /* Check that we can pass NULL for both the callback and error * handler arguments, in which case the method call is sent out * with the flag set to expect no reply. The notify function * should not be called, since we don't care. */ TEST_FEATURE ("with no reply expected (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } my_test_method_notify_called = FALSE; last_pending_call = NULL; last_pending_data = NULL; pending_call = my_test_method (proxy, "test string", 42, NULL, NULL, NULL, -1); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_EQ_P (pending_call, (void *)TRUE); TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, "com.netsplit.Nih.Test", "TestMethod")); TEST_TRUE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test string"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send a reply anyway */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Dispatch until we receive a message */ TEST_DBUS_DISPATCH (client_conn); /* Check the notify function was not called. */ TEST_FALSE (my_test_method_notify_called); nih_free (proxy); } /* Check that the function generated for a deprecated method * has the deprecated attribute, since we want a gcc warning * if the client uses it. */ TEST_FEATURE ("with deprecated method"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "TestMethod"); method->symbol = nih_strdup (method, "test_method"); method->deprecated = TRUE; argument1 = argument_new (method, "Str", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "str"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Flags", "i", NIH_DBUS_ARG_IN); argument2->symbol = nih_strdup (argument2, "flags"); nih_list_add (&method->arguments, &argument2->entry); argument3 = argument_new (method, "Output", "as", NIH_DBUS_ARG_OUT); argument3->symbol = nih_strdup (argument3, "output"); nih_list_add (&method->arguments, &argument3->entry); argument4 = argument_new (method, "Length", "i", NIH_DBUS_ARG_OUT); argument4->symbol = nih_strdup (argument4, "length"); nih_list_add (&method->arguments, &argument4->entry); } str = method_proxy_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_test_method"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "str"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "flags"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyTestMethodReply"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusErrorHandler"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "error_handler"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "timeout"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "deprecated"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int my_handler_called = FALSE; static int my_error_handler_called = FALSE; static NihDBusMessage *last_message = NULL; static DBusConnection *last_conn = NULL; static DBusMessage *last_msg = NULL; static NihError *last_error = NULL; static void my_handler (void * data, NihDBusMessage *message, char * const * output, int32_t length) { my_handler_called++; TEST_EQ_P (data, (void *)my_handler); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_message = message; TEST_FREE_TAG (last_message); last_conn = message->connection; dbus_connection_ref (last_conn); last_msg = message->message; dbus_message_ref (last_msg); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); TEST_ALLOC_SIZE (output, sizeof (char *) * 5); TEST_EQ_STR (output[0], "land"); TEST_ALLOC_PARENT (output[0], output); TEST_EQ_STR (output[1], "of"); TEST_ALLOC_PARENT (output[1], output); TEST_EQ_STR (output[2], "make"); TEST_ALLOC_PARENT (output[2], output); TEST_EQ_STR (output[3], "believe"); TEST_ALLOC_PARENT (output[3], output); TEST_EQ_P (output[4], NULL); TEST_EQ (length, 1234); } static void my_error_handler (void * data, NihDBusMessage *message) { my_error_handler_called++; TEST_EQ_P (data, (void *)my_handler); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_message = message; TEST_FREE_TAG (last_message); last_conn = message->connection; dbus_connection_ref (last_conn); last_msg = message->message; dbus_message_ref (last_msg); last_error = nih_error_steal (); TEST_NE_P (last_error, NULL); } void test_proxy_notify_function (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; DBusConnection * flakey_conn; NihList prototypes; NihList typedefs; NihList structs; Interface * interface = NULL; Method * method = NULL; Argument * argument1 = NULL; Argument * argument2 = NULL; Argument * argument3 = NULL; Argument * argument4 = NULL; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; dbus_uint32_t serial; DBusPendingCall * pending_call; NihDBusPendingData *pending_data = NULL; DBusMessage * method_call; DBusMessage * reply; DBusMessageIter iter; DBusMessageIter subiter; char * str_value; int32_t int32_value; double double_value; NihDBusError * dbus_err; TEST_FUNCTION ("method_proxy_notify_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that takes a pending call * and pending data structure, stealing the D-Bus message and * demarshalling the arguments before making a call to either the * handler for a valid reply or error handler for an invalid * reply. The typedef for the handler function is returned in * addition to the prototype. */ TEST_FEATURE ("with reply"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); argument1 = argument_new (method, "Str", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "str"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Flags", "i", NIH_DBUS_ARG_IN); argument2->symbol = nih_strdup (argument2, "flags"); nih_list_add (&method->arguments, &argument2->entry); argument3 = argument_new (method, "Output", "as", NIH_DBUS_ARG_OUT); argument3->symbol = nih_strdup (argument3, "output"); nih_list_add (&method->arguments, &argument3->entry); argument4 = argument_new (method, "Length", "i", NIH_DBUS_ARG_OUT); argument4->symbol = nih_strdup (argument4, "length"); nih_list_add (&method->arguments, &argument4->entry); } str = method_proxy_notify_function (NULL, "my", interface, method, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_notify_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Method_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyMethodReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char * const *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "output"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "length"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that we can generate a function for a method with no * arguments. */ TEST_FEATURE ("with no arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); } str = method_proxy_notify_function (NULL, "my", interface, method, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_notify_function_no_args.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Method_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyMethodReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a method call with a structure as an output argument * is correctly generated, with the structure type passed back * in the structs array. */ TEST_FEATURE ("with structure argument"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); argument1 = argument_new (method, "structure", "(su)", NIH_DBUS_ARG_OUT); argument1->symbol = nih_strdup (argument1, "structure"); nih_list_add (&method->arguments, &argument1->entry); } str = method_proxy_notify_function (NULL, "my", interface, method, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_notify_function_structure.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Method_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyMethodReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyMethodStructure *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "structure"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyMethodStructure"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that we can use the generated code to handle a completed * pending call, demarshalling the arguments from the reply and * passing them to our handler. */ TEST_FEATURE ("with reply (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "land"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "make"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "believe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); int32_value = 1234; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_handler, my_error_handler, (void *)my_handler); } my_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_Method_notify (pending_call, pending_data); TEST_TRUE (my_handler_called); TEST_FALSE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the caller can omit the reply handler when it has * no useful information it wants to obtain from the reply (thus * only requiring the error handler), in which case the handler * function should not be called. */ TEST_FEATURE ("with no handler (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "land"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "make"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "believe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); int32_value = 1234; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, NULL, my_error_handler, (void *)my_handler); } my_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; my_com_netsplit_Nih_Test_Method_notify (pending_call, pending_data); TEST_FALSE (my_handler_called); TEST_FALSE (my_error_handler_called); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that we can use the generated code to handle an error * reply to a pending call, passing them instead to the error * handler as a raised error. */ TEST_FEATURE ("with error reply (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_error (method_call, "com.netsplit.Nih.Test.Method.Fail", "Things didn't work out"); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_handler, my_error_handler, (void *)my_handler); } my_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; last_error = NULL; my_com_netsplit_Nih_Test_Method_notify (pending_call, pending_data); TEST_FALSE (my_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Method.Fail"); TEST_EQ_STR (last_error->message, "Things didn't work out"); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches a timeout of the pending * call and runs the error handler with the D-Bus timeout error * raised. */ TEST_FEATURE ("with timeout (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); dbus_message_unref (method_call); /* Wait for timeout */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_handler, my_error_handler, (void *)my_handler); } my_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; last_error = NULL; my_com_netsplit_Nih_Test_Method_notify (pending_call, pending_data); TEST_FALSE (my_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches disconnection of the * remote end during a pending call call and runs the error handler * with the D-Bus timeout error raised. */ TEST_FEATURE ("with disconnection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, 50); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (flakey_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); dbus_message_unref (method_call); TEST_DBUS_CLOSE (flakey_conn); /* Wait for error */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_handler, my_error_handler, (void *)my_handler); } my_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; last_error = NULL; my_com_netsplit_Nih_Test_Method_notify (pending_call, pending_data); TEST_FALSE (my_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches an invalid argument type in * the reply and calls the error handler with the invalid arguments * error raised. */ TEST_FEATURE ("with incorrect argument type (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "land"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "make"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "believe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); double_value = 1.618; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_handler, my_error_handler, (void *)my_handler); } my_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; last_error = NULL; my_com_netsplit_Nih_Test_Method_notify (pending_call, pending_data); TEST_FALSE (my_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches an invalid argument type in * the reply even when there's no handler for it and still calls the * error handler with the invalid arguments error raised. */ TEST_FEATURE ("with incorrect argument type and no handler (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "land"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "make"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "believe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); double_value = 1.618; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, NULL, my_error_handler, (void *)my_handler); } my_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; last_error = NULL; my_com_netsplit_Nih_Test_Method_notify (pending_call, pending_data); TEST_FALSE (my_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches insufficient arguments in * the reply and calls the error handler with the invalid arguments * error raised. */ TEST_FEATURE ("with missing argument (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "land"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "make"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "believe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_handler, my_error_handler, (void *)my_handler); } my_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; last_error = NULL; my_com_netsplit_Nih_Test_Method_notify (pending_call, pending_data); TEST_FALSE (my_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated code catches too many arguments in * the reply and calls the error handler with the invalid arguments * error raised. */ TEST_FEATURE ("with too many arguments (generated code)"); TEST_ALLOC_FAIL { /* Make the method call */ method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Test", "Method"); pending_call = NULL; dbus_connection_send_with_reply (client_conn, method_call, &pending_call, -1); dbus_connection_flush (client_conn); serial = dbus_message_get_serial (method_call); dbus_message_unref (method_call); /* Catch it */ TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); /* Reply to it */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "land"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "make"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "believe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); int32_value = 1234; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); double_value = 1.618; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); /* Send the reply */ dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); /* Now we should have the reply */ dbus_pending_call_block (pending_call); assert (dbus_pending_call_get_completed (pending_call)); TEST_ALLOC_SAFE { pending_data = nih_dbus_pending_data_new ( NULL, client_conn, (NihDBusReplyHandler)my_handler, my_error_handler, (void *)my_handler); } my_handler_called = FALSE; my_error_handler_called = FALSE; last_message = NULL; last_conn = NULL; last_msg = NULL; last_error = NULL; my_com_netsplit_Nih_Test_Method_notify (pending_call, pending_data); TEST_FALSE (my_handler_called); TEST_TRUE (my_error_handler_called); TEST_NE_P (last_message, NULL); TEST_FREE (last_message); TEST_EQ_P (last_conn, client_conn); dbus_connection_unref (last_conn); TEST_NE_P (last_msg, NULL); TEST_EQ (dbus_message_get_reply_serial (last_msg), serial); dbus_message_unref (last_msg); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_INVALID_ARGS); nih_free (last_error); nih_free (pending_data); dbus_pending_call_unref (pending_call); } /* Check that the generated function for a deprecated method is * not marked deprecated, since it's implementation. */ TEST_FEATURE ("with deprecated method"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&typedefs); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); method->deprecated = TRUE; argument1 = argument_new (method, "Str", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "str"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Flags", "i", NIH_DBUS_ARG_IN); argument2->symbol = nih_strdup (argument2, "flags"); nih_list_add (&method->arguments, &argument2->entry); argument3 = argument_new (method, "Output", "as", NIH_DBUS_ARG_OUT); argument3->symbol = nih_strdup (argument3, "output"); nih_list_add (&method->arguments, &argument3->entry); argument4 = argument_new (method, "Length", "i", NIH_DBUS_ARG_OUT); argument4->symbol = nih_strdup (argument4, "length"); nih_list_add (&method->arguments, &argument4->entry); } str = method_proxy_notify_function (NULL, "my", interface, method, &prototypes, &typedefs, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_notify_function_array.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_com_netsplit_Nih_Test_Method_notify"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "DBusPendingCall *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_call"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusPendingData *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "pending_data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&typedefs); func = (TypeFunc *)typedefs.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "typedef void"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "(*MyMethodReply)"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "data"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusMessage *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "message"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char * const *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "output"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "length"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&typedefs); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_proxy_sync_function (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; DBusConnection * flakey_conn; NihList prototypes; NihList structs; Interface * interface = NULL; Method * method = NULL; Argument * argument1 = NULL; Argument * argument2 = NULL; Argument * argument3 = NULL; Argument * argument4 = NULL; char * str; TypeFunc * func; TypeVar * arg; TypeStruct * structure; TypeVar * var; NihListEntry * attrib; pid_t pid; int status; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusMessage * method_call; DBusMessage * reply; DBusMessageIter iter; DBusMessageIter subiter; char * str_value; int32_t int32_value; char ** output; int ret; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("method_proxy_sync_function"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can generate a function that marshals its * arguments into a D-Bus message, makes a method call, waits for * the reply, demarshals the reply message into its output * arguments and returns the message context for the reply. */ TEST_FEATURE ("with method call"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); argument1 = argument_new (method, "Str", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "str"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Flags", "i", NIH_DBUS_ARG_IN); argument2->symbol = nih_strdup (argument2, "flags"); nih_list_add (&method->arguments, &argument2->entry); argument3 = argument_new (method, "Output", "as", NIH_DBUS_ARG_OUT); argument3->symbol = nih_strdup (argument3, "output"); nih_list_add (&method->arguments, &argument3->entry); argument4 = argument_new (method, "Length", "i", NIH_DBUS_ARG_OUT); argument4->symbol = nih_strdup (argument4, "length"); nih_list_add (&method->arguments, &argument4->entry); } str = method_proxy_sync_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_sync_function_standard.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "str"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "flags"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char ***"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "output"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "length"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a function with no input arguments still results in * correctly generated code. */ TEST_FEATURE ("with no input arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); argument1 = argument_new (method, "Output", "as", NIH_DBUS_ARG_OUT); argument1->symbol = nih_strdup (argument1, "output"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Length", "i", NIH_DBUS_ARG_OUT); argument2->symbol = nih_strdup (argument2, "length"); nih_list_add (&method->arguments, &argument2->entry); } str = method_proxy_sync_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_sync_function_no_input.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "char ***"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "output"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "length"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a method call with no output arguments still results * in correctly generated code. */ TEST_FEATURE ("with no output arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); argument1 = argument_new (method, "Str", "s", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "str"); nih_list_add (&method->arguments, &argument1->entry); argument2 = argument_new (method, "Flags", "i", NIH_DBUS_ARG_IN); argument2->symbol = nih_strdup (argument2, "flags"); nih_list_add (&method->arguments, &argument2->entry); } str = method_proxy_sync_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_sync_function_no_output.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const char *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "str"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "flags"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a method call with no arguments at all still results * in correctly generated code. */ TEST_FEATURE ("with no arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); } str = method_proxy_sync_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_sync_function_no_args.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a method call with a structure as an input argument * is correctly generated, with the structure type passed back * in the structs array. */ TEST_FEATURE ("with structure input argument"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); argument1 = argument_new (method, "structure", "(su)", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "structure"); nih_list_add (&method->arguments, &argument1->entry); } str = method_proxy_sync_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_sync_function_structure_input.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const MyMethodStructure *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "structure"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyMethodStructure"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that a method call with a structure as an output argument * is correctly generated, with the structure type passed back * in the structs array. */ TEST_FEATURE ("with structure output argument"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); argument1 = argument_new (method, "structure", "(su)", NIH_DBUS_ARG_OUT); argument1->symbol = nih_strdup (argument1, "structure"); nih_list_add (&method->arguments, &argument1->entry); } str = method_proxy_sync_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_sync_function_structure_output.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "MyMethodStructure **"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "structure"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyMethodStructure"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that an array input argument may be NULL if the length * is zero. */ TEST_FEATURE ("with array input argument"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); argument1 = argument_new (method, "Value", "ai", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "value"); nih_list_add (&method->arguments, &argument1->entry); } str = method_proxy_sync_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_sync_function_array_input.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const int32_t *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "size_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "value_len"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } /* Check that we can use the generated code to make a method call, * and that it returns an NihDBusMessage * which is the parent of * the output arguments placed in the pointer we provided. */ TEST_FEATURE ("with method call (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, "com.netsplit.Nih.Test", "Method")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test string"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "land"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "make"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "believe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); int32_value = 1234; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } output = NULL; int32_value = 0; ret = my_method_sync (parent, proxy, "test string", 42, &output, &int32_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (output, NULL); TEST_EQ (int32_value, 0); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (ret, 0); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, parent); TEST_ALLOC_SIZE (output, sizeof (char *) * 5); TEST_EQ_STR (output[0], "land"); TEST_ALLOC_PARENT (output[0], output); TEST_EQ_STR (output[1], "of"); TEST_ALLOC_PARENT (output[1], output); TEST_EQ_STR (output[2], "make"); TEST_ALLOC_PARENT (output[2], output); TEST_EQ_STR (output[3], "believe"); TEST_ALLOC_PARENT (output[3], output); TEST_EQ_P (output[4], NULL); TEST_EQ (int32_value, 1234); nih_free (proxy); } /* Check that the generated code handles an out-of-memory error * from the remote end, and returns it as if there was an * out-of-memory error on the local end so it can be repeated in * the same manner. */ TEST_FEATURE ("with no memory error (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, "com.netsplit.Nih.Test", "Method")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test string"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_error (method_call, DBUS_ERROR_NO_MEMORY, "Out of hunk!"); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } output = NULL; int32_value = 0; ret = my_method_sync (parent, proxy, "test string", 42, &output, &int32_value); kill (pid, SIGTERM); waitpid (pid, &status, 0); if (! WIFSIGNALED (status)) { TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); } else { TEST_EQ (WTERMSIG (status), SIGTERM); } TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); } /* Check that the generated code handles an error returned * from the remote end, and returns it as a raised error on the * local end. */ TEST_FEATURE ("with error return (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, "com.netsplit.Nih.Test", "Method")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test string"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_error (method_call, "com.netsplit.Nih.Test.Method.Failed", "Didn't work out, sorry"); dbus_message_unref (method_call); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } output = NULL; int32_value = 0; ret = my_method_sync (parent, proxy, "test string", 42, &output, &int32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (output, NULL); TEST_EQ (int32_value, 0); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Method.Failed"); TEST_EQ_STR (err->message, "Didn't work out, sorry"); nih_free (err); nih_free (proxy); } /* Check that the generated code returns a raised disconnected * error when called on a disconnected connection. */ TEST_FEATURE ("with disconnected connection (generated code)"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } TEST_DBUS_CLOSE (flakey_conn); output = NULL; int32_value = 0; ret = my_method_sync (parent, proxy, "test string", 42, &output, &int32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); TEST_EQ_P (output, NULL); TEST_EQ (int32_value, 0); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_EQ_P (output, NULL); TEST_EQ (int32_value, 0); nih_free (proxy); } /* Check that if the remote method returns a wrong type in the * reply, an error is returned by the proxied call to indicate * that it refused to accept the reply. */ TEST_FEATURE ("with incorrect type (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, "com.netsplit.Nih.Test", "Method")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test string"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "land"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "make"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "believe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); str_value = "wibble"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } output = NULL; int32_value = 0; ret = my_method_sync (parent, proxy, "test string", 42, &output, &int32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (output, NULL); TEST_EQ (int32_value, 0); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); nih_free (proxy); } /* Check that if the remote method returns with a missing output * argument, an error is returned by the proxied call to indicate * that it refused to accept the reply. */ TEST_FEATURE ("with missing argument (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, "com.netsplit.Nih.Test", "Method")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test string"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "land"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "make"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "believe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } output = NULL; int32_value = 0; ret = my_method_sync (parent, proxy, "test string", 42, &output, &int32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (output, NULL); TEST_EQ (int32_value, 0); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); nih_free (proxy); } /* Check that if the remote method returns with too many arguments, * an error is returned by the proxied call to indicate that it * refused to accept the reply. */ TEST_FEATURE ("with too many arguments (generated code)"); TEST_ALLOC_FAIL { TEST_CHILD (pid) { TEST_DBUS_MESSAGE (server_conn, method_call); /* Check the incoming message */ TEST_TRUE (dbus_message_is_method_call (method_call, "com.netsplit.Nih.Test", "Method")); TEST_FALSE (dbus_message_get_no_reply (method_call)); dbus_message_iter_init (method_call, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&iter, &str_value); TEST_EQ_STR (str_value, "test string"); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INT32); dbus_message_iter_get_basic (&iter, &int32_value); TEST_EQ (int32_value, 42); dbus_message_iter_next (&iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); /* Construct and send the reply */ reply = dbus_message_new_method_return (method_call); dbus_message_unref (method_call); dbus_message_iter_init_append (reply, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "land"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "of"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "make"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "believe"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); int32_value = 1234; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); str_value = "wibble"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); dbus_connection_send (server_conn, reply, NULL); dbus_connection_flush (server_conn); dbus_message_unref (reply); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); parent = nih_alloc (proxy, 0); } output = NULL; int32_value = 0; ret = my_method_sync (parent, proxy, "test string", 42, &output, &int32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); /* If we failed with ENOMEM, the server must not * have processed the reply */ kill (pid, SIGTERM); waitpid (pid, &status, 0); TEST_TRUE (WIFSIGNALED (status)); TEST_EQ (WTERMSIG (status), SIGTERM); TEST_EQ_P (output, NULL); TEST_EQ (int32_value, 0); nih_free (proxy); continue; } waitpid (pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_EQ (err->number, NIH_DBUS_INVALID_ARGS); nih_free (err); nih_free (proxy); } /* Check that a deprecated method call has the deprecated attribute * added to its prototype, so using it results in a compiler * warning. */ TEST_FEATURE ("with deprecated method"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); nih_list_init (&structs); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = NULL; method = method_new (NULL, "Method"); method->symbol = nih_strdup (method, "method"); method->deprecated = TRUE; argument1 = argument_new (method, "Flags", "i", NIH_DBUS_ARG_IN); argument1->symbol = nih_strdup (argument1, "flags"); nih_list_add (&method->arguments, &argument1->entry); } str = method_proxy_sync_function (NULL, "my", interface, method, &prototypes, &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (method); nih_free (interface); continue; } TEST_EXPECTED_STR (str, "test_method_proxy_sync_function_deprecated.c"); TEST_LIST_NOT_EMPTY (&prototypes); func = (TypeFunc *)prototypes.next; TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_ALLOC_PARENT (func, str); TEST_EQ_STR (func->type, "int"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "my_method_sync"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "const void *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "parent"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "NihDBusProxy *"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "proxy"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_NOT_EMPTY (&func->args); arg = (TypeVar *)func->args.next; TEST_ALLOC_SIZE (arg, sizeof (TypeVar)); TEST_ALLOC_PARENT (arg, func); TEST_EQ_STR (arg->type, "int32_t"); TEST_ALLOC_PARENT (arg->type, arg); TEST_EQ_STR (arg->name, "flags"); TEST_ALLOC_PARENT (arg->name, arg); nih_free (arg); TEST_LIST_EMPTY (&func->args); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "warn_unused_result"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_NOT_EMPTY (&func->attribs); attrib = (NihListEntry *)func->attribs.next; TEST_ALLOC_SIZE (attrib, sizeof (NihListEntry *)); TEST_ALLOC_PARENT (attrib, func); TEST_EQ_STR (attrib->str, "deprecated"); TEST_ALLOC_PARENT (attrib->str, attrib); nih_free (attrib); TEST_LIST_EMPTY (&func->attribs); nih_free (func); TEST_LIST_EMPTY (&prototypes); TEST_LIST_EMPTY (&structs); nih_free (str); nih_free (method); nih_free (interface); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_args_array (void) { NihList prototypes; Interface *interface = NULL; Method * method = NULL; Argument * arg1 = NULL; Argument * arg2 = NULL; Argument * arg3 = NULL; char * str; TypeVar * var; TEST_FUNCTION ("method_args_array"); /* Check that we can generate an array of argument definitions for * a method, with each name and type lined up with each other and * the final part lined up too. Arguments without names should have * NULL in place of the name. */ TEST_FEATURE ("with arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; method = method_new (interface, "Method"); method->symbol = "method"; nih_list_add (&interface->methods, &method->entry); arg1 = argument_new (method, "foo", "as", NIH_DBUS_ARG_IN); arg1->symbol = "foo"; nih_list_add (&method->arguments, &arg1->entry); arg2 = argument_new (method, "wibble", "i", NIH_DBUS_ARG_OUT); arg2->symbol = "wibble"; nih_list_add (&method->arguments, &arg2->entry); arg3 = argument_new (method, NULL, "a(iii)", NIH_DBUS_ARG_IN); arg3->symbol = "arg3"; nih_list_add (&method->arguments, &arg3->entry); } str = method_args_array (NULL, "my", interface, method, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "const NihDBusArg my_com_netsplit_Nih_Test_Method_method_args[] = {\n" "\t{ \"foo\", \"as\", NIH_DBUS_ARG_IN },\n" "\t{ \"wibble\", \"i\", NIH_DBUS_ARG_OUT },\n" "\t{ NULL, \"a(iii)\", NIH_DBUS_ARG_IN },\n" "\t{ NULL }\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusArg"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test_Method_method_args"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } /* Check that a method with no arguments has an empty array * returned. */ TEST_FEATURE ("with no arguments"); TEST_ALLOC_FAIL { nih_list_init (&prototypes); TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); interface->symbol = "test"; method = method_new (interface, "Method"); method->symbol = "method"; nih_list_add (&interface->methods, &method->entry); } str = method_args_array (NULL, "my", interface, method, &prototypes); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&prototypes); nih_free (interface); continue; } TEST_EQ_STR (str, "const NihDBusArg my_com_netsplit_Nih_Test_Method_method_args[] = {\n" "\t{ NULL }\n" "};\n"); TEST_LIST_NOT_EMPTY (&prototypes); var = (TypeVar *)prototypes.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const NihDBusArg"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "my_com_netsplit_Nih_Test_Method_method_args"); TEST_ALLOC_PARENT (var->name, var); TEST_TRUE (var->array); nih_free (var); TEST_LIST_EMPTY (&prototypes); nih_free (str); nih_free (interface); } } int main (int argc, char *argv[]) { program_name = "test"; nih_error_init (); test_name_valid (); test_new (); test_start_tag (); test_end_tag (); test_annotation (); test_lookup (); test_lookup_argument (); test_object_function (); test_reply_function (); test_proxy_function (); test_proxy_notify_function (); test_proxy_sync_function (); test_args_array (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/test_parse.c0000644000175000017500000101376311445765555016100 00000000000000/* nih-dbus-tool * * test_parse.c - test suite for nih-dbus-tool/parse.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "node.h" #include "interface.h" #include "method.h" #include "signal.h" #include "property.h" #include "argument.h" #include "parse.h" #include "errors.h" void test_stack_push (void) { NihList stack; ParseStack *entry; ParseStack base; Node * node = NULL; Interface * interface = NULL; Method * method = NULL; Signal * signal = NULL; Property * property = NULL; Argument * argument = NULL; TEST_FUNCTION ("parse_stack_push"); /* Check that we can push a Node object onto the stack; a new * stack entry should be allocated and returned with the Node * stored in its data union, and a reference should be added * as well. */ TEST_FEATURE ("with node"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { nih_list_init (&stack); nih_list_init (&base.entry); nih_list_add (&stack, &base.entry); node = node_new (NULL, "/com/netsplit/Nih/Test"); } entry = parse_stack_push (NULL, &stack, PARSE_NODE, node); if (test_alloc_failed) { TEST_EQ_P (entry, NULL); TEST_EQ_P (stack.next, &base.entry); nih_free (node); continue; } TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_NODE); TEST_EQ_P (entry->node, node); TEST_ALLOC_PARENT (node, entry); TEST_LIST_NOT_EMPTY (&stack); TEST_EQ_P (stack.next, &entry->entry); nih_free (entry); nih_free (node); } /* Check that we can push an Interface object onto the stack; a new * stack entry should be allocated and returned with the Interface * stored in its data union, and a reference should be added * as well. */ TEST_FEATURE ("with interface"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { nih_list_init (&stack); nih_list_init (&base.entry); nih_list_add (&stack, &base.entry); interface = interface_new (NULL, "com.netsplit.Nih.Test"); } entry = parse_stack_push (NULL, &stack, PARSE_INTERFACE, interface); if (test_alloc_failed) { TEST_EQ_P (entry, NULL); TEST_EQ_P (stack.next, &base.entry); nih_free (interface); continue; } TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_INTERFACE); TEST_EQ_P (entry->interface, interface); TEST_ALLOC_PARENT (interface, entry); TEST_LIST_NOT_EMPTY (&stack); TEST_EQ_P (stack.next, &entry->entry); nih_free (entry); nih_free (interface); } /* Check that we can push a Method object onto the stack; a new * stack entry should be allocated and returned with the Method * stored in its data union, and a reference should be added * as well. */ TEST_FEATURE ("with method"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { nih_list_init (&stack); nih_list_init (&base.entry); nih_list_add (&stack, &base.entry); method = method_new (NULL, "TestMethod"); } entry = parse_stack_push (NULL, &stack, PARSE_METHOD, method); if (test_alloc_failed) { TEST_EQ_P (entry, NULL); TEST_EQ_P (stack.next, &base.entry); nih_free (method); continue; } TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_METHOD); TEST_EQ_P (entry->method, method); TEST_ALLOC_PARENT (method, entry); TEST_LIST_NOT_EMPTY (&stack); TEST_EQ_P (stack.next, &entry->entry); nih_free (entry); nih_free (method); } /* Check that we can push a Signal object onto the stack; a new * stack entry should be allocated and returned with the Signal * stored in its data union, and a reference should be added * as well. */ TEST_FEATURE ("with signal"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { nih_list_init (&stack); nih_list_init (&base.entry); nih_list_add (&stack, &base.entry); signal = signal_new (NULL, "TestSignal"); } entry = parse_stack_push (NULL, &stack, PARSE_SIGNAL, signal); if (test_alloc_failed) { TEST_EQ_P (entry, NULL); TEST_EQ_P (stack.next, &base.entry); nih_free (signal); continue; } TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_SIGNAL); TEST_EQ_P (entry->signal, signal); TEST_ALLOC_PARENT (signal, entry); TEST_LIST_NOT_EMPTY (&stack); TEST_EQ_P (stack.next, &entry->entry); nih_free (entry); nih_free (signal); } /* Check that we can push a Property object onto the stack; a new * stack entry should be allocated and returned with the Property * stored in its data union, and a reference should be added * as well. */ TEST_FEATURE ("with property"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { nih_list_init (&stack); nih_list_init (&base.entry); nih_list_add (&stack, &base.entry); property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); } entry = parse_stack_push (NULL, &stack, PARSE_PROPERTY, property); if (test_alloc_failed) { TEST_EQ_P (entry, NULL); TEST_EQ_P (stack.next, &base.entry); nih_free (property); continue; } TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_PROPERTY); TEST_EQ_P (entry->property, property); TEST_ALLOC_PARENT (property, entry); TEST_LIST_NOT_EMPTY (&stack); TEST_EQ_P (stack.next, &entry->entry); nih_free (entry); nih_free (property); } /* Check that we can push an Argument object onto the stack; a new * stack entry should be allocated and returned with the Argument * stored in its data union, and a reference should be added * as well. */ TEST_FEATURE ("with argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { nih_list_init (&stack); nih_list_init (&base.entry); nih_list_add (&stack, &base.entry); argument = argument_new (NULL, "test_arg", "i", NIH_DBUS_ARG_IN); } entry = parse_stack_push (NULL, &stack, PARSE_ARGUMENT, argument); if (test_alloc_failed) { TEST_EQ_P (entry, NULL); TEST_EQ_P (stack.next, &base.entry); nih_free (argument); continue; } TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ARGUMENT); TEST_EQ_P (entry->argument, argument); TEST_ALLOC_PARENT (argument, entry); TEST_LIST_NOT_EMPTY (&stack); TEST_EQ_P (stack.next, &entry->entry); nih_free (entry); nih_free (argument); } /* Check that we can push an Annotation reference onto the stack, * which has a NULL pointer for data. A new stack entry should be * allocated and returned with the right type but NULL data. */ TEST_FEATURE ("with annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { nih_list_init (&stack); nih_list_init (&base.entry); nih_list_add (&stack, &base.entry); } entry = parse_stack_push (NULL, &stack, PARSE_ANNOTATION, NULL); if (test_alloc_failed) { TEST_EQ_P (entry, NULL); TEST_EQ_P (stack.next, &base.entry); continue; } TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ANNOTATION); TEST_EQ_P (entry->data, NULL); TEST_LIST_NOT_EMPTY (&stack); TEST_EQ_P (stack.next, &entry->entry); nih_free (entry); } /* Check that we can push an ignored reference onto the stack, * which has a NULL pointer for data. A new stack entry should be * allocated and returned with the right type but NULL data. */ TEST_FEATURE ("with ignored entity"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { nih_list_init (&stack); nih_list_init (&base.entry); nih_list_add (&stack, &base.entry); } entry = parse_stack_push (NULL, &stack, PARSE_IGNORED, NULL); if (test_alloc_failed) { TEST_EQ_P (entry, NULL); TEST_EQ_P (stack.next, &base.entry); continue; } TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_LIST_NOT_EMPTY (&stack); TEST_EQ_P (stack.next, &entry->entry); nih_free (entry); } } void test_stack_top (void) { NihList stack; ParseStack entry1; ParseStack entry2; ParseStack *ret; TEST_FUNCTION ("parse_stack_top"); /* Check that the first item in the stack is returned when there * are multiple items in the stack. */ TEST_FEATURE ("with multiple items"); TEST_ALLOC_FAIL { nih_list_init (&stack); nih_list_init (&entry1.entry); nih_list_add_after (&stack, &entry1.entry); nih_list_init (&entry2.entry); nih_list_add_after (&stack, &entry2.entry); ret = parse_stack_top (&stack); TEST_EQ_P (ret, &entry2); } /* Check that when there is only one item in the stack, that item * is returned. */ TEST_FEATURE ("with multiple items"); TEST_ALLOC_FAIL { nih_list_init (&stack); nih_list_init (&entry1.entry); nih_list_add_after (&stack, &entry1.entry); ret = parse_stack_top (&stack); TEST_EQ_P (ret, &entry1); } /* Check that when the stack is empty, NULL is returned. */ TEST_FEATURE ("with empty stack"); TEST_ALLOC_FAIL { nih_list_init (&stack); ret = parse_stack_top (&stack); TEST_EQ_P (ret, NULL); } } void test_start_tag (void) { XML_ParsingStatus status; ParseContext context; ParseStack * parent = NULL; ParseStack * entry; XML_Parser xmlp; Node * node = NULL; Interface * interface = NULL; Method * method = NULL; Signal * signal; Property * property; Argument * argument; char * attr[7]; NihError * err; FILE * output; TEST_FUNCTION ("parse_start_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); output = tmpfile (); /* Check that a node tag is handled by calling node_start_tag() * and all of the expected side-effects occur. In case of error, * the parser should be stopped and an error raised. */ TEST_FEATURE ("with node"); TEST_ALLOC_FAIL { assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); attr[0] = "name"; attr[1] = "/com/netsplit/Nih/Test"; attr[2] = NULL; parse_start_tag (xmlp, "node", attr); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_EQ_P (parse_stack_top (&context.stack), NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, NULL); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_NODE); node = entry->node; TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_ALLOC_PARENT (node, entry); TEST_EQ_STR (node->path, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (node->path, node); TEST_LIST_EMPTY (&node->interfaces); nih_free (entry); } /* Check that a interface tag is handled by calling interface_start_tag() * and all of the expected side-effects occur. In case of error, * the parser should be stopped and an error raised. */ TEST_FEATURE ("with interface"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); attr[0] = "name"; attr[1] = "com.netsplit.Nih.Test"; attr[2] = NULL; parse_start_tag (xmlp, "interface", attr); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, NULL); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_INTERFACE); interface = entry->interface; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, entry); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); nih_free (entry); nih_free (parent); } /* Check that a method tag is handled by calling method_start_tag() * and all of the expected side-effects occur. In case of error, * the parser should be stopped and an error raised. */ TEST_FEATURE ("with method"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); attr[0] = "name"; attr[1] = "TestMethod"; attr[2] = NULL; parse_start_tag (xmlp, "method", attr); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, NULL); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_METHOD); method = entry->method; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, entry); TEST_EQ_STR (method->name, "TestMethod"); TEST_ALLOC_PARENT (method->name, method); TEST_LIST_EMPTY (&method->arguments); nih_free (entry); nih_free (parent); } /* Check that a signal tag is handled by calling signal_start_tag() * and all of the expected side-effects occur. In case of error, * the parser should be stopped and an error raised. */ TEST_FEATURE ("with signal"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); attr[0] = "name"; attr[1] = "TestSignal"; attr[2] = NULL; parse_start_tag (xmlp, "signal", attr); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, NULL); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_SIGNAL); signal = entry->signal; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, entry); TEST_EQ_STR (signal->name, "TestSignal"); TEST_ALLOC_PARENT (signal->name, signal); TEST_LIST_EMPTY (&signal->arguments); nih_free (entry); nih_free (parent); } /* Check that a property tag is handled by calling property_start_tag() * and all of the expected side-effects occur. In case of error, * the parser should be stopped and an error raised. */ TEST_FEATURE ("with property"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); attr[0] = "name"; attr[1] = "TestProperty"; attr[2] = "type"; attr[3] = "s"; attr[4] = "access"; attr[5] = "read"; attr[6] = NULL; parse_start_tag (xmlp, "property", attr); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, NULL); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_PROPERTY); property = entry->property; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, entry); TEST_EQ_STR (property->name, "TestProperty"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->type, "s"); TEST_ALLOC_PARENT (property->type, property); TEST_EQ (property->access, NIH_DBUS_READ); nih_free (entry); nih_free (parent); } /* Check that a argument tag is handled by calling argument_start_tag() * and all of the expected side-effects occur. In case of error, * the parser should be stopped and an error raised. */ TEST_FEATURE ("with argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); attr[0] = "name"; attr[1] = "test_arg"; attr[2] = "type"; attr[3] = "s"; attr[4] = NULL; parse_start_tag (xmlp, "arg", attr); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, NULL); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ARGUMENT); argument = entry->argument; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, entry); TEST_EQ_STR (argument->name, "test_arg"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_free (entry); nih_free (parent); } /* Check that a annotation tag is handled by calling * annotation_start_tag() and all of the expected side-effects * occur. In case of error, the parser should be stopped and * an error raised. */ TEST_FEATURE ("with annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); attr[0] = "name"; attr[1] = "org.freedesktop.DBus.Deprecated"; attr[2] = "value"; attr[3] = "true"; attr[4] = NULL; parse_start_tag (xmlp, "annotation", attr); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, NULL); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ANNOTATION); TEST_EQ_P (entry->data, NULL); TEST_TRUE (method->deprecated); nih_free (entry); nih_free (parent); } /* Check that when an ignored tag is on the stack, another ignored * tag is pushed with no other side-effects. */ TEST_FEATURE ("with ignored tag on stack"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { parent = parse_stack_push (NULL, &context.stack, PARSE_IGNORED, NULL); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); attr[0] = "name"; attr[1] = "TestMethod"; attr[2] = NULL; parse_start_tag (xmlp, "method", attr); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, NULL); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); nih_free (entry); nih_free (parent); } /* Check that the function has no effect when parsing is finished * (ie. when an error occurs or EOF has been reached). */ TEST_FEATURE ("with finished parser"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); assert (XML_StopParser (xmlp, FALSE) == XML_STATUS_OK); attr[0] = "name"; attr[1] = "TestMethod"; attr[2] = NULL; parse_start_tag (xmlp, "method", attr); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_EQ_P (parse_stack_top (&context.stack), parent); nih_free (parent); } /* Check that an error while handling a tag stops the parser so that * no further parsing is performed. */ TEST_FEATURE ("with error while handling"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); attr[0] = "name"; attr[1] = "Test Method"; attr[2] = NULL; parse_start_tag (xmlp, "method", attr); XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, METHOD_INVALID_NAME); nih_free (err); nih_free (parent); } /* Check that an unknown tag results in a warning being printed * to standard error and an ignored tag being pushed onto the * stack. */ TEST_FEATURE ("with unknown tag"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); attr[0] = "name"; attr[1] = "TestWidget"; attr[2] = NULL; } TEST_DIVERT_STDERR (output) { parse_start_tag (xmlp, "widget", attr); } rewind (output); XML_GetParsingStatus (xmlp, &status); if (test_alloc_failed && (status.parsing == XML_FINISHED)) { TEST_EQ (status.parsing, XML_FINISHED); TEST_EQ_P (parse_stack_top (&context.stack), parent); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (status.parsing, XML_PARSING); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, NULL); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unknown tag: widget\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } XML_ParserFree (xmlp); fclose (output); } void test_end_tag (void) { XML_ParsingStatus status; ParseContext context; ParseStack * parent = NULL; ParseStack * entry = NULL; XML_Parser xmlp; Node * node = NULL; Interface * interface = NULL; Method * method = NULL; Signal * signal = NULL; Property * property = NULL; Argument * argument = NULL; NihError * err; TEST_FUNCTION ("node_end_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); /* Check that a node end tag is handled by calling node_end_tag() * and all of the expected side-effects occur. In case of error, * the parser should be stopped and an error raised. */ TEST_FEATURE ("with node"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, "/com/netsplit/Nih/Test"); entry = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); TEST_FREE_TAG (entry); parse_end_tag (xmlp, "node"); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_NOT_FREE (entry); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); TEST_FREE (entry); TEST_ALLOC_PARENT (node, NULL); TEST_EQ_P (context.node, node); nih_free (node); context.node = NULL; } /* Check that an interface end tag is handled by calling * interface_end_tag() and all of the expected side-effects * occur. In case of error the parser should be stopped and * an error raised. */ TEST_FEATURE ("with interface"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, "/com/netsplit/Nih/Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); interface = interface_new (NULL, "com.netsplit.Nih.Test"); entry = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); TEST_FREE_TAG (entry); parse_end_tag (xmlp, "interface"); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&node->interfaces); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); TEST_FREE (entry); TEST_ALLOC_PARENT (interface, node); TEST_LIST_NOT_EMPTY (&node->interfaces); TEST_EQ_P (node->interfaces.next, &interface->entry); nih_free (parent); } /* Check that a method end tag is handled by calling * method_end_tag() and all of the expected side-effects * occur. In case of error the parser should be stopped and * an error raised. */ TEST_FEATURE ("with method"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); method = method_new (NULL, "TestMethod"); entry = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); TEST_FREE_TAG (entry); parse_end_tag (xmlp, "method"); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->methods); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); TEST_FREE (entry); TEST_ALLOC_PARENT (method, interface); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_EQ_P (interface->methods.next, &method->entry); nih_free (parent); } /* Check that a signal end tag is handled by calling * signal_end_tag() and all of the expected side-effects * occur. In case of error the parser should be stopped and * an error raised. */ TEST_FEATURE ("with signal"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); signal = signal_new (NULL, "TestSignal"); entry = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); TEST_FREE_TAG (entry); parse_end_tag (xmlp, "signal"); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->signals); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); TEST_FREE (entry); TEST_ALLOC_PARENT (signal, interface); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_EQ_P (interface->signals.next, &signal->entry); nih_free (parent); } /* Check that a property end tag is handled by calling * property_end_tag() and all of the expected side-effects * occur. In case of error the parser should be stopped and * an error raised. */ TEST_FEATURE ("with property"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { interface = interface_new (NULL, "com.netsplit.Nih.Test"); parent = parse_stack_push (NULL, &context.stack, PARSE_INTERFACE, interface); nih_discard (interface); property = property_new (NULL, "TestProperty", "s", NIH_DBUS_READ); entry = parse_stack_push (NULL, &context.stack, PARSE_PROPERTY, property); nih_discard (property); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); TEST_FREE_TAG (entry); parse_end_tag (xmlp, "property"); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&interface->properties); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); TEST_FREE (entry); TEST_ALLOC_PARENT (property, interface); TEST_LIST_NOT_EMPTY (&interface->properties); TEST_EQ_P (interface->properties.next, &property->entry); nih_free (parent); } /* Check that an argument end tag is handled by calling * property_end_tag() and all of the expected side-effects * occur. In case of error the parser should be stopped and * an error raised. */ TEST_FEATURE ("with argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); argument = argument_new (NULL, "test_arg", "s", NIH_DBUS_ARG_IN); entry = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); TEST_FREE_TAG (entry); parse_end_tag (xmlp, "arg"); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); TEST_FREE (entry); TEST_ALLOC_PARENT (argument, method); TEST_LIST_NOT_EMPTY (&method->arguments); TEST_EQ_P (method->arguments.next, &argument->entry); nih_free (parent); } /* Check that an annotation end tag is handled by calling * property_end_tag() and all of the expected side-effects * occur. In case of error the parser should be stopped and * an error raised. */ TEST_FEATURE ("with annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); entry = parse_stack_push (NULL, &context.stack, PARSE_ANNOTATION, NULL); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); TEST_FREE_TAG (entry); parse_end_tag (xmlp, "annotation"); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_NOT_FREE (entry); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); TEST_FREE (entry); nih_free (parent); } /* Check that an ignored tag is freed and no other handling * takes place. */ TEST_FEATURE ("with ignored tag"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); entry = parse_stack_push (NULL, &context.stack, PARSE_IGNORED, NULL); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); TEST_FREE_TAG (entry); parse_end_tag (xmlp, "arg"); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_PARSING); TEST_FREE (entry); TEST_LIST_EMPTY (&method->arguments); nih_free (parent); } /* Check that no handling takes place when parsing is finished, * and even the stack is not freed (so as to provide context to * the error, and because the error may cause a stack imbalance). */ TEST_FEATURE ("with finished parser"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); argument = argument_new (NULL, "test_arg", "s", NIH_DBUS_ARG_IN); entry = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); } assert (XML_ParserReset (xmlp, "UTF-8")); XML_SetUserData (xmlp, &context); XML_Parse (xmlp, "", 0, 0); assert (XML_StopParser (xmlp, FALSE) == XML_STATUS_OK); TEST_FREE_TAG (entry); parse_end_tag (xmlp, "arg"); if (test_alloc_failed) { XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } XML_GetParsingStatus (xmlp, &status); TEST_EQ (status.parsing, XML_FINISHED); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&method->arguments); nih_free (entry); nih_free (parent); } XML_ParserFree (xmlp); } void test_parse_xml (void) { FILE * fp; FILE * output; Node * node = NULL; Interface *interface; Method * method; Signal * signal; Property * property; Argument * argument; TEST_FUNCTION ("parse_xml"); fp = tmpfile (); output = tmpfile (); /* Check that a file containing a single node entity is parsed * successfully, returning a Node structure with no information * attached. */ TEST_FEATURE ("with empty node"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that the node entity may have a name attribute, which is * stored into the Node structure's name member. */ TEST_FEATURE ("with named node"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_STR (node->path, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (node->path, node); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a node may define an interface, which appears in * its interfaces list as an Interface structure with the name * filled in. */ TEST_FEATURE ("with single empty interface"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface may be marked deprecated using an * annotation tag inside it. */ TEST_FEATURE ("with deprecated interface"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_TRUE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface may be explicitly marked as not deprecated * using an annotation tag inside it. */ TEST_FEATURE ("with explicitly non-deprecated interface"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface may have an alternate C symbol fragment * given by using an annotation tag inside it. */ TEST_FEATURE ("with alternative symbol for interface"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "ITest"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that when multiple alternative symbols are given for an * interface, the last is used. */ TEST_FEATURE ("with multiple alternative symbols for interface"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "ITest"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface may define a method, which appears in * its methods list as a Method structure with the name filled * in. */ TEST_FEATURE ("with argument-less method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method may be marked as deprecated using an * annotation tag within it. */ TEST_FEATURE ("with deprecated method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_TRUE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method may be marked as explicitly not deprecated * using an annotation tag within it. */ TEST_FEATURE ("with explicitly non-deprecated method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method may have an alternate C symbol fragment * supplied using an annotation tag within it. */ TEST_FEATURE ("with alternate symbol for method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wib"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that when multiple alternative symbols are given for a * method, the last is used. */ TEST_FEATURE ("with multiple alternative symbols for method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wib"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method may be marked to not expect a reply using an * annotation tag within it. */ TEST_FEATURE ("with no reply method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_TRUE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method may be marked as explicitly to expect a reply * using an annotation tag within it. */ TEST_FEATURE ("with explicitly replying method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method may be marked as asynchronous in implementation * using an annotation tag within it. */ TEST_FEATURE ("with asynchronous method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_TRUE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method may be marked as explicitly synchronous in * implementation using an annotation tag within it. */ TEST_FEATURE ("with explicitly synchronous method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method may define an argument, which appears in its * arguments list as an Argument structure. For methods, the * argument direction should default to in. */ TEST_FEATURE ("with argument to method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an argument may have its direction explicitly defined * as "in". */ TEST_FEATURE ("with input argument"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an argument may have its argument explicitly defined * as "out". */ TEST_FEATURE ("with output argument"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that the name attribute of an argument may be optional * and that NULL is stored instead. */ TEST_FEATURE ("with unnamed argument"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_P (argument->name, NULL); TEST_EQ_STR (argument->symbol, "arg1"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that multiple arguments may have no name attribute, and * that a symbol is generated for each one. */ TEST_FEATURE ("with multiple unnamed arguments"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_P (argument->name, NULL); TEST_EQ_STR (argument->symbol, "arg1"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_P (argument->name, NULL); TEST_EQ_STR (argument->symbol, "arg2"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_P (argument->name, NULL); TEST_EQ_STR (argument->symbol, "arg3"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an argument may have an alternate C symbol supplied * using an annotation within it. */ TEST_FEATURE ("with alternate symbol for argument"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "wibble_str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that when multiple alternative symbols are given for an * argument, the last is used. */ TEST_FEATURE ("with multiple alternative symbols for argument"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "wibble_str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method may define multiple arguments, each one * added to the arguments list as a separate Argument structure. */ TEST_FEATURE ("with multiple arguments to method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "len"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "len"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "result"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "result"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface may define multiple methods, each one * with its own arguments and each added to the methods list as a * separate Method structure. */ TEST_FEATURE ("with multiple methods"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "len"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "len"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "result"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "result"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_NOT_EMPTY (&interface->methods); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wobble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wobble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "bounce"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "bounce"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_NOT_EMPTY (&interface->methods); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Flounce"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "flounce"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface may define a signal, which appears in * its signals list as a Signal structure with the name filled * in. */ TEST_FEATURE ("with argument-less signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wibble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a signal can be marked as deprecated using an * annotation tag within it. */ TEST_FEATURE ("with deprecated signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wibble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_TRUE (signal->deprecated); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a signal can be marked as explicitly not deprecated * using an annotation tag within it. */ TEST_FEATURE ("with explicitly non-deprecated signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wibble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an alternate C symbol fragment can be supplied for a * signal using an annotation tag within it. */ TEST_FEATURE ("with alternate symbol for signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wib"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that when multiple alternative symbols are given for a * signal, the last is used. */ TEST_FEATURE ("with multiple alternative symbols for signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wib"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a signal may define an argument, which appears in its * arguments list as an Argument structure. For signals, the * argument direction should default to out. */ TEST_FEATURE ("with argument to signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wibble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an argument may have its argument explicitly defined * as "out". */ TEST_FEATURE ("with output argument"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wibble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that the name attribute of an argument may be optional * and that NULL is stored instead. */ TEST_FEATURE ("with unnamed argument"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wibble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_P (argument->name, NULL); TEST_EQ_STR (argument->symbol, "arg1"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that multiple arguments may have no name attribute and * that a symbol is generated for each one. */ TEST_FEATURE ("with multiple unnamed arguments"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wibble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_P (argument->name, NULL); TEST_EQ_STR (argument->symbol, "arg1"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_P (argument->name, NULL); TEST_EQ_STR (argument->symbol, "arg2"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_P (argument->name, NULL); TEST_EQ_STR (argument->symbol, "arg3"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a signal may define multiple arguments, each one * added to the arguments list as a separate Argument structure. */ TEST_FEATURE ("with multiple arguments to signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wibble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "len"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "len"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "result"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "result"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface may define multiple signals, each one * with its own arguments and each added to the signals list as a * separate Signal structure. */ TEST_FEATURE ("with multiple signals"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wibble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "len"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "len"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "result"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "result"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_NOT_EMPTY (&interface->signals); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wobble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wobble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "bounce"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "bounce"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_NOT_EMPTY (&interface->signals); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Flounce"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "flounce"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface may define a read-only property, which * appears in its properties list as a Property structure with the * name, type and access filled in. */ TEST_FEATURE ("with read-only property"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "size"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READ); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface may define a write-only property, which * appears in its properties list as a Property structure with the * name, type and access filled in. */ TEST_FEATURE ("with write-only property"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "secret"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "secret"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "s"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_WRITE); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface may define a read/write property, which * appears in its properties list as a Property structure with the * name, type and access filled in. */ TEST_FEATURE ("with read/write property"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "nickname"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "nickname"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "s"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READWRITE); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a property can be marked as deprecated using an * annotation tag within it. */ TEST_FEATURE ("with deprecated property"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "size"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_TRUE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READ); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a property can be marked as explicitly not deprecated * using an annotation tag within it. */ TEST_FEATURE ("with explicitly non-deprecated property"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "size"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READ); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an alternate C symbol fragment for a property can be * specified using an annotation tag within it. */ TEST_FEATURE ("with alternate symbol for property"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "sz"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READ); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that when multiple alternative symbols are given for a * property, the last is used. */ TEST_FEATURE ("with multiple alternative symbols for property"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "sz"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READ); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface may define multiple properties, each with * their own name, type and access and each stored as a Property * structure in the interface's properties list. */ TEST_FEATURE ("with multiple properties"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "size"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READ); nih_list_remove (&property->entry); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "secret"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "secret"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "s"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_WRITE); nih_list_remove (&property->entry); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "nickname"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "nickname"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "s"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READWRITE); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface may define any number of methods, * signals and properties each one placed in the appropriate part * of the list. */ TEST_FEATURE ("with methods, signals and properties"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "len"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "len"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "result"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "result"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_NOT_EMPTY (&interface->methods); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wobble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wobble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "bounce"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "bounce"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_NOT_EMPTY (&interface->methods); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Flounce"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "flounce"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Honk"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "honk"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "len"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "len"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "result"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "result"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_NOT_EMPTY (&interface->signals); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Bonk"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "bonk"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "bounce"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "bounce"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_NOT_EMPTY (&interface->signals); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Flonk"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "flonk"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "size"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READ); nih_list_remove (&property->entry); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "secret"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "secret"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "s"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_WRITE); nih_list_remove (&property->entry); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "nickname"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "nickname"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "s"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READWRITE); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a node may define multiple interfaces, each one with * their own set of methods, signals and properties and each of those * with their own arguments and annotations. */ TEST_FEATURE ("with multiple interfaces"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "len"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "len"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "result"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "result"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_NOT_EMPTY (&interface->methods); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wobble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wobble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "bounce"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "bounce"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_NOT_EMPTY (&interface->methods); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Flounce"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "flounce"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Honk"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "honk"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "len"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "len"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "result"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "result"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_NOT_EMPTY (&interface->signals); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Bonk"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "bonk"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "bounce"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "bounce"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_NOT_EMPTY (&interface->signals); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Flonk"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "flonk"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "size"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READ); nih_list_remove (&property->entry); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "secret"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "secret"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "s"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_WRITE); nih_list_remove (&property->entry); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "nickname"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "nickname"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "s"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READWRITE); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Peer"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "peer"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Register"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "register"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "name"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "name"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "id"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "id"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "NewPeer"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "new_peer"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "name"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "name"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_NOT_EMPTY (&signal->arguments); argument = (Argument *)signal->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, signal); TEST_EQ_STR (argument->name, "id"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "id"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "i"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a node may have child node entities, which may * have their own contents, but that they entire thing is ignored * without so much as a warning. */ TEST_FEATURE ("with child node"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed) { TEST_EQ_P (node, NULL); TEST_FILE_MATCH (output, ("test:foo:[0-9]*:[0-9]*: " "Cannot allocate memory\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); continue; } TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_STR (node->path, "/"); TEST_ALLOC_PARENT (node->path, node); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown node attribute generates a warning, but * otherwise returns a node. */ TEST_FEATURE ("with unknown node attribute"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_STR (node->path, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (node->path, node); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:1:0: " "Ignored unknown attribute: frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown attribute to the interface tag generates * a warning but is otherwise ignored. */ TEST_FEATURE ("with unknown interface attribute"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:2:2: " "Ignored unknown attribute: frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown attribute to the method tag generates * a warning but is otherwise ignored. */ TEST_FEATURE ("with unknown method attribute"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:3:4: " "Ignored unknown attribute: frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown attribute to the signal tag generates * a warning but is otherwise ignored. */ TEST_FEATURE ("with unknown signal attribute"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wibble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:3:4: " "Ignored unknown attribute: frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown attribute to the property tag generates * a warning but is otherwise ignored. */ TEST_FEATURE ("with unknown property attribute"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "size"); TEST_ALLOC_PARENT (property->symbol, property); TEST_FALSE (property->deprecated); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_EQ (property->access, NIH_DBUS_READ); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:3:4: " "Ignored unknown attribute: frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown attribute to the argument tag generates * a warning but is otherwise ignored. */ TEST_FEATURE ("with unknown argument attribute"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:4:6: " "Ignored unknown attribute: frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown attribute to the annotation tag generates * a warning but is otherwise ignored. */ TEST_FEATURE ("with unknown annotation attribute"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_TRUE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:4:6: " "Ignored unknown attribute: frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a node tag not inside another node tag or at the * top level is ignored generating a warning but that a Node is * otherwise returned. */ TEST_FEATURE ("with node tag outside of top-level or node"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:3:4: Ignored unexpected tag\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface tag outside of a node tag is ignored * generating a warning but that a Node is otherwise returned. */ TEST_FEATURE ("with interface tag outside of node"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:3:4: Ignored unexpected tag\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method tag outside of an interface tag is ignored * generating a warning but that a Node is otherwise returned. */ TEST_FEATURE ("with method tag outside of interface"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:2:2: Ignored unexpected tag\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a signal tag outside of an interface tag is ignored * generating a warning but that a Node is otherwise returned. */ TEST_FEATURE ("with signal tag outside of interface"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:2:2: Ignored unexpected tag\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a property tag outside of an interface tag is ignored * generating a warning but that a Node is otherwise returned. */ TEST_FEATURE ("with property tag outside of interface"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:2:2: Ignored unexpected tag\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an argument tag outside of a method or signal tag is * ignored generating a warning but that a Node is otherwise returned. */ TEST_FEATURE ("with argument tag outside of method or signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:2:2: Ignored unexpected tag\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Make sure that properties don't have arguments. */ TEST_FEATURE ("with argument tag for property"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "size"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READ); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:4:6: Ignored unexpected tag\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an annotation tag is ignored with a warning if it * is given for a node. */ TEST_FEATURE ("with annotation for node"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:2:2: Ignored unexpected tag\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown annotation for an interface generates a * warning but is otherwise ignored. */ TEST_FEATURE ("with unknown annotation for interface"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:3:4: Ignored unknown interface annotation: " "com.netsplit.Apple.Jack\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown annotation for a method generates a * warning but is otherwise ignored. */ TEST_FEATURE ("with unknown annotation for method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:4:6: Ignored unknown method annotation: " "com.netsplit.Apple.Jack\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown annotation for a signal generates a * warning but is otherwise ignored. */ TEST_FEATURE ("with unknown annotation for signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wibble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:4:6: Ignored unknown signal annotation: " "com.netsplit.Apple.Jack\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that the method no reply annotation for a signal generates a * warning but is otherwise ignored. */ TEST_FEATURE ("with no reply annotation for signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wibble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:4:6: Ignored unknown signal annotation: " "org.freedesktop.DBus.Method.NoReply\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that the method async annotation for a signal generates a * warning but is otherwise ignored. */ TEST_FEATURE ("with async annotation for signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_NOT_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); signal = (Signal *)interface->signals.next; TEST_ALLOC_SIZE (signal, sizeof (Signal)); TEST_ALLOC_PARENT (signal, interface); TEST_EQ_STR (signal->name, "Wibble"); TEST_ALLOC_PARENT (signal->name, signal); TEST_EQ_STR (signal->symbol, "wibble"); TEST_ALLOC_PARENT (signal->symbol, signal); TEST_FALSE (signal->deprecated); TEST_LIST_EMPTY (&signal->arguments); nih_list_remove (&signal->entry); TEST_LIST_EMPTY (&interface->signals); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:4:6: Ignored unknown signal annotation: " "com.netsplit.Nih.Method.Async\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown annotation for a property generates a * warning but is otherwise ignored. */ TEST_FEATURE ("with unknown annotation for property"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "size"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READ); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:5:6: Ignored unknown property annotation: " "com.netsplit.Apple.Jack\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method no reply annotation for a property generates a * warning but is otherwise ignored. */ TEST_FEATURE ("with no reply annotation for property"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "size"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READ); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:5:6: Ignored unknown property annotation: " "org.freedesktop.DBus.Method.NoReply\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method async annotation for a property generates a * warning but is otherwise ignored. */ TEST_FEATURE ("with async annotation for property"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_NOT_EMPTY (&interface->properties); property = (Property *)interface->properties.next; TEST_ALLOC_SIZE (property, sizeof (Property)); TEST_ALLOC_PARENT (property, interface); TEST_EQ_STR (property->name, "size"); TEST_ALLOC_PARENT (property->name, property); TEST_EQ_STR (property->symbol, "size"); TEST_ALLOC_PARENT (property->symbol, property); TEST_EQ_STR (property->type, "i"); TEST_ALLOC_PARENT (property->type, property); TEST_FALSE (property->deprecated); TEST_EQ (property->access, NIH_DBUS_READ); nih_list_remove (&property->entry); TEST_LIST_EMPTY (&interface->properties); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:5:6: Ignored unknown property annotation: " "com.netsplit.Nih.Method.Async\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown annotation for an argument generates a * warning but is otherwise ignored. */ TEST_FEATURE ("with unknown annotation for argument"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:5:8: Ignored unknown argument annotation: " "com.netsplit.Apple.Jack\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a deprecated annotation for an argument generates a * warning but is otherwise ignored. */ TEST_FEATURE ("with deprecated annotation for argument"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:5:8: Ignored unknown argument annotation: " "org.freedesktop.DBus.Deprecated\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method no reply annotation for an argument generates a * warning but is otherwise ignored. */ TEST_FEATURE ("with no reply annotation for argument"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:5:8: Ignored unknown argument annotation: " "org.freedesktop.DBus.Method.NoReply\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an async method annotation for an argument generates a * warning but is otherwise ignored. */ TEST_FEATURE ("with async annotation for argument"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_NOT_EMPTY (&node->interfaces); interface = (Interface *)node->interfaces.next; TEST_ALLOC_SIZE (interface, sizeof (Interface)); TEST_ALLOC_PARENT (interface, node); TEST_EQ_STR (interface->name, "com.netsplit.Nih.Test"); TEST_ALLOC_PARENT (interface->name, interface); TEST_EQ_STR (interface->symbol, "test"); TEST_ALLOC_PARENT (interface->symbol, interface); TEST_FALSE (interface->deprecated); TEST_LIST_NOT_EMPTY (&interface->methods); TEST_LIST_EMPTY (&interface->signals); TEST_LIST_EMPTY (&interface->properties); method = (Method *)interface->methods.next; TEST_ALLOC_SIZE (method, sizeof (Method)); TEST_ALLOC_PARENT (method, interface); TEST_EQ_STR (method->name, "Wibble"); TEST_ALLOC_PARENT (method->name, method); TEST_EQ_STR (method->symbol, "wibble"); TEST_ALLOC_PARENT (method->symbol, method); TEST_FALSE (method->deprecated); TEST_FALSE (method->no_reply); TEST_FALSE (method->async); TEST_LIST_NOT_EMPTY (&method->arguments); argument = (Argument *)method->arguments.next; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, method); TEST_EQ_STR (argument->name, "str"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->symbol, "str"); TEST_ALLOC_PARENT (argument->symbol, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_list_remove (&argument->entry); TEST_LIST_EMPTY (&method->arguments); nih_list_remove (&method->entry); TEST_LIST_EMPTY (&interface->methods); nih_list_remove (&interface->entry); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:5:8: Ignored unknown argument annotation: " "com.netsplit.Nih.Method.Async\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown tag within the parsing stack is ignored * generating a warning but that a Node is otherwise returned. */ TEST_FEATURE ("with unknown tag"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:2:2: Ignored unknown tag: flirble\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that the contents of an unknown tag are ignored, even if * they are tags we'd normally parse. This ensures that future * specifications can add them in a way we ignore. */ TEST_FEATURE ("with unknown tag and contents"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_NE_P (node, NULL); TEST_ALLOC_SIZE (node, sizeof (Node)); TEST_EQ_P (node->path, NULL); TEST_LIST_EMPTY (&node->interfaces); nih_free (node); TEST_FILE_EQ (output, ("test:foo:2:2: Ignored unknown tag: flirble\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an unknown tag may not be the root */ TEST_FEATURE ("with unknown root tag"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:1:0: Ignored unknown tag: flirble\n")); TEST_FILE_EQ (output, ("test:foo: No node present\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid node name is rejected at the point of * parsing. */ TEST_FEATURE ("with invalid node name"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:2:0: " "Invalid object path in name attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an interface may not be missing its name. */ TEST_FEATURE ("with missing interface name"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " "); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:2:14: " " missing required name attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid interface name is rejected at the point * of parsing. */ TEST_FEATURE ("with invalid interface name"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:2:44: " "Invalid interface name in name attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a method may not be missing its name. */ TEST_FEATURE ("with missing method name"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:3:13: " " missing required name attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid method name is rejected at the point * of parsing. */ TEST_FEATURE ("with invalid method name"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:3:28: " "Invalid method name in name attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a signal may not be missing its name. */ TEST_FEATURE ("with missing signal name"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:3:13: " " missing required name attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid signal name is rejected at the point * of parsing. */ TEST_FEATURE ("with invalid signal name"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:3:28: " "Invalid signal name in name attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a property may not be missing its name. */ TEST_FEATURE ("with missing property name"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:4:29: " " missing required name attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid property name is rejected at the point * of parsing. */ TEST_FEATURE ("with invalid property name"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:4:29: " "Invalid property name in name attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a property may not be missing its type. */ TEST_FEATURE ("with missing property type"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:4:29: " " missing required type attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid property type is rejected at the point * of parsing. */ TEST_FEATURE ("with invalid property type"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:4:29: " "Invalid D-Bus type in type attribute: " "Exactly one complete type required in signature\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that a property may not be missing its access (there is no * default according to the specification). */ TEST_FEATURE ("with missing property access"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:3:36: " " missing required access attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid property access is rejected at the point * of parsing. */ TEST_FEATURE ("with invalid property access"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:4:30: " "Illegal value for access attribute, " "expected 'read', 'write' or 'readwrite'\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid argument name is rejected at the point * of parsing. */ TEST_FEATURE ("with invalid argument name"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:4:36: " "Invalid argument name in name attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an argument may not be missing its type. */ TEST_FEATURE ("with missing argument type"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:4:23: " " missing required type attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid argument type is rejected at the point * of parsing. */ TEST_FEATURE ("with invalid argument type"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:4:32: " "Invalid D-Bus type in type attribute: " "Unknown typecode\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid argument direction is rejected at the point * of parsing. */ TEST_FEATURE ("with invalid argument direction"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:5:36: " "Illegal value for direction attribute, " "expected 'in' or 'out'\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that "in" is an invalid argument direction for signals, * and is rejected at the point of parsing. */ TEST_FEATURE ("with invalid argument direction for signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:5:27: " "Illegal value for direction attribute, " "expected 'out'\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an annotation may not be missing its name. */ TEST_FEATURE ("with missing annotation name"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:4:32: " " missing required name attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an annotation may not be missing its value. */ TEST_FEATURE ("with missing annotation value"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:4:58: " " missing required value attribute\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an illegal value for the deprecated annotation on an * interface results in an error. */ TEST_FEATURE ("with illegal value for deprecated interface"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:4:31: Illegal value for org.freedesktop.DBus.Deprecated interface annotation, " "expected 'true' or 'false'\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid C symbol part for the annotation on an * interface results in an error. */ TEST_FEATURE ("with invalid symbol for interface"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, "test:foo:4:33: Invalid C symbol for interface\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an illegal value for the deprecated annotation on a * method results in an error. */ TEST_FEATURE ("with illegal value for deprecated method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:5:33: Illegal value for org.freedesktop.DBus.Deprecated method annotation, " "expected 'true' or 'false'\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid C symbol part for the annotation on a * method results in an error. */ TEST_FEATURE ("with invalid symbol for method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, "test:foo:5:35: Invalid C symbol for method\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an illegal value for the no reply annotation on a * method results in an error. */ TEST_FEATURE ("with illegal value for no reply method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:5:33: Illegal value for org.freedesktop.DBus.Method.NoReply method annotation, " "expected 'true' or 'false'\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an illegal value for the async annotation on a * method results in an error. */ TEST_FEATURE ("with illegal value for async method"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:5:33: Illegal value for com.netsplit.Nih.Method.Async method annotation, " "expected 'true' or 'false'\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an illegal value for the deprecated annotation on a * signal results in an error. */ TEST_FEATURE ("with illegal value for deprecated signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:5:33: Illegal value for org.freedesktop.DBus.Deprecated signal annotation, " "expected 'true' or 'false'\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid C symbol part for the annotation on a * signal results in an error. */ TEST_FEATURE ("with invalid symbol for signal"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, "test:foo:5:35: Invalid C symbol for signal\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an illegal value for the deprecated annotation on a * property results in an error. */ TEST_FEATURE ("with illegal value for deprecated property"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:6:33: Illegal value for org.freedesktop.DBus.Deprecated property annotation, " "expected 'true' or 'false'\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid C symbol part for the annotation on a * property results in an error. */ TEST_FEATURE ("with invalid symbol for property"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, "test:foo:6:35: Invalid C symbol for property\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that an invalid C symbol part for the annotation on an * argument results in an error. */ TEST_FEATURE ("with invalid symbol for argument"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, "test:foo:6:37: Invalid C symbol for argument\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); } /* Check that ordinary XML parsing errors are picked up by the * parser and treated as errors. */ TEST_FEATURE ("with XML error"); TEST_ALLOC_FAIL { TEST_FILE_RESET (fp); fprintf (fp, "\n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, " \n"); fprintf (fp, "\n"); fflush (fp); rewind (fp); TEST_DIVERT_STDERR (output) { node = parse_xml (NULL, fileno (fp), "foo"); } rewind (output); if (test_alloc_failed && (node == NULL)) { TEST_FILE_RESET (output); continue; } TEST_EQ_P (node, NULL); TEST_FILE_EQ (output, ("test:foo:6:4: XML parse error: " "mismatched tag\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); } fclose (fp); fclose (output); } int main (int argc, char *argv[]) { program_name = "test"; nih_error_init (); test_stack_push (); test_stack_top (); test_start_tag (); test_end_tag (); test_parse_xml (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c0000644000175000017500000543007211504722746022270 00000000000000/* libnih * * test_com.netsplit.Nih.Test_proxy.c - test suite for auto-generated * proxy bindings. * * Copyright © 2010 Scott James Remnant . * Copyright © 2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "tests/com.netsplit.Nih.Test_proxy.h" #include "tests/com.netsplit.Nih.Test_object.h" #include "tests/com.netsplit.Nih.Test_impl.h" static int error_handler_called; static void * last_data; static NihError *last_error; static void my_error_handler (void * data, NihDBusMessage *message) { error_handler_called++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_error = nih_error_steal (); } static int ordinary_method_replied; const char *last_str_value; static void my_ordinary_method_reply (void * data, NihDBusMessage *message, const char * output) { ordinary_method_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_ordinary_method (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_ordinary_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; ordinary_method_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_ordinary_method (proxy, "she needs more of ze punishment", my_ordinary_method_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (ordinary_method_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "she needs more of ze punishment"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; ordinary_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_ordinary_method (proxy, "", my_ordinary_method_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (ordinary_method_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.OrdinaryMethod.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; ordinary_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_ordinary_method (proxy, "invalid", my_ordinary_method_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (ordinary_method_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; ordinary_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_ordinary_method (proxy, "she needs more of ze punishment", my_ordinary_method_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (ordinary_method_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; ordinary_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_ordinary_method (proxy, "she needs more of ze punishment", my_ordinary_method_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (ordinary_method_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; ordinary_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_ordinary_method (proxy, "she needs more of ze punishment", my_ordinary_method_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (ordinary_method_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_ordinary_method_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_ordinary_method_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_ordinary_method_sync (parent, proxy, "she needs more of ze punishment", &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "she needs more of ze punishment"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_ordinary_method_sync (parent, proxy, "", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.OrdinaryMethod.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_ordinary_method_sync (parent, proxy, "invalid", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_ordinary_method_sync (parent, proxy, "she needs more of ze punishment", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int nameless_method_replied; static void my_nameless_method_reply (void * data, NihDBusMessage *message, const char * arg2) { nameless_method_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (arg2, NULL); TEST_ALLOC_PARENT (arg2, message); last_data = data; last_str_value = arg2; nih_ref (last_str_value, last_data); } void test_nameless_method (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_nameless_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; nameless_method_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_nameless_method (proxy, "she needs more of ze punishment", my_nameless_method_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (nameless_method_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "she needs more of ze punishment"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; nameless_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_nameless_method (proxy, "", my_nameless_method_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (nameless_method_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.NamelessMethod.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; nameless_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_nameless_method (proxy, "invalid", my_nameless_method_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (nameless_method_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; nameless_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_nameless_method (proxy, "she needs more of ze punishment", my_nameless_method_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (nameless_method_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; nameless_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_nameless_method (proxy, "she needs more of ze punishment", my_nameless_method_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (nameless_method_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; nameless_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_nameless_method (proxy, "she needs more of ze punishment", my_nameless_method_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (nameless_method_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_nameless_method_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_nameless_method_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_nameless_method_sync (parent, proxy, "she needs more of ze punishment", &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "she needs more of ze punishment"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_nameless_method_sync (parent, proxy, "", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.NamelessMethod.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_nameless_method_sync (parent, proxy, "invalid", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_nameless_method_sync (parent, proxy, "she needs more of ze punishment", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int async_method_replied; static void my_async_method_reply (void * data, NihDBusMessage *message, const char * output) { async_method_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_async_method (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_async_method"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; async_method_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_async_method (proxy, "she needs more of ze punishment", my_async_method_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } async_method_input = NULL; async_method_message = NULL; TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); assert (async_method_input != NULL); assert (async_method_message != NULL); TEST_ALLOC_SAFE { assert0 (my_test_async_method_reply ( async_method_message, async_method_input)); } nih_free (async_method_message); nih_free (async_method_input); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (async_method_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "she needs more of ze punishment"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; async_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_async_method (proxy, "", my_async_method_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (async_method_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.AsyncMethod.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; async_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_async_method (proxy, "invalid", my_async_method_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (async_method_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; async_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_async_method (proxy, "she needs more of ze punishment", my_async_method_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (async_method_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; async_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_async_method (proxy, "she needs more of ze punishment", my_async_method_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (async_method_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; async_method_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_async_method (proxy, "she needs more of ze punishment", my_async_method_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (async_method_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_async_method_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_async_method_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { async_method_main_loop = TRUE; async_method_input = NULL; async_method_message = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_async_method_sync (parent, proxy, "she needs more of ze punishment", &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "she needs more of ze punishment"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_async_method_sync (parent, proxy, "", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.AsyncMethod.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_async_method_sync (parent, proxy, "invalid", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_async_method_sync (parent, proxy, "she needs more of ze punishment", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int byte_to_str_replied; static void my_byte_to_str_reply (void * data, NihDBusMessage *message, const char * output) { byte_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_byte_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_byte_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; byte_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_byte_to_str (proxy, 97, my_byte_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (byte_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "97"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; byte_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_byte_to_str (proxy, 0, my_byte_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (byte_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.ByteToStr.ZeroInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; byte_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_byte_to_str (proxy, 4, my_byte_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (byte_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; byte_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_byte_to_str (proxy, 97, my_byte_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (byte_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; byte_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_byte_to_str (proxy, 97, my_byte_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (byte_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; byte_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_byte_to_str (proxy, 97, my_byte_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (byte_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_byte_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_byte_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_byte_to_str_sync (parent, proxy, 97, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "97"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_byte_to_str_sync (parent, proxy, 0, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.ByteToStr.ZeroInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_byte_to_str_sync (parent, proxy, 4, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_byte_to_str_sync (parent, proxy, 97, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_byte_replied; static uint8_t last_byte_value; static void my_str_to_byte_reply (void * data, NihDBusMessage *message, uint8_t output) { str_to_byte_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_byte_value = output; } void test_str_to_byte (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_byte"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_byte_replied = FALSE; last_data = NULL; last_byte_value = 0; pending_call = proxy_test_str_to_byte (proxy, "97", my_str_to_byte_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_byte_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_byte_value, 97); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_byte_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_byte (proxy, "", my_str_to_byte_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_byte_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToByte.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_byte_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_byte (proxy, "invalid", my_str_to_byte_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_byte_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_byte_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_byte (proxy, "97", my_str_to_byte_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_byte_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_byte_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_byte (proxy, "97", my_str_to_byte_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_byte_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_byte_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_byte (proxy, "97", my_str_to_byte_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_byte_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_byte_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; uint8_t byte_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_byte_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } byte_value = 0; ret = proxy_test_str_to_byte_sync (parent, proxy, "97", &byte_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (byte_value, 97); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_byte_sync (parent, proxy, "", &byte_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToByte.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_byte_sync (parent, proxy, "invalid", &byte_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_byte_sync (parent, proxy, "97", &byte_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int boolean_to_str_replied; static void my_boolean_to_str_reply (void * data, NihDBusMessage *message, const char * output) { boolean_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_boolean_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_boolean_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; boolean_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_boolean_to_str (proxy, TRUE, my_boolean_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (boolean_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "True"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; boolean_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_boolean_to_str (proxy, FALSE, my_boolean_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (boolean_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.BooleanToStr.ZeroInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; boolean_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_boolean_to_str (proxy, TRUE, my_boolean_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (boolean_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; boolean_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_boolean_to_str (proxy, TRUE, my_boolean_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (boolean_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; boolean_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_boolean_to_str (proxy, TRUE, my_boolean_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (boolean_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_boolean_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_boolean_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_boolean_to_str_sync (parent, proxy, TRUE, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "True"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_boolean_to_str_sync (parent, proxy, FALSE, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.BooleanToStr.ZeroInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_boolean_to_str_sync (parent, proxy, TRUE, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_boolean_replied; static int last_boolean_value; static void my_str_to_boolean_reply (void * data, NihDBusMessage *message, int output) { str_to_boolean_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_boolean_value = output; } void test_str_to_boolean (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_boolean"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_boolean_replied = FALSE; last_data = NULL; last_boolean_value = 0; pending_call = proxy_test_str_to_boolean (proxy, "True", my_str_to_boolean_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_boolean_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_boolean_value, TRUE); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_boolean_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_boolean (proxy, "", my_str_to_boolean_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_boolean_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToBoolean.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_boolean_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_boolean (proxy, "invalid", my_str_to_boolean_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_boolean_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_boolean_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_boolean (proxy, "True", my_str_to_boolean_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_boolean_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_boolean_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_boolean (proxy, "True", my_str_to_boolean_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_boolean_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_boolean_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_boolean (proxy, "True", my_str_to_boolean_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_boolean_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_boolean_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int boolean_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_boolean_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } boolean_value = 0; ret = proxy_test_str_to_boolean_sync (parent, proxy, "True", &boolean_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (boolean_value, TRUE); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_boolean_sync (parent, proxy, "", &boolean_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToBoolean.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_boolean_sync (parent, proxy, "invalid", &boolean_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_boolean_sync (parent, proxy, "True", &boolean_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int int16_to_str_replied; static void my_int16_to_str_reply (void * data, NihDBusMessage *message, const char * output) { int16_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_int16_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_int16_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int16_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_int16_to_str (proxy, -42, my_int16_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (int16_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "-42"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int16_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int16_to_str (proxy, 0, my_int16_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int16_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int16ToStr.ZeroInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int16_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int16_to_str (proxy, 4, my_int16_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int16_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int16_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int16_to_str (proxy, -42, my_int16_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int16_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int16_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int16_to_str (proxy, -42, my_int16_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int16_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; int16_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int16_to_str (proxy, -42, my_int16_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (int16_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_int16_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_int16_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_int16_to_str_sync (parent, proxy, -42, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "-42"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_int16_to_str_sync (parent, proxy, 0, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int16ToStr.ZeroInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_int16_to_str_sync (parent, proxy, 4, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_int16_to_str_sync (parent, proxy, -42, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_int16_replied; static int16_t last_int16_value; static void my_str_to_int16_reply (void * data, NihDBusMessage *message, int16_t output) { str_to_int16_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_int16_value = output; } void test_str_to_int16 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_int16"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int16_replied = FALSE; last_data = NULL; last_int16_value = 0; pending_call = proxy_test_str_to_int16 (proxy, "-42", my_str_to_int16_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_int16_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_int16_value, -42); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int16 (proxy, "", my_str_to_int16_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToInt16.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int16 (proxy, "invalid", my_str_to_int16_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int16 (proxy, "-42", my_str_to_int16_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int16 (proxy, "-42", my_str_to_int16_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_int16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int16 (proxy, "-42", my_str_to_int16_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_int16_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_int16_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int16_t int16_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_int16_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int16_value = 0; ret = proxy_test_str_to_int16_sync (parent, proxy, "-42", &int16_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (int16_value, -42); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_int16_sync (parent, proxy, "", &int16_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToInt16.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_int16_sync (parent, proxy, "invalid", &int16_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_int16_sync (parent, proxy, "-42", &int16_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int uint16_to_str_replied; static void my_uint16_to_str_reply (void * data, NihDBusMessage *message, const char * output) { uint16_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_uint16_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_uint16_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint16_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_uint16_to_str (proxy, 42, my_uint16_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (uint16_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "42"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint16_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint16_to_str (proxy, 0, my_uint16_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (uint16_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt16ToStr.ZeroInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint16_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint16_to_str (proxy, 4, my_uint16_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (uint16_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint16_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint16_to_str (proxy, 42, my_uint16_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (uint16_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint16_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint16_to_str (proxy, 42, my_uint16_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (uint16_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; uint16_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint16_to_str (proxy, 42, my_uint16_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (uint16_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_uint16_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_uint16_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_uint16_to_str_sync (parent, proxy, 42, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "42"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_uint16_to_str_sync (parent, proxy, 0, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt16ToStr.ZeroInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_uint16_to_str_sync (parent, proxy, 4, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_uint16_to_str_sync (parent, proxy, 42, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_uint16_replied; static int16_t last_uint16_value; static void my_str_to_uint16_reply (void * data, NihDBusMessage *message, uint16_t output) { str_to_uint16_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_uint16_value = output; } void test_str_to_uint16 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_uint16"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint16_replied = FALSE; last_data = NULL; last_uint16_value = 0; pending_call = proxy_test_str_to_uint16 (proxy, "42", my_str_to_uint16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_uint16_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_uint16_value, 42); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint16 (proxy, "", my_str_to_uint16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_uint16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToUInt16.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint16 (proxy, "invalid", my_str_to_uint16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_uint16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint16 (proxy, "42", my_str_to_uint16_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_uint16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint16 (proxy, "42", my_str_to_uint16_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_uint16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_uint16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint16 (proxy, "42", my_str_to_uint16_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_uint16_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_uint16_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; uint16_t uint16_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_uint16_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint16_value = 0; ret = proxy_test_str_to_uint16_sync (parent, proxy, "42", &uint16_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (uint16_value, 42); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_uint16_sync (parent, proxy, "", &uint16_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToUInt16.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_uint16_sync (parent, proxy, "invalid", &uint16_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_uint16_sync (parent, proxy, "42", &uint16_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int int32_to_str_replied; static void my_int32_to_str_reply (void * data, NihDBusMessage *message, const char * output) { int32_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_int32_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_int32_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int32_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_int32_to_str (proxy, -1048576, my_int32_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (int32_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "-1048576"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int32_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_to_str (proxy, 0, my_int32_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int32_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32ToStr.ZeroInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int32_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_to_str (proxy, 4, my_int32_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int32_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int32_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_to_str (proxy, -1048576, my_int32_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int32_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int32_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_to_str (proxy, -1048576, my_int32_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int32_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; int32_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_to_str (proxy, -1048576, my_int32_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (int32_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_int32_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_int32_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_int32_to_str_sync (parent, proxy, -1048576, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "-1048576"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_int32_to_str_sync (parent, proxy, 0, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32ToStr.ZeroInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_int32_to_str_sync (parent, proxy, 4, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_int32_to_str_sync (parent, proxy, -1048576, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_int32_replied; static int32_t last_int32_value; static void my_str_to_int32_reply (void * data, NihDBusMessage *message, int32_t output) { str_to_int32_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_int32_value = output; } void test_str_to_int32 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_int32"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_replied = FALSE; last_data = NULL; last_int32_value = 0; pending_call = proxy_test_str_to_int32 (proxy, "-1048576", my_str_to_int32_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_int32_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_int32_value, -1048576); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32 (proxy, "", my_str_to_int32_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToInt32.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32 (proxy, "invalid", my_str_to_int32_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32 (proxy, "-1048576", my_str_to_int32_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32 (proxy, "-1048576", my_str_to_int32_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_int32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32 (proxy, "-1048576", my_str_to_int32_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_int32_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_int32_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t int32_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_int32_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_value = 0; ret = proxy_test_str_to_int32_sync (parent, proxy, "-1048576", &int32_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (int32_value, -1048576); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_int32_sync (parent, proxy, "", &int32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToInt32.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_int32_sync (parent, proxy, "invalid", &int32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_int32_sync (parent, proxy, "-1048576", &int32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int uint32_to_str_replied; static void my_uint32_to_str_reply (void * data, NihDBusMessage *message, const char * output) { uint32_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_uint32_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_uint32_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint32_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_uint32_to_str (proxy, 1048576, my_uint32_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (uint32_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "1048576"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint32_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint32_to_str (proxy, 0, my_uint32_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (uint32_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt32ToStr.ZeroInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint32_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint32_to_str (proxy, 4, my_uint32_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (uint32_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint32_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint32_to_str (proxy, 1048576, my_uint32_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (uint32_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint32_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint32_to_str (proxy, 1048576, my_uint32_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (uint32_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; uint32_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint32_to_str (proxy, 1048576, my_uint32_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (uint32_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_uint32_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_uint32_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_uint32_to_str_sync (parent, proxy, 1048576, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "1048576"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_uint32_to_str_sync (parent, proxy, 0, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt32ToStr.ZeroInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_uint32_to_str_sync (parent, proxy, 4, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_uint32_to_str_sync (parent, proxy, 1048576, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_uint32_replied; static int32_t last_uint32_value; static void my_str_to_uint32_reply (void * data, NihDBusMessage *message, uint32_t output) { str_to_uint32_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_uint32_value = output; } void test_str_to_uint32 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_uint32"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint32_replied = FALSE; last_data = NULL; last_uint32_value = 0; pending_call = proxy_test_str_to_uint32 (proxy, "1048576", my_str_to_uint32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_uint32_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_uint32_value, 1048576); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint32 (proxy, "", my_str_to_uint32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_uint32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToUInt32.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint32 (proxy, "invalid", my_str_to_uint32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_uint32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint32 (proxy, "1048576", my_str_to_uint32_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_uint32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint32 (proxy, "1048576", my_str_to_uint32_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_uint32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_uint32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint32 (proxy, "1048576", my_str_to_uint32_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_uint32_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_uint32_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; uint32_t uint32_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_uint32_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint32_value = 0; ret = proxy_test_str_to_uint32_sync (parent, proxy, "1048576", &uint32_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (uint32_value, 1048576); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_uint32_sync (parent, proxy, "", &uint32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToUInt32.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_uint32_sync (parent, proxy, "invalid", &uint32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_uint32_sync (parent, proxy, "1048576", &uint32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int int64_to_str_replied; static void my_int64_to_str_reply (void * data, NihDBusMessage *message, const char * output) { int64_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_int64_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_int64_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int64_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_int64_to_str (proxy, -4815162342L, my_int64_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (int64_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "-4815162342"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int64_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int64_to_str (proxy, 0, my_int64_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int64_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int64ToStr.ZeroInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int64_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int64_to_str (proxy, 4, my_int64_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int64_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int64_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int64_to_str (proxy, -4815162342L, my_int64_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int64_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int64_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int64_to_str (proxy, -4815162342L, my_int64_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int64_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; int64_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int64_to_str (proxy, -4815162342L, my_int64_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (int64_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_int64_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_int64_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_int64_to_str_sync (parent, proxy, -4815162342L, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "-4815162342"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_int64_to_str_sync (parent, proxy, 0, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int64ToStr.ZeroInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_int64_to_str_sync (parent, proxy, 4, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_int64_to_str_sync (parent, proxy, -4815162342L, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_int64_replied; static int64_t last_int64_value; static void my_str_to_int64_reply (void * data, NihDBusMessage *message, int64_t output) { str_to_int64_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_int64_value = output; } void test_str_to_int64 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_int64"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int64_replied = FALSE; last_data = NULL; last_int64_value = 0; pending_call = proxy_test_str_to_int64 (proxy, "-4815162342", my_str_to_int64_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_int64_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_int64_value, -4815162342L); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int64 (proxy, "", my_str_to_int64_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToInt64.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int64 (proxy, "invalid", my_str_to_int64_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int64 (proxy, "-4815162342", my_str_to_int64_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int64 (proxy, "-4815162342", my_str_to_int64_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_int64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int64 (proxy, "-4815162342", my_str_to_int64_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_int64_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_int64_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int64_t int64_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_int64_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int64_value = 0; ret = proxy_test_str_to_int64_sync (parent, proxy, "-4815162342", &int64_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (int64_value, -4815162342L); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_int64_sync (parent, proxy, "", &int64_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToInt64.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_int64_sync (parent, proxy, "invalid", &int64_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_int64_sync (parent, proxy, "-4815162342", &int64_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int uint64_to_str_replied; static void my_uint64_to_str_reply (void * data, NihDBusMessage *message, const char * output) { uint64_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_uint64_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_uint64_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint64_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_uint64_to_str (proxy, 4815162342L, my_uint64_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (uint64_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "4815162342"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint64_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint64_to_str (proxy, 0, my_uint64_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (uint64_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt64ToStr.ZeroInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint64_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint64_to_str (proxy, 4, my_uint64_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (uint64_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint64_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint64_to_str (proxy, 4815162342L, my_uint64_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (uint64_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; uint64_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint64_to_str (proxy, 4815162342L, my_uint64_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (uint64_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; uint64_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_uint64_to_str (proxy, 4815162342L, my_uint64_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (uint64_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_uint64_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_uint64_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_uint64_to_str_sync (parent, proxy, 4815162342L, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "4815162342"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_uint64_to_str_sync (parent, proxy, 0, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt64ToStr.ZeroInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_uint64_to_str_sync (parent, proxy, 4, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_uint64_to_str_sync (parent, proxy, 4815162342L, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_uint64_replied; static int64_t last_uint64_value; static void my_str_to_uint64_reply (void * data, NihDBusMessage *message, uint64_t output) { str_to_uint64_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_uint64_value = output; } void test_str_to_uint64 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_uint64"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint64_replied = FALSE; last_data = NULL; last_uint64_value = 0; pending_call = proxy_test_str_to_uint64 (proxy, "4815162342", my_str_to_uint64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_uint64_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_uint64_value, 4815162342L); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint64 (proxy, "", my_str_to_uint64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_uint64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToUInt64.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint64 (proxy, "invalid", my_str_to_uint64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_uint64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint64 (proxy, "4815162342", my_str_to_uint64_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_uint64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_uint64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint64 (proxy, "4815162342", my_str_to_uint64_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_uint64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_uint64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_uint64 (proxy, "4815162342", my_str_to_uint64_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_uint64_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_uint64_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; uint64_t uint64_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_uint64_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint64_value = 0; ret = proxy_test_str_to_uint64_sync (parent, proxy, "4815162342", &uint64_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (uint64_value, 4815162342L); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_uint64_sync (parent, proxy, "", &uint64_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToUInt64.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_uint64_sync (parent, proxy, "invalid", &uint64_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_uint64_sync (parent, proxy, "4815162342", &uint64_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int double_to_str_replied; static void my_double_to_str_reply (void * data, NihDBusMessage *message, const char * output) { double_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_double_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_double_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; double_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_double_to_str (proxy, 3.141597, my_double_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (double_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "3.141597"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; double_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_double_to_str (proxy, 0, my_double_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (double_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.DoubleToStr.ZeroInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; double_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_double_to_str (proxy, 4, my_double_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (double_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; double_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_double_to_str (proxy, 3.141597, my_double_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (double_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; double_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_double_to_str (proxy, 3.141597, my_double_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (double_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; double_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_double_to_str (proxy, 3.141597, my_double_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (double_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_double_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_double_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_double_to_str_sync (parent, proxy, 3.141597, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "3.141597"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_double_to_str_sync (parent, proxy, 0, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.DoubleToStr.ZeroInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_double_to_str_sync (parent, proxy, 4, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_double_to_str_sync (parent, proxy, 3.141597, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_double_replied; static double last_double_value; static void my_str_to_double_reply (void * data, NihDBusMessage *message, double output) { str_to_double_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_double_value = output; } void test_str_to_double (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_double"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_double_replied = FALSE; last_data = NULL; last_double_value = 0; pending_call = proxy_test_str_to_double (proxy, "3.141597", my_str_to_double_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_double_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_double_value, 3.141597); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_double_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_double (proxy, "", my_str_to_double_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_double_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToDouble.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_double_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_double (proxy, "invalid", my_str_to_double_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_double_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_double_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_double (proxy, "3.141597", my_str_to_double_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_double_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_double_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_double (proxy, "3.141597", my_str_to_double_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_double_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_double_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_double (proxy, "3.141597", my_str_to_double_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_double_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_double_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; double double_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_double_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } double_value = 0; ret = proxy_test_str_to_double_sync (parent, proxy, "3.141597", &double_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (double_value, 3.141597); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_double_sync (parent, proxy, "", &double_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToDouble.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_double_sync (parent, proxy, "invalid", &double_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_double_sync (parent, proxy, "3.141597", &double_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int object_path_to_str_replied; static void my_object_path_to_str_reply (void * data, NihDBusMessage *message, const char * output) { object_path_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_object_path_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_object_path_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; object_path_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_object_path_to_str (proxy, "/com/netsplit/Nih/Test", my_object_path_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (object_path_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; object_path_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_object_path_to_str (proxy, "/", my_object_path_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (object_path_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.ObjectPathToStr.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; object_path_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_object_path_to_str (proxy, "/invalid", my_object_path_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (object_path_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; object_path_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_object_path_to_str (proxy, "/com/netsplit/Nih/Test", my_object_path_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (object_path_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; object_path_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_object_path_to_str (proxy, "/com/netsplit/Nih/Test", my_object_path_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (object_path_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; object_path_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_object_path_to_str (proxy, "/com/netsplit/Nih/Test", my_object_path_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (object_path_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_object_path_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_object_path_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_object_path_to_str_sync (parent, proxy, "/com/netsplit/Nih/Test", &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_object_path_to_str_sync (parent, proxy, "/", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.ObjectPathToStr.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_object_path_to_str_sync (parent, proxy, "/invalid", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_object_path_to_str_sync (parent, proxy, "/com/netsplit/Nih/Test", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_object_path_replied; static void my_str_to_object_path_reply (void * data, NihDBusMessage *message, const char * output) { str_to_object_path_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_str_to_object_path (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_object_path"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_object_path_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_str_to_object_path (proxy, "/com/netsplit/Nih/Test", my_str_to_object_path_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_object_path_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_object_path_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_object_path (proxy, "", my_str_to_object_path_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_object_path_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToObjectPath.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_object_path_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_object_path (proxy, "invalid", my_str_to_object_path_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_object_path_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_object_path_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_object_path (proxy, "/com/netsplit/Nih/Test", my_str_to_object_path_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_object_path_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_object_path_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_object_path (proxy, "/com/netsplit/Nih/Test", my_str_to_object_path_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_object_path_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_object_path_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_object_path (proxy, "/com/netsplit/Nih/Test", my_str_to_object_path_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_object_path_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_object_path_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_object_path_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_str_to_object_path_sync (parent, proxy, "/com/netsplit/Nih/Test", &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_object_path_sync (parent, proxy, "", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToObjectPath.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_object_path_sync (parent, proxy, "invalid", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_object_path_sync (parent, proxy, "/com/netsplit/Nih/Test", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int signature_to_str_replied; static void my_signature_to_str_reply (void * data, NihDBusMessage *message, const char * output) { signature_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_signature_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_signature_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; signature_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_signature_to_str (proxy, "a(ib)", my_signature_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (signature_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "a(ib)"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; signature_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_signature_to_str (proxy, "", my_signature_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (signature_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.SignatureToStr.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; signature_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_signature_to_str (proxy, "inva(x)id", my_signature_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (signature_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; signature_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_signature_to_str (proxy, "a(ib)", my_signature_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (signature_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; signature_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_signature_to_str (proxy, "a(ib)", my_signature_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (signature_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; signature_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_signature_to_str (proxy, "a(ib)", my_signature_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (signature_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_signature_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_signature_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_signature_to_str_sync (parent, proxy, "a(ib)", &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "a(ib)"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_signature_to_str_sync (parent, proxy, "", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.SignatureToStr.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_signature_to_str_sync (parent, proxy, "inva(x)id", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_signature_to_str_sync (parent, proxy, "a(ib)", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_signature_replied; static void my_str_to_signature_reply (void * data, NihDBusMessage *message, const char * output) { str_to_signature_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_str_to_signature (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_signature"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_signature_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_str_to_signature (proxy, "a(ib)", my_str_to_signature_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_signature_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "a(ib)"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_signature_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_signature (proxy, "", my_str_to_signature_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_signature_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToSignature.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_signature_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_signature (proxy, "invalid", my_str_to_signature_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_signature_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_signature_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_signature (proxy, "a(ib)", my_str_to_signature_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_signature_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_signature_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_signature (proxy, "a(ib)", my_str_to_signature_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_signature_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_signature_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_signature (proxy, "a(ib)", my_str_to_signature_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_signature_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_signature_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_signature_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_str_to_signature_sync (parent, proxy, "a(ib)", &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "a(ib)"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_signature_sync (parent, proxy, "", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToSignature.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_signature_sync (parent, proxy, "invalid", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_signature_sync (parent, proxy, "a(ib)", &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int struct_to_str_replied; static void my_struct_to_str_reply (void * data, NihDBusMessage *message, const char * output) { struct_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_struct_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestStructToStrInput *struct_value = NULL; DBusPendingCall * pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_struct_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructToStrInput); struct_value->item0 = "Joe"; struct_value->item1 = 34; } error_handler_called = FALSE; struct_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_struct_to_str (proxy, struct_value, my_struct_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (struct_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "Joe 34"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructToStrInput); struct_value->item0 = ""; struct_value->item1 = 34; } error_handler_called = FALSE; struct_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_struct_to_str (proxy, struct_value, my_struct_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (struct_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StructToStr.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructToStrInput); struct_value->item0 = "invalid"; struct_value->item1 = 34; } error_handler_called = FALSE; struct_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_struct_to_str (proxy, struct_value, my_struct_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (struct_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructToStrInput); struct_value->item0 = "Joe"; struct_value->item1 = 34; } error_handler_called = FALSE; struct_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_struct_to_str (proxy, struct_value, my_struct_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (struct_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructToStrInput); struct_value->item0 = "Joe"; struct_value->item1 = 34; } error_handler_called = FALSE; struct_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_struct_to_str (proxy, struct_value, my_struct_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (struct_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructToStrInput); struct_value->item0 = "Joe"; struct_value->item1 = 34; } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; struct_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_struct_to_str (proxy, struct_value, my_struct_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (struct_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_struct_to_str_sync (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestStructToStrInput *struct_value = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_struct_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructToStrInput); struct_value->item0 = "Joe"; struct_value->item1 = 34; } str_value = NULL; ret = proxy_test_struct_to_str_sync (parent, proxy, struct_value, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "Joe 34"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructToStrInput); struct_value->item0 = ""; struct_value->item1 = 34; } ret = proxy_test_struct_to_str_sync (parent, proxy, struct_value, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StructToStr.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructToStrInput); struct_value->item0 = "invalid"; struct_value->item1 = 34; } ret = proxy_test_struct_to_str_sync (parent, proxy, struct_value, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructToStrInput); struct_value->item0 = "Joe"; struct_value->item1 = 34; } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_struct_to_str_sync (parent, proxy, struct_value, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_struct_replied; static const MyStruct *last_struct_value; static void my_str_to_struct_reply (void * data, NihDBusMessage *message, const ProxyTestStrToStructOutput *output) { str_to_struct_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_struct_value = (MyStruct *)output; nih_ref (last_struct_value, last_data); } void test_str_to_struct (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_struct"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_struct_replied = FALSE; last_data = NULL; last_struct_value = NULL; pending_call = proxy_test_str_to_struct (proxy, "Joe 34", my_str_to_struct_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_struct_replied); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_struct_value, sizeof (MyStruct)); TEST_ALLOC_PARENT (last_struct_value, parent); TEST_EQ_STR (last_struct_value->item0, "Joe"); TEST_ALLOC_PARENT (last_struct_value->item0, last_struct_value); TEST_EQ (last_struct_value->item1, 34); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_struct_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_struct (proxy, "", my_str_to_struct_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_struct_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToStruct.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_struct_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_struct (proxy, "invalid", my_str_to_struct_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_struct_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_struct_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_struct (proxy, "Joe 34", my_str_to_struct_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_struct_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_struct_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_struct (proxy, "Joe 34", my_str_to_struct_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_struct_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_struct_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_struct (proxy, "Joe 34", my_str_to_struct_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_struct_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_struct_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestStrToStructOutput *struct_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_struct_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } struct_value = NULL; ret = proxy_test_str_to_struct_sync (parent, proxy, "Joe 34", &struct_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (struct_value, sizeof (ProxyTestStrToStructOutput)); TEST_ALLOC_PARENT (struct_value, parent); TEST_EQ_STR (struct_value->item0, "Joe"); TEST_ALLOC_PARENT (struct_value->item0, struct_value); TEST_EQ (struct_value->item1, 34); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_struct_sync (parent, proxy, "", &struct_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToStruct.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_struct_sync (parent, proxy, "invalid", &struct_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_struct_sync (parent, proxy, "Joe 34", &struct_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int int32_array_to_str_replied; static void my_int32_array_to_str_reply (void * data, NihDBusMessage *message, const char * output) { int32_array_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_int32_array_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t * int32_array = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_int32_array_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; } error_handler_called = FALSE; int32_array_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_int32_array_to_str ( proxy, int32_array, 6, my_int32_array_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (int32_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "4 8 15 16 23 42"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; int32_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_array_to_str ( proxy, NULL, 0, my_int32_array_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int32_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32ArrayToStr.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 4); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; } error_handler_called = FALSE; int32_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_array_to_str ( proxy, int32_array, 4, my_int32_array_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int32_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; } error_handler_called = FALSE; int32_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_array_to_str ( proxy, int32_array, 6, my_int32_array_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int32_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; } error_handler_called = FALSE; int32_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_array_to_str ( proxy, int32_array, 6, my_int32_array_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int32_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; int32_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_array_to_str ( proxy, int32_array, 6, my_int32_array_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (int32_array_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_int32_array_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t * int32_array = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_int32_array_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; } str_value = NULL; ret = proxy_test_int32_array_to_str_sync (parent, proxy, int32_array, 6, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "4 8 15 16 23 42"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_int32_array_to_str_sync (parent, proxy, NULL, 0, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32ArrayToStr.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; } ret = proxy_test_int32_array_to_str_sync (parent, proxy, int32_array, 4, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_int32_array_to_str_sync (parent, proxy, int32_array, 6, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_int32_array_replied; static const int32_t *last_int32_array; static size_t last_int32_array_len; static void my_str_to_int32_array_reply (void * data, NihDBusMessage *message, const int32_t * output, size_t output_len) { str_to_int32_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); if (output_len) TEST_NE_P (output, NULL); last_data = data; last_int32_array = output; nih_ref (last_int32_array, last_data); last_int32_array_len = output_len; } void test_str_to_int32_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_int32_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_array_replied = FALSE; last_data = NULL; last_int32_array = NULL; last_int32_array_len = 0; pending_call = proxy_test_str_to_int32_array (proxy, "4 8 15 16 23 42", my_str_to_int32_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_int32_array_len, 6); TEST_ALLOC_SIZE (last_int32_array, sizeof (int32_t) * 6); TEST_ALLOC_PARENT (last_int32_array, parent); TEST_EQ (last_int32_array[0], 4); TEST_EQ (last_int32_array[1], 8); TEST_EQ (last_int32_array[2], 15); TEST_EQ (last_int32_array[3], 16); TEST_EQ (last_int32_array[4], 23); TEST_EQ (last_int32_array[5], 42); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32_array (proxy, "", my_str_to_int32_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToInt32Array.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32_array (proxy, "invalid", my_str_to_int32_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32_array (proxy, "4 8 15 16 23 42", my_str_to_int32_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32_array (proxy, "4 8 15 16 23 42", my_str_to_int32_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_int32_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32_array (proxy, "4 8 15 16 23 42", my_str_to_int32_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_int32_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_int32_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t * int32_array; size_t int32_array_len; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_int32_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_array = NULL; int32_array_len = 0; ret = proxy_test_str_to_int32_array_sync (parent, proxy, "4 8 15 16 23 42", &int32_array, &int32_array_len); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (int32_array_len, 6); TEST_ALLOC_SIZE (int32_array, sizeof (int32_t) * 6); TEST_ALLOC_PARENT (int32_array, parent); TEST_EQ (int32_array[0], 4); TEST_EQ (int32_array[1], 8); TEST_EQ (int32_array[2], 15); TEST_EQ (int32_array[3], 16); TEST_EQ (int32_array[4], 23); TEST_EQ (int32_array[5], 42); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_array = NULL; int32_array_len = 0; ret = proxy_test_str_to_int32_array_sync (parent, proxy, "", &int32_array, &int32_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToInt32Array.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_array = NULL; int32_array_len = 0; ret = proxy_test_str_to_int32_array_sync (parent, proxy, "invalid", &int32_array, &int32_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_int32_array_sync (parent, proxy, "4 8 15 16 23 42", &int32_array, &int32_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_array_to_str_replied; static void my_str_array_to_str_reply (void * data, NihDBusMessage *message, const char * output) { str_array_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_str_array_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char ** str_array = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_array_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; } error_handler_called = FALSE; str_array_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_str_array_to_str ( proxy, str_array, my_str_array_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "she needs more of ze punishment"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 1); str_array[0] = NULL; } error_handler_called = FALSE; str_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_array_to_str ( proxy, str_array, my_str_array_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrArrayToStr.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 5); str_array[0] = "this"; str_array[1] = "is"; str_array[2] = "a"; str_array[3] = "test"; str_array[4] = NULL; } error_handler_called = FALSE; str_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_array_to_str ( proxy, str_array, my_str_array_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; } error_handler_called = FALSE; str_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_array_to_str ( proxy, str_array, my_str_array_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; } error_handler_called = FALSE; str_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_array_to_str ( proxy, str_array, my_str_array_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_array_to_str ( proxy, str_array, my_str_array_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_array_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_array_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char ** str_array = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_array_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; } str_value = NULL; ret = proxy_test_str_array_to_str_sync (parent, proxy, str_array, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "she needs more of ze punishment"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 1); str_array[0] = NULL; } ret = proxy_test_str_array_to_str_sync (parent, proxy, str_array, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrArrayToStr.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 5); str_array[0] = "this"; str_array[1] = "is"; str_array[2] = "a"; str_array[3] = "test"; str_array[4] = NULL; } ret = proxy_test_str_array_to_str_sync (parent, proxy, str_array, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_array_to_str_sync (parent, proxy, str_array, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_str_array_replied; static char * const *last_str_array; static void my_str_to_str_array_reply (void * data, NihDBusMessage *message, char * const * output) { str_to_str_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_array = output; nih_ref (last_str_array, last_data); } void test_str_to_str_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_str_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_str_array_replied = FALSE; last_data = NULL; last_str_array = NULL; pending_call = proxy_test_str_to_str_array (proxy, "she needs more of ze punishment", my_str_to_str_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_str_array_replied); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_str_array, sizeof (char *) * 7); TEST_ALLOC_PARENT (last_str_array, parent); TEST_EQ_STR (last_str_array[0], "she"); TEST_EQ_STR (last_str_array[1], "needs"); TEST_EQ_STR (last_str_array[2], "more"); TEST_EQ_STR (last_str_array[3], "of"); TEST_EQ_STR (last_str_array[4], "ze"); TEST_EQ_STR (last_str_array[5], "punishment"); TEST_EQ_P (last_str_array[6], NULL); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_str_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_str_array (proxy, "", my_str_to_str_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_str_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToStrArray.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_str_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_str_array (proxy, "invalid", my_str_to_str_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_str_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_str_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_str_array (proxy, "she needs more of ze punishment", my_str_to_str_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_str_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_str_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_str_array (proxy, "she needs more of ze punishment", my_str_to_str_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_str_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_str_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_str_array (proxy, "she needs more of ze punishment", my_str_to_str_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_str_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_str_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char ** str_array; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_str_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_array = NULL; ret = proxy_test_str_to_str_array_sync (parent, proxy, "she needs more of ze punishment", &str_array); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (str_array, sizeof (char *) * 7); TEST_ALLOC_PARENT (str_array, parent); TEST_EQ_STR (str_array[0], "she"); TEST_EQ_STR (str_array[1], "needs"); TEST_EQ_STR (str_array[2], "more"); TEST_EQ_STR (str_array[3], "of"); TEST_EQ_STR (str_array[4], "ze"); TEST_EQ_STR (str_array[5], "punishment"); TEST_EQ_P (str_array[6], NULL); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_array = NULL; ret = proxy_test_str_to_str_array_sync (parent, proxy, "", &str_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToStrArray.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_array = NULL; ret = proxy_test_str_to_str_array_sync (parent, proxy, "invalid", &str_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_str_array_sync (parent, proxy, "she needs more of ze punishment", &str_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int int32_array_array_to_str_replied; static void my_int32_array_array_to_str_reply (void * data, NihDBusMessage *message, const char * output) { int32_array_array_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_int32_array_array_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t ** int32_array_array = NULL; size_t * int32_array_array_len = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_int32_array_array_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (parent, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; } error_handler_called = FALSE; int32_array_array_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_int32_array_array_to_str ( proxy, int32_array_array, int32_array_array_len, my_int32_array_array_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (int32_array_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "4 8 15 16 23 42\n1 1 2 3 5 8"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 1); int32_array_array_len = NULL; int32_array_array[0] = NULL; } error_handler_called = FALSE; int32_array_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_array_array_to_str ( proxy, int32_array_array, int32_array_array_len, my_int32_array_array_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int32_array_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32ArrayArrayToStr.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 2); int32_array_array_len = nih_alloc (parent, sizeof (size_t) * 1); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = NULL; } error_handler_called = FALSE; int32_array_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_array_array_to_str ( proxy, int32_array_array, int32_array_array_len, my_int32_array_array_to_str_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int32_array_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (parent, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; } error_handler_called = FALSE; int32_array_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_array_array_to_str ( proxy, int32_array_array, int32_array_array_len, my_int32_array_array_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int32_array_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (parent, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; } error_handler_called = FALSE; int32_array_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_array_array_to_str ( proxy, int32_array_array, int32_array_array_len, my_int32_array_array_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (int32_array_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (parent, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; int32_array_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_int32_array_array_to_str ( proxy, int32_array_array, int32_array_array_len, my_int32_array_array_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (int32_array_array_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_int32_array_array_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t ** int32_array_array = NULL; size_t * int32_array_array_len = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_int32_array_array_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (parent, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; } str_value = NULL; ret = proxy_test_int32_array_array_to_str_sync ( parent, proxy, int32_array_array, int32_array_array_len, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "4 8 15 16 23 42\n1 1 2 3 5 8"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 1); int32_array_array_len = NULL; int32_array_array[0] = NULL; } ret = proxy_test_int32_array_array_to_str_sync ( parent, proxy, int32_array_array, int32_array_array_len, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32ArrayArrayToStr.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 2); int32_array_array_len = nih_alloc (parent, sizeof (size_t) * 1); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = NULL; } ret = proxy_test_int32_array_array_to_str_sync ( parent, proxy, int32_array_array, int32_array_array_len, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (parent, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_int32_array_array_to_str_sync ( parent, proxy, int32_array_array, int32_array_array_len, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_int32_array_array_replied; static int32_t * const *last_int32_array_array; static const size_t * last_int32_array_array_len; static void my_str_to_int32_array_array_reply (void * data, NihDBusMessage * message, int32_t * const *output, const size_t * output_len) { str_to_int32_array_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); if (*output) { TEST_NE_P (output_len, NULL); TEST_ALLOC_PARENT (output_len, output); } last_data = data; last_int32_array_array = output; nih_ref (last_int32_array_array, last_data); last_int32_array_array_len = output_len; nih_ref (last_int32_array_array_len, last_data); } void test_str_to_int32_array_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_int32_array_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_array_array_replied = FALSE; last_data = NULL; last_int32_array_array = NULL; last_int32_array_array_len = NULL; pending_call = proxy_test_str_to_int32_array_array ( proxy, "4 8 15 16 23 42\n1 1 2 3 5 8", my_str_to_int32_array_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_int32_array_array_len, sizeof (size_t) * 2); TEST_ALLOC_PARENT (last_int32_array_array_len, parent); TEST_ALLOC_SIZE (last_int32_array_array, sizeof (int32_t *) * 3); TEST_EQ (last_int32_array_array_len[0], 6); TEST_ALLOC_SIZE (last_int32_array_array[0], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (last_int32_array_array[0], last_int32_array_array); TEST_EQ (last_int32_array_array[0][0], 4); TEST_EQ (last_int32_array_array[0][1], 8); TEST_EQ (last_int32_array_array[0][2], 15); TEST_EQ (last_int32_array_array[0][3], 16); TEST_EQ (last_int32_array_array[0][4], 23); TEST_EQ (last_int32_array_array[0][5], 42); TEST_EQ (last_int32_array_array_len[1], 6); TEST_ALLOC_SIZE (last_int32_array_array[1], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (last_int32_array_array[1], last_int32_array_array); TEST_EQ (last_int32_array_array[1][0], 1); TEST_EQ (last_int32_array_array[1][1], 1); TEST_EQ (last_int32_array_array[1][2], 2); TEST_EQ (last_int32_array_array[1][3], 3); TEST_EQ (last_int32_array_array[1][4], 5); TEST_EQ (last_int32_array_array[1][5], 8); TEST_EQ_P (last_int32_array_array[2], NULL); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_array_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32_array_array ( proxy, "", my_str_to_int32_array_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToInt32ArrayArray.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_array_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32_array_array ( proxy, "invalid", my_str_to_int32_array_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_array_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32_array_array ( proxy, "4 8 15 16 23 42\n1 1 2 3 5 8", my_str_to_int32_array_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_int32_array_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32_array_array ( proxy, "4 8 15 16 23 42\n1 1 2 3 5 8", my_str_to_int32_array_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_int32_array_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_int32_array_array ( proxy, "4 8 15 16 23 42\n1 1 2 3 5 8", my_str_to_int32_array_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_int32_array_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_int32_array_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t ** int32_array_array; size_t * int32_array_array_len; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_int32_array_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_array_array = NULL; int32_array_array_len = NULL; ret = proxy_test_str_to_int32_array_array_sync ( parent, proxy, "4 8 15 16 23 42\n1 1 2 3 5 8", &int32_array_array, &int32_array_array_len); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (int32_array_array_len, sizeof (size_t) * 2); TEST_ALLOC_PARENT (int32_array_array_len, int32_array_array); TEST_ALLOC_SIZE (int32_array_array, sizeof (int32_t) * 3); TEST_ALLOC_PARENT (int32_array_array, parent); TEST_EQ (int32_array_array_len[0], 6); TEST_ALLOC_SIZE (int32_array_array[0], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (int32_array_array[0], int32_array_array); TEST_EQ (int32_array_array[0][0], 4); TEST_EQ (int32_array_array[0][1], 8); TEST_EQ (int32_array_array[0][2], 15); TEST_EQ (int32_array_array[0][3], 16); TEST_EQ (int32_array_array[0][4], 23); TEST_EQ (int32_array_array[0][5], 42); TEST_EQ (int32_array_array_len[1], 6); TEST_ALLOC_SIZE (int32_array_array[1], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (int32_array_array[1], int32_array_array); TEST_EQ (int32_array_array[1][0], 1); TEST_EQ (int32_array_array[1][1], 1); TEST_EQ (int32_array_array[1][2], 2); TEST_EQ (int32_array_array[1][3], 3); TEST_EQ (int32_array_array[1][4], 5); TEST_EQ (int32_array_array[1][5], 8); TEST_EQ_P (int32_array_array[2], NULL); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_array_array = NULL; int32_array_array_len = NULL; ret = proxy_test_str_to_int32_array_array_sync ( parent, proxy, "", &int32_array_array, &int32_array_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToInt32ArrayArray.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_array_array = NULL; int32_array_array_len = NULL; ret = proxy_test_str_to_int32_array_array_sync ( parent, proxy, "invalid", &int32_array_array, &int32_array_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_int32_array_array_sync ( parent, proxy, "4 8 15 16 23 42\n1 1 2 3 5 8", &int32_array_array, &int32_array_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int struct_array_to_str_replied; static void my_struct_array_to_str_reply (void * data, NihDBusMessage *message, const char * output) { struct_array_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_struct_array_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestStructArrayToStrInputElement **struct_array = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_struct_array_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayToStrInputElement) * 3); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; } error_handler_called = FALSE; struct_array_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_struct_array_to_str (proxy, struct_array, my_struct_array_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (struct_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "Joe 34\nPaul 27"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayToStrInputElement) * 1); struct_array[0] = NULL; } error_handler_called = FALSE; struct_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_struct_array_to_str (proxy, struct_array, my_struct_array_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (struct_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StructArrayToStr.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayToStrInputElement) * 2); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = NULL; } error_handler_called = FALSE; struct_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_struct_array_to_str (proxy, struct_array, my_struct_array_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (struct_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayToStrInputElement) * 3); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; } error_handler_called = FALSE; struct_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_struct_array_to_str (proxy, struct_array, my_struct_array_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (struct_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayToStrInputElement) * 3); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; } error_handler_called = FALSE; struct_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_struct_array_to_str (proxy, struct_array, my_struct_array_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (struct_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayToStrInputElement) * 3); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; struct_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_struct_array_to_str (proxy, struct_array, my_struct_array_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (struct_array_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_struct_array_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestStructArrayToStrInputElement **struct_array = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_struct_array_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayToStrInputElement) * 3); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; } str_value = NULL; ret = proxy_test_struct_array_to_str_sync (parent, proxy, struct_array, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "Joe 34\nPaul 27"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayToStrInputElement) * 1); struct_array[0] = NULL; } ret = proxy_test_struct_array_to_str_sync (parent, proxy, struct_array, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StructArrayToStr.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayToStrInputElement) * 2); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = NULL; } ret = proxy_test_struct_array_to_str_sync (parent, proxy, struct_array, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayToStrInputElement) * 3); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, ProxyTestStructArrayToStrInputElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_struct_array_to_str_sync (parent, proxy, struct_array, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_struct_array_replied; static MyStruct * const *last_struct_array; static void my_str_to_struct_array_reply (void * data, NihDBusMessage *message, ProxyTestStrToStructArrayOutputElement * const *output) { str_to_struct_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_struct_array = (MyStruct * const *)output; nih_ref (last_struct_array, last_data); } void test_str_to_struct_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_struct_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_struct_array_replied = FALSE; last_data = NULL; last_struct_array = NULL; pending_call = proxy_test_str_to_struct_array (proxy, "Joe 34\nPaul 27", my_str_to_struct_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_struct_array, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (last_struct_array, parent); TEST_ALLOC_SIZE (last_struct_array[0], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_struct_array[0], last_struct_array); TEST_EQ_STR (last_struct_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (last_struct_array[0]->item0, last_struct_array[0]); TEST_EQ (last_struct_array[0]->item1, 34); TEST_ALLOC_SIZE (last_struct_array[1], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_struct_array[1], last_struct_array); TEST_EQ_STR (last_struct_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (last_struct_array[1]->item0, last_struct_array[1]); TEST_EQ (last_struct_array[1]->item1, 27); TEST_EQ_P (last_struct_array[2], NULL); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_struct_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_struct_array (proxy, "", my_str_to_struct_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToStructArray.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_struct_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_struct_array (proxy, "invalid", my_str_to_struct_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_struct_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_struct_array (proxy, "Joe 34\nPaul 27", my_str_to_struct_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_struct_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_struct_array (proxy, "Joe 34\nPaul 27", my_str_to_struct_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_struct_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_struct_array (proxy, "Joe 34\nPaul 27", my_str_to_struct_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_struct_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_struct_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestStrToStructArrayOutputElement **struct_array; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_struct_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } struct_array = NULL; ret = proxy_test_str_to_struct_array_sync (parent, proxy, "Joe 34\nPaul 27", &struct_array); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (struct_array, sizeof (ProxyTestStrToStructArrayOutputElement *) * 3); TEST_ALLOC_PARENT (struct_array, parent); TEST_ALLOC_SIZE (struct_array[0], sizeof (ProxyTestStrToStructArrayOutputElement)); TEST_ALLOC_PARENT (struct_array[0], struct_array); TEST_EQ_STR (struct_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (struct_array[0]->item0, struct_array[0]); TEST_EQ (struct_array[0]->item1, 34); TEST_ALLOC_SIZE (struct_array[1], sizeof (ProxyTestStrToStructArrayOutputElement)); TEST_ALLOC_PARENT (struct_array[1], struct_array); TEST_EQ_STR (struct_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (struct_array[1]->item0, struct_array[1]); TEST_EQ (struct_array[1]->item1, 27); TEST_EQ_P (struct_array[2], NULL); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_struct_array_sync (parent, proxy, "", &struct_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToStructArray.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_struct_array_sync (parent, proxy, "invalid", &struct_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_struct_array_sync (parent, proxy, "Joe 34\nPaul 27", &struct_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int dict_entry_array_to_str_replied; static void my_dict_entry_array_to_str_reply (void * data, NihDBusMessage *message, const char * output) { dict_entry_array_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_dict_entry_array_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestDictEntryArrayToStrInputElement **dict_entry_array = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_dict_entry_array_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayToStrInputElement) * 3); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; } error_handler_called = FALSE; dict_entry_array_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_dict_entry_array_to_str (proxy, dict_entry_array, my_dict_entry_array_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (dict_entry_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "Joe 34\nPaul 27"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayToStrInputElement) * 1); dict_entry_array[0] = NULL; } error_handler_called = FALSE; dict_entry_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_dict_entry_array_to_str (proxy, dict_entry_array, my_dict_entry_array_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (dict_entry_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.DictEntryArrayToStr.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayToStrInputElement) * 2); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = NULL; } error_handler_called = FALSE; dict_entry_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_dict_entry_array_to_str (proxy, dict_entry_array, my_dict_entry_array_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (dict_entry_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayToStrInputElement) * 3); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; } error_handler_called = FALSE; dict_entry_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_dict_entry_array_to_str (proxy, dict_entry_array, my_dict_entry_array_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (dict_entry_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayToStrInputElement) * 3); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; } error_handler_called = FALSE; dict_entry_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_dict_entry_array_to_str (proxy, dict_entry_array, my_dict_entry_array_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (dict_entry_array_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayToStrInputElement) * 3); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; dict_entry_array_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_dict_entry_array_to_str (proxy, dict_entry_array, my_dict_entry_array_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (dict_entry_array_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_dict_entry_array_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestDictEntryArrayToStrInputElement **dict_entry_array = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_dict_entry_array_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayToStrInputElement) * 3); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; } str_value = NULL; ret = proxy_test_dict_entry_array_to_str_sync (parent, proxy, dict_entry_array, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "Joe 34\nPaul 27"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayToStrInputElement) * 1); dict_entry_array[0] = NULL; } ret = proxy_test_dict_entry_array_to_str_sync (parent, proxy, dict_entry_array, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.DictEntryArrayToStr.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayToStrInputElement) * 2); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = NULL; } ret = proxy_test_dict_entry_array_to_str_sync (parent, proxy, dict_entry_array, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayToStrInputElement) * 3); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, ProxyTestDictEntryArrayToStrInputElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_dict_entry_array_to_str_sync (parent, proxy, dict_entry_array, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_dict_entry_array_replied; static MyStruct * const *last_dict_entry_array; static void my_str_to_dict_entry_array_reply (void * data, NihDBusMessage *message, ProxyTestStrToDictEntryArrayOutputElement * const *output) { str_to_dict_entry_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_dict_entry_array = (MyStruct * const *)output; nih_ref (last_dict_entry_array, last_data); } void test_str_to_dict_entry_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_dict_entry_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_dict_entry_array_replied = FALSE; last_data = NULL; last_dict_entry_array = NULL; pending_call = proxy_test_str_to_dict_entry_array (proxy, "Joe 34\nPaul 27", my_str_to_dict_entry_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_dict_entry_array, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (last_dict_entry_array, parent); TEST_ALLOC_SIZE (last_dict_entry_array[0], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_dict_entry_array[0], last_dict_entry_array); TEST_EQ_STR (last_dict_entry_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (last_dict_entry_array[0]->item0, last_dict_entry_array[0]); TEST_EQ (last_dict_entry_array[0]->item1, 34); TEST_ALLOC_SIZE (last_dict_entry_array[1], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_dict_entry_array[1], last_dict_entry_array); TEST_EQ_STR (last_dict_entry_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (last_dict_entry_array[1]->item0, last_dict_entry_array[1]); TEST_EQ (last_dict_entry_array[1]->item1, 27); TEST_EQ_P (last_dict_entry_array[2], NULL); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_dict_entry_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_dict_entry_array (proxy, "", my_str_to_dict_entry_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToDictEntryArray.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_dict_entry_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_dict_entry_array (proxy, "invalid", my_str_to_dict_entry_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_dict_entry_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_dict_entry_array (proxy, "Joe 34\nPaul 27", my_str_to_dict_entry_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_dict_entry_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_dict_entry_array (proxy, "Joe 34\nPaul 27", my_str_to_dict_entry_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_dict_entry_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_dict_entry_array (proxy, "Joe 34\nPaul 27", my_str_to_dict_entry_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_dict_entry_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_dict_entry_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestStrToDictEntryArrayOutputElement **dict_entry_array; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_dict_entry_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } dict_entry_array = NULL; ret = proxy_test_str_to_dict_entry_array_sync (parent, proxy, "Joe 34\nPaul 27", &dict_entry_array); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (dict_entry_array, sizeof (ProxyTestStrToDictEntryArrayOutputElement *) * 3); TEST_ALLOC_PARENT (dict_entry_array, parent); TEST_ALLOC_SIZE (dict_entry_array[0], sizeof (ProxyTestStrToDictEntryArrayOutputElement)); TEST_ALLOC_PARENT (dict_entry_array[0], dict_entry_array); TEST_EQ_STR (dict_entry_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (dict_entry_array[0]->item0, dict_entry_array[0]); TEST_EQ (dict_entry_array[0]->item1, 34); TEST_ALLOC_SIZE (dict_entry_array[1], sizeof (ProxyTestStrToDictEntryArrayOutputElement)); TEST_ALLOC_PARENT (dict_entry_array[1], dict_entry_array); TEST_EQ_STR (dict_entry_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (dict_entry_array[1]->item0, dict_entry_array[1]); TEST_EQ (dict_entry_array[1]->item1, 27); TEST_EQ_P (dict_entry_array[2], NULL); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_dict_entry_array_sync (parent, proxy, "", &dict_entry_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToDictEntryArray.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_dict_entry_array_sync (parent, proxy, "invalid", &dict_entry_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_dict_entry_array_sync (parent, proxy, "Joe 34\nPaul 27", &dict_entry_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int unix_fd_to_str_replied; static void my_unix_fd_to_str_reply (void * data, NihDBusMessage *message, const char * output) { unix_fd_to_str_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); TEST_ALLOC_PARENT (output, message); last_data = data; last_str_value = output; nih_ref (last_str_value, last_data); } void test_unix_fd_to_str (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_unix_fd_to_str"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; unix_fd_to_str_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_unix_fd_to_str (proxy, 1, my_unix_fd_to_str_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (unix_fd_to_str_replied); TEST_EQ_P (last_data, parent); TEST_TRUE (strchr ("0123456789", last_str_value[0])); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; unix_fd_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_unix_fd_to_str (proxy, 1, my_unix_fd_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (unix_fd_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; unix_fd_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_unix_fd_to_str (proxy, 1, my_unix_fd_to_str_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (unix_fd_to_str_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; unix_fd_to_str_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_unix_fd_to_str (proxy, 1, my_unix_fd_to_str_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (unix_fd_to_str_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_unix_fd_to_str_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_unix_fd_to_str_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_unix_fd_to_str_sync (parent, proxy, 1, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_TRUE (strchr ("0123456789", str_value[0])); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_unix_fd_to_str_sync (parent, proxy, 1, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int str_to_unix_fd_replied; static int last_unix_fd_value; static void my_str_to_unix_fd_reply (void * data, NihDBusMessage *message, int output) { str_to_unix_fd_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_unix_fd_value = output; } void test_str_to_unix_fd (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_str_to_unix_fd"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_unix_fd_replied = FALSE; last_data = NULL; last_unix_fd_value = 0; pending_call = proxy_test_str_to_unix_fd (proxy, "1", my_str_to_unix_fd_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (str_to_unix_fd_replied); TEST_EQ_P (last_data, parent); TEST_GT (last_unix_fd_value, 2); // dup'd by dbus close (last_unix_fd_value); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_unix_fd_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_unix_fd (proxy, "", my_str_to_unix_fd_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_unix_fd_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToUnixFd.EmptyInput"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_unix_fd_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_unix_fd (proxy, "invalid", my_str_to_unix_fd_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_unix_fd_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_unix_fd_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_unix_fd (proxy, "1", my_str_to_unix_fd_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_unix_fd_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; str_to_unix_fd_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_unix_fd (proxy, "1", my_str_to_unix_fd_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (str_to_unix_fd_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; str_to_unix_fd_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_str_to_unix_fd (proxy, "1", my_str_to_unix_fd_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (str_to_unix_fd_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_str_to_unix_fd_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int unix_fd_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_str_to_unix_fd_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } unix_fd_value = -1; ret = proxy_test_str_to_unix_fd_sync (parent, proxy, "1", &unix_fd_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_GT (unix_fd_value, 2); // dbus dups this close (unix_fd_value); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_unix_fd_sync (parent, proxy, "", &unix_fd_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrToUnixFd.EmptyInput"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_str_to_unix_fd_sync (parent, proxy, "invalid", &unix_fd_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_str_to_unix_fd_sync (parent, proxy, "1", &unix_fd_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_byte_handled; static void my_new_byte_handler (void * data, NihDBusMessage *message, uint8_t value) { new_byte_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_byte_value = value; } void test_new_byte (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewByte_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewByte", (NihDBusSignalHandler)my_new_byte_handler, parent)); assert0 (my_test_emit_new_byte (server_conn, "/com/netsplit/Nih/Test", 97)); } new_byte_handled = FALSE; last_data = NULL; last_byte_value = 0; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_byte_handled); TEST_EQ_P (last_data, parent); TEST_EQ (last_byte_value, 97); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_boolean_handled; static void my_new_boolean_handler (void * data, NihDBusMessage *message, int value) { new_boolean_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_boolean_value = value; } void test_new_boolean (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewBoolean_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewBoolean", (NihDBusSignalHandler)my_new_boolean_handler, parent)); assert0 (my_test_emit_new_boolean (server_conn, "/com/netsplit/Nih/Test", TRUE)); } new_boolean_handled = FALSE; last_data = NULL; last_boolean_value = 0; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_boolean_handled); TEST_EQ_P (last_data, parent); TEST_EQ (last_boolean_value, TRUE); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_int16_handled; static void my_new_int16_handler (void * data, NihDBusMessage *message, int16_t value) { new_int16_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_int16_value = value; } void test_new_int16 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewInt16_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewInt16", (NihDBusSignalHandler)my_new_int16_handler, parent)); assert0 (my_test_emit_new_int16 (server_conn, "/com/netsplit/Nih/Test", -42)); } new_int16_handled = FALSE; last_data = NULL; last_int16_value = 0; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_int16_handled); TEST_EQ_P (last_data, parent); TEST_EQ (last_int16_value, -42); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_uint16_handled; static void my_new_uint16_handler (void * data, NihDBusMessage *message, uint16_t value) { new_uint16_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_uint16_value = value; } void test_new_uint16 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewUInt16_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewUInt16", (NihDBusSignalHandler)my_new_uint16_handler, parent)); assert0 (my_test_emit_new_uint16 (server_conn, "/com/netsplit/Nih/Test", 42)); } new_uint16_handled = FALSE; last_data = NULL; last_uint16_value = 0; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_uint16_handled); TEST_EQ_P (last_data, parent); TEST_EQ (last_uint16_value, 42); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_int32_handled; static void my_new_int32_handler (void * data, NihDBusMessage *message, int32_t value) { new_int32_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_int32_value = value; } void test_new_int32 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewInt32_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewInt32", (NihDBusSignalHandler)my_new_int32_handler, parent)); assert0 (my_test_emit_new_int32 (server_conn, "/com/netsplit/Nih/Test", -1048576)); } new_int32_handled = FALSE; last_data = NULL; last_int32_value = 0; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_int32_handled); TEST_EQ_P (last_data, parent); TEST_EQ (last_int32_value, -1048576); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_uint32_handled; static void my_new_uint32_handler (void * data, NihDBusMessage *message, uint32_t value) { new_uint32_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_uint32_value = value; } void test_new_uint32 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewUInt32_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewUInt32", (NihDBusSignalHandler)my_new_uint32_handler, parent)); assert0 (my_test_emit_new_uint32 (server_conn, "/com/netsplit/Nih/Test", 1048576)); } new_uint32_handled = FALSE; last_data = NULL; last_uint32_value = 0; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_uint32_handled); TEST_EQ_P (last_data, parent); TEST_EQ (last_uint32_value, 1048576); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_int64_handled; static void my_new_int64_handler (void * data, NihDBusMessage *message, int64_t value) { new_int64_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_int64_value = value; } void test_new_int64 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewInt64_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewInt64", (NihDBusSignalHandler)my_new_int64_handler, parent)); assert0 (my_test_emit_new_int64 (server_conn, "/com/netsplit/Nih/Test", -4815162342L)); } new_int64_handled = FALSE; last_data = NULL; last_int64_value = 0; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_int64_handled); TEST_EQ_P (last_data, parent); TEST_EQ (last_int64_value, -4815162342L); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_uint64_handled; static void my_new_uint64_handler (void * data, NihDBusMessage *message, uint64_t value) { new_uint64_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_uint64_value = value; } void test_new_uint64 (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewUInt64_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewUInt64", (NihDBusSignalHandler)my_new_uint64_handler, parent)); assert0 (my_test_emit_new_uint64 (server_conn, "/com/netsplit/Nih/Test", 48151623L)); } new_uint64_handled = FALSE; last_data = NULL; last_uint64_value = 0; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_uint64_handled); TEST_EQ_P (last_data, parent); TEST_EQ (last_uint64_value, 48151623L); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_double_handled; static void my_new_double_handler (void * data, NihDBusMessage *message, double value) { new_double_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_double_value = value; } void test_new_double (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewDouble_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewDouble", (NihDBusSignalHandler)my_new_double_handler, parent)); assert0 (my_test_emit_new_double (server_conn, "/com/netsplit/Nih/Test", 3.141597)); } new_double_handled = FALSE; last_data = NULL; last_double_value = 0; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_double_handled); TEST_EQ_P (last_data, parent); TEST_EQ (last_double_value, 3.141597); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_string_handled; static void my_new_string_handler (void * data, NihDBusMessage *message, const char * value) { new_string_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_str_value = value; nih_ref (last_str_value, last_data); } void test_new_string (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewString_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewString", (NihDBusSignalHandler)my_new_string_handler, parent)); assert0 (my_test_emit_new_string (server_conn, "/com/netsplit/Nih/Test", "she needs more of ze punishment")); } new_string_handled = FALSE; last_data = NULL; last_str_value = NULL; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_string_handled); TEST_EQ_P (last_data, parent); TEST_ALLOC_PARENT (last_str_value, parent); TEST_EQ_STR (last_str_value, "she needs more of ze punishment"); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_object_path_handled; static void my_new_object_path_handler (void * data, NihDBusMessage *message, const char * value) { new_object_path_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_str_value = value; nih_ref (last_str_value, last_data); } void test_new_object_path (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewObjectPath_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewObjectPath", (NihDBusSignalHandler)my_new_object_path_handler, parent)); assert0 (my_test_emit_new_object_path (server_conn, "/com/netsplit/Nih/Test", "/com/netsplit/Nih/Test")); } new_object_path_handled = FALSE; last_data = NULL; last_str_value = NULL; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_object_path_handled); TEST_EQ_P (last_data, parent); TEST_ALLOC_PARENT (last_str_value, parent); TEST_EQ_STR (last_str_value, "/com/netsplit/Nih/Test"); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_signature_handled; static void my_new_signature_handler (void * data, NihDBusMessage *message, const char * value) { new_signature_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_str_value = value; nih_ref (last_str_value, last_data); } void test_new_signature (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewSignature_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewSignature", (NihDBusSignalHandler)my_new_signature_handler, parent)); assert0 (my_test_emit_new_signature (server_conn, "/com/netsplit/Nih/Test", "a(ib)")); } new_signature_handled = FALSE; last_data = NULL; last_str_value = NULL; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_signature_handled); TEST_EQ_P (last_data, parent); TEST_ALLOC_PARENT (last_str_value, parent); TEST_EQ_STR (last_str_value, "a(ib)"); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_struct_handled; static void my_new_struct_handler (void * data, NihDBusMessage *message, const ProxyTestNewStructValue *value) { new_struct_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_struct_value = (const MyStruct *)value; nih_ref (last_struct_value, last_data); } void test_new_struct (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; MyTestNewStructValue *struct_value = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewStruct_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, MyTestNewStructValue); struct_value->item0 = "Joe"; struct_value->item1 = 34; assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewStruct", (NihDBusSignalHandler)my_new_struct_handler, parent)); assert0 (my_test_emit_new_struct (server_conn, "/com/netsplit/Nih/Test", struct_value)); } new_struct_handled = FALSE; last_data = NULL; last_struct_value = NULL; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_struct_handled); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_struct_value, sizeof (MyStruct)); TEST_ALLOC_PARENT (last_struct_value, parent); TEST_EQ_STR (last_struct_value->item0, "Joe"); TEST_ALLOC_PARENT (last_struct_value->item0, last_struct_value); TEST_EQ (last_struct_value->item1, 34); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_int32_array_handled; static void my_new_int32_array_handler (void * data, NihDBusMessage *message, int32_t * value, size_t value_len) { new_int32_array_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); if (value_len) { TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); } last_data = data; last_int32_array = value; if (value) nih_ref (last_int32_array, data); last_int32_array_len = value_len; } void test_new_int32_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t * int32_array; size_t int32_array_len; TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewInt32Array_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FEATURE ("with array"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewInt32Array", (NihDBusSignalHandler)my_new_int32_array_handler, parent)); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; int32_array_len = 6; assert0 (my_test_emit_new_int32_array ( server_conn, "/com/netsplit/Nih/Test", int32_array, int32_array_len)); } new_int32_array_handled = FALSE; last_data = NULL; last_int32_array = NULL; last_int32_array_len = 0; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_int32_array_handled); TEST_EQ_P (last_data, parent); TEST_EQ (last_int32_array_len, 6); TEST_ALLOC_SIZE (last_int32_array, sizeof (int32_t) * 6); TEST_ALLOC_PARENT (last_int32_array, parent); TEST_EQ (last_int32_array[0], 4); TEST_EQ (last_int32_array[1], 8); TEST_EQ (last_int32_array[2], 15); TEST_EQ (last_int32_array[3], 16); TEST_EQ (last_int32_array[4], 23); TEST_EQ (last_int32_array[5], 42); nih_free (parent); nih_free (proxy); } /* Check that we can receive an empty array, which is actually * NULL with a zero length. */ TEST_FEATURE ("with empty array"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewInt32Array", (NihDBusSignalHandler)my_new_int32_array_handler, parent)); int32_array = NULL; int32_array_len = 0; assert0 (my_test_emit_new_int32_array ( server_conn, "/com/netsplit/Nih/Test", int32_array, int32_array_len)); } new_int32_array_handled = FALSE; last_data = NULL; last_int32_array = NULL; last_int32_array_len = 0; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_int32_array_handled); TEST_EQ_P (last_data, parent); TEST_EQ (last_int32_array_len, 0); TEST_EQ_P (last_int32_array, NULL); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_str_array_handled; static void my_new_str_array_handler (void * data, NihDBusMessage *message, char * const * value) { new_str_array_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_str_array = value; nih_ref (last_str_array, data); } void test_new_str_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; char ** str_array; TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewStrArray_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FEATURE ("with array"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewStrArray", (NihDBusSignalHandler)my_new_str_array_handler, parent)); str_array = nih_alloc (parent, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; assert0 (my_test_emit_new_str_array ( server_conn, "/com/netsplit/Nih/Test", str_array)); } new_str_array_handled = FALSE; last_data = NULL; last_str_array = NULL; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_str_array_handled); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_str_array, sizeof (char *) * 7); TEST_ALLOC_PARENT (last_str_array, parent); TEST_EQ_STR (last_str_array[0], "she"); TEST_ALLOC_PARENT (last_str_array[0], last_str_array); TEST_EQ_STR (last_str_array[1], "needs"); TEST_ALLOC_PARENT (last_str_array[1], last_str_array); TEST_EQ_STR (last_str_array[2], "more"); TEST_ALLOC_PARENT (last_str_array[2], last_str_array); TEST_EQ_STR (last_str_array[3], "of"); TEST_ALLOC_PARENT (last_str_array[3], last_str_array); TEST_EQ_STR (last_str_array[4], "ze"); TEST_ALLOC_PARENT (last_str_array[4], last_str_array); TEST_EQ_STR (last_str_array[5], "punishment"); TEST_ALLOC_PARENT (last_str_array[5], last_str_array); TEST_EQ_P (last_str_array[6], NULL); nih_free (parent); nih_free (proxy); } /* Check that we can receive an empty string array consisting of * only the NULL pointer. */ TEST_FEATURE ("with empty array"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewStrArray", (NihDBusSignalHandler)my_new_str_array_handler, parent)); str_array = nih_alloc (parent, sizeof (char *) * 1); str_array[0] = NULL; assert0 (my_test_emit_new_str_array ( server_conn, "/com/netsplit/Nih/Test", str_array)); } new_str_array_handled = FALSE; last_data = NULL; last_str_array = NULL; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_str_array_handled); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_str_array, sizeof (char *) * 1); TEST_ALLOC_PARENT (last_str_array, parent); TEST_EQ_P (last_str_array[0], NULL); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_int32_array_array_handled; static void my_new_int32_array_array_handler (void * data, NihDBusMessage * message, int32_t * const *value, size_t * value_len) { new_int32_array_array_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); if (*value) { TEST_NE_P (value_len, NULL); TEST_ALLOC_PARENT (value_len, value); } last_data = data; last_int32_array_array = value; nih_ref (last_int32_array_array, data); last_int32_array_array_len = value_len; if (value_len) nih_ref (last_int32_array_array_len, data); } void test_new_int32_array_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t ** int32_array_array; size_t * int32_array_array_len; TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewInt32ArrayArray_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FEATURE ("with array"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewInt32ArrayArray", (NihDBusSignalHandler)my_new_int32_array_array_handler, parent)); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (parent, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; assert0 (my_test_emit_new_int32_array_array ( server_conn, "/com/netsplit/Nih/Test", int32_array_array, int32_array_array_len)); } new_int32_array_array_handled = FALSE; last_data = NULL; last_int32_array_array = NULL; last_int32_array_array_len = NULL; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_int32_array_array_handled); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_int32_array_array, sizeof (int32_t *) * 3); TEST_ALLOC_PARENT (last_int32_array_array, parent); TEST_ALLOC_SIZE (last_int32_array_array_len, sizeof (size_t) * 2); TEST_ALLOC_PARENT (last_int32_array_array_len, last_int32_array_array); TEST_EQ (last_int32_array_array_len[0], 6); TEST_ALLOC_SIZE (last_int32_array_array[0], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (last_int32_array_array[0], last_int32_array_array); TEST_EQ (last_int32_array_array[0][0], 4); TEST_EQ (last_int32_array_array[0][1], 8); TEST_EQ (last_int32_array_array[0][2], 15); TEST_EQ (last_int32_array_array[0][3], 16); TEST_EQ (last_int32_array_array[0][4], 23); TEST_EQ (last_int32_array_array[0][5], 42); TEST_EQ (last_int32_array_array_len[1], 6); TEST_ALLOC_SIZE (last_int32_array_array[1], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (last_int32_array_array[1], last_int32_array_array); TEST_EQ (last_int32_array_array[1][0], 1); TEST_EQ (last_int32_array_array[1][1], 1); TEST_EQ (last_int32_array_array[1][2], 2); TEST_EQ (last_int32_array_array[1][3], 3); TEST_EQ (last_int32_array_array[1][4], 5); TEST_EQ (last_int32_array_array[1][5], 8); TEST_EQ_P (last_int32_array_array[2], NULL); nih_free (parent); nih_free (proxy); } /* Check that we can receive an empty array which has NULL as its * first element and NULL for its size array. */ TEST_FEATURE ("with array"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewInt32ArrayArray", (NihDBusSignalHandler)my_new_int32_array_array_handler, parent)); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 1); int32_array_array_len = NULL; int32_array_array[0] = NULL; assert0 (my_test_emit_new_int32_array_array ( server_conn, "/com/netsplit/Nih/Test", int32_array_array, int32_array_array_len)); } new_int32_array_array_handled = FALSE; last_data = NULL; last_int32_array_array = NULL; last_int32_array_array_len = NULL; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_int32_array_array_handled); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_int32_array_array, sizeof (int32_t *) * 1); TEST_ALLOC_PARENT (last_int32_array_array, parent); TEST_EQ_P (last_int32_array_array[0], NULL); TEST_EQ_P (last_int32_array_array_len, NULL); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_struct_array_handled; static void my_new_struct_array_handler (void * data, NihDBusMessage *message, ProxyTestNewStructArrayValueElement * const *value) { new_struct_array_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_struct_array = (MyStruct * const *)value; nih_ref (last_struct_array, last_data); } void test_new_struct_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; MyTestNewStructArrayValueElement **struct_array = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewStructArray_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (MyTestNewStructArrayValueElement) * 3); struct_array[0] = nih_new (struct_array, MyTestNewStructArrayValueElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, MyTestNewStructArrayValueElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewStructArray", (NihDBusSignalHandler)my_new_struct_array_handler, parent)); assert0 (my_test_emit_new_struct_array (server_conn, "/com/netsplit/Nih/Test", struct_array)); } new_struct_array_handled = FALSE; last_data = NULL; last_struct_array = NULL; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_struct_array_handled); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_struct_array, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (last_struct_array, parent); TEST_ALLOC_SIZE (last_struct_array[0], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_struct_array[0], last_struct_array); TEST_EQ_STR (last_struct_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (last_struct_array[0]->item0, last_struct_array[0]); TEST_EQ (last_struct_array[0]->item1, 34); TEST_ALLOC_SIZE (last_struct_array[1], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_struct_array[1], last_struct_array); TEST_EQ_STR (last_struct_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (last_struct_array[1]->item0, last_struct_array[1]); TEST_EQ (last_struct_array[1]->item1, 27); TEST_EQ_P (last_struct_array[2], NULL); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_dict_entry_array_handled; static void my_new_dict_entry_array_handler (void * data, NihDBusMessage *message, ProxyTestNewDictEntryArrayValueElement * const *value) { new_dict_entry_array_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_dict_entry_array = (MyStruct * const *)value; nih_ref (last_dict_entry_array, last_data); } void test_new_dict_entry_array (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; MyTestNewDictEntryArrayValueElement **dict_entry_array = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewDictEntryArray_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (MyTestNewDictEntryArrayValueElement) * 3); dict_entry_array[0] = nih_new (dict_entry_array, MyTestNewDictEntryArrayValueElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, MyTestNewDictEntryArrayValueElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewDictEntryArray", (NihDBusSignalHandler)my_new_dict_entry_array_handler, parent)); assert0 (my_test_emit_new_dict_entry_array (server_conn, "/com/netsplit/Nih/Test", dict_entry_array)); } new_dict_entry_array_handled = FALSE; last_data = NULL; last_dict_entry_array = NULL; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_dict_entry_array_handled); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_dict_entry_array, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (last_dict_entry_array, parent); TEST_ALLOC_SIZE (last_dict_entry_array[0], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_dict_entry_array[0], last_dict_entry_array); TEST_EQ_STR (last_dict_entry_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (last_dict_entry_array[0]->item0, last_dict_entry_array[0]); TEST_EQ (last_dict_entry_array[0]->item1, 34); TEST_ALLOC_SIZE (last_dict_entry_array[1], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_dict_entry_array[1], last_dict_entry_array); TEST_EQ_STR (last_dict_entry_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (last_dict_entry_array[1]->item0, last_dict_entry_array[1]); TEST_EQ (last_dict_entry_array[1]->item1, 27); TEST_EQ_P (last_dict_entry_array[2], NULL); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int new_unix_fd_handled; static void my_new_unix_fd_handler (void * data, NihDBusMessage *message, int value) { new_unix_fd_handled++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_unix_fd_value = value; } void test_new_unix_fd (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; NihDBusProxy * proxy = NULL; void * parent = NULL; /* Check that we can use nih_dbus_proxy_connect() to have our handler * function called when the matching signal is emitted by the server. */ TEST_FUNCTION ("proxy_com_netsplit_Nih_Test_NewUnixFd_signal"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); assert (nih_dbus_proxy_connect (proxy, &proxy_com_netsplit_Nih_Test, "NewUnixFd", (NihDBusSignalHandler)my_new_unix_fd_handler, parent)); assert0 (my_test_emit_new_unix_fd (server_conn, "/com/netsplit/Nih/Test", TRUE)); } new_unix_fd_handled = FALSE; last_data = NULL; last_unix_fd_value = -1; dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (new_unix_fd_handled); TEST_EQ_P (last_data, parent); TEST_GT (last_unix_fd_value, 2); // dbus dups this close (last_unix_fd_value); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_byte_replied; static void my_get_byte_reply (void * data, NihDBusMessage *message, uint8_t value) { get_byte_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_byte_value = value; } void test_get_byte (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_byte"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { byte_property = 97; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_byte_replied = FALSE; last_data = NULL; last_byte_value = 0; pending_call = proxy_test_get_byte (proxy, my_get_byte_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_byte_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_byte_value, 97); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { byte_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_byte_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_byte (proxy, my_get_byte_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_byte_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Byte.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { byte_property = 4; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_byte_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_byte (proxy, my_get_byte_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_byte_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_byte_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_byte (proxy, my_get_byte_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_byte_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_byte_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_byte (proxy, my_get_byte_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_byte_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_byte_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_byte (proxy, my_get_byte_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_byte_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_byte_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; uint8_t byte_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_byte_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { byte_property = 97; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } byte_value = 0; ret = proxy_test_get_byte_sync (parent, proxy, &byte_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (byte_value, 97); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { byte_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } byte_value = 0; ret = proxy_test_get_byte_sync (parent, proxy, &byte_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Byte.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { byte_property = 4; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } byte_value = 0; ret = proxy_test_get_byte_sync (parent, proxy, &byte_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_byte_sync (parent, proxy, &byte_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_byte_replied; static void my_set_byte_reply (void * data, NihDBusMessage *message) { set_byte_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_byte (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_byte"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { byte_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_byte_replied = FALSE; last_data = NULL; last_byte_value = 0; pending_call = proxy_test_set_byte (proxy, 97, my_set_byte_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_byte_replied); TEST_EQ_P (last_data, parent); TEST_EQ (byte_property, 97); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_byte_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_byte (proxy, 0, my_set_byte_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_byte_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Byte.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_byte_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_byte (proxy, 4, my_set_byte_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_byte_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_byte_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_byte (proxy, 97, my_set_byte_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_byte_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_byte_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_byte (proxy, 97, my_set_byte_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_byte_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_byte_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_byte (proxy, 97, my_set_byte_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_byte_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_byte_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; uint8_t byte_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_byte_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { byte_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } byte_value = 0; ret = proxy_test_set_byte_sync (parent, proxy, 97); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SAFE { assert0 (proxy_test_get_byte_sync (parent, proxy, &byte_value)); } TEST_EQ (byte_value, 97); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_byte_sync (parent, proxy, 0); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Byte.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_byte_sync (parent, proxy, 4); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_byte_sync (parent, proxy, 97); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_boolean_replied; static void my_get_boolean_reply (void * data, NihDBusMessage *message, int value) { get_boolean_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_boolean_value = value; } void test_get_boolean (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_boolean"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { boolean_property = TRUE; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_boolean_replied = FALSE; last_data = NULL; last_boolean_value = 0; pending_call = proxy_test_get_boolean (proxy, my_get_boolean_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_boolean_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_boolean_value, TRUE); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { boolean_property = FALSE; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_boolean_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_boolean (proxy, my_get_boolean_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_boolean_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Boolean.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_boolean_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_boolean (proxy, my_get_boolean_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_boolean_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_boolean_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_boolean (proxy, my_get_boolean_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_boolean_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_boolean_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_boolean (proxy, my_get_boolean_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_boolean_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_boolean_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int boolean_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_boolean_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { boolean_property = TRUE; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } boolean_value = 0; ret = proxy_test_get_boolean_sync (parent, proxy, &boolean_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (boolean_value, TRUE); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { boolean_property = FALSE; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } boolean_value = 0; ret = proxy_test_get_boolean_sync (parent, proxy, &boolean_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Boolean.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_boolean_sync (parent, proxy, &boolean_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_boolean_replied; static void my_set_boolean_reply (void * data, NihDBusMessage *message) { set_boolean_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_boolean (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_boolean"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { boolean_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_boolean_replied = FALSE; last_data = NULL; last_boolean_value = FALSE; pending_call = proxy_test_set_boolean (proxy, TRUE, my_set_boolean_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_boolean_replied); TEST_EQ_P (last_data, parent); TEST_EQ (boolean_property, TRUE); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_boolean_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_boolean (proxy, FALSE, my_set_boolean_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_boolean_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Boolean.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_boolean_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_boolean (proxy, TRUE, my_set_boolean_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_boolean_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_boolean_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_boolean (proxy, TRUE, my_set_boolean_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_boolean_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_boolean_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_boolean (proxy, TRUE, my_set_boolean_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_boolean_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_boolean_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int boolean_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_boolean_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { boolean_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } boolean_value = FALSE; ret = proxy_test_set_boolean_sync (parent, proxy, TRUE); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SAFE { assert0 (proxy_test_get_boolean_sync (parent, proxy, &boolean_value)); } TEST_EQ (boolean_value, TRUE); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_boolean_sync (parent, proxy, FALSE); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Boolean.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_boolean_sync (parent, proxy, TRUE); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_int16_replied; static void my_get_int16_reply (void * data, NihDBusMessage *message, int16_t value) { get_int16_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_int16_value = value; } void test_get_int16 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_int16"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { int16_property = -42; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int16_replied = FALSE; last_data = NULL; last_int16_value = 0; pending_call = proxy_test_get_int16 (proxy, my_get_int16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_int16_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_int16_value, -42); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { int16_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int16_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_int16 (proxy, my_get_int16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int16.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { int16_property = 4; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int16_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_int16 (proxy, my_get_int16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int16 (proxy, my_get_int16_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int16 (proxy, my_get_int16_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_int16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int16 (proxy, my_get_int16_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_int16_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_int16_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int16_t int16_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_int16_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { int16_property = -42; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int16_value = 0; ret = proxy_test_get_int16_sync (parent, proxy, &int16_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (int16_value, -42); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { int16_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int16_value = 0; ret = proxy_test_get_int16_sync (parent, proxy, &int16_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int16.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { int16_property = 4; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int16_value = 0; ret = proxy_test_get_int16_sync (parent, proxy, &int16_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_int16_sync (parent, proxy, &int16_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_int16_replied; static void my_set_int16_reply (void * data, NihDBusMessage *message) { set_int16_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_int16 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_int16"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { int16_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int16_replied = FALSE; last_data = NULL; last_int16_value = 0; pending_call = proxy_test_set_int16 (proxy, -42, my_set_int16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_int16_replied); TEST_EQ_P (last_data, parent); TEST_EQ (int16_property, -42); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int16 (proxy, 0, my_set_int16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int16.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int16 (proxy, 4, my_set_int16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int16 (proxy, -42, my_set_int16_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int16 (proxy, -42, my_set_int16_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_int16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int16 (proxy, -42, my_set_int16_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_int16_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_int16_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int16_t int16_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_int16_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { int16_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int16_value = 0; ret = proxy_test_set_int16_sync (parent, proxy, -42); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SAFE { assert0 (proxy_test_get_int16_sync (parent, proxy, &int16_value)); } TEST_EQ (int16_value, -42); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_int16_sync (parent, proxy, 0); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int16.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_int16_sync (parent, proxy, 4); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_int16_sync (parent, proxy, -42); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_uint16_replied; static void my_get_uint16_reply (void * data, NihDBusMessage *message, uint16_t value) { get_uint16_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_uint16_value = value; } void test_get_uint16 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_uint16"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { uint16_property = 42; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint16_replied = FALSE; last_data = NULL; last_uint16_value = 0; pending_call = proxy_test_get_uint16 (proxy, my_get_uint16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_uint16_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_uint16_value, 42); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { uint16_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint16_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_uint16 (proxy, my_get_uint16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_uint16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt16.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { uint16_property = 4; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint16_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_uint16 (proxy, my_get_uint16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_uint16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_uint16 (proxy, my_get_uint16_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_uint16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_uint16 (proxy, my_get_uint16_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_uint16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_uint16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_uint16 (proxy, my_get_uint16_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_uint16_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_uint16_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; uint16_t uint16_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_uint16_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { uint16_property = 42; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint16_value = 0; ret = proxy_test_get_uint16_sync (parent, proxy, &uint16_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (uint16_value, 42); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { uint16_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint16_value = 0; ret = proxy_test_get_uint16_sync (parent, proxy, &uint16_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt16.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { uint16_property = 4; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint16_value = 0; ret = proxy_test_get_uint16_sync (parent, proxy, &uint16_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_uint16_sync (parent, proxy, &uint16_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_uint16_replied; static void my_set_uint16_reply (void * data, NihDBusMessage *message) { set_uint16_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_uint16 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_uint16"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { uint16_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint16_replied = FALSE; last_data = NULL; last_uint16_value = 0; pending_call = proxy_test_set_uint16 (proxy, 42, my_set_uint16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_uint16_replied); TEST_EQ_P (last_data, parent); TEST_EQ (uint16_property, 42); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint16 (proxy, 0, my_set_uint16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_uint16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt16.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint16 (proxy, 4, my_set_uint16_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_uint16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint16 (proxy, 42, my_set_uint16_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_uint16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint16 (proxy, 42, my_set_uint16_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_uint16_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_uint16_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint16 (proxy, 42, my_set_uint16_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_uint16_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_uint16_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; uint16_t uint16_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_uint16_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { uint16_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint16_value = 0; ret = proxy_test_set_uint16_sync (parent, proxy, 42); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SAFE { assert0 (proxy_test_get_uint16_sync (parent, proxy, &uint16_value)); } TEST_EQ (uint16_value, 42); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_uint16_sync (parent, proxy, 0); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt16.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_uint16_sync (parent, proxy, 4); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_uint16_sync (parent, proxy, 42); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_int32_replied; static void my_get_int32_reply (void * data, NihDBusMessage *message, int32_t value) { get_int32_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_int32_value = value; } void test_get_int32 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_int32"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { int32_property = -1048576; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_replied = FALSE; last_data = NULL; last_int32_value = 0; pending_call = proxy_test_get_int32 (proxy, my_get_int32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_int32_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_int32_value, -1048576); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { int32_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_int32 (proxy, my_get_int32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { int32_property = 4; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_int32 (proxy, my_get_int32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int32 (proxy, my_get_int32_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int32 (proxy, my_get_int32_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_int32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int32 (proxy, my_get_int32_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_int32_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_int32_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t int32_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_int32_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { int32_property = -1048576; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_value = 0; ret = proxy_test_get_int32_sync (parent, proxy, &int32_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (int32_value, -1048576); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { int32_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_value = 0; ret = proxy_test_get_int32_sync (parent, proxy, &int32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { int32_property = 4; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_value = 0; ret = proxy_test_get_int32_sync (parent, proxy, &int32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_int32_sync (parent, proxy, &int32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_int32_replied; static void my_set_int32_reply (void * data, NihDBusMessage *message) { set_int32_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_int32 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_int32"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { int32_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int32_replied = FALSE; last_data = NULL; last_int32_value = 0; pending_call = proxy_test_set_int32 (proxy, -1048576, my_set_int32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_int32_replied); TEST_EQ_P (last_data, parent); TEST_EQ (int32_property, -1048576); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32 (proxy, 0, my_set_int32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32 (proxy, 4, my_set_int32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32 (proxy, -1048576, my_set_int32_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32 (proxy, -1048576, my_set_int32_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_int32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32 (proxy, -1048576, my_set_int32_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_int32_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_int32_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t int32_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_int32_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { int32_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_value = 0; ret = proxy_test_set_int32_sync (parent, proxy, -1048576); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SAFE { assert0 (proxy_test_get_int32_sync (parent, proxy, &int32_value)); } TEST_EQ (int32_value, -1048576); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_int32_sync (parent, proxy, 0); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_int32_sync (parent, proxy, 4); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_int32_sync (parent, proxy, -1048576); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_uint32_replied; static void my_get_uint32_reply (void * data, NihDBusMessage *message, uint32_t value) { get_uint32_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_uint32_value = value; } void test_get_uint32 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_uint32"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { uint32_property = 1048576; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint32_replied = FALSE; last_data = NULL; last_uint32_value = 0; pending_call = proxy_test_get_uint32 (proxy, my_get_uint32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_uint32_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_uint32_value, 1048576); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { uint32_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint32_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_uint32 (proxy, my_get_uint32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_uint32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt32.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { uint32_property = 4; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint32_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_uint32 (proxy, my_get_uint32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_uint32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_uint32 (proxy, my_get_uint32_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_uint32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_uint32 (proxy, my_get_uint32_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_uint32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_uint32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_uint32 (proxy, my_get_uint32_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_uint32_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_uint32_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; uint32_t uint32_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_uint32_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { uint32_property = 1048576; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint32_value = 0; ret = proxy_test_get_uint32_sync (parent, proxy, &uint32_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (uint32_value, 1048576); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { uint32_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint32_value = 0; ret = proxy_test_get_uint32_sync (parent, proxy, &uint32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt32.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { uint32_property = 4; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint32_value = 0; ret = proxy_test_get_uint32_sync (parent, proxy, &uint32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_uint32_sync (parent, proxy, &uint32_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_uint32_replied; static void my_set_uint32_reply (void * data, NihDBusMessage *message) { set_uint32_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_uint32 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_uint32"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { uint32_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint32_replied = FALSE; last_data = NULL; last_uint32_value = 0; pending_call = proxy_test_set_uint32 (proxy, 1048576, my_set_uint32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_uint32_replied); TEST_EQ_P (last_data, parent); TEST_EQ (uint32_property, 1048576); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint32 (proxy, 0, my_set_uint32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_uint32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt32.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint32 (proxy, 4, my_set_uint32_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_uint32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint32 (proxy, 1048576, my_set_uint32_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_uint32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint32 (proxy, 1048576, my_set_uint32_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_uint32_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_uint32_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint32 (proxy, 1048576, my_set_uint32_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_uint32_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_uint32_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; uint32_t uint32_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_uint32_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { uint32_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint32_value = 0; ret = proxy_test_set_uint32_sync (parent, proxy, 1048576); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SAFE { assert0 (proxy_test_get_uint32_sync (parent, proxy, &uint32_value)); } TEST_EQ (uint32_value, 1048576); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_uint32_sync (parent, proxy, 0); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt32.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_uint32_sync (parent, proxy, 4); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_uint32_sync (parent, proxy, 1048576); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_int64_replied; static void my_get_int64_reply (void * data, NihDBusMessage *message, int64_t value) { get_int64_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_int64_value = value; } void test_get_int64 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_int64"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { int64_property = -4815162342; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int64_replied = FALSE; last_data = NULL; last_int64_value = 0; pending_call = proxy_test_get_int64 (proxy, my_get_int64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_int64_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_int64_value, -4815162342); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { int64_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int64_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_int64 (proxy, my_get_int64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int64.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { int64_property = 4; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int64_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_int64 (proxy, my_get_int64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int64 (proxy, my_get_int64_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int64 (proxy, my_get_int64_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_int64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int64 (proxy, my_get_int64_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_int64_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_int64_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int64_t int64_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_int64_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { int64_property = -4815162342; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int64_value = 0; ret = proxy_test_get_int64_sync (parent, proxy, &int64_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (int64_value, -4815162342); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { int64_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int64_value = 0; ret = proxy_test_get_int64_sync (parent, proxy, &int64_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int64.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { int64_property = 4; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int64_value = 0; ret = proxy_test_get_int64_sync (parent, proxy, &int64_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_int64_sync (parent, proxy, &int64_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_int64_replied; static void my_set_int64_reply (void * data, NihDBusMessage *message) { set_int64_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_int64 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_int64"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { int64_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int64_replied = FALSE; last_data = NULL; last_int64_value = 0; pending_call = proxy_test_set_int64 (proxy, -4815162342L, my_set_int64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_int64_replied); TEST_EQ_P (last_data, parent); TEST_EQ (int64_property, -4815162342); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int64 (proxy, 0, my_set_int64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int64.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int64 (proxy, 4, my_set_int64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int64 (proxy, -4815162342L, my_set_int64_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int64 (proxy, -4815162342L, my_set_int64_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_int64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int64 (proxy, -4815162342L, my_set_int64_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_int64_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_int64_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int64_t int64_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_int64_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { int64_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int64_value = 0; ret = proxy_test_set_int64_sync (parent, proxy, -4815162342); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SAFE { assert0 (proxy_test_get_int64_sync (parent, proxy, &int64_value)); } TEST_EQ (int64_value, -4815162342); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_int64_sync (parent, proxy, 0); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int64.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_int64_sync (parent, proxy, 4); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_int64_sync (parent, proxy, -4815162342); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_uint64_replied; static void my_get_uint64_reply (void * data, NihDBusMessage *message, uint64_t value) { get_uint64_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_uint64_value = value; } void test_get_uint64 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_uint64"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { uint64_property = 4815162342; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint64_replied = FALSE; last_data = NULL; last_uint64_value = 0; pending_call = proxy_test_get_uint64 (proxy, my_get_uint64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_uint64_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_uint64_value, 4815162342); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { uint64_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint64_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_uint64 (proxy, my_get_uint64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_uint64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt64.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { uint64_property = 4; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint64_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_uint64 (proxy, my_get_uint64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_uint64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_uint64 (proxy, my_get_uint64_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_uint64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_uint64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_uint64 (proxy, my_get_uint64_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_uint64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_uint64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_uint64 (proxy, my_get_uint64_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_uint64_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_uint64_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; uint64_t uint64_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_uint64_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { uint64_property = 4815162342; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint64_value = 0; ret = proxy_test_get_uint64_sync (parent, proxy, &uint64_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (uint64_value, 4815162342); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { uint64_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint64_value = 0; ret = proxy_test_get_uint64_sync (parent, proxy, &uint64_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt64.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { uint64_property = 4; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint64_value = 0; ret = proxy_test_get_uint64_sync (parent, proxy, &uint64_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_uint64_sync (parent, proxy, &uint64_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_uint64_replied; static void my_set_uint64_reply (void * data, NihDBusMessage *message) { set_uint64_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_uint64 (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_uint64"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { uint64_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint64_replied = FALSE; last_data = NULL; last_uint64_value = 0; pending_call = proxy_test_set_uint64 (proxy, 4815162342L, my_set_uint64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_uint64_replied); TEST_EQ_P (last_data, parent); TEST_EQ (uint64_property, 4815162342); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint64 (proxy, 0, my_set_uint64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_uint64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt64.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint64 (proxy, 4, my_set_uint64_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_uint64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint64 (proxy, 4815162342L, my_set_uint64_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_uint64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_uint64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint64 (proxy, 4815162342L, my_set_uint64_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_uint64_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_uint64_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_uint64 (proxy, 4815162342L, my_set_uint64_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_uint64_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_uint64_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; uint64_t uint64_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_uint64_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { uint64_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } uint64_value = 0; ret = proxy_test_set_uint64_sync (parent, proxy, 4815162342); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SAFE { assert0 (proxy_test_get_uint64_sync (parent, proxy, &uint64_value)); } TEST_EQ (uint64_value, 4815162342); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_uint64_sync (parent, proxy, 0); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UInt64.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_uint64_sync (parent, proxy, 4); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_uint64_sync (parent, proxy, 4815162342); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_double_replied; static void my_get_double_reply (void * data, NihDBusMessage *message, double value) { get_double_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_double_value = value; } void test_get_double (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_double"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { double_property = 3.141597; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_double_replied = FALSE; last_data = NULL; last_double_value = 0; pending_call = proxy_test_get_dubble (proxy, my_get_double_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_double_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_double_value, 3.141597); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { double_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_double_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_dubble (proxy, my_get_double_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_double_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Double.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { double_property = 4; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_double_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_dubble (proxy, my_get_double_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_double_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_double_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_dubble (proxy, my_get_double_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_double_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_double_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_dubble (proxy, my_get_double_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_double_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_double_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_dubble (proxy, my_get_double_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_double_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_double_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; double double_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_double_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { double_property = 3.141597; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } double_value = 0; ret = proxy_test_get_dubble_sync (parent, proxy, &double_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (double_value, 3.141597); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { double_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } double_value = 0; ret = proxy_test_get_dubble_sync (parent, proxy, &double_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Double.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { double_property = 4; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } double_value = 0; ret = proxy_test_get_dubble_sync (parent, proxy, &double_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_dubble_sync (parent, proxy, &double_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_double_replied; static void my_set_double_reply (void * data, NihDBusMessage *message) { set_double_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_double (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_double"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { double_property = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_double_replied = FALSE; last_data = NULL; last_double_value = 0; pending_call = proxy_test_set_dubble (proxy, 3.141597, my_set_double_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_double_replied); TEST_EQ_P (last_data, parent); TEST_EQ (double_property, 3.141597); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_double_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_dubble (proxy, 0, my_set_double_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_double_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Double.Zero"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_double_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_dubble (proxy, 4, my_set_double_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_double_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_double_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_dubble (proxy, 3.141597, my_set_double_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_double_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_double_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_dubble (proxy, 3.141597, my_set_double_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_double_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_double_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_dubble (proxy, 3.141597, my_set_double_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_double_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_double_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; double double_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_double_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { double_property = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } double_value = 0; ret = proxy_test_set_dubble_sync (parent, proxy, 3.141597); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SAFE { assert0 (proxy_test_get_dubble_sync (parent, proxy, &double_value)); } TEST_EQ (double_value, 3.141597); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_dubble_sync (parent, proxy, 0); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Double.Zero"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_dubble_sync (parent, proxy, 4); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_dubble_sync (parent, proxy, 3.141597); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_string_replied; static void my_get_string_reply (void * data, NihDBusMessage *message, const char * value) { get_string_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_str_value = value; nih_ref (last_str_value, last_data); } void test_get_string (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_string"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { str_property = "she needs more of ze punishment"; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_string_replied = FALSE; last_data = NULL; last_str_value = FALSE; pending_call = proxy_test_get_string (proxy, my_get_string_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_string_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "she needs more of ze punishment"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { str_property = ""; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_string_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_string (proxy, my_get_string_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_string_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.String.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { str_property = "invalid"; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_string_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_string (proxy, my_get_string_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_string_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_string_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_string (proxy, my_get_string_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_string_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_string_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_string (proxy, my_get_string_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_string_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_string_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_string (proxy, my_get_string_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_string_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_string_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_string_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { str_property = "she needs more of ze punishment"; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = 0; ret = proxy_test_get_string_sync (parent, proxy, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "she needs more of ze punishment"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { str_property = ""; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = 0; ret = proxy_test_get_string_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.String.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { str_property = "invalid"; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = 0; ret = proxy_test_get_string_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_string_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_string_replied; static void my_set_string_reply (void * data, NihDBusMessage *message) { set_string_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_string (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_string"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { str_property = NULL; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_string_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_set_string (proxy, "she needs more of ze punishment", my_set_string_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_string_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (str_property, "she needs more of ze punishment"); nih_free (str_property); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_string_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_string (proxy, "", my_set_string_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_string_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.String.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_string_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_string (proxy, "invalid", my_set_string_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_string_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_string_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_string (proxy, "she needs more of ze punishment", my_set_string_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_string_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_string_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_string (proxy, "she needs more of ze punishment", my_set_string_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_string_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_string_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_string (proxy, "she needs more of ze punishment", my_set_string_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_string_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_string_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_string_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { str_property = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); if (str_property) nih_free (str_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_set_string_sync (parent, proxy, "she needs more of ze punishment"); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SAFE { assert0 (proxy_test_get_string_sync (parent, proxy, &str_value)); } TEST_EQ_STR (str_value, "she needs more of ze punishment"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_string_sync (parent, proxy, ""); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.String.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_string_sync (parent, proxy, "invalid"); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_string_sync (parent, proxy, "she needs more of ze punishment"); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_object_path_replied; static void my_get_object_path_reply (void * data, NihDBusMessage *message, const char * value) { get_object_path_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_str_value = value; nih_ref (last_str_value, last_data); } void test_get_object_path (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_object_path"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { object_path_property = "/com/netsplit/Nih/Test"; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_object_path_replied = FALSE; last_data = NULL; last_str_value = FALSE; pending_call = proxy_test_get_object_path (proxy, my_get_object_path_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_object_path_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { object_path_property = "/"; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_object_path_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_object_path (proxy, my_get_object_path_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_object_path_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.ObjectPath.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { object_path_property = "/invalid"; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_object_path_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_object_path (proxy, my_get_object_path_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_object_path_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_object_path_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_object_path (proxy, my_get_object_path_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_object_path_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_object_path_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_object_path (proxy, my_get_object_path_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_object_path_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_object_path_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_object_path (proxy, my_get_object_path_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_object_path_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_object_path_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_object_path_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { object_path_property = "/com/netsplit/Nih/Test"; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = 0; ret = proxy_test_get_object_path_sync (parent, proxy, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { object_path_property = "/"; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = 0; ret = proxy_test_get_object_path_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.ObjectPath.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { object_path_property = "/invalid"; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = 0; ret = proxy_test_get_object_path_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_object_path_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_object_path_replied; static void my_set_object_path_reply (void * data, NihDBusMessage *message) { set_object_path_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_object_path (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_object_path"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { object_path_property = NULL; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_object_path_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_set_object_path (proxy, "/com/netsplit/Nih/Test", my_set_object_path_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_object_path_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (object_path_property, "/com/netsplit/Nih/Test"); nih_free (object_path_property); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_object_path_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_object_path (proxy, "/", my_set_object_path_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_object_path_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.ObjectPath.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_object_path_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_object_path (proxy, "/invalid", my_set_object_path_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_object_path_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_object_path_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_object_path (proxy, "/com/netsplit/Nih/Test", my_set_object_path_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_object_path_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_object_path_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_object_path (proxy, "/com/netsplit/Nih/Test", my_set_object_path_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_object_path_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_object_path_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_object_path (proxy, "/com/netsplit/Nih/Test", my_set_object_path_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_object_path_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_object_path_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_object_path_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { object_path_property = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); if (object_path_property) nih_free (object_path_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_set_object_path_sync (parent, proxy, "/com/netsplit/Nih/Test"); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SAFE { assert0 (proxy_test_get_object_path_sync (parent, proxy, &str_value)); } TEST_EQ_STR (str_value, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_object_path_sync (parent, proxy, "/"); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.ObjectPath.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_object_path_sync (parent, proxy, "/invalid"); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_object_path_sync (parent, proxy, "/com/netsplit/Nih/Test"); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_signature_replied; static void my_get_signature_reply (void * data, NihDBusMessage *message, const char * value) { get_signature_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_str_value = value; nih_ref (last_str_value, last_data); } void test_get_signature (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_signature"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { signature_property = "a(ib)"; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_signature_replied = FALSE; last_data = NULL; last_str_value = FALSE; pending_call = proxy_test_get_signature (proxy, my_get_signature_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_signature_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (last_str_value, "a(ib)"); TEST_ALLOC_PARENT (last_str_value, parent); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { signature_property = ""; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_signature_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_signature (proxy, my_get_signature_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_signature_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Signature.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { signature_property = "inva(x)id"; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_signature_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_signature (proxy, my_get_signature_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_signature_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_signature_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_signature (proxy, my_get_signature_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_signature_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_signature_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_signature (proxy, my_get_signature_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_signature_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_signature_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_signature (proxy, my_get_signature_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_signature_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_signature_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_signature_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { signature_property = "a(ib)"; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = 0; ret = proxy_test_get_signature_sync (parent, proxy, &str_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "a(ib)"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { signature_property = ""; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = 0; ret = proxy_test_get_signature_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Signature.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { signature_property = "inva(x)id"; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = 0; ret = proxy_test_get_signature_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_signature_sync (parent, proxy, &str_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_signature_replied; static void my_set_signature_reply (void * data, NihDBusMessage *message) { set_signature_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_signature (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_signature"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { signature_property = NULL; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_signature_replied = FALSE; last_data = NULL; last_str_value = NULL; pending_call = proxy_test_set_signature (proxy, "a(ib)", my_set_signature_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_signature_replied); TEST_EQ_P (last_data, parent); TEST_EQ_STR (signature_property, "a(ib)"); nih_free (signature_property); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_signature_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_signature (proxy, "", my_set_signature_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_signature_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Signature.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_signature_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_signature (proxy, "inva(x)id", my_set_signature_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_signature_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_signature_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_signature (proxy, "a(ib)", my_set_signature_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_signature_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_signature_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_signature (proxy, "a(ib)", my_set_signature_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_signature_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_signature_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_signature (proxy, "a(ib)", my_set_signature_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_signature_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_signature_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char * str_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_signature_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { signature_property = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); if (signature_property) nih_free (signature_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_value = NULL; ret = proxy_test_set_signature_sync (parent, proxy, "a(ib)"); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SAFE { assert0 (proxy_test_get_signature_sync (parent, proxy, &str_value)); } TEST_EQ_STR (str_value, "a(ib)"); TEST_ALLOC_PARENT (str_value, parent); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_signature_sync (parent, proxy, ""); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Signature.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_signature_sync (parent, proxy, "inva(x)id"); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_signature_sync (parent, proxy, "a(ib)"); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_structure_replied; static void my_get_structure_reply (void * data, NihDBusMessage * message, const ProxyTestStructure *value) { get_structure_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_struct_value = (const MyStruct *)value; nih_ref (last_struct_value, last_data); } void test_get_structure (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_structure"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_property = nih_new (parent, MyStruct); struct_property->item0 = "Joe"; struct_property->item1 = 34; } error_handler_called = FALSE; get_structure_replied = FALSE; last_data = NULL; last_struct_value = FALSE; pending_call = proxy_test_get_structure (proxy, my_get_structure_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_structure_replied); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_struct_value, sizeof (MyStruct)); TEST_ALLOC_PARENT (last_struct_value, parent); TEST_EQ_STR (last_struct_value->item0, "Joe"); TEST_ALLOC_PARENT (last_struct_value->item0, last_struct_value); TEST_EQ (last_struct_value->item1, 34); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_property = nih_new (parent, MyStruct); struct_property->item0 = ""; struct_property->item1 = 34; } error_handler_called = FALSE; get_structure_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_structure (proxy, my_get_structure_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_structure_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Structure.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_property = nih_new (parent, MyStruct); struct_property->item0 = "invalid"; struct_property->item1 = 34; } error_handler_called = FALSE; get_structure_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_structure (proxy, my_get_structure_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_structure_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_structure_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_structure (proxy, my_get_structure_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_structure_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_structure_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_structure (proxy, my_get_structure_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_structure_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_structure_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_structure (proxy, my_get_structure_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_structure_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_structure_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestStructure *struct_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_structure_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { struct_property = nih_new (NULL, MyStruct); struct_property->item0 = "Joe"; struct_property->item1 = 34; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (struct_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } struct_value = NULL; ret = proxy_test_get_structure_sync (parent, proxy, &struct_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (struct_value, sizeof (ProxyTestStructure)); TEST_ALLOC_PARENT (struct_value, parent); TEST_EQ_STR (struct_value->item0, "Joe"); TEST_ALLOC_PARENT (struct_value->item0, struct_value); TEST_EQ (struct_value->item1, 34); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { struct_property = nih_new (NULL, MyStruct); struct_property->item0 = ""; struct_property->item1 = 34; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (struct_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } struct_value = NULL; ret = proxy_test_get_structure_sync (parent, proxy, &struct_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Structure.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { struct_property = nih_new (NULL, MyStruct); struct_property->item0 = "invalid"; struct_property->item1 = 34; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (struct_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } struct_value = NULL; ret = proxy_test_get_structure_sync (parent, proxy, &struct_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_structure_sync (parent, proxy, &struct_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_structure_replied; static void my_set_structure_reply (void * data, NihDBusMessage *message) { set_structure_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_structure (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestStructure *struct_value = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_structure"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { struct_property = NULL; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructure); struct_value->item0 = "Joe"; struct_value->item1 = 34; } error_handler_called = FALSE; set_structure_replied = FALSE; last_data = NULL; pending_call = proxy_test_set_structure (proxy, struct_value, my_set_structure_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_structure_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (struct_property, NULL); TEST_ALLOC_SIZE (struct_property, sizeof (MyStruct)); TEST_EQ_STR (struct_property->item0, "Joe"); TEST_EQ (struct_property->item1, 34); nih_free (struct_property); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructure); struct_value->item0 = ""; struct_value->item1 = 34; } error_handler_called = FALSE; set_structure_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_structure (proxy, struct_value, my_set_structure_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_structure_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Structure.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructure); struct_value->item0 = "invalid"; struct_value->item1 = 34; } error_handler_called = FALSE; set_structure_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_structure (proxy, struct_value, my_set_structure_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_structure_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructure); struct_value->item0 = "Joe"; struct_value->item1 = 34; } error_handler_called = FALSE; set_structure_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_structure (proxy, struct_value, my_set_structure_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_structure_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructure); struct_value->item0 = "Joe"; struct_value->item1 = 34; } error_handler_called = FALSE; set_structure_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_structure (proxy, struct_value, my_set_structure_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_structure_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructure); struct_value->item0 = "Joe"; struct_value->item1 = 34; } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_structure_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_structure (proxy, struct_value, my_set_structure_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_structure_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_structure_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestStructure *struct_value = NULL; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_structure_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { struct_property = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); if (struct_property) nih_free (struct_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructure); struct_value->item0 = "Joe"; struct_value->item1 = 34; } ret = proxy_test_set_structure_sync (parent, proxy, struct_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); nih_free (struct_value); struct_value = NULL; TEST_ALLOC_SAFE { assert0 (proxy_test_get_structure_sync (parent, proxy, &struct_value)); } TEST_ALLOC_SIZE (struct_value, sizeof (ProxyTestStrToStructOutput)); TEST_ALLOC_PARENT (struct_value, parent); TEST_EQ_STR (struct_value->item0, "Joe"); TEST_ALLOC_PARENT (struct_value->item0, struct_value); TEST_EQ (struct_value->item1, 34); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructure); struct_value->item0 = ""; struct_value->item1 = 34; } ret = proxy_test_set_structure_sync (parent, proxy, struct_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Structure.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructure); struct_value->item0 = "invalid"; struct_value->item1 = 34; } ret = proxy_test_set_structure_sync (parent, proxy, struct_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_value = nih_new (parent, ProxyTestStructure); struct_value->item0 = "Joe"; struct_value->item1 = 34; } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_structure_sync (parent, proxy, struct_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_int32_array_replied; static void my_get_int32_array_reply (void * data, NihDBusMessage *message, const int32_t * value, size_t value_len) { get_int32_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); if (value_len) { TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); } last_data = data; last_int32_array = value; if (value) nih_ref (last_int32_array, data); last_int32_array_len = value_len; } void test_get_int32_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_int32_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { int32_array_property = nih_alloc (NULL, sizeof (int32_t) * 6); int32_array_property[0] = 4; int32_array_property[1] = 8; int32_array_property[2] = 15; int32_array_property[3] = 16; int32_array_property[4] = 23; int32_array_property[5] = 42; int32_array_property_len = 6; object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_array_replied = FALSE; last_data = NULL; last_int32_array = NULL; last_int32_array_len = 0; pending_call = proxy_test_get_int32_array ( proxy, my_get_int32_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (int32_array_property); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_EQ (last_int32_array_len, 6); TEST_ALLOC_SIZE (last_int32_array, sizeof (int32_t) * 6); TEST_ALLOC_PARENT (last_int32_array, parent); TEST_EQ (last_int32_array[0], 4); TEST_EQ (last_int32_array[1], 8); TEST_EQ (last_int32_array[2], 15); TEST_EQ (last_int32_array[3], 16); TEST_EQ (last_int32_array[4], 23); TEST_EQ (last_int32_array[5], 42); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (int32_array_property); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { int32_array_property = NULL; int32_array_property_len = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_array_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_int32_array ( proxy, my_get_int32_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32Array.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { int32_array_property = nih_alloc (NULL, sizeof (int32_t) * 4); int32_array_property[0] = 4; int32_array_property[1] = 8; int32_array_property[2] = 15; int32_array_property[3] = 16; int32_array_property_len = 4; object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_array_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_int32_array ( proxy, my_get_int32_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (int32_array_property); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (int32_array_property); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int32_array ( proxy, my_get_int32_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int32_array ( proxy, my_get_int32_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_int32_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int32_array ( proxy, my_get_int32_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_int32_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_int32_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t * int32_array; size_t int32_array_len; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_int32_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { int32_array_property = nih_alloc (NULL, sizeof (int32_t) * 6); int32_array_property[0] = 4; int32_array_property[1] = 8; int32_array_property[2] = 15; int32_array_property[3] = 16; int32_array_property[4] = 23; int32_array_property[5] = 42; int32_array_property_len = 6; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (int32_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_array = NULL; int32_array_len = 0; ret = proxy_test_get_int32_array_sync (parent, proxy, &int32_array, &int32_array_len); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_EQ (int32_array_len, 6); TEST_ALLOC_SIZE (int32_array, sizeof (int32_t) * 6); TEST_ALLOC_PARENT (int32_array, parent); TEST_EQ (int32_array[0], 4); TEST_EQ (int32_array[1], 8); TEST_EQ (int32_array[2], 15); TEST_EQ (int32_array[3], 16); TEST_EQ (int32_array[4], 23); TEST_EQ (int32_array[5], 42); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { int32_array_property = NULL; int32_array_property_len = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_array = NULL; int32_array_len = 0; ret = proxy_test_get_int32_array_sync (parent, proxy, &int32_array, &int32_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32Array.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { int32_array_property = nih_alloc (NULL, sizeof (int32_t) * 4); int32_array_property[0] = 4; int32_array_property[1] = 8; int32_array_property[2] = 15; int32_array_property[3] = 16; int32_array_property_len = 4; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (int32_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_array = NULL; int32_array_len = 0; ret = proxy_test_get_int32_array_sync (parent, proxy, &int32_array, &int32_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_int32_array_sync (parent, proxy, &int32_array, &int32_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_int32_array_replied; static void my_set_int32_array_reply (void * data, NihDBusMessage *message) { set_int32_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_int32_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t * int32_array = NULL; size_t int32_array_len; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_int32_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { int32_array_property = NULL; int32_array_property_len = 0; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; int32_array_len = 6; } error_handler_called = FALSE; set_int32_array_replied = FALSE; last_data = NULL; last_int32_array = NULL; last_int32_array_len = 0; pending_call = proxy_test_set_int32_array ( proxy, int32_array, int32_array_len, my_set_int32_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_EQ (int32_array_property_len, 6); TEST_ALLOC_SIZE (int32_array_property, sizeof (int32_t) * 6); TEST_EQ (int32_array_property[0], 4); TEST_EQ (int32_array_property[1], 8); TEST_EQ (int32_array_property[2], 15); TEST_EQ (int32_array_property[3], 16); TEST_EQ (int32_array_property[4], 23); TEST_EQ (int32_array_property[5], 42); nih_free (int32_array_property); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_int32_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32_array ( proxy, NULL, 0, my_set_int32_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32Array.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 4); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array_len = 4; } error_handler_called = FALSE; set_int32_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32_array ( proxy, int32_array, int32_array_len, my_set_int32_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; int32_array_len = 6; } error_handler_called = FALSE; set_int32_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32_array ( proxy, int32_array, int32_array_len, my_set_int32_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; int32_array_len = 6; } error_handler_called = FALSE; set_int32_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32_array ( proxy, int32_array, int32_array_len, my_set_int32_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int32_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; int32_array_len = 6; } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_int32_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32_array ( proxy, int32_array, int32_array_len, my_set_int32_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_int32_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_int32_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t * int32_array; size_t int32_array_len; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_int32_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { int32_array_property = NULL; int32_array_property_len = 0; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); if (int32_array_property) nih_free (int32_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; int32_array_len = 6; } ret = proxy_test_set_int32_array_sync (parent, proxy, int32_array, int32_array_len); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); nih_free (int32_array); TEST_ALLOC_SAFE { assert0 (proxy_test_get_int32_array_sync ( parent, proxy, &int32_array, &int32_array_len)); } TEST_EQ (int32_array_len, 6); TEST_ALLOC_SIZE (int32_array, sizeof (int32_t) * 6); TEST_ALLOC_PARENT (int32_array, parent); TEST_EQ (int32_array[0], 4); TEST_EQ (int32_array[1], 8); TEST_EQ (int32_array[2], 15); TEST_EQ (int32_array[3], 16); TEST_EQ (int32_array[4], 23); TEST_EQ (int32_array[5], 42); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } ret = proxy_test_set_int32_array_sync (parent, proxy, NULL, 0); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32Array.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 4); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array_len = 4; } ret = proxy_test_set_int32_array_sync (parent, proxy, int32_array, int32_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array = nih_alloc (parent, sizeof (int32_t) * 6); int32_array[0] = 4; int32_array[1] = 8; int32_array[2] = 15; int32_array[3] = 16; int32_array[4] = 23; int32_array[5] = 42; int32_array_len = 6; } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_int32_array_sync (parent, proxy, int32_array, int32_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_str_array_replied; static void my_get_str_array_reply (void * data, NihDBusMessage *message, char * const * value) { get_str_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_str_array = value; nih_ref (last_str_array, data); } void test_get_str_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_str_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str_array_property = nih_alloc (NULL, sizeof (char *) * 7); str_array_property[0] = "she"; str_array_property[1] = "needs"; str_array_property[2] = "more"; str_array_property[3] = "of"; str_array_property[4] = "ze"; str_array_property[5] = "punishment"; str_array_property[6] = NULL; object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_str_array_replied = FALSE; last_data = NULL; last_str_array = NULL; pending_call = proxy_test_get_str_array ( proxy, my_get_str_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (str_array_property); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_str_array_replied); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_str_array, sizeof (char *) * 7); TEST_ALLOC_PARENT (last_str_array, parent); TEST_EQ_STR (last_str_array[0], "she"); TEST_ALLOC_PARENT (last_str_array[0], last_str_array); TEST_EQ_STR (last_str_array[1], "needs"); TEST_ALLOC_PARENT (last_str_array[1], last_str_array); TEST_EQ_STR (last_str_array[2], "more"); TEST_ALLOC_PARENT (last_str_array[2], last_str_array); TEST_EQ_STR (last_str_array[3], "of"); TEST_ALLOC_PARENT (last_str_array[3], last_str_array); TEST_EQ_STR (last_str_array[4], "ze"); TEST_ALLOC_PARENT (last_str_array[4], last_str_array); TEST_EQ_STR (last_str_array[5], "punishment"); TEST_ALLOC_PARENT (last_str_array[5], last_str_array); TEST_EQ_P (last_str_array[6], NULL); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (str_array_property); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str_array_property = nih_alloc (NULL, sizeof (char *) * 1); str_array_property[0] = NULL; object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_str_array_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_str_array ( proxy, my_get_str_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (str_array_property); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_str_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrArray.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (str_array_property); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str_array_property = nih_alloc (NULL, sizeof (char *) * 5); str_array_property[0] = "this"; str_array_property[1] = "is"; str_array_property[2] = "a"; str_array_property[3] = "test"; str_array_property[4] = NULL; object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_str_array_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_str_array ( proxy, my_get_str_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (str_array_property); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_str_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (str_array_property); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_str_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_str_array ( proxy, my_get_str_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_str_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_str_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_str_array ( proxy, my_get_str_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_str_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_str_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_str_array ( proxy, my_get_str_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_str_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_str_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char ** str_array; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_str_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { str_array_property = nih_alloc (NULL, sizeof (char *) * 7); str_array_property[0] = "she"; str_array_property[1] = "needs"; str_array_property[2] = "more"; str_array_property[3] = "of"; str_array_property[4] = "ze"; str_array_property[5] = "punishment"; str_array_property[6] = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (str_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_array = NULL; ret = proxy_test_get_str_array_sync (parent, proxy, &str_array); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (str_array, sizeof (char *) * 7); TEST_ALLOC_PARENT (str_array, parent); TEST_EQ_STR (str_array[0], "she"); TEST_ALLOC_PARENT (str_array[0], str_array); TEST_EQ_STR (str_array[1], "needs"); TEST_ALLOC_PARENT (str_array[1], str_array); TEST_EQ_STR (str_array[2], "more"); TEST_ALLOC_PARENT (str_array[2], str_array); TEST_EQ_STR (str_array[3], "of"); TEST_ALLOC_PARENT (str_array[3], str_array); TEST_EQ_STR (str_array[4], "ze"); TEST_ALLOC_PARENT (str_array[4], str_array); TEST_EQ_STR (str_array[5], "punishment"); TEST_ALLOC_PARENT (str_array[5], str_array); TEST_EQ_P (str_array[6], NULL); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { str_array_property = nih_alloc (NULL, sizeof (char *) * 1); str_array_property[0] = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (str_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_array = NULL; ret = proxy_test_get_str_array_sync (parent, proxy, &str_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrArray.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { str_array_property = nih_alloc (NULL, sizeof (char *) * 5); str_array_property[0] = "this"; str_array_property[1] = "is"; str_array_property[2] = "a"; str_array_property[3] = "test"; str_array_property[4] = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (str_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } str_array = NULL; ret = proxy_test_get_str_array_sync (parent, proxy, &str_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_str_array_sync (parent, proxy, &str_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_str_array_replied; static void my_set_str_array_reply (void * data, NihDBusMessage *message) { set_str_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_str_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char ** str_array = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_str_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { str_array_property = NULL; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; } error_handler_called = FALSE; set_str_array_replied = FALSE; last_data = NULL; last_str_array = NULL; pending_call = proxy_test_set_str_array ( proxy, str_array, my_set_str_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_str_array_replied); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (str_array_property, sizeof (char *) * 7); TEST_EQ_STR (str_array_property[0], "she"); TEST_ALLOC_PARENT (str_array_property[0], str_array_property); TEST_EQ_STR (str_array_property[1], "needs"); TEST_ALLOC_PARENT (str_array_property[1], str_array_property); TEST_EQ_STR (str_array_property[2], "more"); TEST_ALLOC_PARENT (str_array_property[2], str_array_property); TEST_EQ_STR (str_array_property[3], "of"); TEST_ALLOC_PARENT (str_array_property[3], str_array_property); TEST_EQ_STR (str_array_property[4], "ze"); TEST_ALLOC_PARENT (str_array_property[4], str_array_property); TEST_EQ_STR (str_array_property[5], "punishment"); TEST_ALLOC_PARENT (str_array_property[5], str_array_property); TEST_EQ_P (str_array_property[6], NULL); nih_free (str_array_property); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 1); str_array[0] = NULL; } error_handler_called = FALSE; set_str_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_str_array ( proxy, str_array, my_set_str_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_str_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrArray.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 5); str_array[0] = "this"; str_array[1] = "is"; str_array[2] = "a"; str_array[3] = "test"; str_array[4] = NULL; } error_handler_called = FALSE; set_str_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_str_array ( proxy, str_array, my_set_str_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_str_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; } error_handler_called = FALSE; set_str_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_str_array ( proxy, str_array, my_set_str_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_str_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; } error_handler_called = FALSE; set_str_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_str_array ( proxy, str_array, my_set_str_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_str_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_str_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_str_array ( proxy, str_array, my_set_str_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_str_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_str_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; char ** str_array; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_str_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { str_array_property = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); if (str_array_property) nih_free (str_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; } ret = proxy_test_set_str_array_sync (parent, proxy, str_array); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); nih_free (str_array); TEST_ALLOC_SAFE { assert0 (proxy_test_get_str_array_sync ( parent, proxy, &str_array)); } TEST_ALLOC_SIZE (str_array, sizeof (char *) * 7); TEST_ALLOC_PARENT (str_array, parent); TEST_EQ_STR (str_array[0], "she"); TEST_ALLOC_PARENT (str_array[0], str_array); TEST_EQ_STR (str_array[1], "needs"); TEST_ALLOC_PARENT (str_array[1], str_array); TEST_EQ_STR (str_array[2], "more"); TEST_ALLOC_PARENT (str_array[2], str_array); TEST_EQ_STR (str_array[3], "of"); TEST_ALLOC_PARENT (str_array[3], str_array); TEST_EQ_STR (str_array[4], "ze"); TEST_ALLOC_PARENT (str_array[4], str_array); TEST_EQ_STR (str_array[5], "punishment"); TEST_ALLOC_PARENT (str_array[5], str_array); TEST_EQ_P (str_array[6], NULL); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 1); str_array[0] = NULL; } ret = proxy_test_set_str_array_sync (parent, proxy, str_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StrArray.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 5); str_array[0] = "this"; str_array[1] = "is"; str_array[2] = "a"; str_array[3] = "test"; str_array[4] = NULL; } ret = proxy_test_set_str_array_sync (parent, proxy, str_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); str_array = nih_alloc (parent, sizeof (char *) * 7); str_array[0] = "she"; str_array[1] = "needs"; str_array[2] = "more"; str_array[3] = "of"; str_array[4] = "ze"; str_array[5] = "punishment"; str_array[6] = NULL; } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_str_array_sync (parent, proxy, str_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_int32_array_array_replied; static void my_get_int32_array_array_reply (void * data, NihDBusMessage * message, int32_t * const *value, const size_t * value_len) { get_int32_array_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); if (*value) { TEST_NE_P (value_len, NULL); TEST_ALLOC_PARENT (value_len, value); } last_data = data; last_int32_array_array = value; nih_ref (last_int32_array_array, data); last_int32_array_array_len = value_len; if (value_len) nih_ref (last_int32_array_array_len, data); } void test_get_int32_array_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_int32_array_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { int32_array_array_property = nih_alloc (NULL, sizeof (int32_t *) * 3); int32_array_array_property_len = nih_alloc (int32_array_array_property, sizeof (size_t) * 2); int32_array_array_property[0] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[0][0] = 4; int32_array_array_property[0][1] = 8; int32_array_array_property[0][2] = 15; int32_array_array_property[0][3] = 16; int32_array_array_property[0][4] = 23; int32_array_array_property[0][5] = 42; int32_array_array_property_len[0] = 6; int32_array_array_property[1] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[1][0] = 1; int32_array_array_property[1][1] = 1; int32_array_array_property[1][2] = 2; int32_array_array_property[1][3] = 3; int32_array_array_property[1][4] = 5; int32_array_array_property[1][5] = 8; int32_array_array_property_len[1] = 6; int32_array_array_property[2] = NULL; object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_array_array_replied = FALSE; last_data = NULL; last_int32_array_array = NULL; last_int32_array_array_len = NULL; pending_call = proxy_test_get_int32_array_array ( proxy, my_get_int32_array_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (int32_array_array_property); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_int32_array_array, sizeof (int32_t *) * 3); TEST_ALLOC_PARENT (last_int32_array_array, parent); TEST_ALLOC_SIZE (last_int32_array_array_len, sizeof (size_t) * 2); TEST_ALLOC_PARENT (last_int32_array_array_len, last_int32_array_array); TEST_EQ (last_int32_array_array_len[0], 6); TEST_ALLOC_SIZE (last_int32_array_array[0], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (last_int32_array_array[0], last_int32_array_array); TEST_EQ (last_int32_array_array[0][0], 4); TEST_EQ (last_int32_array_array[0][1], 8); TEST_EQ (last_int32_array_array[0][2], 15); TEST_EQ (last_int32_array_array[0][3], 16); TEST_EQ (last_int32_array_array[0][4], 23); TEST_EQ (last_int32_array_array[0][5], 42); TEST_EQ (last_int32_array_array_len[1], 6); TEST_ALLOC_SIZE (last_int32_array_array[1], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (last_int32_array_array[1], last_int32_array_array); TEST_EQ (last_int32_array_array[1][0], 1); TEST_EQ (last_int32_array_array[1][1], 1); TEST_EQ (last_int32_array_array[1][2], 2); TEST_EQ (last_int32_array_array[1][3], 3); TEST_EQ (last_int32_array_array[1][4], 5); TEST_EQ (last_int32_array_array[1][5], 8); TEST_EQ_P (last_int32_array_array[2], NULL); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (int32_array_array_property); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { int32_array_array_property = nih_alloc (NULL, sizeof (int32_t *) * 1); int32_array_array_property_len = NULL; int32_array_array_property[0] = NULL; object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_array_array_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_int32_array_array ( proxy, my_get_int32_array_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (int32_array_array_property); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32ArrayArray.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (int32_array_array_property); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { int32_array_array_property = nih_alloc (NULL, sizeof (int32_t *) * 2); int32_array_array_property_len = nih_alloc (int32_array_array_property, sizeof (size_t) * 1); int32_array_array_property[0] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[0][0] = 4; int32_array_array_property[0][1] = 8; int32_array_array_property[0][2] = 15; int32_array_array_property[0][3] = 16; int32_array_array_property[0][4] = 23; int32_array_array_property[0][5] = 42; int32_array_array_property_len[0] = 6; int32_array_array_property[1] = NULL; object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_array_array_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_int32_array_array ( proxy, my_get_int32_array_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (int32_array_array_property_len); nih_free (int32_array_array_property); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); nih_free (int32_array_array_property_len); nih_free (int32_array_array_property); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_array_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int32_array_array ( proxy, my_get_int32_array_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_int32_array_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int32_array_array ( proxy, my_get_int32_array_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_int32_array_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_int32_array_array ( proxy, my_get_int32_array_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_int32_array_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_int32_array_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t ** int32_array_array; size_t * int32_array_array_len; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_int32_array_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { int32_array_array_property = nih_alloc (NULL, sizeof (int32_t *) * 3); int32_array_array_property_len = nih_alloc (int32_array_array_property, sizeof (size_t) * 2); int32_array_array_property[0] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[0][0] = 4; int32_array_array_property[0][1] = 8; int32_array_array_property[0][2] = 15; int32_array_array_property[0][3] = 16; int32_array_array_property[0][4] = 23; int32_array_array_property[0][5] = 42; int32_array_array_property_len[0] = 6; int32_array_array_property[1] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[1][0] = 1; int32_array_array_property[1][1] = 1; int32_array_array_property[1][2] = 2; int32_array_array_property[1][3] = 3; int32_array_array_property[1][4] = 5; int32_array_array_property[1][5] = 8; int32_array_array_property_len[1] = 6; int32_array_array_property[2] = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (int32_array_array_property_len); nih_free (int32_array_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_array_array = NULL; int32_array_array_len = NULL; ret = proxy_test_get_int32_array_array_sync (parent, proxy, &int32_array_array, &int32_array_array_len); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (int32_array_array, sizeof (int32_t *) * 3); TEST_ALLOC_PARENT (int32_array_array, parent); TEST_ALLOC_SIZE (int32_array_array_len, sizeof (size_t) * 2); TEST_ALLOC_PARENT (int32_array_array_len, int32_array_array); TEST_EQ (int32_array_array_len[0], 6); TEST_ALLOC_SIZE (int32_array_array[0], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (int32_array_array[0], int32_array_array); TEST_EQ (int32_array_array[0][0], 4); TEST_EQ (int32_array_array[0][1], 8); TEST_EQ (int32_array_array[0][2], 15); TEST_EQ (int32_array_array[0][3], 16); TEST_EQ (int32_array_array[0][4], 23); TEST_EQ (int32_array_array[0][5], 42); TEST_EQ (int32_array_array_len[1], 6); TEST_ALLOC_SIZE (int32_array_array[1], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (int32_array_array[1], int32_array_array); TEST_EQ (int32_array_array[1][0], 1); TEST_EQ (int32_array_array[1][1], 1); TEST_EQ (int32_array_array[1][2], 2); TEST_EQ (int32_array_array[1][3], 3); TEST_EQ (int32_array_array[1][4], 5); TEST_EQ (int32_array_array[1][5], 8); TEST_EQ_P (int32_array_array[2], NULL); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { int32_array_array_property = nih_alloc (NULL, sizeof (int32_t *) * 1); int32_array_array_property_len = NULL; int32_array_array_property[0] = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (int32_array_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_array_array = NULL; int32_array_array_len = NULL; ret = proxy_test_get_int32_array_array_sync (parent, proxy, &int32_array_array, &int32_array_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32ArrayArray.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { int32_array_array_property = nih_alloc (NULL, sizeof (int32_t *) * 2); int32_array_array_property_len = nih_alloc (int32_array_array_property, sizeof (size_t) * 1); int32_array_array_property[0] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[0][0] = 4; int32_array_array_property[0][1] = 8; int32_array_array_property[0][2] = 15; int32_array_array_property[0][3] = 16; int32_array_array_property[0][4] = 23; int32_array_array_property[0][5] = 42; int32_array_array_property_len[0] = 6; int32_array_array_property[1] = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (int32_array_array_property_len); nih_free (int32_array_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } int32_array_array = NULL; int32_array_array_len = NULL; ret = proxy_test_get_int32_array_array_sync (parent, proxy, &int32_array_array, &int32_array_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_int32_array_array_sync (parent, proxy, &int32_array_array, &int32_array_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_int32_array_array_replied; static void my_set_int32_array_array_reply (void * data, NihDBusMessage *message) { set_int32_array_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_int32_array_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t ** int32_array_array = NULL; size_t * int32_array_array_len = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_int32_array_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { int32_array_array_property = NULL; int32_array_array_property_len = NULL; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (int32_array_array, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; } error_handler_called = FALSE; set_int32_array_array_replied = FALSE; last_data = NULL; last_int32_array_array = NULL; last_int32_array_array_len = NULL; pending_call = proxy_test_set_int32_array_array ( proxy, int32_array_array, int32_array_array_len, my_set_int32_array_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (int32_array_array_property, sizeof (int32_t *) * 3); TEST_ALLOC_SIZE (int32_array_array_property_len, sizeof (size_t) * 2); TEST_EQ (int32_array_array_property_len[0], 6); TEST_ALLOC_SIZE (int32_array_array_property[0], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (int32_array_array_property[0], int32_array_array_property); TEST_EQ (int32_array_array_property[0][0], 4); TEST_EQ (int32_array_array_property[0][1], 8); TEST_EQ (int32_array_array_property[0][2], 15); TEST_EQ (int32_array_array_property[0][3], 16); TEST_EQ (int32_array_array_property[0][4], 23); TEST_EQ (int32_array_array_property[0][5], 42); TEST_EQ (int32_array_array_property_len[1], 6); TEST_ALLOC_SIZE (int32_array_array_property[1], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (int32_array_array_property[1], int32_array_array_property); TEST_EQ (int32_array_array_property[1][0], 1); TEST_EQ (int32_array_array_property[1][1], 1); TEST_EQ (int32_array_array_property[1][2], 2); TEST_EQ (int32_array_array_property[1][3], 3); TEST_EQ (int32_array_array_property[1][4], 5); TEST_EQ (int32_array_array_property[1][5], 8); TEST_EQ_P (int32_array_array_property[2], NULL); nih_free (int32_array_array_property_len); nih_free (int32_array_array_property); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 1); int32_array_array_len = NULL; int32_array_array[0] = NULL; } error_handler_called = FALSE; set_int32_array_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32_array_array ( proxy, int32_array_array, int32_array_array_len, my_set_int32_array_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32ArrayArray.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 2); int32_array_array_len = nih_alloc (int32_array_array, sizeof (size_t) * 1); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = NULL; } error_handler_called = FALSE; set_int32_array_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32_array_array ( proxy, int32_array_array, int32_array_array_len, my_set_int32_array_array_reply, my_error_handler, parent, NIH_DBUS_TIMEOUT_DEFAULT); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (int32_array_array, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; } error_handler_called = FALSE; set_int32_array_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32_array_array ( proxy, int32_array_array, int32_array_array_len, my_set_int32_array_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (int32_array_array, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; } error_handler_called = FALSE; set_int32_array_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32_array_array ( proxy, int32_array_array, int32_array_array_len, my_set_int32_array_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_int32_array_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (int32_array_array, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_int32_array_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_int32_array_array ( proxy, int32_array_array, int32_array_array_len, my_set_int32_array_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_int32_array_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_int32_array_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int32_t ** int32_array_array; size_t * int32_array_array_len; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_int32_array_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { int32_array_array_property = NULL; int32_array_array_property_len = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); if (int32_array_array_property_len) nih_free (int32_array_array_property_len); if (int32_array_array_property) nih_free (int32_array_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (int32_array_array, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; } ret = proxy_test_set_int32_array_array_sync (parent, proxy, int32_array_array, int32_array_array_len); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); nih_free (int32_array_array); TEST_ALLOC_SAFE { assert0 (proxy_test_get_int32_array_array_sync ( parent, proxy, &int32_array_array, &int32_array_array_len)); } TEST_ALLOC_SIZE (int32_array_array, sizeof (int32_t *) * 3); TEST_ALLOC_PARENT (int32_array_array, parent); TEST_ALLOC_SIZE (int32_array_array_len, sizeof (size_t) * 2); TEST_ALLOC_PARENT (int32_array_array_len, int32_array_array); TEST_EQ (int32_array_array_len[0], 6); TEST_ALLOC_SIZE (int32_array_array[0], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (int32_array_array[0], int32_array_array); TEST_EQ (int32_array_array[0][0], 4); TEST_EQ (int32_array_array[0][1], 8); TEST_EQ (int32_array_array[0][2], 15); TEST_EQ (int32_array_array[0][3], 16); TEST_EQ (int32_array_array[0][4], 23); TEST_EQ (int32_array_array[0][5], 42); TEST_EQ (int32_array_array_len[1], 6); TEST_ALLOC_SIZE (int32_array_array[1], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (int32_array_array[1], int32_array_array); TEST_EQ (int32_array_array[1][0], 1); TEST_EQ (int32_array_array[1][1], 1); TEST_EQ (int32_array_array[1][2], 2); TEST_EQ (int32_array_array[1][3], 3); TEST_EQ (int32_array_array[1][4], 5); TEST_EQ (int32_array_array[1][5], 8); TEST_EQ_P (int32_array_array[2], NULL); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 1); int32_array_array_len = NULL; int32_array_array[0] = NULL; } ret = proxy_test_set_int32_array_array_sync (parent, proxy, int32_array_array, int32_array_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32ArrayArray.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 2); int32_array_array_len = nih_alloc (int32_array_array, sizeof (size_t) * 1); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = NULL; } ret = proxy_test_set_int32_array_array_sync (parent, proxy, int32_array_array, int32_array_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); int32_array_array = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_len = nih_alloc (int32_array_array, sizeof (size_t) * 2); int32_array_array[0] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[0][0] = 4; int32_array_array[0][1] = 8; int32_array_array[0][2] = 15; int32_array_array[0][3] = 16; int32_array_array[0][4] = 23; int32_array_array[0][5] = 42; int32_array_array_len[0] = 6; int32_array_array[1] = nih_alloc (int32_array_array, sizeof (int32_t) * 6); int32_array_array[1][0] = 1; int32_array_array[1][1] = 1; int32_array_array[1][2] = 2; int32_array_array[1][3] = 3; int32_array_array[1][4] = 5; int32_array_array[1][5] = 8; int32_array_array_len[1] = 6; int32_array_array[2] = NULL; } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_int32_array_array_sync (parent, proxy, int32_array_array, int32_array_array_len); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_struct_array_replied; static void my_get_struct_array_reply (void * data, NihDBusMessage *message, ProxyTestStructArrayElement * const *value) { get_struct_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_struct_array = (MyStruct * const *)value; nih_ref (last_struct_array, last_data); } void test_get_struct_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_struct_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); struct_array_property[0] = nih_new (struct_array_property, MyStruct); struct_array_property[0]->item0 = "Joe"; struct_array_property[0]->item1 = 34; struct_array_property[1] = nih_new (struct_array_property, MyStruct); struct_array_property[1]->item0 = "Paul"; struct_array_property[1]->item1 = 27; struct_array_property[2] = NULL; } error_handler_called = FALSE; get_struct_array_replied = FALSE; last_data = NULL; last_struct_array = FALSE; pending_call = proxy_test_get_struct_array (proxy, my_get_struct_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_struct_array, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (last_struct_array, parent); TEST_ALLOC_SIZE (last_struct_array[0], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_struct_array[0], last_struct_array); TEST_EQ_STR (last_struct_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (last_struct_array[0]->item0, last_struct_array[0]); TEST_EQ (last_struct_array[0]->item1, 34); TEST_ALLOC_SIZE (last_struct_array[1], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_struct_array[1], last_struct_array); TEST_EQ_STR (last_struct_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (last_struct_array[1]->item0, last_struct_array[1]); TEST_EQ (last_struct_array[1]->item1, 27); TEST_EQ_P (last_struct_array[2], NULL); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); struct_array_property[0] = NULL; } error_handler_called = FALSE; get_struct_array_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_struct_array (proxy, my_get_struct_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StructArray.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array_property = nih_alloc (parent, sizeof (MyStruct *) * 2); struct_array_property[0] = nih_new (struct_array_property, MyStruct); struct_array_property[0]->item0 = "Joe"; struct_array_property[0]->item1 = 34; struct_array_property[1] = NULL; } error_handler_called = FALSE; get_struct_array_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_struct_array (proxy, my_get_struct_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_struct_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_struct_array (proxy, my_get_struct_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_struct_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_struct_array (proxy, my_get_struct_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_struct_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_struct_array (proxy, my_get_struct_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_struct_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_struct_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestStructArrayElement **struct_array; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_struct_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { struct_array_property = nih_alloc (NULL, sizeof (MyStruct *) * 3); struct_array_property[0] = nih_new (struct_array_property, MyStruct); struct_array_property[0]->item0 = "Joe"; struct_array_property[0]->item1 = 34; struct_array_property[1] = nih_new (struct_array_property, MyStruct); struct_array_property[1]->item0 = "Paul"; struct_array_property[1]->item1 = 27; struct_array_property[2] = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (struct_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } struct_array = NULL; ret = proxy_test_get_struct_array_sync (parent, proxy, &struct_array); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (struct_array, sizeof (ProxyTestStrToStructArrayOutputElement *) * 3); TEST_ALLOC_PARENT (struct_array, parent); TEST_ALLOC_SIZE (struct_array[0], sizeof (ProxyTestStrToStructArrayOutputElement)); TEST_ALLOC_PARENT (struct_array[0], struct_array); TEST_EQ_STR (struct_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (struct_array[0]->item0, struct_array[0]); TEST_EQ (struct_array[0]->item1, 34); TEST_ALLOC_SIZE (struct_array[1], sizeof (ProxyTestStrToStructArrayOutputElement)); TEST_ALLOC_PARENT (struct_array[1], struct_array); TEST_EQ_STR (struct_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (struct_array[1]->item0, struct_array[1]); TEST_EQ (struct_array[1]->item1, 27); TEST_EQ_P (struct_array[2], NULL); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { struct_array_property = nih_alloc (NULL, sizeof (MyStruct *) * 1); struct_array_property[0] = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (struct_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } struct_array = NULL; ret = proxy_test_get_struct_array_sync (parent, proxy, &struct_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StructArray.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { struct_array_property = nih_alloc (NULL, sizeof (MyStruct *) * 2); struct_array_property[0] = nih_new (struct_array_property, MyStruct); struct_array_property[0]->item0 = "Joe"; struct_array_property[0]->item1 = 34; struct_array_property[1] = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (struct_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } struct_array = NULL; ret = proxy_test_get_struct_array_sync (parent, proxy, &struct_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_struct_array_sync (parent, proxy, &struct_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_struct_array_replied; static void my_set_struct_array_reply (void * data, NihDBusMessage *message) { set_struct_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_struct_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestStructArrayElement **struct_array = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_struct_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { struct_array_property = NULL; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayElement) * 3); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; } error_handler_called = FALSE; set_struct_array_replied = FALSE; last_data = NULL; pending_call = proxy_test_set_struct_array (proxy, struct_array, my_set_struct_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (struct_array_property, NULL); TEST_ALLOC_SIZE (struct_array_property, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (struct_array_property[0], struct_array_property); TEST_ALLOC_SIZE (struct_array_property[0], sizeof (MyStruct)); TEST_EQ_STR (struct_array_property[0]->item0, "Joe"); TEST_EQ (struct_array_property[0]->item1, 34); TEST_ALLOC_PARENT (struct_array_property[1], struct_array_property); TEST_ALLOC_SIZE (struct_array_property[1], sizeof (MyStruct)); TEST_EQ_STR (struct_array_property[1]->item0, "Paul"); TEST_EQ (struct_array_property[1]->item1, 27); TEST_EQ_P (struct_array_property[2], NULL); nih_free (struct_array_property); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayElement) * 1); struct_array[0] = NULL; } error_handler_called = FALSE; set_struct_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_struct_array (proxy, struct_array, my_set_struct_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StructArray.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayElement) * 2); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = NULL; } error_handler_called = FALSE; set_struct_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_struct_array (proxy, struct_array, my_set_struct_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayElement) * 3); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; } error_handler_called = FALSE; set_struct_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_struct_array (proxy, struct_array, my_set_struct_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayElement) * 3); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; } error_handler_called = FALSE; set_struct_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_struct_array (proxy, struct_array, my_set_struct_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_struct_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayElement) * 3); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_struct_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_struct_array (proxy, struct_array, my_set_struct_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_struct_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_struct_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestStructArrayElement **struct_array = NULL; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_struct_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { struct_array_property = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); if (struct_array_property) nih_free (struct_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayElement) * 3); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; } ret = proxy_test_set_struct_array_sync (parent, proxy, struct_array); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); nih_free (struct_array); struct_array = NULL; TEST_ALLOC_SAFE { assert0 (proxy_test_get_struct_array_sync (parent, proxy, &struct_array)); } TEST_ALLOC_SIZE (struct_array, sizeof (ProxyTestStrToStructArrayOutputElement *) * 3); TEST_ALLOC_PARENT (struct_array, parent); TEST_ALLOC_SIZE (struct_array[0], sizeof (ProxyTestStrToStructArrayOutputElement)); TEST_ALLOC_PARENT (struct_array[0], struct_array); TEST_EQ_STR (struct_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (struct_array[0]->item0, struct_array[0]); TEST_EQ (struct_array[0]->item1, 34); TEST_ALLOC_SIZE (struct_array[1], sizeof (ProxyTestStrToStructArrayOutputElement)); TEST_ALLOC_PARENT (struct_array[1], struct_array); TEST_EQ_STR (struct_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (struct_array[1]->item0, struct_array[1]); TEST_EQ (struct_array[1]->item1, 27); TEST_EQ_P (struct_array[2], NULL); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayElement) * 1); struct_array[0] = NULL; } ret = proxy_test_set_struct_array_sync (parent, proxy, struct_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.StructArray.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayElement) * 2); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = NULL; } ret = proxy_test_set_struct_array_sync (parent, proxy, struct_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); struct_array = nih_alloc (parent, sizeof (ProxyTestStructArrayElement) * 3); struct_array[0] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[0]->item0 = "Joe"; struct_array[0]->item1 = 34; struct_array[1] = nih_new (struct_array, ProxyTestStructArrayElement); struct_array[1]->item0 = "Paul"; struct_array[1]->item1 = 27; struct_array[2] = NULL; } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_struct_array_sync (parent, proxy, struct_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_dict_entry_array_replied; static void my_get_dict_entry_array_reply (void * data, NihDBusMessage *message, ProxyTestDictEntryArrayElement * const *value) { get_dict_entry_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_ALLOC_PARENT (value, message); last_data = data; last_dict_entry_array = (MyStruct * const *)value; nih_ref (last_dict_entry_array, last_data); } void test_get_dict_entry_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_dict_entry_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); dict_entry_array_property[0] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[0]->item0 = "Joe"; dict_entry_array_property[0]->item1 = 34; dict_entry_array_property[1] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[1]->item0 = "Paul"; dict_entry_array_property[1]->item1 = 27; dict_entry_array_property[2] = NULL; } error_handler_called = FALSE; get_dict_entry_array_replied = FALSE; last_data = NULL; last_dict_entry_array = FALSE; pending_call = proxy_test_get_dict_entry_array (proxy, my_get_dict_entry_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_dict_entry_array, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (last_dict_entry_array, parent); TEST_ALLOC_SIZE (last_dict_entry_array[0], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_dict_entry_array[0], last_dict_entry_array); TEST_EQ_STR (last_dict_entry_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (last_dict_entry_array[0]->item0, last_dict_entry_array[0]); TEST_EQ (last_dict_entry_array[0]->item1, 34); TEST_ALLOC_SIZE (last_dict_entry_array[1], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_dict_entry_array[1], last_dict_entry_array); TEST_EQ_STR (last_dict_entry_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (last_dict_entry_array[1]->item0, last_dict_entry_array[1]); TEST_EQ (last_dict_entry_array[1]->item1, 27); TEST_EQ_P (last_dict_entry_array[2], NULL); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); dict_entry_array_property[0] = NULL; } error_handler_called = FALSE; get_dict_entry_array_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_dict_entry_array (proxy, my_get_dict_entry_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.DictEntryArray.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from the handler function * results in the error handler being called with a D-Bus failed * error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array_property = nih_alloc (parent, sizeof (MyStruct *) * 2); dict_entry_array_property[0] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[0]->item0 = "Joe"; dict_entry_array_property[0]->item1 = 34; dict_entry_array_property[1] = NULL; } error_handler_called = FALSE; get_dict_entry_array_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_dict_entry_array (proxy, my_get_dict_entry_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_dict_entry_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_dict_entry_array (proxy, my_get_dict_entry_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_dict_entry_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_dict_entry_array (proxy, my_get_dict_entry_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_dict_entry_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_dict_entry_array (proxy, my_get_dict_entry_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_dict_entry_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_dict_entry_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestDictEntryArrayElement **dict_entry_array; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_dict_entry_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { dict_entry_array_property = nih_alloc (NULL, sizeof (MyStruct *) * 3); dict_entry_array_property[0] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[0]->item0 = "Joe"; dict_entry_array_property[0]->item1 = 34; dict_entry_array_property[1] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[1]->item0 = "Paul"; dict_entry_array_property[1]->item1 = 27; dict_entry_array_property[2] = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (dict_entry_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } dict_entry_array = NULL; ret = proxy_test_get_dict_entry_array_sync (parent, proxy, &dict_entry_array); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (dict_entry_array, sizeof (ProxyTestStrToDictEntryArrayOutputElement *) * 3); TEST_ALLOC_PARENT (dict_entry_array, parent); TEST_ALLOC_SIZE (dict_entry_array[0], sizeof (ProxyTestStrToDictEntryArrayOutputElement)); TEST_ALLOC_PARENT (dict_entry_array[0], dict_entry_array); TEST_EQ_STR (dict_entry_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (dict_entry_array[0]->item0, dict_entry_array[0]); TEST_EQ (dict_entry_array[0]->item1, 34); TEST_ALLOC_SIZE (dict_entry_array[1], sizeof (ProxyTestStrToDictEntryArrayOutputElement)); TEST_ALLOC_PARENT (dict_entry_array[1], dict_entry_array); TEST_EQ_STR (dict_entry_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (dict_entry_array[1]->item0, dict_entry_array[1]); TEST_EQ (dict_entry_array[1]->item1, 27); TEST_EQ_P (dict_entry_array[2], NULL); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { dict_entry_array_property = nih_alloc (NULL, sizeof (MyStruct *) * 1); dict_entry_array_property[0] = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (dict_entry_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } dict_entry_array = NULL; ret = proxy_test_get_dict_entry_array_sync (parent, proxy, &dict_entry_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.DictEntryArray.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { dict_entry_array_property = nih_alloc (NULL, sizeof (MyStruct *) * 2); dict_entry_array_property[0] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[0]->item0 = "Joe"; dict_entry_array_property[0]->item1 = 34; dict_entry_array_property[1] = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (dict_entry_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } dict_entry_array = NULL; ret = proxy_test_get_dict_entry_array_sync (parent, proxy, &dict_entry_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_dict_entry_array_sync (parent, proxy, &dict_entry_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_dict_entry_array_replied; static void my_set_dict_entry_array_reply (void * data, NihDBusMessage *message) { set_dict_entry_array_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_dict_entry_array (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestDictEntryArrayElement **dict_entry_array = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_dict_entry_array"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { dict_entry_array_property = NULL; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayElement) * 3); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; } error_handler_called = FALSE; set_dict_entry_array_replied = FALSE; last_data = NULL; pending_call = proxy_test_set_dict_entry_array (proxy, dict_entry_array, my_set_dict_entry_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (dict_entry_array_property, NULL); TEST_ALLOC_SIZE (dict_entry_array_property, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (dict_entry_array_property[0], dict_entry_array_property); TEST_ALLOC_SIZE (dict_entry_array_property[0], sizeof (MyStruct)); TEST_EQ_STR (dict_entry_array_property[0]->item0, "Joe"); TEST_EQ (dict_entry_array_property[0]->item1, 34); TEST_ALLOC_PARENT (dict_entry_array_property[1], dict_entry_array_property); TEST_ALLOC_SIZE (dict_entry_array_property[1], sizeof (MyStruct)); TEST_EQ_STR (dict_entry_array_property[1]->item0, "Paul"); TEST_EQ (dict_entry_array_property[1]->item1, 27); TEST_EQ_P (dict_entry_array_property[2], NULL); nih_free (dict_entry_array_property); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error is returned resulting in the error * handler being called with the error raised. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayElement) * 1); dict_entry_array[0] = NULL; } error_handler_called = FALSE; set_dict_entry_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_dict_entry_array (proxy, dict_entry_array, my_set_dict_entry_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.DictEntryArray.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error is returned resulting in the error * handler being called with the D-Bus "failed" error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayElement) * 2); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = NULL; } error_handler_called = FALSE; set_dict_entry_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_dict_entry_array (proxy, dict_entry_array, my_set_dict_entry_array_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayElement) * 3); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; } error_handler_called = FALSE; set_dict_entry_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_dict_entry_array (proxy, dict_entry_array, my_set_dict_entry_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayElement) * 3); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; } error_handler_called = FALSE; set_dict_entry_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_dict_entry_array (proxy, dict_entry_array, my_set_dict_entry_array_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_dict_entry_array_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayElement) * 3); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_dict_entry_array_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_dict_entry_array (proxy, dict_entry_array, my_set_dict_entry_array_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_dict_entry_array_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_dict_entry_array_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestDictEntryArrayElement **dict_entry_array = NULL; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_dict_entry_array_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { dict_entry_array_property = NULL; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); if (dict_entry_array_property) nih_free (dict_entry_array_property); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayElement) * 3); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; } ret = proxy_test_set_dict_entry_array_sync (parent, proxy, dict_entry_array); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); nih_free (dict_entry_array); dict_entry_array = NULL; TEST_ALLOC_SAFE { assert0 (proxy_test_get_dict_entry_array_sync (parent, proxy, &dict_entry_array)); } TEST_ALLOC_SIZE (dict_entry_array, sizeof (ProxyTestStrToDictEntryArrayOutputElement *) * 3); TEST_ALLOC_PARENT (dict_entry_array, parent); TEST_ALLOC_SIZE (dict_entry_array[0], sizeof (ProxyTestStrToDictEntryArrayOutputElement)); TEST_ALLOC_PARENT (dict_entry_array[0], dict_entry_array); TEST_EQ_STR (dict_entry_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (dict_entry_array[0]->item0, dict_entry_array[0]); TEST_EQ (dict_entry_array[0]->item1, 34); TEST_ALLOC_SIZE (dict_entry_array[1], sizeof (ProxyTestStrToDictEntryArrayOutputElement)); TEST_ALLOC_PARENT (dict_entry_array[1], dict_entry_array); TEST_EQ_STR (dict_entry_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (dict_entry_array[1]->item0, dict_entry_array[1]); TEST_EQ (dict_entry_array[1]->item1, 27); TEST_EQ_P (dict_entry_array[2], NULL); nih_free (parent); nih_free (proxy); } /* Check that a D-Bus error is returned as a raised error, with * an appropriate return value. */ TEST_FEATURE ("with invalid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayElement) * 1); dict_entry_array[0] = NULL; } ret = proxy_test_set_dict_entry_array_sync (parent, proxy, dict_entry_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.DictEntryArray.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that a generic error is returned as a raised D-Bus error * with the "failed" name. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayElement) * 2); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = NULL; } ret = proxy_test_set_dict_entry_array_sync (parent, proxy, dict_entry_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (err); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); dict_entry_array = nih_alloc (parent, sizeof (ProxyTestDictEntryArrayElement) * 3); dict_entry_array[0] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[0]->item0 = "Joe"; dict_entry_array[0]->item1 = 34; dict_entry_array[1] = nih_new (dict_entry_array, ProxyTestDictEntryArrayElement); dict_entry_array[1]->item0 = "Paul"; dict_entry_array[1]->item1 = 27; dict_entry_array[2] = NULL; } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_dict_entry_array_sync (parent, proxy, dict_entry_array); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_unix_fd_replied; static void my_get_unix_fd_reply (void * data, NihDBusMessage *message, int value) { get_unix_fd_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_unix_fd_value = value; } void test_get_unix_fd (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_unix_fd"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { unix_fd_property = 1; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_unix_fd_replied = FALSE; last_data = NULL; last_unix_fd_value = -1; pending_call = proxy_test_get_unix_fd (proxy, my_get_unix_fd_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_unix_fd_replied); TEST_EQ_P (last_data, parent); TEST_GT (last_unix_fd_value, 2); // dbus dups this close (last_unix_fd_value); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from the handler function * results in the error handler being called with the error * raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { unix_fd_property = -1; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_unix_fd_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_unix_fd (proxy, my_get_unix_fd_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_unix_fd_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UnixFd.Invalid"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_unix_fd_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_unix_fd (proxy, my_get_unix_fd_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_unix_fd_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_unix_fd_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_unix_fd (proxy, my_get_unix_fd_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_unix_fd_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_unix_fd_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_unix_fd (proxy, my_get_unix_fd_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_unix_fd_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_unix_fd_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int unix_fd_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_unix_fd_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { unix_fd_property = 1; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } unix_fd_value = -1; ret = proxy_test_get_unix_fd_sync (parent, proxy, &unix_fd_value); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_GT (unix_fd_value, 2); // dbus dups this close (unix_fd_value); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { unix_fd_property = -1; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } unix_fd_value = -1; ret = proxy_test_get_unix_fd_sync (parent, proxy, &unix_fd_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.UnixFd.Invalid"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_unix_fd_sync (parent, proxy, &unix_fd_value); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int set_unix_fd_replied; static void my_set_unix_fd_reply (void * data, NihDBusMessage *message) { set_unix_fd_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; } void test_set_unix_fd (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_set_unix_fd"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { unix_fd_property = -1; TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_unix_fd_replied = FALSE; last_data = NULL; last_unix_fd_value = FALSE; pending_call = proxy_test_set_unix_fd (proxy, 1, my_set_unix_fd_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (set_unix_fd_replied); TEST_EQ_P (last_data, parent); TEST_GT (unix_fd_property, 2); // dbus dups this close (unix_fd_property); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_unix_fd_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_unix_fd (proxy, 1, my_set_unix_fd_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_unix_fd_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; set_unix_fd_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_unix_fd (proxy, 1, my_set_unix_fd_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (set_unix_fd_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; set_unix_fd_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_set_unix_fd (proxy, 1, my_set_unix_fd_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (set_unix_fd_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_set_unix_fd_sync (void) { pid_t dbus_pid; DBusConnection *client_conn; DBusConnection *server_conn; DBusConnection *flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; int unix_fd_value; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_set_unix_fd_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_CHILD_WAIT (server_pid, wait_fd) { unix_fd_property = -1; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } unix_fd_value = -1; ret = proxy_test_set_unix_fd_sync (parent, proxy, 1); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SAFE { assert0 (proxy_test_get_unix_fd_sync (parent, proxy, &unix_fd_value)); } TEST_GT (unix_fd_value, 2); // dbus dups this close (unix_fd_value); nih_free (parent); nih_free (proxy); } /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_set_unix_fd_sync (parent, proxy, 1); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int get_all_replied; static const ProxyTestProperties *last_properties; static void my_get_all_reply (void * data, NihDBusMessage * message, const ProxyTestProperties *properties) { get_all_replied++; TEST_NE_P (data, NULL); TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); last_data = data; last_properties = properties; nih_ref (last_properties, last_data); } void test_get_all (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; DBusPendingCall *pending_call; NihError * err; NihDBusError * dbus_err; TEST_FUNCTION ("proxy_test_get_all"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that we receive a pending call object after giving a * valid input, dispatching from the server side should result * in the call being completed and our handler being called with * the output arguments. */ TEST_FEATURE ("with valid argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); byte_property = 97; boolean_property = TRUE; int16_property = -42; uint16_property = 42; int32_property = -1048576; uint32_property = 1048576; int64_property = -4815162342L; uint64_property = 4815162342L; double_property = 3.14; str_property = "she needs more of ze punishment"; object_path_property = "/com/netsplit/Nih/Test"; signature_property = "a(ib)"; struct_property = nih_new (parent, MyStruct); struct_property->item0 = "Joe"; struct_property->item1 = 34; int32_array_property = nih_alloc (parent, sizeof (int32_t) * 6); int32_array_property[0] = 4; int32_array_property[1] = 8; int32_array_property[2] = 15; int32_array_property[3] = 16; int32_array_property[4] = 23; int32_array_property[5] = 42; int32_array_property_len = 6; str_array_property = nih_alloc (parent, sizeof (char *) * 7); str_array_property[0] = "she"; str_array_property[1] = "needs"; str_array_property[2] = "more"; str_array_property[3] = "of"; str_array_property[4] = "ze"; str_array_property[5] = "punishment"; str_array_property[6] = NULL; int32_array_array_property = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_property_len = nih_alloc (int32_array_array_property, sizeof (size_t) * 2); int32_array_array_property[0] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[0][0] = 4; int32_array_array_property[0][1] = 8; int32_array_array_property[0][2] = 15; int32_array_array_property[0][3] = 16; int32_array_array_property[0][4] = 23; int32_array_array_property[0][5] = 42; int32_array_array_property_len[0] = 6; int32_array_array_property[1] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[1][0] = 1; int32_array_array_property[1][1] = 1; int32_array_array_property[1][2] = 2; int32_array_array_property[1][3] = 3; int32_array_array_property[1][4] = 5; int32_array_array_property[1][5] = 8; int32_array_array_property_len[1] = 6; int32_array_array_property[2] = NULL; struct_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); struct_array_property[0] = nih_new (struct_array_property, MyStruct); struct_array_property[0]->item0 = "Joe"; struct_array_property[0]->item1 = 34; struct_array_property[1] = nih_new (struct_array_property, MyStruct); struct_array_property[1]->item0 = "Paul"; struct_array_property[1]->item1 = 27; struct_array_property[2] = NULL; dict_entry_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); dict_entry_array_property[0] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[0]->item0 = "Joe"; dict_entry_array_property[0]->item1 = 34; dict_entry_array_property[1] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[1]->item0 = "Paul"; dict_entry_array_property[1]->item1 = 27; dict_entry_array_property[2] = NULL; unix_fd_property = 1; } error_handler_called = FALSE; get_all_replied = FALSE; last_data = NULL; last_properties = NULL; pending_call = proxy_test_get_all (proxy, my_get_all_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_FALSE (error_handler_called); TEST_TRUE (get_all_replied); TEST_EQ_P (last_data, parent); TEST_ALLOC_SIZE (last_properties, sizeof (ProxyTestProperties)); TEST_ALLOC_PARENT (last_properties, parent); TEST_EQ (last_properties->byte, 97); TEST_EQ (last_properties->boolean, TRUE); TEST_EQ (last_properties->int16, -42); TEST_EQ (last_properties->uint16, 42); TEST_EQ (last_properties->int32, -1048576); TEST_EQ (last_properties->uint32, 1048576); TEST_EQ (last_properties->int64, -4815162342L); TEST_EQ (last_properties->uint64, 4815162342L); TEST_EQ (last_properties->dubble, 3.14); TEST_EQ_STR (last_properties->string, "she needs more of ze punishment"); TEST_ALLOC_PARENT (last_properties->string, last_properties); TEST_EQ_STR (last_properties->object_path, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (last_properties->string, last_properties); TEST_EQ_STR (last_properties->signature, "a(ib)"); TEST_ALLOC_PARENT (last_properties->string, last_properties); TEST_ALLOC_SIZE (last_properties->structure, sizeof (MyStruct)); TEST_ALLOC_PARENT (last_properties->structure, last_properties); TEST_EQ_STR (last_properties->structure->item0, "Joe"); TEST_ALLOC_PARENT (last_properties->structure->item0, last_properties->structure); TEST_EQ (last_properties->structure->item1, 34); TEST_EQ (last_properties->int32_array_len, 6); TEST_ALLOC_SIZE (last_properties->int32_array, sizeof (int32_t) * 6); TEST_ALLOC_PARENT (last_properties->int32_array, last_properties); TEST_EQ (last_properties->int32_array[0], 4); TEST_EQ (last_properties->int32_array[1], 8); TEST_EQ (last_properties->int32_array[2], 15); TEST_EQ (last_properties->int32_array[3], 16); TEST_EQ (last_properties->int32_array[4], 23); TEST_EQ (last_properties->int32_array[5], 42); TEST_ALLOC_SIZE (last_properties->str_array, sizeof (char *) * 7); TEST_ALLOC_PARENT (last_properties->str_array, last_properties); TEST_EQ_STR (last_properties->str_array[0], "she"); TEST_ALLOC_PARENT (last_properties->str_array[0], last_properties->str_array); TEST_EQ_STR (last_properties->str_array[1], "needs"); TEST_ALLOC_PARENT (last_properties->str_array[1], last_properties->str_array); TEST_EQ_STR (last_properties->str_array[2], "more"); TEST_ALLOC_PARENT (last_properties->str_array[2], last_properties->str_array); TEST_EQ_STR (last_properties->str_array[3], "of"); TEST_ALLOC_PARENT (last_properties->str_array[3], last_properties->str_array); TEST_EQ_STR (last_properties->str_array[4], "ze"); TEST_ALLOC_PARENT (last_properties->str_array[4], last_properties->str_array); TEST_EQ_STR (last_properties->str_array[5], "punishment"); TEST_ALLOC_PARENT (last_properties->str_array[5], last_properties->str_array); TEST_EQ_P (last_properties->str_array[6], NULL); TEST_ALLOC_SIZE (last_properties->int32_array_array, sizeof (int32_t *) * 3); TEST_ALLOC_PARENT (last_properties->int32_array_array, last_properties); TEST_ALLOC_SIZE (last_properties->int32_array_array_len, sizeof (size_t) * 2); TEST_ALLOC_PARENT (last_properties->int32_array_array_len, last_properties->int32_array_array); TEST_EQ (last_properties->int32_array_array_len[0], 6); TEST_ALLOC_SIZE (last_properties->int32_array_array[0], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (last_properties->int32_array_array[0], last_properties->int32_array_array); TEST_EQ (last_properties->int32_array_array[0][0], 4); TEST_EQ (last_properties->int32_array_array[0][1], 8); TEST_EQ (last_properties->int32_array_array[0][2], 15); TEST_EQ (last_properties->int32_array_array[0][3], 16); TEST_EQ (last_properties->int32_array_array[0][4], 23); TEST_EQ (last_properties->int32_array_array[0][5], 42); TEST_EQ (last_properties->int32_array_array_len[1], 6); TEST_ALLOC_SIZE (last_properties->int32_array_array[1], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (last_properties->int32_array_array[1], last_properties->int32_array_array); TEST_EQ (last_properties->int32_array_array[1][0], 1); TEST_EQ (last_properties->int32_array_array[1][1], 1); TEST_EQ (last_properties->int32_array_array[1][2], 2); TEST_EQ (last_properties->int32_array_array[1][3], 3); TEST_EQ (last_properties->int32_array_array[1][4], 5); TEST_EQ (last_properties->int32_array_array[1][5], 8); TEST_EQ_P (last_properties->int32_array_array[2], NULL); TEST_ALLOC_SIZE (last_properties->struct_array, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (last_properties->struct_array, last_properties); TEST_ALLOC_SIZE (last_properties->struct_array[0], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_properties->struct_array[0], last_properties->struct_array); TEST_EQ_STR (last_properties->struct_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (last_properties->struct_array[0]->item0, last_properties->struct_array[0]); TEST_EQ (last_properties->struct_array[0]->item1, 34); TEST_ALLOC_SIZE (last_properties->struct_array[1], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_properties->struct_array[1], last_properties->struct_array); TEST_EQ_STR (last_properties->struct_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (last_properties->struct_array[1]->item0, last_properties->struct_array[1]); TEST_EQ (last_properties->struct_array[1]->item1, 27); TEST_EQ_P (last_properties->struct_array[2], NULL); TEST_ALLOC_SIZE (last_properties->dict_entry_array, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (last_properties->dict_entry_array, last_properties); TEST_ALLOC_SIZE (last_properties->dict_entry_array[0], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_properties->dict_entry_array[0], last_properties->dict_entry_array); TEST_EQ_STR (last_properties->dict_entry_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (last_properties->dict_entry_array[0]->item0, last_properties->dict_entry_array[0]); TEST_EQ (last_properties->dict_entry_array[0]->item1, 34); TEST_ALLOC_SIZE (last_properties->dict_entry_array[1], sizeof (MyStruct)); TEST_ALLOC_PARENT (last_properties->dict_entry_array[1], last_properties->dict_entry_array); TEST_EQ_STR (last_properties->dict_entry_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (last_properties->dict_entry_array[1]->item0, last_properties->dict_entry_array[1]); TEST_EQ (last_properties->dict_entry_array[1]->item1, 27); TEST_EQ_P (last_properties->dict_entry_array[2], NULL); TEST_GT (last_properties->unix_fd, 2); // dbus dups this close (last_properties->unix_fd); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a D-Bus error returned from any single property's * handler function results in the error handler being called * with the error raised. */ TEST_FEATURE ("with D-Bus error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); byte_property = 97; boolean_property = TRUE; int16_property = -42; uint16_property = 42; int32_property = -1048576; uint32_property = 1048576; int64_property = -4815162342L; uint64_property = 4815162342L; double_property = 3.14; str_property = "she needs more of ze punishment"; object_path_property = "/com/netsplit/Nih/Test"; signature_property = "a(ib)"; struct_property = nih_new (parent, MyStruct); struct_property->item0 = "Joe"; struct_property->item1 = 34; int32_array_property = NULL; int32_array_property_len = 0; str_array_property = nih_alloc (parent, sizeof (char *) * 7); str_array_property[0] = "she"; str_array_property[1] = "needs"; str_array_property[2] = "more"; str_array_property[3] = "of"; str_array_property[4] = "ze"; str_array_property[5] = "punishment"; str_array_property[6] = NULL; int32_array_array_property = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_property_len = nih_alloc (int32_array_array_property, sizeof (size_t) * 2); int32_array_array_property[0] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[0][0] = 4; int32_array_array_property[0][1] = 8; int32_array_array_property[0][2] = 15; int32_array_array_property[0][3] = 16; int32_array_array_property[0][4] = 23; int32_array_array_property[0][5] = 42; int32_array_array_property_len[0] = 6; int32_array_array_property[1] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[1][0] = 1; int32_array_array_property[1][1] = 1; int32_array_array_property[1][2] = 2; int32_array_array_property[1][3] = 3; int32_array_array_property[1][4] = 5; int32_array_array_property[1][5] = 8; int32_array_array_property_len[1] = 6; int32_array_array_property[2] = NULL; struct_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); struct_array_property[0] = nih_new (struct_array_property, MyStruct); struct_array_property[0]->item0 = "Joe"; struct_array_property[0]->item1 = 34; struct_array_property[1] = nih_new (struct_array_property, MyStruct); struct_array_property[1]->item0 = "Paul"; struct_array_property[1]->item1 = 27; struct_array_property[2] = NULL; dict_entry_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); dict_entry_array_property[0] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[0]->item0 = "Joe"; dict_entry_array_property[0]->item1 = 34; dict_entry_array_property[1] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[1]->item0 = "Paul"; dict_entry_array_property[1]->item1 = 27; dict_entry_array_property[2] = NULL; unix_fd_property = 1; } error_handler_called = FALSE; get_all_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_all (proxy, my_get_all_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_all_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32Array.Empty"); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a generic error returned from any single property's * handler function results in the error handler being called * with the error raised. */ TEST_FEATURE ("with generic error"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); byte_property = 97; boolean_property = TRUE; int16_property = -42; uint16_property = 42; int32_property = -1048576; uint32_property = 1048576; int64_property = -4815162342L; uint64_property = 4815162342L; double_property = 3.14; str_property = "she needs more of ze punishment"; object_path_property = "/com/netsplit/Nih/Test"; signature_property = "inva(x)id"; struct_property = nih_new (parent, MyStruct); struct_property->item0 = "Joe"; struct_property->item1 = 34; int32_array_property = nih_alloc (parent, sizeof (int32_t) * 6); int32_array_property[0] = 4; int32_array_property[1] = 8; int32_array_property[2] = 15; int32_array_property[3] = 16; int32_array_property[4] = 23; int32_array_property[5] = 42; int32_array_property_len = 6; str_array_property = nih_alloc (parent, sizeof (char *) * 7); str_array_property[0] = "she"; str_array_property[1] = "needs"; str_array_property[2] = "more"; str_array_property[3] = "of"; str_array_property[4] = "ze"; str_array_property[5] = "punishment"; str_array_property[6] = NULL; int32_array_array_property = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_property_len = nih_alloc (int32_array_array_property, sizeof (size_t) * 2); int32_array_array_property[0] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[0][0] = 4; int32_array_array_property[0][1] = 8; int32_array_array_property[0][2] = 15; int32_array_array_property[0][3] = 16; int32_array_array_property[0][4] = 23; int32_array_array_property[0][5] = 42; int32_array_array_property_len[0] = 6; int32_array_array_property[1] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[1][0] = 1; int32_array_array_property[1][1] = 1; int32_array_array_property[1][2] = 2; int32_array_array_property[1][3] = 3; int32_array_array_property[1][4] = 5; int32_array_array_property[1][5] = 8; int32_array_array_property_len[1] = 6; int32_array_array_property[2] = NULL; struct_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); struct_array_property[0] = nih_new (struct_array_property, MyStruct); struct_array_property[0]->item0 = "Joe"; struct_array_property[0]->item1 = 34; struct_array_property[1] = nih_new (struct_array_property, MyStruct); struct_array_property[1]->item0 = "Paul"; struct_array_property[1]->item1 = 27; struct_array_property[2] = NULL; dict_entry_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); dict_entry_array_property[0] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[0]->item0 = "Joe"; dict_entry_array_property[0]->item1 = 34; dict_entry_array_property[1] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[1]->item0 = "Paul"; dict_entry_array_property[1]->item1 = 27; dict_entry_array_property[2] = NULL; unix_fd_property = 1; } error_handler_called = FALSE; get_all_replied = FALSE; last_data = NULL; pending_call = proxy_test_get_all (proxy, my_get_all_reply, my_error_handler, parent, 0); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_connection_flush (client_conn); TEST_DBUS_DISPATCH (server_conn); dbus_connection_flush (server_conn); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_all_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a timeout (along with other D-Bus generated errors) * also results in the error handler being called with the D-Bus * error raised. */ TEST_FEATURE ("with timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_all_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_all (proxy, my_get_all_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_all_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that a remote end disconnection (along with other D-Bus * generated errors) also results in the error handler being * called with the D-Bus error raised. */ TEST_FEATURE ("with server disconnection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (flakey_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } error_handler_called = FALSE; get_all_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_all (proxy, my_get_all_reply, my_error_handler, parent, 50); if (test_alloc_failed && (pending_call == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); TEST_DBUS_CLOSE (flakey_conn); continue; } TEST_NE_P (pending_call, NULL); TEST_FALSE (dbus_pending_call_get_completed (pending_call)); TEST_DBUS_CLOSE (flakey_conn); dbus_pending_call_block (pending_call); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); dbus_pending_call_unref (pending_call); TEST_TRUE (error_handler_called); TEST_FALSE (get_all_replied); TEST_EQ_P (last_data, parent); TEST_NE_P (last_error, NULL); TEST_EQ (last_error->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (last_error, sizeof (NihDBusError)); dbus_err = (NihDBusError *)last_error; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_NO_REPLY); nih_free (last_error); nih_free (parent); nih_free (proxy); nih_free (object); } /* Check that sending to a disconnected local end results in the * function returning NULL and the D-Bus disconnected error being * raised. */ TEST_FEATURE ("with unconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); error_handler_called = FALSE; get_all_replied = FALSE; last_data = NULL; last_error = NULL; pending_call = proxy_test_get_all (proxy, my_get_all_reply, my_error_handler, parent, 50); TEST_EQ_P (pending_call, NULL); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); nih_free (object); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); TEST_FALSE (error_handler_called); TEST_FALSE (get_all_replied); nih_free (parent); nih_free (proxy); nih_free (object); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_get_all_sync (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; DBusConnection * flakey_conn; pid_t server_pid; int wait_fd; NihDBusObject * object = NULL; NihDBusProxy * proxy = NULL; void * parent = NULL; ProxyTestProperties *properties; int ret; NihError * err; NihDBusError * dbus_err; int status; TEST_FUNCTION ("proxy_test_get_all_sync"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); /* Check that when we give a valid input, we receive a valid * output in our pointer, allocated as a child of the parent. */ TEST_FEATURE ("with valid argument"); TEST_CHILD_WAIT (server_pid, wait_fd) { parent = nih_alloc (NULL, 0); byte_property = 97; boolean_property = TRUE; int16_property = -42; uint16_property = 42; int32_property = -1048576; uint32_property = 1048576; int64_property = -4815162342L; uint64_property = 4815162342L; double_property = 3.14; str_property = "she needs more of ze punishment"; object_path_property = "/com/netsplit/Nih/Test"; signature_property = "a(ib)"; struct_property = nih_new (parent, MyStruct); struct_property->item0 = "Joe"; struct_property->item1 = 34; int32_array_property = nih_alloc (parent, sizeof (int32_t) * 6); int32_array_property[0] = 4; int32_array_property[1] = 8; int32_array_property[2] = 15; int32_array_property[3] = 16; int32_array_property[4] = 23; int32_array_property[5] = 42; int32_array_property_len = 6; str_array_property = nih_alloc (parent, sizeof (char *) * 7); str_array_property[0] = "she"; str_array_property[1] = "needs"; str_array_property[2] = "more"; str_array_property[3] = "of"; str_array_property[4] = "ze"; str_array_property[5] = "punishment"; str_array_property[6] = NULL; int32_array_array_property = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_property_len = nih_alloc (int32_array_array_property, sizeof (size_t) * 2); int32_array_array_property[0] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[0][0] = 4; int32_array_array_property[0][1] = 8; int32_array_array_property[0][2] = 15; int32_array_array_property[0][3] = 16; int32_array_array_property[0][4] = 23; int32_array_array_property[0][5] = 42; int32_array_array_property_len[0] = 6; int32_array_array_property[1] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[1][0] = 1; int32_array_array_property[1][1] = 1; int32_array_array_property[1][2] = 2; int32_array_array_property[1][3] = 3; int32_array_array_property[1][4] = 5; int32_array_array_property[1][5] = 8; int32_array_array_property_len[1] = 6; int32_array_array_property[2] = NULL; struct_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); struct_array_property[0] = nih_new (struct_array_property, MyStruct); struct_array_property[0]->item0 = "Joe"; struct_array_property[0]->item1 = 34; struct_array_property[1] = nih_new (struct_array_property, MyStruct); struct_array_property[1]->item0 = "Paul"; struct_array_property[1]->item1 = 27; struct_array_property[2] = NULL; dict_entry_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); dict_entry_array_property[0] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[0]->item0 = "Joe"; dict_entry_array_property[0]->item1 = 34; dict_entry_array_property[1] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[1]->item0 = "Paul"; dict_entry_array_property[1]->item1 = 27; dict_entry_array_property[2] = NULL; unix_fd_property = 1; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); nih_free (parent); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } properties = NULL; ret = proxy_test_get_all_sync (parent, proxy, &properties); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (ret, 0); TEST_ALLOC_SIZE (properties, sizeof (ProxyTestProperties)); TEST_ALLOC_PARENT (properties, parent); TEST_EQ (properties->byte, 97); TEST_EQ (properties->boolean, TRUE); TEST_EQ (properties->int16, -42); TEST_EQ (properties->uint16, 42); TEST_EQ (properties->int32, -1048576); TEST_EQ (properties->uint32, 1048576); TEST_EQ (properties->int64, -4815162342L); TEST_EQ (properties->uint64, 4815162342L); TEST_EQ (properties->dubble, 3.14); TEST_EQ_STR (properties->string, "she needs more of ze punishment"); TEST_ALLOC_PARENT (properties->string, properties); TEST_EQ_STR (properties->object_path, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (properties->string, properties); TEST_EQ_STR (properties->signature, "a(ib)"); TEST_ALLOC_PARENT (properties->string, properties); TEST_ALLOC_SIZE (properties->structure, sizeof (MyStruct)); TEST_ALLOC_PARENT (properties->structure, properties); TEST_EQ_STR (properties->structure->item0, "Joe"); TEST_ALLOC_PARENT (properties->structure->item0, properties->structure); TEST_EQ (properties->structure->item1, 34); TEST_EQ (properties->int32_array_len, 6); TEST_ALLOC_SIZE (properties->int32_array, sizeof (int32_t) * 6); TEST_ALLOC_PARENT (properties->int32_array, properties); TEST_EQ (properties->int32_array[0], 4); TEST_EQ (properties->int32_array[1], 8); TEST_EQ (properties->int32_array[2], 15); TEST_EQ (properties->int32_array[3], 16); TEST_EQ (properties->int32_array[4], 23); TEST_EQ (properties->int32_array[5], 42); TEST_ALLOC_SIZE (properties->str_array, sizeof (char *) * 7); TEST_ALLOC_PARENT (properties->str_array, properties); TEST_EQ_STR (properties->str_array[0], "she"); TEST_ALLOC_PARENT (properties->str_array[0], properties->str_array); TEST_EQ_STR (properties->str_array[1], "needs"); TEST_ALLOC_PARENT (properties->str_array[1], properties->str_array); TEST_EQ_STR (properties->str_array[2], "more"); TEST_ALLOC_PARENT (properties->str_array[2], properties->str_array); TEST_EQ_STR (properties->str_array[3], "of"); TEST_ALLOC_PARENT (properties->str_array[3], properties->str_array); TEST_EQ_STR (properties->str_array[4], "ze"); TEST_ALLOC_PARENT (properties->str_array[4], properties->str_array); TEST_EQ_STR (properties->str_array[5], "punishment"); TEST_ALLOC_PARENT (properties->str_array[5], properties->str_array); TEST_EQ_P (properties->str_array[6], NULL); TEST_ALLOC_SIZE (properties->int32_array_array, sizeof (int32_t *) * 3); TEST_ALLOC_PARENT (properties->int32_array_array, properties); TEST_ALLOC_SIZE (properties->int32_array_array_len, sizeof (size_t) * 2); TEST_ALLOC_PARENT (properties->int32_array_array_len, properties->int32_array_array); TEST_EQ (properties->int32_array_array_len[0], 6); TEST_ALLOC_SIZE (properties->int32_array_array[0], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (properties->int32_array_array[0], properties->int32_array_array); TEST_EQ (properties->int32_array_array[0][0], 4); TEST_EQ (properties->int32_array_array[0][1], 8); TEST_EQ (properties->int32_array_array[0][2], 15); TEST_EQ (properties->int32_array_array[0][3], 16); TEST_EQ (properties->int32_array_array[0][4], 23); TEST_EQ (properties->int32_array_array[0][5], 42); TEST_EQ (properties->int32_array_array_len[1], 6); TEST_ALLOC_SIZE (properties->int32_array_array[1], sizeof (int32_t) * 6); TEST_ALLOC_PARENT (properties->int32_array_array[1], properties->int32_array_array); TEST_EQ (properties->int32_array_array[1][0], 1); TEST_EQ (properties->int32_array_array[1][1], 1); TEST_EQ (properties->int32_array_array[1][2], 2); TEST_EQ (properties->int32_array_array[1][3], 3); TEST_EQ (properties->int32_array_array[1][4], 5); TEST_EQ (properties->int32_array_array[1][5], 8); TEST_EQ_P (properties->int32_array_array[2], NULL); TEST_ALLOC_SIZE (properties->struct_array, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (properties->struct_array, properties); TEST_ALLOC_SIZE (properties->struct_array[0], sizeof (MyStruct)); TEST_ALLOC_PARENT (properties->struct_array[0], properties->struct_array); TEST_EQ_STR (properties->struct_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (properties->struct_array[0]->item0, properties->struct_array[0]); TEST_EQ (properties->struct_array[0]->item1, 34); TEST_ALLOC_SIZE (properties->struct_array[1], sizeof (MyStruct)); TEST_ALLOC_PARENT (properties->struct_array[1], properties->struct_array); TEST_EQ_STR (properties->struct_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (properties->struct_array[1]->item0, properties->struct_array[1]); TEST_EQ (properties->struct_array[1]->item1, 27); TEST_EQ_P (properties->struct_array[2], NULL); TEST_ALLOC_SIZE (properties->dict_entry_array, sizeof (MyStruct *) * 3); TEST_ALLOC_PARENT (properties->dict_entry_array, properties); TEST_ALLOC_SIZE (properties->dict_entry_array[0], sizeof (MyStruct)); TEST_ALLOC_PARENT (properties->dict_entry_array[0], properties->dict_entry_array); TEST_EQ_STR (properties->dict_entry_array[0]->item0, "Joe"); TEST_ALLOC_PARENT (properties->dict_entry_array[0]->item0, properties->dict_entry_array[0]); TEST_EQ (properties->dict_entry_array[0]->item1, 34); TEST_ALLOC_SIZE (properties->dict_entry_array[1], sizeof (MyStruct)); TEST_ALLOC_PARENT (properties->dict_entry_array[1], properties->dict_entry_array); TEST_EQ_STR (properties->dict_entry_array[1]->item0, "Paul"); TEST_ALLOC_PARENT (properties->dict_entry_array[1]->item0, properties->dict_entry_array[1]); TEST_EQ (properties->dict_entry_array[1]->item1, 27); TEST_EQ_P (properties->dict_entry_array[2], NULL); TEST_GT (properties->unix_fd, 2); // dbus dups this close (properties->unix_fd); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a D-Bus error, * that error is raised on the returning side and the function * returns -1. */ TEST_FEATURE ("with D-Bus error"); TEST_CHILD_WAIT (server_pid, wait_fd) { parent = nih_alloc (NULL, 0); byte_property = 97; boolean_property = TRUE; int16_property = -42; uint16_property = 42; int32_property = -1048576; uint32_property = 1048576; int64_property = -4815162342L; uint64_property = 4815162342L; double_property = 3.14; str_property = "she needs more of ze punishment"; object_path_property = "/com/netsplit/Nih/Test"; signature_property = "a(ib)"; struct_property = nih_new (parent, MyStruct); struct_property->item0 = "Joe"; struct_property->item1 = 34; int32_array_property = NULL; int32_array_property_len = 0; str_array_property = nih_alloc (parent, sizeof (char *) * 7); str_array_property[0] = "she"; str_array_property[1] = "needs"; str_array_property[2] = "more"; str_array_property[3] = "of"; str_array_property[4] = "ze"; str_array_property[5] = "punishment"; str_array_property[6] = NULL; int32_array_array_property = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_property_len = nih_alloc (int32_array_array_property, sizeof (size_t) * 2); int32_array_array_property[0] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[0][0] = 4; int32_array_array_property[0][1] = 8; int32_array_array_property[0][2] = 15; int32_array_array_property[0][3] = 16; int32_array_array_property[0][4] = 23; int32_array_array_property[0][5] = 42; int32_array_array_property_len[0] = 6; int32_array_array_property[1] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[1][0] = 1; int32_array_array_property[1][1] = 1; int32_array_array_property[1][2] = 2; int32_array_array_property[1][3] = 3; int32_array_array_property[1][4] = 5; int32_array_array_property[1][5] = 8; int32_array_array_property_len[1] = 6; int32_array_array_property[2] = NULL; struct_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); struct_array_property[0] = nih_new (struct_array_property, MyStruct); struct_array_property[0]->item0 = "Joe"; struct_array_property[0]->item1 = 34; struct_array_property[1] = nih_new (struct_array_property, MyStruct); struct_array_property[1]->item0 = "Paul"; struct_array_property[1]->item1 = 27; struct_array_property[2] = NULL; dict_entry_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); dict_entry_array_property[0] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[0]->item0 = "Joe"; dict_entry_array_property[0]->item1 = 34; dict_entry_array_property[1] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[1]->item0 = "Paul"; dict_entry_array_property[1]->item1 = 27; dict_entry_array_property[2] = NULL; unix_fd_property = 1; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); nih_free (parent); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } properties = NULL; ret = proxy_test_get_all_sync (parent, proxy, &properties); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "com.netsplit.Nih.Test.Int32Array.Empty"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that when the remote end's handler returns a generic error, * the D-Bus "failed" error is raised on the returning side and the * function returns -1. */ TEST_FEATURE ("with generic error"); TEST_CHILD_WAIT (server_pid, wait_fd) { parent = nih_alloc (NULL, 0); byte_property = 97; boolean_property = TRUE; int16_property = -42; uint16_property = 42; int32_property = -1048576; uint32_property = 1048576; int64_property = -4815162342L; uint64_property = 4815162342L; double_property = 3.14; str_property = "she needs more of ze punishment"; object_path_property = "/com/netsplit/Nih/Test"; signature_property = "inva(x)id"; struct_property = nih_new (parent, MyStruct); struct_property->item0 = "Joe"; struct_property->item1 = 34; int32_array_property = nih_alloc (parent, sizeof (int32_t) * 6); int32_array_property[0] = 4; int32_array_property[1] = 8; int32_array_property[2] = 15; int32_array_property[3] = 16; int32_array_property[4] = 23; int32_array_property[5] = 42; int32_array_property_len = 6; str_array_property = nih_alloc (parent, sizeof (char *) * 7); str_array_property[0] = "she"; str_array_property[1] = "needs"; str_array_property[2] = "more"; str_array_property[3] = "of"; str_array_property[4] = "ze"; str_array_property[5] = "punishment"; str_array_property[6] = NULL; int32_array_array_property = nih_alloc (parent, sizeof (int32_t *) * 3); int32_array_array_property_len = nih_alloc (int32_array_array_property, sizeof (size_t) * 2); int32_array_array_property[0] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[0][0] = 4; int32_array_array_property[0][1] = 8; int32_array_array_property[0][2] = 15; int32_array_array_property[0][3] = 16; int32_array_array_property[0][4] = 23; int32_array_array_property[0][5] = 42; int32_array_array_property_len[0] = 6; int32_array_array_property[1] = nih_alloc (int32_array_array_property, sizeof (int32_t) * 6); int32_array_array_property[1][0] = 1; int32_array_array_property[1][1] = 1; int32_array_array_property[1][2] = 2; int32_array_array_property[1][3] = 3; int32_array_array_property[1][4] = 5; int32_array_array_property[1][5] = 8; int32_array_array_property_len[1] = 6; int32_array_array_property[2] = NULL; struct_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); struct_array_property[0] = nih_new (struct_array_property, MyStruct); struct_array_property[0]->item0 = "Joe"; struct_array_property[0]->item1 = 34; struct_array_property[1] = nih_new (struct_array_property, MyStruct); struct_array_property[1]->item0 = "Paul"; struct_array_property[1]->item1 = 27; struct_array_property[2] = NULL; dict_entry_array_property = nih_alloc (parent, sizeof (MyStruct *) * 3); dict_entry_array_property[0] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[0]->item0 = "Joe"; dict_entry_array_property[0]->item1 = 34; dict_entry_array_property[1] = nih_new (dict_entry_array_property, MyStruct); dict_entry_array_property[1]->item0 = "Paul"; dict_entry_array_property[1]->item1 = 27; dict_entry_array_property[2] = NULL; unix_fd_property = 1; assert0 (nih_dbus_setup (server_conn, NULL)); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Test", my_interfaces, NULL); nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (nih_signal_add_handler (object, SIGTERM, nih_main_term_signal, NULL)); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); dbus_shutdown (); nih_free (parent); exit (0); } TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } properties = NULL; ret = proxy_test_get_all_sync (parent, proxy, &properties); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (err); nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_FAILED); TEST_EQ_STR (err->message, "Invalid argument"); nih_free (err); nih_free (parent); nih_free (proxy); } kill (server_pid, SIGTERM); waitpid (server_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); /* Check that attempting to send to a disconnected connection * returns a raised D-Bus disconnected error. */ TEST_FEATURE ("with disconnected connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (flakey_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, flakey_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih/Test", NULL, NULL); parent = nih_alloc (NULL, 0); } TEST_DBUS_CLOSE (flakey_conn); ret = proxy_test_get_all_sync (parent, proxy, &properties); TEST_LT (ret, 0); err = nih_error_get (); if (test_alloc_failed && (err->number == ENOMEM)) { nih_free (parent); nih_free (proxy); continue; } TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, DBUS_ERROR_DISCONNECTED); nih_free (err); nih_free (parent); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } int main (int argc, char *argv[]) { nih_error_init (); test_ordinary_method (); test_ordinary_method_sync (); test_nameless_method (); test_nameless_method_sync (); test_async_method (); test_async_method_sync (); test_byte_to_str (); test_byte_to_str_sync (); test_str_to_byte (); test_str_to_byte_sync (); test_boolean_to_str (); test_boolean_to_str_sync (); test_str_to_boolean (); test_str_to_boolean_sync (); test_int16_to_str (); test_int16_to_str_sync (); test_str_to_int16 (); test_str_to_int16_sync (); test_uint16_to_str (); test_uint16_to_str_sync (); test_str_to_uint16 (); test_str_to_uint16_sync (); test_int32_to_str (); test_int32_to_str_sync (); test_str_to_int32 (); test_str_to_int32_sync (); test_uint32_to_str (); test_uint32_to_str_sync (); test_str_to_uint32 (); test_str_to_uint32_sync (); test_int64_to_str (); test_int64_to_str_sync (); test_str_to_int64 (); test_str_to_int64_sync (); test_uint64_to_str (); test_uint64_to_str_sync (); test_str_to_uint64 (); test_str_to_uint64_sync (); test_double_to_str (); test_double_to_str_sync (); test_str_to_double (); test_str_to_double_sync (); test_object_path_to_str (); test_object_path_to_str_sync (); test_str_to_object_path (); test_str_to_object_path_sync (); test_signature_to_str (); test_signature_to_str_sync (); test_str_to_signature (); test_str_to_signature_sync (); test_struct_to_str (); test_struct_to_str_sync (); test_str_to_struct (); test_str_to_struct_sync (); test_int32_array_to_str (); test_int32_array_to_str_sync (); test_str_to_int32_array (); test_str_to_int32_array_sync (); test_str_array_to_str (); test_str_array_to_str_sync (); test_str_to_str_array (); test_str_to_str_array_sync (); test_int32_array_array_to_str (); test_int32_array_array_to_str_sync (); test_str_to_int32_array_array (); test_str_to_int32_array_array_sync (); test_struct_array_to_str (); test_struct_array_to_str_sync (); test_str_to_struct_array (); test_str_to_struct_array_sync (); test_dict_entry_array_to_str (); test_dict_entry_array_to_str_sync (); test_str_to_dict_entry_array (); test_str_to_dict_entry_array_sync (); test_unix_fd_to_str (); test_unix_fd_to_str_sync (); test_str_to_unix_fd (); test_str_to_unix_fd_sync (); test_new_byte (); test_new_boolean (); test_new_int16 (); test_new_uint16 (); test_new_int32 (); test_new_uint32 (); test_new_int64 (); test_new_uint64 (); test_new_double (); test_new_string (); test_new_object_path (); test_new_signature (); test_new_struct (); test_new_int32_array (); test_new_str_array (); test_new_int32_array_array (); test_new_struct_array (); test_new_dict_entry_array (); test_new_unix_fd (); test_get_byte (); test_get_byte_sync (); test_set_byte (); test_set_byte_sync (); test_get_boolean (); test_get_boolean_sync (); test_set_boolean (); test_set_boolean_sync (); test_get_int16 (); test_get_int16_sync (); test_set_int16 (); test_set_int16_sync (); test_get_uint16 (); test_get_uint16_sync (); test_set_uint16 (); test_set_uint16_sync (); test_get_int32 (); test_get_int32_sync (); test_set_int32 (); test_set_int32_sync (); test_get_uint32 (); test_get_uint32_sync (); test_set_uint32 (); test_set_uint32_sync (); test_get_int64 (); test_get_int64_sync (); test_set_int64 (); test_set_int64_sync (); test_get_uint64 (); test_get_uint64_sync (); test_set_uint64 (); test_set_uint64_sync (); test_get_double (); test_get_double_sync (); test_set_double (); test_set_double_sync (); test_get_string (); test_get_string_sync (); test_set_string (); test_set_string_sync (); test_get_object_path (); test_get_object_path_sync (); test_set_object_path (); test_set_object_path_sync (); test_get_signature (); test_get_signature_sync (); test_set_signature (); test_set_signature_sync (); test_get_structure (); test_get_structure_sync (); test_set_structure (); test_set_structure_sync (); test_get_int32_array (); test_get_int32_array_sync (); test_set_int32_array (); test_set_int32_array_sync (); test_get_str_array (); test_get_str_array_sync (); test_set_str_array (); test_set_str_array_sync (); test_get_int32_array_array (); test_get_int32_array_array_sync (); test_set_int32_array_array (); test_set_int32_array_array_sync (); test_get_struct_array (); test_get_struct_array_sync (); test_set_struct_array (); test_set_struct_array_sync (); test_get_dict_entry_array (); test_get_dict_entry_array_sync (); test_set_dict_entry_array (); test_set_dict_entry_array_sync (); test_get_unix_fd (); test_get_unix_fd_sync (); test_set_unix_fd (); test_set_unix_fd_sync (); test_get_all (); test_get_all_sync (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/test_argument.c0000644000175000017500000011654011445765555016604 00000000000000/* nih-dbus-tool * * test_argument.c - test suite for nih-dbus-tool/argument.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include "node.h" #include "method.h" #include "signal.h" #include "argument.h" #include "parse.h" #include "errors.h" void test_name_valid (void) { TEST_FUNCTION ("argument_name_valid"); /* Check that a typical argument name is valid. */ TEST_FEATURE ("with typical argument name"); TEST_TRUE (argument_name_valid ("Wibble")); /* Check that an argument name is not valid if it is has an * initial period. */ TEST_FEATURE ("with initial period"); TEST_FALSE (argument_name_valid (".Wibble")); /* Check that an argument name is not valid if it ends with a period */ TEST_FEATURE ("with final period"); TEST_FALSE (argument_name_valid ("Wibble.")); /* Check that an argument name is not valid if it contains a period */ TEST_FEATURE ("with period"); TEST_FALSE (argument_name_valid ("Wib.ble")); /* Check that a argument name may contain numbers */ TEST_FEATURE ("with numbers"); TEST_TRUE (argument_name_valid ("Wib43ble")); /* Check that a argument name may not begin with numbers */ TEST_FEATURE ("with leading digits"); TEST_FALSE (argument_name_valid ("43Wibble")); /* Check that a argument name may end with numbers */ TEST_FEATURE ("with trailing digits"); TEST_TRUE (argument_name_valid ("Wibble43")); /* Check that a argument name may contain underscores */ TEST_FEATURE ("with underscore"); TEST_TRUE (argument_name_valid ("Wib_ble")); /* Check that a argument name may begin with underscores */ TEST_FEATURE ("with initial underscore"); TEST_TRUE (argument_name_valid ("_Wibble")); /* Check that a argument name may end with underscores */ TEST_FEATURE ("with final underscore"); TEST_TRUE (argument_name_valid ("Wibble_")); /* Check that other characters are not permitted */ TEST_FEATURE ("with non-permitted characters"); TEST_FALSE (argument_name_valid ("Wib-ble")); /* Check that an empty argument name is invalid */ TEST_FEATURE ("with empty string"); TEST_FALSE (argument_name_valid ("")); } void test_new (void) { Argument *argument; TEST_FUNCTION ("argument_new"); /* Check that an Argument object is allocated with the structure * filled in properly, but not placed in a list. */ TEST_FEATURE ("with name"); TEST_ALLOC_FAIL { argument = argument_new (NULL, "name", "s", NIH_DBUS_ARG_IN); if (test_alloc_failed) { TEST_EQ_P (argument, NULL); continue; } TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_LIST_EMPTY (&argument->entry); TEST_EQ_STR (argument->name, "name"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ_P (argument->symbol, NULL); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); nih_free (argument); } /* Check that the name of an Argument can be left as NULL and that * is stored in the structure. */ TEST_FEATURE ("without name"); TEST_ALLOC_FAIL { argument = argument_new (NULL, NULL, "s", NIH_DBUS_ARG_OUT); if (test_alloc_failed) { TEST_EQ_P (argument, NULL); continue; } TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_LIST_EMPTY (&argument->entry); TEST_EQ_P (argument->name, NULL); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ_P (argument->symbol, NULL); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); nih_free (argument); } } void test_start_tag (void) { ParseContext context; ParseStack * parent = NULL; ParseStack * entry; XML_Parser xmlp; Node * node = NULL; Method * method = NULL; Signal * signal = NULL; Argument * argument; char * attr[7]; int ret = 0; NihError * err; FILE * output; TEST_FUNCTION ("argument_start_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); output = tmpfile (); /* Check that an argument tag for a method with the usual name and * type attributes results in an Argument member being created and * pushed onto the stack with those attributes filled in correctly. * Method argument direction should default to "in". */ TEST_FEATURE ("with method argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); } attr[0] = "name"; attr[1] = "test_arg"; attr[2] = "type"; attr[3] = "s"; attr[4] = NULL; ret = argument_start_tag (xmlp, "arg", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ARGUMENT); argument = entry->argument; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, entry); TEST_EQ_STR (argument->name, "test_arg"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ_P (argument->symbol, NULL); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); TEST_LIST_EMPTY (&method->arguments); nih_free (entry); nih_free (parent); } /* Check that an argument tag for a signal with the usual name and * type attributes results in an Argument member being created and * pushed onto the stack with those attributes filled in correctly. * Signal argument direction should default to "in". */ TEST_FEATURE ("with signal argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); parent = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); } attr[0] = "name"; attr[1] = "test_arg"; attr[2] = "type"; attr[3] = "s"; attr[4] = NULL; ret = argument_start_tag (xmlp, "arg", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&signal->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ARGUMENT); argument = entry->argument; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, entry); TEST_EQ_STR (argument->name, "test_arg"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ_P (argument->symbol, NULL); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); TEST_LIST_EMPTY (&signal->arguments); nih_free (entry); nih_free (parent); } /* Check that direction of a method argument can be specified in * an attribute as "in" (the default). */ TEST_FEATURE ("with method input argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); } attr[0] = "name"; attr[1] = "test_arg"; attr[2] = "type"; attr[3] = "s"; attr[4] = "direction"; attr[5] = "in"; attr[6] = NULL; ret = argument_start_tag (xmlp, "arg", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ARGUMENT); argument = entry->argument; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, entry); TEST_EQ_STR (argument->name, "test_arg"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ_P (argument->symbol, NULL); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); TEST_LIST_EMPTY (&method->arguments); nih_free (entry); nih_free (parent); } /* Check that direction of a method argument can be specified in * an attribute as "out". */ TEST_FEATURE ("with method output argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); } attr[0] = "name"; attr[1] = "test_arg"; attr[2] = "type"; attr[3] = "s"; attr[4] = "direction"; attr[5] = "out"; attr[6] = NULL; ret = argument_start_tag (xmlp, "arg", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ARGUMENT); argument = entry->argument; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, entry); TEST_EQ_STR (argument->name, "test_arg"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ_P (argument->symbol, NULL); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); TEST_LIST_EMPTY (&method->arguments); nih_free (entry); nih_free (parent); } /* Check that direction of a signal argument can be specified in * an attribute as "out". */ TEST_FEATURE ("with signal output argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); parent = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); } attr[0] = "name"; attr[1] = "test_arg"; attr[2] = "type"; attr[3] = "s"; attr[4] = "direction"; attr[5] = "out"; attr[6] = NULL; ret = argument_start_tag (xmlp, "arg", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&signal->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ARGUMENT); argument = entry->argument; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, entry); TEST_EQ_STR (argument->name, "test_arg"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ_P (argument->symbol, NULL); TEST_EQ (argument->direction, NIH_DBUS_ARG_OUT); TEST_LIST_EMPTY (&signal->arguments); nih_free (entry); nih_free (parent); } /* Check that the name attribute to an argument is optional, and when * omitted NULL is stored in the structure. */ TEST_FEATURE ("with unnamed argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); } attr[0] = "type"; attr[1] = "s"; attr[2] = NULL; ret = argument_start_tag (xmlp, "arg", attr); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ARGUMENT); argument = entry->argument; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, entry); TEST_EQ_P (argument->name, NULL); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ_P (argument->symbol, NULL); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); TEST_LIST_EMPTY (&method->arguments); nih_free (entry); nih_free (parent); } /* Check that an argument with an invalid name results in an * error being raised. */ TEST_FEATURE ("with invalid argument name"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); attr[0] = "name"; attr[1] = "test arg"; attr[2] = "type"; attr[3] = "s"; attr[4] = NULL; } ret = argument_start_tag (xmlp, "arg", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ARGUMENT_INVALID_NAME); nih_free (err); nih_free (parent); } /* Check that an argument with a missing type attribute results * in an error being raised. */ TEST_FEATURE ("with missing argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); attr[0] = "name"; attr[1] = "test_arg"; attr[2] = NULL; } ret = argument_start_tag (xmlp, "arg", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ARGUMENT_MISSING_TYPE); nih_free (err); nih_free (parent); } /* Check that an argument with an invalid type results in an * error being raised. */ TEST_FEATURE ("with invalid argument type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); attr[0] = "name"; attr[1] = "test_arg"; attr[2] = "type"; attr[3] = "!"; attr[4] = NULL; } ret = argument_start_tag (xmlp, "arg", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ARGUMENT_INVALID_TYPE); nih_free (err); nih_free (parent); } /* Check that a method argument with an invalid direction results * in an error being raised. */ TEST_FEATURE ("with invalid method argument direction"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); attr[0] = "name"; attr[1] = "test_arg"; attr[2] = "type"; attr[3] = "s"; attr[4] = "direction"; attr[5] = "widdershins"; attr[6] = NULL; } ret = argument_start_tag (xmlp, "arg", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ARGUMENT_ILLEGAL_METHOD_DIRECTION); nih_free (err); nih_free (parent); } /* Check that a signal argument with an invalid direction results * in an error being raised. */ TEST_FEATURE ("with invalid signal argument direction"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); parent = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); attr[0] = "name"; attr[1] = "test_arg"; attr[2] = "type"; attr[3] = "s"; attr[4] = "direction"; attr[5] = "widdershins"; attr[6] = NULL; } ret = argument_start_tag (xmlp, "arg", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&signal->arguments); err = nih_error_get (); TEST_EQ (err->number, ARGUMENT_ILLEGAL_SIGNAL_DIRECTION); nih_free (err); nih_free (parent); } /* Check that "in" is an invalid direction for a signal argument * and results in an error being raised. */ TEST_FEATURE ("with input signal argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); parent = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); attr[0] = "name"; attr[1] = "test_arg"; attr[2] = "type"; attr[3] = "s"; attr[4] = "direction"; attr[5] = "in"; attr[6] = NULL; } ret = argument_start_tag (xmlp, "arg", attr); TEST_LT (ret, 0); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_LIST_EMPTY (&signal->arguments); err = nih_error_get (); TEST_EQ (err->number, ARGUMENT_ILLEGAL_SIGNAL_DIRECTION); nih_free (err); nih_free (parent); } /* Check that an unknown argument attribute results in a warning * being printed to standard error, but is otherwise ignored * and the normal processing finished. */ TEST_FEATURE ("with unknown attribute"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); attr[0] = "name"; attr[1] = "test_arg"; attr[2] = "type"; attr[3] = "s"; attr[4] = "frodo"; attr[5] = "baggins"; attr[6] = NULL; } TEST_DIVERT_STDERR (output) { ret = argument_start_tag (xmlp, "arg", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_ARGUMENT); argument = entry->argument; TEST_ALLOC_SIZE (argument, sizeof (Argument)); TEST_ALLOC_PARENT (argument, entry); TEST_EQ_STR (argument->name, "test_arg"); TEST_ALLOC_PARENT (argument->name, argument); TEST_EQ_STR (argument->type, "s"); TEST_ALLOC_PARENT (argument->type, argument); TEST_EQ_P (argument->symbol, NULL); TEST_EQ (argument->direction, NIH_DBUS_ARG_IN); TEST_LIST_EMPTY (&method->arguments); TEST_FILE_EQ (output, ("test:foo:1:0: Ignored unknown attribute: " "frodo\n")); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } /* Check that an argument on an empty stack (ie. a top-level * argument element) results in a warning being printed on * standard error and an ignored element being pushed onto the * stack. */ TEST_FEATURE ("with empty stack"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { attr[0] = "name"; attr[1] = "test_arg"; attr[2] = "type"; attr[3] = "s"; attr[4] = NULL; } TEST_DIVERT_STDERR (output) { ret = argument_start_tag (xmlp, "arg", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), NULL); TEST_FILE_RESET (output); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unexpected tag\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); } /* Check that an argument on top of a stack entry that's not a * method or signal results in a warning being printed on * standard error and an ignored element being pushed onto the * stack. */ TEST_FEATURE ("with non-method/signal on stack"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { node = node_new (NULL, NULL); parent = parse_stack_push (NULL, &context.stack, PARSE_NODE, node); nih_discard (node); attr[0] = "name"; attr[1] = "test_arg"; attr[2] = "type"; attr[3] = "s"; attr[4] = NULL; } TEST_DIVERT_STDERR (output) { ret = argument_start_tag (xmlp, "arg", attr); } rewind (output); if (test_alloc_failed && (ret < 0)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_EQ_P (parse_stack_top (&context.stack), parent); TEST_FILE_RESET (output); nih_free (parent); continue; } TEST_EQ (ret, 0); entry = parse_stack_top (&context.stack); TEST_NE_P (entry, parent); TEST_ALLOC_SIZE (entry, sizeof (ParseStack)); TEST_EQ (entry->type, PARSE_IGNORED); TEST_EQ_P (entry->data, NULL); TEST_FILE_EQ (output, "test:foo:1:0: Ignored unexpected tag\n"); TEST_FILE_END (output); TEST_FILE_RESET (output); nih_free (entry); nih_free (parent); } XML_ParserFree (xmlp); fclose (output); } void test_end_tag (void) { ParseContext context; ParseStack * parent = NULL; ParseStack * entry = NULL; XML_Parser xmlp; Method * method = NULL; Signal * signal = NULL; Argument * argument = NULL; Argument * other1 = NULL; Argument * other2 = NULL; int ret; NihError * err; TEST_FUNCTION ("argument_end_tag"); context.parent = NULL; nih_list_init (&context.stack); context.filename = "foo"; context.node = NULL; assert (xmlp = XML_ParserCreate ("UTF-8")); XML_SetUserData (xmlp, &context); /* Check that when we parse the end tag for a named method argument, * we pop the Argument object off the stack (freeing and removing * it) and append it to the parent method's arguments list, adding * a reference to the method as well. A symbol should be generated * for the argument by converting its name to C style. */ TEST_FEATURE ("with named method argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); argument = argument_new (NULL, "test_arg", "s", NIH_DBUS_ARG_IN); entry = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); } TEST_FREE_TAG (entry); ret = argument_end_tag (xmlp, "arg"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (argument, method); TEST_LIST_NOT_EMPTY (&method->arguments); TEST_EQ_P (method->arguments.next, &argument->entry); TEST_EQ_STR (argument->symbol, "test_arg"); TEST_ALLOC_PARENT (argument->symbol, argument); nih_free (parent); } /* Check that when the symbol for a named method argument has been * pre-assigned by the data, it's not overriden and is used even * if different. */ TEST_FEATURE ("with symbol for named method argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); argument = argument_new (NULL, "test_arg", "s", NIH_DBUS_ARG_IN); argument->symbol = nih_strdup (argument, "test"); entry = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); } TEST_FREE_TAG (entry); ret = argument_end_tag (xmlp, "arg"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (argument, method); TEST_LIST_NOT_EMPTY (&method->arguments); TEST_EQ_P (method->arguments.next, &argument->entry); TEST_EQ_STR (argument->symbol, "test"); TEST_ALLOC_PARENT (argument->symbol, argument); nih_free (parent); } /* Check that an unnamed argument without a symbol has the name * argNN assigned, where NN is its position in the list. */ TEST_FEATURE ("with unnamed method argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); other1 = argument_new (method, NULL, "s", NIH_DBUS_ARG_IN); nih_list_add (&method->arguments, &other1->entry); other2 = argument_new (method, NULL, "i", NIH_DBUS_ARG_IN); nih_list_add (&method->arguments, &other2->entry); argument = argument_new (NULL, NULL, "s", NIH_DBUS_ARG_IN); entry = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); } TEST_FREE_TAG (entry); ret = argument_end_tag (xmlp, "arg"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (argument, method); TEST_LIST_NOT_EMPTY (&method->arguments); TEST_EQ_P (method->arguments.prev, &argument->entry); TEST_EQ_STR (argument->symbol, "arg3"); TEST_ALLOC_PARENT (argument->symbol, argument); nih_free (parent); } /* Check that a symbol can be supplied even when a name isn't, * and that symbol is used in preference to generating a name. */ TEST_FEATURE ("with symbol for unnamed method argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); other1 = argument_new (method, NULL, "s", NIH_DBUS_ARG_IN); nih_list_add (&method->arguments, &other1->entry); other2 = argument_new (method, NULL, "i", NIH_DBUS_ARG_IN); nih_list_add (&method->arguments, &other2->entry); argument = argument_new (NULL, NULL, "s", NIH_DBUS_ARG_IN); argument->symbol = nih_strdup (argument, "test"); entry = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); } TEST_FREE_TAG (entry); ret = argument_end_tag (xmlp, "arg"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&method->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (argument, method); TEST_LIST_NOT_EMPTY (&method->arguments); TEST_EQ_P (method->arguments.prev, &argument->entry); TEST_EQ_STR (argument->symbol, "test"); TEST_ALLOC_PARENT (argument->symbol, argument); nih_free (parent); } /* Check that when we parse the end tag for a named signal argument, * we pop the Argument object off the stack (freeing and removing * it) and append it to the parent signal's arguments list, adding * a reference to the signal as well. A symbol should be generated * for the argument by converting its name to C style. */ TEST_FEATURE ("with named signal argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); parent = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); argument = argument_new (NULL, "test_arg", "s", NIH_DBUS_ARG_IN); entry = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); } TEST_FREE_TAG (entry); ret = argument_end_tag (xmlp, "arg"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&signal->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (argument, signal); TEST_LIST_NOT_EMPTY (&signal->arguments); TEST_EQ_P (signal->arguments.next, &argument->entry); TEST_EQ_STR (argument->symbol, "test_arg"); TEST_ALLOC_PARENT (argument->symbol, argument); nih_free (parent); } /* Check that when the symbol for a named signal argument has been * pre-assigned by the data, it's not overriden and is used even * if different. */ TEST_FEATURE ("with symbol for named signal argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); parent = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); argument = argument_new (NULL, "test_arg", "s", NIH_DBUS_ARG_IN); argument->symbol = nih_strdup (argument, "test"); entry = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); } TEST_FREE_TAG (entry); ret = argument_end_tag (xmlp, "arg"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&signal->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (argument, signal); TEST_LIST_NOT_EMPTY (&signal->arguments); TEST_EQ_P (signal->arguments.next, &argument->entry); TEST_EQ_STR (argument->symbol, "test"); TEST_ALLOC_PARENT (argument->symbol, argument); nih_free (parent); } /* Check that an unnamed argument without a symbol has the name * argNN assigned, where NN is its position in the list. */ TEST_FEATURE ("with unnamed signal argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); parent = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); other1 = argument_new (signal, NULL, "s", NIH_DBUS_ARG_IN); nih_list_add (&signal->arguments, &other1->entry); other2 = argument_new (signal, NULL, "i", NIH_DBUS_ARG_IN); nih_list_add (&signal->arguments, &other2->entry); argument = argument_new (NULL, NULL, "s", NIH_DBUS_ARG_IN); entry = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); } TEST_FREE_TAG (entry); ret = argument_end_tag (xmlp, "arg"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (argument, signal); TEST_LIST_NOT_EMPTY (&signal->arguments); TEST_EQ_P (signal->arguments.prev, &argument->entry); TEST_EQ_STR (argument->symbol, "arg3"); TEST_ALLOC_PARENT (argument->symbol, argument); nih_free (parent); } /* Check that a symbol can be supplied even when a name isn't, * and that symbol is used in preference to generating a name. */ TEST_FEATURE ("with symbol for unnamed signal argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); parent = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); other1 = argument_new (signal, NULL, "s", NIH_DBUS_ARG_IN); nih_list_add (&signal->arguments, &other1->entry); other2 = argument_new (signal, NULL, "i", NIH_DBUS_ARG_IN); nih_list_add (&signal->arguments, &other2->entry); argument = argument_new (NULL, NULL, "s", NIH_DBUS_ARG_IN); argument->symbol = nih_strdup (argument, "test"); entry = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); } TEST_FREE_TAG (entry); ret = argument_end_tag (xmlp, "arg"); if (test_alloc_failed) { TEST_LT (ret, 0); TEST_NOT_FREE (entry); TEST_LIST_EMPTY (&signal->arguments); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (entry); nih_free (parent); continue; } TEST_EQ (ret, 0); TEST_FREE (entry); TEST_ALLOC_PARENT (argument, signal); TEST_LIST_NOT_EMPTY (&signal->arguments); TEST_EQ_P (signal->arguments.prev, &argument->entry); TEST_EQ_STR (argument->symbol, "test"); TEST_ALLOC_PARENT (argument->symbol, argument); nih_free (parent); } /* Check that we won't allow a duplicate symbol for a method * argument, and instead raise an error and allow the user to * deal with it using the Symbol annotation. We could work * around this, but there's no point since argument names are * only for bindings anyway so they should never clash! */ TEST_FEATURE ("with conflicting symbol for method argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { method = method_new (NULL, "TestMethod"); parent = parse_stack_push (NULL, &context.stack, PARSE_METHOD, method); nih_discard (method); other1 = argument_new (method, "TestArg", "i", NIH_DBUS_ARG_IN); other1->symbol = nih_strdup (other1, "test_arg"); nih_list_add (&method->arguments, &other1->entry); argument = argument_new (NULL, "test_arg", "s", NIH_DBUS_ARG_IN); entry = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); } ret = argument_end_tag (xmlp, "arg"); TEST_LT (ret, 0); err = nih_error_get (); if ((! test_alloc_failed) || (err->number != ENOMEM)) TEST_EQ (err->number, ARGUMENT_DUPLICATE_SYMBOL); nih_free (err); nih_free (entry); nih_free (parent); } /* Check that we won't allow a duplicate symbol for a signal * argument, and instead raise an error and allow the user to * deal with it using the Symbol annotation. We could work * around this, but there's no point since argument names are * only for bindings anyway so they should never clash! */ TEST_FEATURE ("with conflicting symbol for signal argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { signal = signal_new (NULL, "TestSignal"); parent = parse_stack_push (NULL, &context.stack, PARSE_SIGNAL, signal); nih_discard (signal); other1 = argument_new (signal, "TestArg", "i", NIH_DBUS_ARG_IN); other1->symbol = nih_strdup (other1, "test_arg"); nih_list_add (&signal->arguments, &other1->entry); argument = argument_new (NULL, "test_arg", "s", NIH_DBUS_ARG_IN); entry = parse_stack_push (NULL, &context.stack, PARSE_ARGUMENT, argument); nih_discard (argument); } ret = argument_end_tag (xmlp, "arg"); TEST_LT (ret, 0); err = nih_error_get (); if ((! test_alloc_failed) || (err->number != ENOMEM)) TEST_EQ (err->number, ARGUMENT_DUPLICATE_SYMBOL); nih_free (err); nih_free (entry); nih_free (parent); } XML_ParserFree (xmlp); } void test_annotation (void) { Argument *argument = NULL; char * symbol; int ret; NihError *err; TEST_FUNCTION ("argument_annotation"); /* Check that an annotation to add a symbol to the argument is * handled, and the new symbol is stored in the argument. */ TEST_FEATURE ("with symbol annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { argument = argument_new (NULL, "TestArg", "s", NIH_DBUS_ARG_IN); } ret = argument_annotation (argument, "com.netsplit.Nih.Symbol", "foo"); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (argument); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (argument->symbol, "foo"); TEST_ALLOC_PARENT (argument->symbol, argument); nih_free (argument); } /* Check that an annotation to add a symbol to the argument * replaces any previous symbol applied (e.g. by a previous * annotation). */ TEST_FEATURE ("with symbol annotation and existing symbol"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { argument = argument_new (NULL, "TestArg", "s", NIH_DBUS_ARG_IN); argument->symbol = nih_strdup (argument, "test_arg"); } symbol = argument->symbol; TEST_FREE_TAG (symbol); ret = argument_annotation (argument, "com.netsplit.Nih.Symbol", "foo"); if (test_alloc_failed) { TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (argument); continue; } TEST_EQ (ret, 0); TEST_FREE (symbol); TEST_EQ_STR (argument->symbol, "foo"); TEST_ALLOC_PARENT (argument->symbol, argument); nih_free (argument); } /* Check that an invalid symbol in an annotation results in an * error being raised. */ TEST_FEATURE ("with invalid symbol in annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { argument = argument_new (NULL, "TestArg", "s", NIH_DBUS_ARG_IN); } ret = argument_annotation (argument, "com.netsplit.Nih.Symbol", "foo bar"); TEST_LT (ret, 0); TEST_EQ_P (argument->symbol, NULL); err = nih_error_get (); TEST_EQ (err->number, ARGUMENT_INVALID_SYMBOL); nih_free (err); nih_free (argument); } /* Check that an unknown annotation results in an error being * raised. */ TEST_FEATURE ("with unknown annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { argument = argument_new (NULL, "TestArg", "s", NIH_DBUS_ARG_IN); } ret = argument_annotation (argument, "com.netsplit.Nih.Unknown", "true"); TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ARGUMENT_UNKNOWN_ANNOTATION); nih_free (err); nih_free (argument); } /* Check that the deprecated annotation is unknown for an * argument. */ TEST_FEATURE ("with deprecated annotation"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { argument = argument_new (NULL, "TestArg", "s", NIH_DBUS_ARG_IN); } ret = argument_annotation (argument, "org.freedesktop.DBus.Deprecated", "true"); TEST_LT (ret, 0); err = nih_error_get (); TEST_EQ (err->number, ARGUMENT_UNKNOWN_ANNOTATION); nih_free (err); nih_free (argument); } } int main (int argc, char *argv[]) { program_name = "test"; nih_error_init (); test_name_valid (); test_new (); test_start_tag (); test_end_tag (); test_annotation (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/test_type.c0000644000175000017500000014437411504702552015731 00000000000000/* nih-dbus-tool * * test_type.c - test suite for nih-dbus-tool/type.c * * Copyright © 2010 Scott James Remnant . * Copyright © 2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include "type.h" void test_const (void) { TEST_FUNCTION ("type_const"); /* Check that the correct value is returned for a Byte. */ TEST_FEATURE ("with byte"); TEST_EQ_STR (type_const (DBUS_TYPE_BYTE), "DBUS_TYPE_BYTE"); /* Check that the correct value is returned for a Boolean. */ TEST_FEATURE ("with boolean"); TEST_EQ_STR (type_const (DBUS_TYPE_BOOLEAN), "DBUS_TYPE_BOOLEAN"); /* Check that the correct value is returned for an Int16. */ TEST_FEATURE ("with int16"); TEST_EQ_STR (type_const (DBUS_TYPE_INT16), "DBUS_TYPE_INT16"); /* Check that the correct value is returned for a UInt16. */ TEST_FEATURE ("with uint16"); TEST_EQ_STR (type_const (DBUS_TYPE_UINT16), "DBUS_TYPE_UINT16"); /* Check that the correct value is returned for an Int32. */ TEST_FEATURE ("with int32"); TEST_EQ_STR (type_const (DBUS_TYPE_INT32), "DBUS_TYPE_INT32"); /* Check that the correct value is returned for a UInt32. */ TEST_FEATURE ("with uint32"); TEST_EQ_STR (type_const (DBUS_TYPE_UINT32), "DBUS_TYPE_UINT32"); /* Check that the correct value is returned for an Int64. */ TEST_FEATURE ("with int64"); TEST_EQ_STR (type_const (DBUS_TYPE_INT64), "DBUS_TYPE_INT64"); /* Check that the correct value is returned for a UInt64. */ TEST_FEATURE ("with uint64"); TEST_EQ_STR (type_const (DBUS_TYPE_UINT64), "DBUS_TYPE_UINT64"); /* Check that the correct value is returned for a Double. */ TEST_FEATURE ("with double"); TEST_EQ_STR (type_const (DBUS_TYPE_DOUBLE), "DBUS_TYPE_DOUBLE"); /* Check that the correct value is returned for a String. */ TEST_FEATURE ("with stirng"); TEST_EQ_STR (type_const (DBUS_TYPE_STRING), "DBUS_TYPE_STRING"); /* Check that the correct value is returned for an Object Path. */ TEST_FEATURE ("with object path"); TEST_EQ_STR (type_const (DBUS_TYPE_OBJECT_PATH), "DBUS_TYPE_OBJECT_PATH"); /* Check that the correct value is returned for a Signature. */ TEST_FEATURE ("with signature"); TEST_EQ_STR (type_const (DBUS_TYPE_SIGNATURE), "DBUS_TYPE_SIGNATURE"); /* Check that the correct value is returned for an Array. */ TEST_FEATURE ("with array"); TEST_EQ_STR (type_const (DBUS_TYPE_ARRAY), "DBUS_TYPE_ARRAY"); /* Check that the correct value is returned for a Struct. */ TEST_FEATURE ("with struct"); TEST_EQ_STR (type_const (DBUS_TYPE_STRUCT), "DBUS_TYPE_STRUCT"); /* Check that the correct value is returned for a Dict Entry. */ TEST_FEATURE ("with dict entry"); TEST_EQ_STR (type_const (DBUS_TYPE_DICT_ENTRY), "DBUS_TYPE_DICT_ENTRY"); /* Check that the correct value is returned for a file descriptor */ TEST_FEATURE ("with file descriptor"); TEST_EQ_STR (type_const (DBUS_TYPE_UNIX_FD), "DBUS_TYPE_UNIX_FD"); } void test_of (void) { DBusSignatureIter iter; char * str; TEST_FUNCTION ("type_of"); /* Check that the expected C type is returned for a D-Bus Byte * type. */ TEST_FEATURE ("with byte"); TEST_ALLOC_FAIL { dbus_signature_iter_init (&iter, DBUS_TYPE_BYTE_AS_STRING); str = type_of (NULL, &iter); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_ALLOC_PARENT (str, NULL); TEST_EQ_STR (str, "uint8_t"); nih_free (str); } /* Check that the expected C type is returned for a D-Bus Boolean * type. */ TEST_FEATURE ("with boolean"); TEST_ALLOC_FAIL { dbus_signature_iter_init (&iter, DBUS_TYPE_BOOLEAN_AS_STRING); str = type_of (NULL, &iter); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_ALLOC_PARENT (str, NULL); TEST_EQ_STR (str, "int"); nih_free (str); } /* Check that the expected C type is returned for a D-Bus Int16 * type. */ TEST_FEATURE ("with int16"); TEST_ALLOC_FAIL { dbus_signature_iter_init (&iter, DBUS_TYPE_INT16_AS_STRING); str = type_of (NULL, &iter); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_ALLOC_PARENT (str, NULL); TEST_EQ_STR (str, "int16_t"); nih_free (str); } /* Check that the expected C type is returned for a D-Bus UInt16 * type. */ TEST_FEATURE ("with uint16"); TEST_ALLOC_FAIL { dbus_signature_iter_init (&iter, DBUS_TYPE_UINT16_AS_STRING); str = type_of (NULL, &iter); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_ALLOC_PARENT (str, NULL); TEST_EQ_STR (str, "uint16_t"); nih_free (str); } /* Check that the expected C type is returned for a D-Bus Int32 * type. */ TEST_FEATURE ("with int32"); TEST_ALLOC_FAIL { dbus_signature_iter_init (&iter, DBUS_TYPE_INT32_AS_STRING); str = type_of (NULL, &iter); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_ALLOC_PARENT (str, NULL); TEST_EQ_STR (str, "int32_t"); nih_free (str); } /* Check that the expected C type is returned for a D-Bus UInt32 * type. */ TEST_FEATURE ("with uint32"); TEST_ALLOC_FAIL { dbus_signature_iter_init (&iter, DBUS_TYPE_UINT32_AS_STRING); str = type_of (NULL, &iter); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_ALLOC_PARENT (str, NULL); TEST_EQ_STR (str, "uint32_t"); nih_free (str); } /* Check that the expected C type is returned for a D-Bus Int64 * type. */ TEST_FEATURE ("with int64"); TEST_ALLOC_FAIL { dbus_signature_iter_init (&iter, DBUS_TYPE_INT64_AS_STRING); str = type_of (NULL, &iter); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_ALLOC_PARENT (str, NULL); TEST_EQ_STR (str, "int64_t"); nih_free (str); } /* Check that the expected C type is returned for a D-Bus UInt64 * type. */ TEST_FEATURE ("with uint64"); TEST_ALLOC_FAIL { dbus_signature_iter_init (&iter, DBUS_TYPE_UINT64_AS_STRING); str = type_of (NULL, &iter); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_ALLOC_PARENT (str, NULL); TEST_EQ_STR (str, "uint64_t"); nih_free (str); } /* Check that the expected C type is returned for a D-Bus Double * type. */ TEST_FEATURE ("with double"); TEST_ALLOC_FAIL { dbus_signature_iter_init (&iter, DBUS_TYPE_DOUBLE_AS_STRING); str = type_of (NULL, &iter); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_ALLOC_PARENT (str, NULL); TEST_EQ_STR (str, "double"); nih_free (str); } /* Check that the expected C type is returned for a D-Bus String * type. */ TEST_FEATURE ("with string"); TEST_ALLOC_FAIL { dbus_signature_iter_init (&iter, DBUS_TYPE_STRING_AS_STRING); str = type_of (NULL, &iter); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_ALLOC_PARENT (str, NULL); TEST_EQ_STR (str, "char *"); nih_free (str); } /* Check that the expected C type is returned for a D-Bus Object Path * type. */ TEST_FEATURE ("with object path"); TEST_ALLOC_FAIL { dbus_signature_iter_init (&iter, DBUS_TYPE_OBJECT_PATH_AS_STRING); str = type_of (NULL, &iter); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_ALLOC_PARENT (str, NULL); TEST_EQ_STR (str, "char *"); nih_free (str); } /* Check that the expected C type is returned for a D-Bus Signature * type. */ TEST_FEATURE ("with signature"); TEST_ALLOC_FAIL { dbus_signature_iter_init (&iter, DBUS_TYPE_SIGNATURE_AS_STRING); str = type_of (NULL, &iter); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_ALLOC_PARENT (str, NULL); TEST_EQ_STR (str, "char *"); nih_free (str); } /* Check that the expected C type is returned for a D-Bus file * descriptor. */ TEST_FEATURE ("with file descriptor"); TEST_ALLOC_FAIL { dbus_signature_iter_init (&iter, DBUS_TYPE_UNIX_FD_AS_STRING); str = type_of (NULL, &iter); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_ALLOC_PARENT (str, NULL); TEST_EQ_STR (str, "int"); nih_free (str); } } void test_var_new (void) { TypeVar *var; TEST_FUNCTION ("type_var_new"); /* Check to make sure that a TypeVar structure is allocated * correctly and returned. */ TEST_ALLOC_FAIL { var = type_var_new (NULL, "char *", "foo"); if (test_alloc_failed) { TEST_EQ_P (var, NULL); continue; } TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_LIST_EMPTY (&var->entry); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "foo"); TEST_ALLOC_PARENT (var->name, var); TEST_FALSE (var->array); nih_free (var); } } void test_var_to_string (void) { TypeVar *var = NULL; char * str; TEST_FUNCTION ("type_var_to_string"); /* Check to make sure that a non-pointer variable is returned with * the type and name separated by a space. */ TEST_FEATURE ("with non-pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { var = type_var_new (NULL, "int", "foo"); } str = type_var_to_string (NULL, var); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (var); continue; } TEST_EQ_STR (str, "int foo"); nih_free (str); nih_free (var); } /* Check to make sure that a pointer variable is returned with * the type and name separated by no spaces. */ TEST_FEATURE ("with pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { var = type_var_new (NULL, "char *", "foo"); } str = type_var_to_string (NULL, var); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (var); continue; } TEST_EQ_STR (str, "char *foo"); nih_free (str); nih_free (var); } /* Check to make sure that an array variable is returned with [] * after the type and name. */ TEST_FEATURE ("with array"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { var = type_var_new (NULL, "char *", "foo"); var->array = TRUE; } str = type_var_to_string (NULL, var); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (var); continue; } TEST_EQ_STR (str, "char *foo[]"); nih_free (str); nih_free (var); } } void test_var_layout (void) { NihList vars; TypeVar *var1 = NULL; TypeVar *var2 = NULL; TypeVar *var3 = NULL; char * str; TEST_FUNCTION ("test_var_layout"); /* Check that we can lay out a couple of different non-pointer * variables with them lined up with the longest type name * separated by a space and the other names lined up. */ TEST_FEATURE ("with set of non-pointers"); TEST_ALLOC_FAIL { nih_list_init (&vars); TEST_ALLOC_SAFE { var1 = type_var_new (NULL, "int", "foo"); nih_list_add (&vars, &var1->entry); var2 = type_var_new (NULL, "struct bar", "bar"); var2->array = TRUE; nih_list_add (&vars, &var2->entry); var3 = type_var_new (NULL, "uint32_t", "baz"); nih_list_add (&vars, &var3->entry); } str = type_var_layout (NULL, &vars); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (var1); nih_free (var2); nih_free (var3); continue; } TEST_EQ_STR (str, ("int foo;\n" "struct bar bar[];\n" "uint32_t baz;\n")); nih_free (var1); nih_free (var2); nih_free (var3); nih_free (str); } /* Check that we can lay out a couple of different pointer * variables with them lined up with the longest type name * followed by the name with the others lined up under it. */ TEST_FEATURE ("with set of pointers"); TEST_ALLOC_FAIL { nih_list_init (&vars); TEST_ALLOC_SAFE { var1 = type_var_new (NULL, "int *", "foo"); nih_list_add (&vars, &var1->entry); var2 = type_var_new (NULL, "struct bar *", "bar"); var2->array = TRUE; nih_list_add (&vars, &var2->entry); var3 = type_var_new (NULL, "uint32_t *", "baz"); nih_list_add (&vars, &var3->entry); } str = type_var_layout (NULL, &vars); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (var1); nih_free (var2); nih_free (var3); continue; } TEST_EQ_STR (str, ("int * foo;\n" "struct bar *bar[];\n" "uint32_t * baz;\n")); nih_free (var1); nih_free (var2); nih_free (var3); nih_free (str); } /* Check that we can lay out a mix of pointer and non-pointer * variables with them lined up with the longest type name * followed by the name with the others lined up under it. */ TEST_FEATURE ("with mixed set"); TEST_ALLOC_FAIL { nih_list_init (&vars); TEST_ALLOC_SAFE { var1 = type_var_new (NULL, "int *", "foo"); nih_list_add (&vars, &var1->entry); var2 = type_var_new (NULL, "struct bar", "bar"); var2->array = TRUE; nih_list_add (&vars, &var2->entry); var3 = type_var_new (NULL, "uint32_t *", "baz"); nih_list_add (&vars, &var3->entry); } str = type_var_layout (NULL, &vars); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (var1); nih_free (var2); nih_free (var3); continue; } TEST_EQ_STR (str, ("int * foo;\n" "struct bar bar[];\n" "uint32_t * baz;\n")); nih_free (var1); nih_free (var2); nih_free (var3); nih_free (str); } /* Check that we can accept an empty set, and have the empty * string returned. */ TEST_FEATURE ("with empty list"); TEST_ALLOC_FAIL { nih_list_init (&vars); str = type_var_layout (NULL, &vars); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, ""); nih_free (str); } } void test_func_new (void) { TypeFunc *func; TEST_FUNCTION ("type_func_new"); /* Check to make sure that a TypeFunc structure is allocated * correctly and returned. */ TEST_ALLOC_FAIL { func = type_func_new (NULL, "char *", "foo"); if (test_alloc_failed) { TEST_EQ_P (func, NULL); continue; } TEST_ALLOC_SIZE (func, sizeof (TypeFunc)); TEST_LIST_EMPTY (&func->entry); TEST_EQ_STR (func->type, "char *"); TEST_ALLOC_PARENT (func->type, func); TEST_EQ_STR (func->name, "foo"); TEST_ALLOC_PARENT (func->name, func); TEST_LIST_EMPTY (&func->args); TEST_LIST_EMPTY (&func->attribs); nih_free (func); } } void test_func_to_string (void) { TypeFunc * func = NULL; TypeVar * arg = NULL; NihListEntry *attrib = NULL; char * str; TEST_FUNCTION ("type_func_to_string"); /* Make sure that a function declaration with a set of non-pointer * arguments is formatted correctly. */ TEST_FEATURE ("with non-pointer arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "int", "function_name"); arg = type_var_new (func, "int", "foo"); nih_list_add (&func->args, &arg->entry);; arg = type_var_new (func, "struct bar", "bar"); nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "uint32_t", "baz"); nih_list_add (&func->args, &arg->entry); } str = type_func_to_string (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, ("int\n" "function_name (int foo,\n" " struct bar bar,\n" " uint32_t baz)\n")); nih_free (str); nih_free (func); } /* Make sure that a function declaration with a set of pointer * arguments is formatted correctly. */ TEST_FEATURE ("with pointer arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "int", "function_name"); arg = type_var_new (func, "int *", "foo"); nih_list_add (&func->args, &arg->entry);; arg = type_var_new (func, "struct bar *", "bar"); nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "uint32_t *", "baz"); nih_list_add (&func->args, &arg->entry); } str = type_func_to_string (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, ("int\n" "function_name (int * foo,\n" " struct bar *bar,\n" " uint32_t * baz)\n")); nih_free (str); nih_free (func); } /* Make sure that a function declaration with a mixed set of * non-pointer and pointer arguments is formatted correctly. */ TEST_FEATURE ("with mixed arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "int", "function_name"); arg = type_var_new (func, "int", "foo"); nih_list_add (&func->args, &arg->entry);; arg = type_var_new (func, "struct bar *", "bar"); nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "uint32_t *", "baz"); nih_list_add (&func->args, &arg->entry); } str = type_func_to_string (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, ("int\n" "function_name (int foo,\n" " struct bar *bar,\n" " uint32_t * baz)\n")); nih_free (str); nih_free (func); } /* Check that a function declaration with a single non-pointer * argument is formatted correctly. */ TEST_FEATURE ("with single non-pointer argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "int", "function_name"); arg = type_var_new (func, "int", "foo"); nih_list_add (&func->args, &arg->entry);; } str = type_func_to_string (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, ("int\n" "function_name (int foo)\n")); nih_free (str); nih_free (func); } /* Check that a function declaration with a single pointer * argument is formatted correctly. */ TEST_FEATURE ("with single pointer argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "int", "function_name"); arg = type_var_new (func, "int *", "foo"); nih_list_add (&func->args, &arg->entry);; } str = type_func_to_string (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, ("int\n" "function_name (int *foo)\n")); nih_free (str); nih_free (func); } /* Check that a function declaration with no arguments is * formatted correctly. */ TEST_FEATURE ("with no arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "int", "function_name"); } str = type_func_to_string (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, ("int\n" "function_name (void)\n")); nih_free (str); nih_free (func); } /* Check that function attributes have no bearing on the declaration * since they only appear in the prototype. */ TEST_FEATURE ("with attributes"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "void", "function_name"); attrib = nih_list_entry_new (func); attrib->str = nih_strdup (attrib, "warn_unused_result"); nih_list_add (&func->attribs, &attrib->entry); } str = type_func_to_string (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, ("void\n" "function_name (void)\n")); nih_free (str); nih_free (func); } } void test_func_to_typedef (void) { TypeFunc * func = NULL; TypeVar * arg = NULL; NihListEntry *attrib = NULL; char * str; TEST_FUNCTION ("type_func_to_typedef"); /* Make sure that a typedef declaration with a set of non-pointer * arguments is formatted correctly. */ TEST_FEATURE ("with non-pointer arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "typedef int", "(*TypedefName)"); arg = type_var_new (func, "int", "foo"); nih_list_add (&func->args, &arg->entry);; arg = type_var_new (func, "struct bar", "bar"); nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "uint32_t", "baz"); nih_list_add (&func->args, &arg->entry); } str = type_func_to_typedef (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, ("typedef int (*TypedefName) (" "int foo, struct bar bar, uint32_t baz);\n")); nih_free (str); nih_free (func); } /* Make sure that a typedef declaration with a set of pointer * arguments is formatted correctly. */ TEST_FEATURE ("with pointer arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "typedef int", "(*TypedefName)"); arg = type_var_new (func, "int *", "foo"); nih_list_add (&func->args, &arg->entry);; arg = type_var_new (func, "struct bar *", "bar"); nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "uint32_t *", "baz"); nih_list_add (&func->args, &arg->entry); } str = type_func_to_typedef (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, ("typedef int (*TypedefName) (" "int *foo, struct bar *bar, " "uint32_t *baz);\n")); nih_free (str); nih_free (func); } /* Make sure that a typedef declaration with a mixed set of * non-pointer and pointer arguments is formatted correctly. */ TEST_FEATURE ("with mixed arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "typedef int", "(*TypedefName)"); arg = type_var_new (func, "int", "foo"); nih_list_add (&func->args, &arg->entry);; arg = type_var_new (func, "struct bar *", "bar"); nih_list_add (&func->args, &arg->entry); arg = type_var_new (func, "uint32_t *", "baz"); nih_list_add (&func->args, &arg->entry); } str = type_func_to_typedef (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, ("typedef int (*TypedefName) (" "int foo, struct bar *bar, " "uint32_t *baz);\n")); nih_free (str); nih_free (func); } /* Check that a typedef declaration with a single non-pointer * argument is formatted correctly. */ TEST_FEATURE ("with single non-pointer argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "typedef int", "(*TypedefName)"); arg = type_var_new (func, "int", "foo"); nih_list_add (&func->args, &arg->entry);; } str = type_func_to_typedef (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, "typedef int (*TypedefName) (int foo);\n"); nih_free (str); nih_free (func); } /* Check that a typedef declaration with a single pointer * argument is formatted correctly. */ TEST_FEATURE ("with single pointer argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "typedef int", "(*TypedefName)"); arg = type_var_new (func, "int *", "foo"); nih_list_add (&func->args, &arg->entry);; } str = type_func_to_typedef (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, "typedef int (*TypedefName) (int *foo);\n"); nih_free (str); nih_free (func); } /* Check that a typedef declaration with no arguments is * formatted correctly. */ TEST_FEATURE ("with no arguments"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "typedef int", "(*TypedefName)"); } str = type_func_to_typedef (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, "typedef int (*TypedefName) (void);\n"); nih_free (str); nih_free (func); } /* Check that function attributes have no bearing on the typedef * declaration since they only appear in the prototype. */ TEST_FEATURE ("with attributes"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { func = type_func_new (NULL, "typedef int", "(*TypedefName)"); attrib = nih_list_entry_new (func); attrib->str = nih_strdup (attrib, "warn_unused_result"); nih_list_add (&func->attribs, &attrib->entry); } str = type_func_to_typedef (NULL, func); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func); continue; } TEST_EQ_STR (str, "typedef int (*TypedefName) (void);\n"); nih_free (str); nih_free (func); } } void test_func_layout (void) { NihList funcs; TypeFunc * func1 = NULL; TypeFunc * func2 = NULL; TypeFunc * func3 = NULL; TypeFunc * func4 = NULL; TypeVar * arg = NULL; NihListEntry *attrib = NULL; char * str; TEST_FUNCTION ("type_func_layout"); /* Check that functions with non-pointer return types are lined * up properly both by name and type. */ TEST_FEATURE ("with non-pointer return types"); TEST_ALLOC_FAIL { nih_list_init (&funcs); TEST_ALLOC_SAFE { func1 = type_func_new (NULL, "int", "first_function_name"); nih_list_add (&funcs, &func1->entry); arg = type_var_new (func1, "int", "foo"); nih_list_add (&func1->args, &arg->entry); arg = type_var_new (func1, "char *", "bar"); nih_list_add (&func1->args, &arg->entry); func2 = type_func_new (NULL, "double", "second_function_name"); nih_list_add (&funcs, &func2->entry); arg = type_var_new (func2, "int", "foo"); nih_list_add (&func2->args, &arg->entry); arg = type_var_new (func2, "char *", "bar"); nih_list_add (&func2->args, &arg->entry); func3 = type_func_new (NULL, "uint32_t", "third_function_name"); nih_list_add (&funcs, &func3->entry); arg = type_var_new (func3, "int", "foo"); nih_list_add (&func3->args, &arg->entry); arg = type_var_new (func3, "char *", "bar"); nih_list_add (&func3->args, &arg->entry); func4 = type_func_new (NULL, "void", "fourth_function_name"); nih_list_add (&funcs, &func4->entry); } str = type_func_layout (NULL, &funcs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func1); nih_free (func2); nih_free (func3); nih_free (func4); continue; } TEST_EQ_STR (str, ("int first_function_name (int foo, char *bar);\n" "double second_function_name (int foo, char *bar);\n" "uint32_t third_function_name (int foo, char *bar);\n" "void fourth_function_name (void);\n")); nih_free (str); nih_free (func1); nih_free (func2); nih_free (func3); nih_free (func4); } /* Check that functions with pointer return types are lined * up properly both by name and type. */ TEST_FEATURE ("with pointer return types"); TEST_ALLOC_FAIL { nih_list_init (&funcs); TEST_ALLOC_SAFE { func1 = type_func_new (NULL, "int *", "first_function_name"); nih_list_add (&funcs, &func1->entry); arg = type_var_new (func1, "int", "foo"); nih_list_add (&func1->args, &arg->entry); arg = type_var_new (func1, "char *", "bar"); nih_list_add (&func1->args, &arg->entry); func2 = type_func_new (NULL, "struct foo *", "second_function_name"); nih_list_add (&funcs, &func2->entry); arg = type_var_new (func2, "int", "foo"); nih_list_add (&func2->args, &arg->entry); arg = type_var_new (func2, "char *", "bar"); nih_list_add (&func2->args, &arg->entry); func3 = type_func_new (NULL, "uint32_t *", "third_function_name"); nih_list_add (&funcs, &func3->entry); arg = type_var_new (func3, "int", "foo"); nih_list_add (&func3->args, &arg->entry); arg = type_var_new (func3, "char *", "bar"); nih_list_add (&func3->args, &arg->entry); func4 = type_func_new (NULL, "void *", "fourth_function_name"); nih_list_add (&funcs, &func4->entry); } str = type_func_layout (NULL, &funcs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func1); nih_free (func2); nih_free (func3); nih_free (func4); continue; } TEST_EQ_STR (str, ("int * first_function_name (int foo, char *bar);\n" "struct foo *second_function_name (int foo, char *bar);\n" "uint32_t * third_function_name (int foo, char *bar);\n" "void * fourth_function_name (void);\n")); nih_free (str); nih_free (func1); nih_free (func2); nih_free (func3); nih_free (func4); } /* Check that functions with a mix of pointer and non-pointer * return types are lined up properly both by name and type. */ TEST_FEATURE ("with mixed return types"); TEST_ALLOC_FAIL { nih_list_init (&funcs); TEST_ALLOC_SAFE { func1 = type_func_new (NULL, "int *", "first_function_name"); nih_list_add (&funcs, &func1->entry); arg = type_var_new (func1, "int", "foo"); nih_list_add (&func1->args, &arg->entry); arg = type_var_new (func1, "char *", "bar"); nih_list_add (&func1->args, &arg->entry); func2 = type_func_new (NULL, "struct foo *", "second_function_name"); nih_list_add (&funcs, &func2->entry); arg = type_var_new (func2, "int", "foo"); nih_list_add (&func2->args, &arg->entry); arg = type_var_new (func2, "char *", "bar"); nih_list_add (&func2->args, &arg->entry); func3 = type_func_new (NULL, "uint32_t", "third_function_name"); nih_list_add (&funcs, &func3->entry); arg = type_var_new (func3, "int", "foo"); nih_list_add (&func3->args, &arg->entry); arg = type_var_new (func3, "char *", "bar"); nih_list_add (&func3->args, &arg->entry); func4 = type_func_new (NULL, "void", "fourth_function_name"); nih_list_add (&funcs, &func4->entry); } str = type_func_layout (NULL, &funcs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func1); nih_free (func2); nih_free (func3); nih_free (func4); continue; } TEST_EQ_STR (str, ("int * first_function_name (int foo, char *bar);\n" "struct foo *second_function_name (int foo, char *bar);\n" "uint32_t third_function_name (int foo, char *bar);\n" "void fourth_function_name (void);\n")); nih_free (str); nih_free (func1); nih_free (func2); nih_free (func3); nih_free (func4); } /* Check that functions with attributes have them lined up * beneath the function declaration indented by a tab. */ TEST_FEATURE ("with function attributes"); TEST_ALLOC_FAIL { nih_list_init (&funcs); TEST_ALLOC_SAFE { func1 = type_func_new (NULL, "int *", "first_function_name"); nih_list_add (&funcs, &func1->entry); arg = type_var_new (func1, "int", "foo"); nih_list_add (&func1->args, &arg->entry); arg = type_var_new (func1, "char *", "bar"); nih_list_add (&func1->args, &arg->entry); attrib = nih_list_entry_new (func1); attrib->str = nih_strdup (attrib, "warn_unused_result"); nih_list_add (&func1->attribs, &attrib->entry); func2 = type_func_new (NULL, "struct foo *", "second_function_name"); nih_list_add (&funcs, &func2->entry); arg = type_var_new (func2, "int", "foo"); nih_list_add (&func2->args, &arg->entry); arg = type_var_new (func2, "char *", "bar"); nih_list_add (&func2->args, &arg->entry); attrib = nih_list_entry_new (func2); attrib->str = nih_strdup (attrib, "warn_unused_result"); nih_list_add (&func2->attribs, &attrib->entry); attrib = nih_list_entry_new (func2); attrib->str = nih_strdup (attrib, "malloc"); nih_list_add (&func2->attribs, &attrib->entry); func3 = type_func_new (NULL, "uint32_t", "third_function_name"); nih_list_add (&funcs, &func3->entry); arg = type_var_new (func3, "int", "foo"); nih_list_add (&func3->args, &arg->entry); arg = type_var_new (func3, "char *", "bar"); nih_list_add (&func3->args, &arg->entry); attrib = nih_list_entry_new (func3); attrib->str = nih_strdup (attrib, "deprecated"); nih_list_add (&func3->attribs, &attrib->entry); func4 = type_func_new (NULL, "void", "fourth_function_name"); nih_list_add (&funcs, &func4->entry); } str = type_func_layout (NULL, &funcs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (func1); nih_free (func2); nih_free (func3); nih_free (func4); continue; } TEST_EQ_STR (str, ("int * first_function_name (int foo, char *bar)\n" "\t__attribute__ ((warn_unused_result));\n" "struct foo *second_function_name (int foo, char *bar)\n" "\t__attribute__ ((warn_unused_result, malloc));\n" "uint32_t third_function_name (int foo, char *bar)\n" "\t__attribute__ ((deprecated));\n" "void fourth_function_name (void);\n")); nih_free (str); nih_free (func1); nih_free (func2); nih_free (func3); nih_free (func4); } /* Check that an empty list of functions return an empty string. */ TEST_FEATURE ("with empty function list"); TEST_ALLOC_FAIL { nih_list_init (&funcs); str = type_func_layout (NULL, &funcs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); continue; } TEST_EQ_STR (str, ""); nih_free (str); } } void test_struct_new (void) { TypeStruct *structure; /* Check to make sure that a TypeStruct structure is allocated * correctly and returned. */ TEST_FUNCTION ("type_struct_new"); TEST_ALLOC_FAIL { structure = type_struct_new (NULL, "MyStructure"); if (test_alloc_failed) { TEST_EQ_P (structure, NULL); continue; } TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_LIST_EMPTY (&structure->entry); TEST_EQ_STR (structure->name, "MyStructure"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_EMPTY (&structure->members); nih_free (structure); } } void test_struct_to_string (void) { TypeStruct *structure = NULL; TypeVar * var = NULL; char * str; TEST_FUNCTION ("test_struct_to_string"); /* Check that we can lay out a structure definition with a mixed * set of members. The structure name should be as given, with the * C name converted from that into symbol-style. */ TEST_FEATURE ("with members"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { structure = type_struct_new (NULL, "MyTestStructure"); var = type_var_new (structure, "int *", "foo"); nih_list_add (&structure->members, &var->entry); var = type_var_new (structure, "struct bar", "bar"); var->array = TRUE; nih_list_add (&structure->members, &var->entry); var = type_var_new (structure, "uint32_t *", "baz"); nih_list_add (&structure->members, &var->entry); } str = type_struct_to_string (NULL, structure); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (structure); continue; } TEST_EQ_STR (str, ("typedef struct my_test_structure {\n" "\tint * foo;\n" "\tstruct bar bar[];\n" "\tuint32_t * baz;\n" "} MyTestStructure;\n")); nih_free (structure); nih_free (str); } /* Check that we can also lay out a structure with no members. */ TEST_FEATURE ("with no members"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { structure = type_struct_new (NULL, "MyTestStructure"); } str = type_struct_to_string (NULL, structure); if (test_alloc_failed) { TEST_EQ_P (str, NULL); nih_free (structure); continue; } TEST_EQ_STR (str, ("typedef struct my_test_structure {\n" "} MyTestStructure;\n")); nih_free (structure); nih_free (str); } } void test_to_const (void) { char *str = NULL; char *ret; TEST_FUNCTION ("type_to_const"); /* Check to make sure that a non-pointer declaration is returned * unmodified. */ TEST_FEATURE ("with non-pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "int"); } ret = type_to_const (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "int"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "int"); nih_free (str); } /* Check that a simple first-level pointer has the const initialiser * prepended onto the front, before the type name. */ TEST_FEATURE ("with pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "char *"); } ret = type_to_const (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "char *"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "const char *"); nih_free (str); } /* Check that a two-level pointer has the const initialiser * placed before the final pointer operator. */ TEST_FEATURE ("with pointer pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "char **"); } ret = type_to_const (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "char **"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "char * const *"); nih_free (str); } /* Check that a three-level pointer has the const initialiser * placed before the final pointer operator. */ TEST_FEATURE ("with pointer pointer pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "char ***"); } ret = type_to_const (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "char ***"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "char ** const *"); nih_free (str); } /* Check that an already-const pointer declaration is returned * unmodified. */ TEST_FEATURE ("with const pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "const struct foo *"); } ret = type_to_const (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "const struct foo *"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "const struct foo *"); nih_free (str); } /* Check that an already-const pointer pointer declaration is returned * unmodified. */ TEST_FEATURE ("with const pointer pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "struct foo * const *"); } ret = type_to_const (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "struct foo * const *"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "struct foo * const *"); nih_free (str); } /* Check that a pointer to a const pointer is modified to be a * const pointer to a const pointer. */ TEST_FEATURE ("with pointer to const pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "const struct foo **"); } ret = type_to_const (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "const struct foo **"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "const struct foo * const *"); nih_free (str); } /* Check that an already-const pointer pointer pointer declaration * is returned unmodified. */ TEST_FEATURE ("with const pointer pointer pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "struct foo ** const *"); } ret = type_to_const (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "struct foo ** const *"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "struct foo ** const *"); nih_free (str); } /* Check that a pointer to a const pointer pointer is modified * to be a constant pointer to a const pointer pointer. */ TEST_FEATURE ("with pointer to const pointer pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "struct foo * const **"); } ret = type_to_const (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "struct foo * const **"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "struct foo * const * const *"); nih_free (str); } } void test_to_pointer (void) { char *str = NULL; char *ret; TEST_FUNCTION ("type_to_pointer"); /* Check to make sure that a non-pointer declaration is returned * as a pointer. */ TEST_FEATURE ("with non-pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "int"); } ret = type_to_pointer (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "int"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "int *"); nih_free (str); } /* Check that a simple first-level pointer has a further pointer * level added. */ TEST_FEATURE ("with pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "char *"); } ret = type_to_pointer (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "char *"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "char **"); nih_free (str); } /* Check that a two-level pointer has yet another further pointer * level added. */ TEST_FEATURE ("with pointer pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "char **"); } ret = type_to_pointer (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "char **"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "char ***"); nih_free (str); } /* Check that a constant pointer has a further level of pointerness * added, and the const moved to the new first level. */ TEST_FEATURE ("with const pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "const struct foo *"); } ret = type_to_pointer (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "const struct foo *"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "struct foo * const *"); nih_free (str); } /* Check that a constant pointer pointer has a further level of * pointerness added and the const moved to the new first level. */ TEST_FEATURE ("with const pointer pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "struct foo * const *"); } ret = type_to_pointer (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "struct foo * const *"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "struct foo ** const *"); nih_free (str); } /* Check that a constant pointer pointer pointer has a further level * of pointerness added and the const moved to the new first level. */ TEST_FEATURE ("with const pointer pointer pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "struct foo ** const *"); } ret = type_to_pointer (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "struct foo ** const *"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "struct foo *** const *"); nih_free (str); } /* Check that a pointer to a constant pointer only has a further * level of pointerness added, and the const pointer is not * moved to the new first level. */ TEST_FEATURE ("with pointer to const pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "const struct foo **"); } ret = type_to_pointer (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "const struct foo **"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "const struct foo ***"); nih_free (str); } /* Check that a pointer to a constant pointer pointer only has a * further level of pointerness added, and the const pointer is not * moved to the new first level. */ TEST_FEATURE ("with pointer to const pointer pointer"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "struct foo * const **"); } ret = type_to_pointer (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "struct foo * const **"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "struct foo * const ***"); nih_free (str); } } void test_to_static (void) { char *str = NULL; char *ret; TEST_FUNCTION ("type_to_static"); /* Check to make sure that a non-static declaration is returned * with "static" prepended onto it. */ TEST_FEATURE ("with non-static type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "int"); } ret = type_to_static (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "int"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "static int"); nih_free (str); } /* Check to make sure that a static declaration is returned * unmodified. */ TEST_FEATURE ("with static type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "static int"); } ret = type_to_static (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "static int"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "static int"); nih_free (str); } } void test_to_extern (void) { char *str = NULL; char *ret; TEST_FUNCTION ("type_to_extern"); /* Check to make sure that a non-extern declaration is returned * with "extern" prepended onto it. */ TEST_FEATURE ("with non-extern type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "int"); } ret = type_to_extern (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "int"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "extern int"); nih_free (str); } /* Check to make sure that an extern declaration is returned * unmodified. */ TEST_FEATURE ("with extern type"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { str = nih_strdup (NULL, "extern int"); } ret = type_to_extern (&str, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); TEST_EQ_STR (str, "extern int"); nih_free (str); continue; } TEST_EQ_P (ret, str); TEST_EQ_STR (str, "extern int"); nih_free (str); } } void test_strcat_assert (void) { char * block = NULL; TypeVar *var = NULL; TypeVar *other = NULL; char * ret; TEST_FUNCTION ("type_strcat_assert"); /* Check that a non-pointer variable has no assert line added. */ TEST_FEATURE ("with non-pointer variable"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { block = nih_strdup (NULL, ""); var = type_var_new (NULL, "int", "foo"); } ret = type_strcat_assert (&block, NULL, var, NULL, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); nih_free (var); nih_free (block); continue; } TEST_EQ_P (ret, block); TEST_EQ_STR (block, ""); nih_free (var); nih_free (block); } /* Check that a pointer variable has an assert line added for it. */ TEST_FEATURE ("with pointer variable"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { block = nih_strdup (NULL, ""); var = type_var_new (NULL, "int *", "foo"); } ret = type_strcat_assert (&block, NULL, var, NULL, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); nih_free (var); nih_free (block); continue; } TEST_EQ_P (ret, block); TEST_EQ_STR (block, "nih_assert (foo != NULL);\n"); nih_free (var); nih_free (block); } /* Check that a pointer variable with a following size argument's * assert line is modified so it may be NULL if the size is zero. */ TEST_FEATURE ("with array variable"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { block = nih_strdup (NULL, ""); var = type_var_new (NULL, "int *", "foo"); other = type_var_new (NULL, "size_t", "foo_len"); } ret = type_strcat_assert (&block, NULL, var, NULL, other); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); nih_free (other); nih_free (var); nih_free (block); continue; } TEST_EQ_P (ret, block); TEST_EQ_STR (block, "nih_assert ((foo_len == 0) || (foo != NULL));\n"); nih_free (other); nih_free (var); nih_free (block); } /* Make sure that any other following element doesn't result in the * pointer being considered an array. */ TEST_FEATURE ("with pointer variable and following argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { block = nih_strdup (NULL, ""); var = type_var_new (NULL, "int *", "foo"); other = type_var_new (NULL, "int", "foo_len"); } ret = type_strcat_assert (&block, NULL, var, NULL, other); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); nih_free (other); nih_free (var); nih_free (block); continue; } TEST_EQ_P (ret, block); TEST_EQ_STR (block, "nih_assert (foo != NULL);\n"); nih_free (other); nih_free (var); nih_free (block); } /* Check that an array of size variables may be NULL if the first * element of the array is NULL. */ TEST_FEATURE ("with size array variable"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { block = nih_strdup (NULL, ""); var = type_var_new (NULL, "size_t *", "foo_len"); other = type_var_new (NULL, "int32_t **", "foo"); } ret = type_strcat_assert (&block, NULL, var, other, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); nih_free (other); nih_free (var); nih_free (block); continue; } TEST_EQ_P (ret, block); TEST_EQ_STR (block, "nih_assert ((*foo == NULL) || (foo_len != NULL));\n"); nih_free (other); nih_free (var); nih_free (block); } /* Make sure that any other preceeding element doesn't result in the * pointer being considered an array. */ TEST_FEATURE ("with pointer variable and preceeding argument"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { block = nih_strdup (NULL, ""); var = type_var_new (NULL, "int32 *", "foo_len"); other = type_var_new (NULL, "int32_t **", "foo"); } ret = type_strcat_assert (&block, NULL, var, other, NULL); if (test_alloc_failed) { TEST_EQ_P (ret, NULL); nih_free (other); nih_free (var); nih_free (block); continue; } TEST_EQ_P (ret, block); TEST_EQ_STR (block, "nih_assert (foo_len != NULL);\n"); nih_free (other); nih_free (var); nih_free (block); } } int main (int argc, char *argv[]) { test_const (); test_of (); test_var_new (); test_var_to_string (); test_var_layout (); test_func_new (); test_func_to_string (); test_func_to_typedef (); test_func_layout (); test_struct_new (); test_struct_to_string (); test_to_const (); test_to_pointer (); test_to_static (); test_to_extern (); test_strcat_assert (); return 0; } libnih-1.0.3/nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.h0000644000175000017500000000376411504711552021006 00000000000000/* libnih * * Copyright © 2010 Scott James Remnant . * Copyright © 2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef DBUS__COM_NETSPLIT_NIH_TEST_IMPL_H #define DBUS__COM_NETSPLIT_NIH_TEST_IMPL_H #include #include #include typedef struct my_struct { char * item0; uint32_t item1; } MyStruct; NIH_BEGIN_EXTERN extern int async_method_main_loop; extern char * async_method_input; extern NihDBusMessage *async_method_message; extern uint8_t byte_property; extern int boolean_property; extern int16_t int16_property; extern uint16_t uint16_property; extern int32_t int32_property; extern uint32_t uint32_property; extern int64_t int64_property; extern uint64_t uint64_property; extern double double_property; extern char * str_property; extern char * object_path_property; extern char * signature_property; extern MyStruct * struct_property; extern int32_t * int32_array_property; extern size_t int32_array_property_len; extern char ** str_array_property; extern int32_t ** int32_array_array_property; extern size_t * int32_array_array_property_len; extern MyStruct **struct_array_property; extern MyStruct **dict_entry_array_property; extern int unix_fd_property; NIH_END_EXTERN #endif /* DBUS__COM_NETSPLIT_NIH_TEST_IMPL_H */ libnih-1.0.3/nih-dbus-tool/tests/com.netsplit.Nih.Test.xml0000644000175000017500000002135111504711507020326 00000000000000 libnih-1.0.3/nih-dbus-tool/tests/marshal_factory.c0000644000175000017500000001074411504705714017063 00000000000000/* nih-dbus-tool * * tests/marshal_factory.c - generate tests/marshal_code.c * * Copyright © 2010 Scott James Remnant . * Copyright © 2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include "indent.h" #include "type.h" #include "marshal.h" static void marshal_function (const char *name, const char *signature) { DBusSignatureIter iter; nih_local char * code = NULL; NihList locals; NihList inputs; NihList structs; nih_list_init (&inputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&iter, signature); code = marshal (NULL, &iter, "iter", "value", "return -1;\n", &inputs, &locals, "my", NULL, name, "value", &structs); printf ("int\n" "my_%s_marshal (DBusMessage *message", name); NIH_LIST_FOREACH (&inputs, iter) { TypeVar *var = (TypeVar *)iter; assert (type_to_const (&var->type, var)); printf (", %s %s", var->type, var->name); } printf (")\n" "{\n" "\tDBusMessageIter iter;\n"); NIH_LIST_FOREACH (&locals, iter) { TypeVar *local_var = (TypeVar *)iter; printf ("\t%s %s;\n", local_var->type, local_var->name); } printf ("\n" /* FIXME */ "\tnih_assert (message != NULL);\n" "\n" "\tdbus_message_iter_init_append (message, &iter);\n" "\n"); assert (indent (&code, NULL, 1)); printf ("%s", code); printf ("\n" "\treturn 0;\n" "}\n" "\n"); } int main (int argc, char *argv[]) { printf ("#include \n" "\n" "#include \n" "#include \n" "#include \n" "#include \n" "#include \n" "\n" "#include \"tests/marshal_code.h\"\n" "\n"); marshal_function ("byte", DBUS_TYPE_BYTE_AS_STRING); marshal_function ("boolean", DBUS_TYPE_BOOLEAN_AS_STRING); marshal_function ("int16", DBUS_TYPE_INT16_AS_STRING); marshal_function ("uint16", DBUS_TYPE_UINT16_AS_STRING); marshal_function ("int32", DBUS_TYPE_INT32_AS_STRING); marshal_function ("uint32", DBUS_TYPE_UINT32_AS_STRING); marshal_function ("int64", DBUS_TYPE_INT64_AS_STRING); marshal_function ("uint64", DBUS_TYPE_UINT64_AS_STRING); marshal_function ("double", DBUS_TYPE_DOUBLE_AS_STRING); marshal_function ("string", DBUS_TYPE_STRING_AS_STRING); marshal_function ("object_path", DBUS_TYPE_OBJECT_PATH_AS_STRING); marshal_function ("signature", DBUS_TYPE_SIGNATURE_AS_STRING); marshal_function ("int16_array", (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING)); marshal_function ("int16_array_array", (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING)); marshal_function ("string_array", (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)); marshal_function ("string_array_array", (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)); marshal_function ("struct", (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING)); marshal_function ("struct_array", (DBUS_TYPE_ARRAY_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING)); marshal_function ("dict_entry_array", (DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING)); marshal_function ("unix_fd", DBUS_TYPE_UNIX_FD_AS_STRING); return 0; } libnih-1.0.3/nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.c0000644000175000017500000017772611504715052021012 00000000000000/* libnih * * com.netsplit.Nih.Test_impl.c - implementation of test object interfaces * * Copyright © 2010 Scott James Remnant . * Copyright © 2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "tests/com.netsplit.Nih.Test_object.h" #include "tests/com.netsplit.Nih.Test_impl.h" int my_test_ordinary_method (void * data, NihDBusMessage *message, const char * input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.OrdinaryMethod.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_strdup (message, input); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_nameless_method (void * data, NihDBusMessage *message, const char * arg1, char ** arg2) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (arg1, NULL); TEST_NE_P (arg2, NULL); if (! strlen (arg1)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.NamelessMethod.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (arg1, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *arg2 = nih_strdup (message, arg1); if (! *arg2) nih_return_no_memory_error (-1); return 0; } int async_method_main_loop; char * async_method_input; NihDBusMessage *async_method_message; static void my_test_async_method_send_reply (void * data, NihMainLoopFunc *loop) { NIH_ZERO (my_test_async_method_reply (async_method_message, async_method_input)); nih_free (async_method_message); nih_free (async_method_input); async_method_input = NULL; async_method_message = NULL; nih_free (loop); } int my_test_async_method (void * data, NihDBusMessage *message, const char * input) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.AsyncMethod.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } if (async_method_input) nih_free (async_method_input); async_method_input = nih_strdup (NULL, input); if (! async_method_input) nih_return_no_memory_error (-1); async_method_message = message; nih_ref (async_method_message, async_method_input); if (async_method_main_loop) NIH_MUST (nih_main_loop_add_func (NULL, my_test_async_method_send_reply, NULL)); return 0; } int my_test_byte_to_str (void * data, NihDBusMessage *message, uint8_t input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); if (! input) { nih_dbus_error_raise ("com.netsplit.Nih.Test.ByteToStr.ZeroInput", "The input argument was zero"); return -1; } else if (input == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_sprintf (message, "%hhu", (unsigned char)input); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_str_to_byte (void * data, NihDBusMessage *message, const char * input, uint8_t * output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToByte.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = (uint8_t)strtoumax (input, NULL, 10); return 0; } int my_test_boolean_to_str (void * data, NihDBusMessage *message, int input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); /* Yes, this is just wrong, but D-Bus sanitises booleans for us over * the wire so we can only receive TRUE or FALSE. */ if (! input) { nih_dbus_error_raise ("com.netsplit.Nih.Test.BooleanToStr.ZeroInput", "The input argument was zero"); return -1; } *output = nih_strdup (message, input ? "True" : "False"); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_str_to_boolean (void * data, NihDBusMessage *message, const char * input, int * output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToBoolean.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } if (! strcmp (input, "False")) { *output = FALSE; } else { *output = TRUE; } return 0; } int my_test_int16_to_str (void * data, NihDBusMessage *message, int16_t input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); if (! input) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int16ToStr.ZeroInput", "The input argument was zero"); return -1; } else if (input == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_sprintf (message, "%hd", (short)input); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_str_to_int16 (void * data, NihDBusMessage *message, const char * input, int16_t * output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToInt16.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = (int16_t)strtoimax (input, NULL, 10); return 0; } int my_test_uint16_to_str (void * data, NihDBusMessage *message, uint16_t input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); if (! input) { nih_dbus_error_raise ("com.netsplit.Nih.Test.UInt16ToStr.ZeroInput", "The input argument was zero"); return -1; } else if (input == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_sprintf (message, "%hu", (unsigned short)input); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_str_to_uint16 (void * data, NihDBusMessage *message, const char * input, uint16_t * output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToUInt16.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = (uint16_t)strtoumax (input, NULL, 10); return 0; } int my_test_int32_to_str (void * data, NihDBusMessage *message, int32_t input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); if (! input) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int32ToStr.ZeroInput", "The input argument was zero"); return -1; } else if (input == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = NIH_MUST (nih_sprintf (message, "%d", (int)input)); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_str_to_int32 (void * data, NihDBusMessage *message, const char * input, int32_t * output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToInt32.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = (int32_t)strtoimax (input, NULL, 10); return 0; } int my_test_uint32_to_str (void * data, NihDBusMessage *message, uint32_t input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); if (! input) { nih_dbus_error_raise ("com.netsplit.Nih.Test.UInt32ToStr.ZeroInput", "The input argument was zero"); return -1; } else if (input == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_sprintf (message, "%u", (unsigned int)input); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_str_to_uint32 (void * data, NihDBusMessage *message, const char * input, uint32_t * output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToUInt32.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = (uint32_t)strtoumax (input, NULL, 10); return 0; } int my_test_int64_to_str (void * data, NihDBusMessage *message, int64_t input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); if (! input) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int64ToStr.ZeroInput", "The input argument was zero"); return -1; } else if (input == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_sprintf (message, "%lld", (long long)input); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_str_to_int64 (void * data, NihDBusMessage *message, const char * input, int64_t * output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToInt64.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = (int64_t)strtoimax (input, NULL, 10); return 0; } int my_test_uint64_to_str (void * data, NihDBusMessage *message, uint64_t input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); if (! input) { nih_dbus_error_raise ("com.netsplit.Nih.Test.UInt64ToStr.ZeroInput", "The input argument was zero"); return -1; } else if (input == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_sprintf (message, "%llu", (unsigned long long)input); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_str_to_uint64 (void * data, NihDBusMessage *message, const char * input, uint64_t * output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToUInt64.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = (uint64_t)strtoumax (input, NULL, 10); return 0; } int my_test_double_to_str (void * data, NihDBusMessage *message, double input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); if (! input) { nih_dbus_error_raise ("com.netsplit.Nih.Test.DoubleToStr.ZeroInput", "The input argument was zero"); return -1; } else if (input == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_sprintf (message, "%f", input); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_str_to_double (void * data, NihDBusMessage *message, const char * input, double * output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToDouble.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = strtod (input, NULL); return 0; } int my_test_object_path_to_str (void * data, NihDBusMessage *message, const char * input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strcmp (input, "/")) { nih_dbus_error_raise ("com.netsplit.Nih.Test.ObjectPathToStr.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "/invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_strdup (message, input); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_str_to_object_path (void * data, NihDBusMessage *message, const char * input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToObjectPath.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_strdup (message, input); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_signature_to_str (void * data, NihDBusMessage *message, const char * input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.SignatureToStr.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "inva(x)id")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_strdup (message, input); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_str_to_signature (void * data, NihDBusMessage *message, const char * input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToSignature.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_strdup (message, input); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_struct_to_str (void * data, NihDBusMessage * message, const MyTestStructToStrInput *input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_ALLOC_PARENT (input, message); TEST_NE_P (input->item0, NULL); TEST_ALLOC_PARENT (input->item0, input); TEST_NE_P (output, NULL); if (! strlen (input->item0)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StructToStr.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input->item0, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_sprintf (message, "%s %u", input->item0, (unsigned int)input->item1); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_str_to_struct (void * data, NihDBusMessage * message, const char * input, MyTestStrToStructOutput **output) { char item0_value[512]; unsigned int item1_value; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_ALLOC_PARENT (input, message); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToStruct.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } sscanf (input, "%s %d", item0_value, &item1_value); *output = nih_new (message, MyTestStrToStructOutput); if (! *output) nih_return_no_memory_error (-1); (*output)->item0 = nih_strdup (*output, item0_value); if (! (*output)->item0) { nih_error_raise_no_memory (); nih_free (*output); *output = NULL; return -1; } (*output)->item1 = item1_value; return 0; } int my_test_int32_array_to_str (void * data, NihDBusMessage *message, int32_t * input, size_t input_len, char ** output) { char *str; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); if (input_len) TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! input_len) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int32ArrayToStr.EmptyInput", "The input array was empty"); return -1; } else if (input_len == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } str = NULL; for (size_t i = 0; i < input_len; i++) { if (! nih_strcat_sprintf (&str, message, i ? " %d" : "%d", (int)input[i])) { nih_error_raise_no_memory (); if (str) nih_free (str); return -1; } } *output = str; return 0; } int my_test_str_to_int32_array (void * data, NihDBusMessage *message, const char * input, int32_t ** output, size_t * output_len) { nih_local char **parts = NULL; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToInt32Array.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = NULL; *output_len = 0; parts = nih_str_split (NULL, input, " ", FALSE); if (! parts) nih_return_no_memory_error (-1); for (char **part = parts; part && *part; part++) { int32_t *tmp; tmp = nih_realloc (*output, message, sizeof (int32_t) * (*output_len + 1)); if (! tmp) { nih_error_raise_no_memory (); if (*output) { nih_free (*output); *output = NULL; } return -1; } *output = tmp; (*output)[(*output_len)++] = (int32_t)strtoimax (*part, NULL, 10); } return 0; } int my_test_str_array_to_str (void * data, NihDBusMessage *message, char * const * input, char ** output) { char *str; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! *input) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrArrayToStr.EmptyInput", "The input array was empty"); return -1; } else if (input[0] && input[1] && input[2] && input[3] && (! input[4])) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } str = NULL; for (char * const *s = input; s && *s; s++) { if (! nih_strcat_sprintf (&str, message, str ? " %s" : "%s", *s)) { nih_error_raise_no_memory (); if (str) nih_free (str); return -1; } } *output = str; return 0; } int my_test_str_to_str_array (void * data, NihDBusMessage *message, const char * input, char *** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToStrArray.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = nih_str_split (message, input, " ", FALSE); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_int32_array_array_to_str (void * data, NihDBusMessage *message, int32_t ** input, size_t * input_len, char ** output) { char * str; size_t *array_len; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! *input) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int32ArrayArrayToStr.EmptyInput", "The input array was empty"); return -1; } else if (input[0] && (! input[1])) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } str = NULL; array_len = input_len; for (int32_t **array = input; array && *array; array++) { for (size_t i = 0; i < *array_len; i++) { if (! nih_strcat_sprintf (&str, message, i ? " %d" : (str ? "\n%d" : "%d"), (int)(*array)[i])) { nih_error_raise_no_memory (); if (str) nih_free (str); return -1; } } } *output = str; return 0; } int my_test_str_to_int32_array_array (void * data, NihDBusMessage *message, const char * input, int32_t *** output, size_t ** output_len) { nih_local char **lines = NULL; size_t output_size = 0; int32_t ** tmp; size_t * tmp_len; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToInt32ArrayArray.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = NULL; *output_len = NULL; output_size = 0; lines = nih_str_split (NULL, input, "\n", FALSE); if (! lines) nih_return_no_memory_error (-1); for (char **line = lines; line && *line; line++) { nih_local char **parts = NULL; size_t array_size; tmp = nih_realloc (*output, message, sizeof (int32_t *) * (output_size + 1)); if (! tmp) goto error; *output = tmp; (*output)[output_size] = NULL; tmp_len = nih_realloc (*output_len, message, sizeof (size_t) * (output_size + 1)); if (! tmp_len) goto error; *output_len = tmp_len; parts = nih_str_split (NULL, *line, " ", FALSE); if (! parts) goto error; array_size = 0; for (char **part = parts; part && *part; part++) { int32_t *tmp; tmp = nih_realloc ((*output)[output_size], message, sizeof (int32_t) * (array_size + 1)); if (! tmp) goto error; (*output)[output_size] = tmp; (*output)[output_size][array_size++] \ = (int32_t)strtoimax (*part, NULL, 10); } (*output_len)[output_size++] = array_size; } tmp = nih_realloc (*output, message, sizeof (int32_t *) * (output_size + 1)); if (! tmp) goto error; *output = tmp; (*output)[output_size] = NULL; tmp_len = nih_realloc (*output_len, message, sizeof (size_t) * (output_size + 1)); if (! tmp_len) goto error; *output_len = tmp_len; (*output_len)[output_size] = 0; return 0; error: nih_error_raise_no_memory (); if (*output) { nih_free (*output); *output = NULL; } if (*output_len) { nih_free (*output_len); *output_len = NULL; } return -1; } int my_test_struct_array_to_str (void * data, NihDBusMessage *message, MyTestStructArrayToStrInputElement * const *input, char ** output) { char *str; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_ALLOC_PARENT (input, message); TEST_NE_P (output, NULL); if (! input[0]) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StructArrayToStr.EmptyInput", "The input argument was empty"); return -1; } else if (! input[1]) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } str = NULL; for (MyTestStructArrayToStrInputElement * const *element = input; element && *element; element++) { if (! nih_strcat_sprintf (&str, message, str ? "\n%s %u" : "%s %u", (*element)->item0, (unsigned int)(*element)->item1)) { nih_error_raise_no_memory (); if (str) nih_free (str); return -1; } } *output = str; return 0; } int my_test_str_to_struct_array (void * data, NihDBusMessage *message, const char * input, MyTestStrToStructArrayOutputElement ***output) { MyTestStrToStructArrayOutputElement **tmp; MyTestStrToStructArrayOutputElement *element; nih_local char **lines = NULL; size_t output_size; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_ALLOC_PARENT (input, message); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToStructArray.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = NULL; output_size = 0; lines = nih_str_split (NULL, input, "\n", FALSE); if (! lines) nih_return_no_memory_error (-1); for (char **line = lines; line && *line; line++) { char item0_value[512]; uint32_t item1_value; tmp = nih_realloc (*output, message, sizeof (MyTestStrToStructArrayOutputElement *) * (output_size + 1)); if (! tmp) goto error; *output = tmp; sscanf (*line, "%s %d", item0_value, &item1_value); element = nih_new (*output, MyTestStrToStructArrayOutputElement); if (! element) goto error; element->item0 = nih_strdup (element, item0_value); if (! element->item0) goto error; element->item1 = item1_value; (*output)[output_size++] = element; } tmp = nih_realloc (*output, message, sizeof (MyTestStrToStructArrayOutputElement *) * (output_size + 1)); if (! tmp) goto error; *output = tmp; (*output)[output_size++] = NULL;; return 0; error: nih_error_raise_no_memory (); if (*output) { nih_free (*output); *output = NULL; } return -1; } int my_test_dict_entry_array_to_str (void * data, NihDBusMessage *message, MyTestDictEntryArrayToStrInputElement * const *input, char ** output) { char *str; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_ALLOC_PARENT (input, message); TEST_NE_P (output, NULL); if (! input[0]) { nih_dbus_error_raise ("com.netsplit.Nih.Test.DictEntryArrayToStr.EmptyInput", "The input argument was empty"); return -1; } else if (! input[1]) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } str = NULL; for (MyTestDictEntryArrayToStrInputElement * const *element = input; element && *element; element++) { if (! nih_strcat_sprintf (&str, message, str ? "\n%s %u" : "%s %u", (*element)->item0, (unsigned int)(*element)->item1)) { nih_error_raise_no_memory (); if (str) nih_free (str); return -1; } } *output = str; return 0; } int my_test_str_to_dict_entry_array (void * data, NihDBusMessage *message, const char * input, MyTestStrToDictEntryArrayOutputElement ***output) { MyTestStrToDictEntryArrayOutputElement **tmp; MyTestStrToDictEntryArrayOutputElement *element; nih_local char **lines = NULL; size_t output_size; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_ALLOC_PARENT (input, message); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToDictEntryArray.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = NULL; output_size = 0; lines = nih_str_split (NULL, input, "\n", FALSE); if (! lines) nih_return_no_memory_error (-1); for (char **line = lines; line && *line; line++) { char item0_value[512]; uint32_t item1_value; tmp = nih_realloc (*output, message, sizeof (MyTestStrToDictEntryArrayOutputElement *) * (output_size + 1)); if (! tmp) goto error; *output = tmp; sscanf (*line, "%s %d", item0_value, &item1_value); element = nih_new (*output, MyTestStrToDictEntryArrayOutputElement); if (! element) goto error; element->item0 = nih_strdup (element, item0_value); if (! element->item0) goto error; element->item1 = item1_value; (*output)[output_size++] = element; } tmp = nih_realloc (*output, message, sizeof (MyTestStrToDictEntryArrayOutputElement *) * (output_size + 1)); if (! tmp) goto error; *output = tmp; (*output)[output_size++] = NULL;; return 0; error: nih_error_raise_no_memory (); if (*output) { nih_free (*output); *output = NULL; } return -1; } int my_test_unix_fd_to_str (void * data, NihDBusMessage *message, int input, char ** output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (output, NULL); /* We don't care, we just don't want to leak */ close (input); *output = nih_sprintf (message, "%d", input); if (! *output) nih_return_no_memory_error (-1); return 0; } int my_test_str_to_unix_fd (void * data, NihDBusMessage *message, const char * input, int * output) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (input, NULL); TEST_NE_P (output, NULL); if (! strlen (input)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrToUnixFd.EmptyInput", "The input argument was empty"); return -1; } else if (! strcmp (input, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *output = atoi (input); return 0; } uint8_t byte_property; int my_test_get_byte (void * data, NihDBusMessage *message, uint8_t * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! byte_property) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Byte.Zero", "The property value was zero"); return -1; } else if (byte_property == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = byte_property; return 0; } int my_test_set_byte (void * data, NihDBusMessage *message, uint8_t value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); if (! value) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Byte.Zero", "The property value was zero"); return -1; } else if (value == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } byte_property = value; return 0; } int boolean_property; int my_test_get_boolean (void * data, NihDBusMessage *message, int * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); /* Yes, this is just wrong, but D-Bus sanitises booleans for us over * the wire so we can only receive TRUE or FALSE. */ if (! boolean_property) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Boolean.Zero", "The property value was zero"); return -1; } *value = boolean_property; return 0; } int my_test_set_boolean (void * data, NihDBusMessage *message, int value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); /* Yes, this is just wrong, but D-Bus sanitises booleans for us over * the wire so we can only receive TRUE or FALSE. */ if (! value) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Boolean.Zero", "The property value was zero"); return -1; } boolean_property = value; return 0; } int16_t int16_property; int my_test_get_int16 (void * data, NihDBusMessage *message, int16_t * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! int16_property) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int16.Zero", "The property value was zero"); return -1; } else if (int16_property == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = int16_property; return 0; } int my_test_set_int16 (void * data, NihDBusMessage *message, int16_t value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); if (! value) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int16.Zero", "The property value was zero"); return -1; } else if (value == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } int16_property = value; return 0; } uint16_t uint16_property; int my_test_get_uint16 (void * data, NihDBusMessage *message, uint16_t * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! uint16_property) { nih_dbus_error_raise ("com.netsplit.Nih.Test.UInt16.Zero", "The property value was zero"); return -1; } else if (uint16_property == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = uint16_property; return 0; } int my_test_set_uint16 (void * data, NihDBusMessage *message, uint16_t value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); if (! value) { nih_dbus_error_raise ("com.netsplit.Nih.Test.UInt16.Zero", "The property value was zero"); return -1; } else if (value == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } uint16_property = value; return 0; } int32_t int32_property; int my_test_get_int32 (void * data, NihDBusMessage *message, int32_t * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! int32_property) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int32.Zero", "The property value was zero"); return -1; } else if (int32_property == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = int32_property; return 0; } int my_test_set_int32 (void * data, NihDBusMessage *message, int32_t value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); if (! value) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int32.Zero", "The property value was zero"); return -1; } else if (value == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } int32_property = value; return 0; } uint32_t uint32_property; int my_test_get_uint32 (void * data, NihDBusMessage *message, uint32_t * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! uint32_property) { nih_dbus_error_raise ("com.netsplit.Nih.Test.UInt32.Zero", "The property value was zero"); return -1; } else if (uint32_property == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = uint32_property; return 0; } int my_test_set_uint32 (void * data, NihDBusMessage *message, uint32_t value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); if (! value) { nih_dbus_error_raise ("com.netsplit.Nih.Test.UInt32.Zero", "The property value was zero"); return -1; } else if (value == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } uint32_property = value; return 0; } int64_t int64_property; int my_test_get_int64 (void * data, NihDBusMessage *message, int64_t * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! int64_property) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int64.Zero", "The property value was zero"); return -1; } else if (int64_property == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = int64_property; return 0; } int my_test_set_int64 (void * data, NihDBusMessage *message, int64_t value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); if (! value) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int64.Zero", "The property value was zero"); return -1; } else if (value == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } int64_property = value; return 0; } uint64_t uint64_property; int my_test_get_uint64 (void * data, NihDBusMessage *message, uint64_t * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! uint64_property) { nih_dbus_error_raise ("com.netsplit.Nih.Test.UInt64.Zero", "The property value was zero"); return -1; } else if (uint64_property == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = uint64_property; return 0; } int my_test_set_uint64 (void * data, NihDBusMessage *message, uint64_t value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); if (! value) { nih_dbus_error_raise ("com.netsplit.Nih.Test.UInt64.Zero", "The property value was zero"); return -1; } else if (value == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } uint64_property = value; return 0; } double double_property; int my_test_get_dubble (void * data, NihDBusMessage *message, double * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! double_property) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Double.Zero", "The property value was zero"); return -1; } else if (double_property == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = double_property; return 0; } int my_test_set_dubble (void * data, NihDBusMessage *message, double value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); if (! value) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Double.Zero", "The property value was zero"); return -1; } else if (value == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } double_property = value; return 0; } char *str_property; int my_test_get_string (void * data, NihDBusMessage *message, char ** value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! strlen (str_property)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.String.Empty", "The property value was empty"); return -1; } else if (! strcmp (str_property, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = nih_strdup (message, str_property); if (! *value) nih_return_no_memory_error (-1); return 0; } int my_test_set_string (void * data, NihDBusMessage *message, const char * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! strlen (value)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.String.Empty", "The property value was empty"); return -1; } else if (! strcmp (value, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } if (str_property) nih_free (str_property); str_property = nih_strdup (NULL, value); if (! str_property) nih_return_no_memory_error (-1); return 0; } char *object_path_property; int my_test_get_object_path (void * data, NihDBusMessage *message, char ** value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! strcmp (object_path_property, "/")) { nih_dbus_error_raise ("com.netsplit.Nih.Test.ObjectPath.Empty", "The property value was empty"); return -1; } else if (! strcmp (object_path_property, "/invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = nih_strdup (message, object_path_property); if (! *value) nih_return_no_memory_error (-1); return 0; } int my_test_set_object_path (void * data, NihDBusMessage *message, const char * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! strcmp (value, "/")) { nih_dbus_error_raise ("com.netsplit.Nih.Test.ObjectPath.Empty", "The property value was empty"); return -1; } else if (! strcmp (value, "/invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } if (object_path_property) nih_free (object_path_property); object_path_property = nih_strdup (NULL, value); if (! object_path_property) nih_return_no_memory_error (-1); return 0; } char *signature_property; int my_test_get_signature (void * data, NihDBusMessage *message, char ** value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! strlen (signature_property)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Signature.Empty", "The property value was empty"); return -1; } else if (! strcmp (signature_property, "inva(x)id")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = nih_strdup (message, signature_property); if (! *value) nih_return_no_memory_error (-1); return 0; } int my_test_set_signature (void * data, NihDBusMessage *message, const char * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! strlen (value)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Signature.Empty", "The property value was empty"); return -1; } else if (! strcmp (value, "inva(x)id")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } if (signature_property) nih_free (signature_property); signature_property = nih_strdup (NULL, value); if (! signature_property) nih_return_no_memory_error (-1); return 0; } MyStruct *struct_property; int my_test_get_structure (void * data, NihDBusMessage * message, MyTestStructure **value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! strlen (struct_property->item0)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Structure.Empty", "The property value was empty"); return -1; } else if (! strcmp (struct_property->item0, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = nih_new (message, MyTestStructure); if (! *value) nih_return_no_memory_error (-1); (*value)->item0 = nih_strdup (*value, struct_property->item0); if (! (*value)->item0) { nih_error_raise_no_memory (); nih_free (*value); return -1; } (*value)->item1 = struct_property->item1; return 0; } int my_test_set_structure (void * data, NihDBusMessage * message, const MyTestStructure *value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! strlen (value->item0)) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Structure.Empty", "The property value was empty"); return -1; } else if (! strcmp (value->item0, "invalid")) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } if (struct_property) nih_free (struct_property); struct_property = nih_new (NULL, MyStruct); if (! struct_property) nih_return_no_memory_error (-1); struct_property->item0 = nih_strdup (struct_property, value->item0); if (! struct_property->item0) { nih_error_raise_no_memory (); nih_free (struct_property); struct_property = NULL; return -1; } struct_property->item1 = value->item1; return 0; } int32_t *int32_array_property; size_t int32_array_property_len; int my_test_get_int32_array (void * data, NihDBusMessage *message, int32_t ** value, size_t * value_len) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_NE_P (value_len, NULL); if (! int32_array_property_len) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int32Array.Empty", "The property value was empty"); return -1; } else if (int32_array_property_len == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = nih_alloc (message, sizeof (int32_t) * int32_array_property_len); if (! *value) nih_return_no_memory_error (-1); memcpy (*value, int32_array_property, sizeof (int32_t) * int32_array_property_len); *value_len = int32_array_property_len; return 0; } int my_test_set_int32_array (void * data, NihDBusMessage *message, const int32_t * value, size_t value_len) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); if (value_len) TEST_NE_P (value, NULL); if (! value_len) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int32Array.Empty", "The property value was empty"); return -1; } else if (value_len == 4) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } if (int32_array_property) nih_free (int32_array_property); int32_array_property = nih_alloc (NULL, sizeof (int32_t) * value_len); if (! int32_array_property) nih_return_no_memory_error (-1); memcpy (int32_array_property, value, sizeof (int32_t) * value_len); int32_array_property_len = value_len; return 0; } char **str_array_property; int my_test_get_str_array (void * data, NihDBusMessage *message, char *** value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! *str_array_property) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrArray.Empty", "The property array was empty"); return -1; } else if (str_array_property[0] && str_array_property[1] && str_array_property[2] && str_array_property[3] && (! str_array_property[4])) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = nih_str_array_copy (message, NULL, str_array_property); if (! *value) nih_return_no_memory_error (-1); return 0; } int my_test_set_str_array (void * data, NihDBusMessage *message, char * const * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! *value) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StrArray.Empty", "The property array was empty"); return -1; } else if (value[0] && value[1] && value[2] && value[3] && (! value[4])) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } if (str_array_property) nih_free (str_array_property); str_array_property = nih_str_array_copy (NULL, NULL, value); if (! str_array_property) nih_return_no_memory_error (-1); return 0; } int32_t **int32_array_array_property; size_t * int32_array_array_property_len; int my_test_get_int32_array_array (void * data, NihDBusMessage *message, int32_t *** value, size_t ** value_len) { size_t array_size; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); TEST_NE_P (value_len, NULL); if (! *int32_array_array_property) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int32ArrayArray.Empty", "The property array was empty"); return -1; } else if (int32_array_array_property[0] && (! int32_array_array_property[1])) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } array_size = 0; for (int32_t **array = int32_array_array_property; array && *array; array++) array_size++; *value = nih_alloc (message, sizeof (int32_t *) * (array_size + 1)); if (! *value) nih_return_no_memory_error (-1); *value_len = nih_alloc (message, sizeof (size_t) * array_size); if (! *value_len) { nih_free (*value); *value = NULL; nih_return_no_memory_error (-1); } array_size = 0; for (int32_t **array = int32_array_array_property; array && *array; array++) { (*value)[array_size] = nih_alloc (*value, sizeof (int32_t) * int32_array_array_property_len[array_size]); if (! (*value)[array_size]) { nih_free (*value); *value = NULL; nih_free (*value_len); *value_len = NULL; nih_return_no_memory_error (-1); } memcpy ((*value)[array_size], int32_array_array_property[array_size], sizeof (int32_t) * int32_array_array_property_len[array_size]); (*value_len)[array_size] = int32_array_array_property_len[array_size]; array_size++; } (*value)[array_size] = NULL; return 0; } int my_test_set_int32_array_array (void * data, NihDBusMessage * message, int32_t * const *value, size_t * value_len) { size_t value_size; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! *value) { nih_dbus_error_raise ("com.netsplit.Nih.Test.Int32ArrayArray.Empty", "The property array was empty"); return -1; } else if (value[0] && (! value[1])) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } if (int32_array_array_property) nih_free (int32_array_array_property); if (int32_array_array_property_len) nih_free (int32_array_array_property_len); int32_array_array_property = NULL; int32_array_array_property_len = NULL; value_size = 0; for (int32_t * const *array = value; array && *array; array++) value_size++; int32_array_array_property = nih_alloc (NULL, sizeof (int32_t *) * (value_size + 1)); if (! int32_array_array_property) nih_return_no_memory_error (-1); int32_array_array_property_len = nih_alloc (NULL, sizeof (size_t) * value_size); if (! int32_array_array_property_len) { nih_free (int32_array_array_property); int32_array_array_property = NULL; nih_return_no_memory_error (-1); } value_size = 0; for (int32_t * const *array = value; array && *array; array++) { int32_array_array_property[value_size] = nih_alloc (int32_array_array_property, sizeof (int32_t) * value_len[value_size]); if (! int32_array_array_property[value_size]) { nih_free (int32_array_array_property); int32_array_array_property = NULL; nih_free (int32_array_array_property_len); int32_array_array_property_len = NULL; nih_return_no_memory_error (-1); } memcpy (int32_array_array_property[value_size], value[value_size], sizeof (int32_t) * value_len[value_size]); int32_array_array_property_len[value_size] = value_len[value_size]; value_size++; } int32_array_array_property[value_size] = NULL; return 0; } MyStruct **struct_array_property; int my_test_get_struct_array (void * data, NihDBusMessage * message, MyTestStructArrayElement ***value) { MyTestStructArrayElement **tmp; size_t value_size; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! struct_array_property[0]) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StructArray.Empty", "The property value was empty"); return -1; } else if (! struct_array_property[1]) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = NULL; value_size = 0; for (MyStruct **element = struct_array_property; element && *element; element++) { tmp = nih_realloc (*value, message, sizeof (MyTestStructArrayElement *) * (value_size + 1)); if (! tmp) goto error; *value = tmp; (*value)[value_size] = nih_new (*value, MyTestStructArrayElement); if (! (*value)[value_size]) goto error; (*value)[value_size]->item0 = nih_strdup ((*value)[value_size], (*element)->item0); if (! (*value)[value_size]->item0) goto error; (*value)[value_size]->item1 = (*element)->item1; value_size++; } tmp = nih_realloc (*value, message, sizeof (MyTestStructArrayElement *) * (value_size + 1)); if (! tmp) goto error; *value = tmp; (*value)[value_size] = NULL; return 0; error: nih_error_raise_no_memory (); if (*value) { nih_free (*value); *value = NULL; } return -1; } int my_test_set_struct_array (void * data, NihDBusMessage *message, MyTestStructArrayElement * const *value) { MyStruct **tmp; size_t value_size; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! value[0]) { nih_dbus_error_raise ("com.netsplit.Nih.Test.StructArray.Empty", "The property value was empty"); return -1; } else if (! value[1]) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } if (struct_array_property) nih_free (struct_array_property); struct_array_property = NULL; value_size = 0; for (MyTestStructArrayElement * const *element = value; element && *element; element++) { tmp = nih_realloc (struct_array_property, NULL, sizeof (MyStruct *) * (value_size + 1)); if (! tmp) goto error; struct_array_property = tmp; struct_array_property[value_size] = nih_new (struct_array_property, MyStruct); if (! struct_array_property[value_size]) goto error; struct_array_property[value_size]->item0 = nih_strdup (struct_array_property[value_size], (*element)->item0); if (! struct_array_property[value_size]->item0) goto error; struct_array_property[value_size]->item1 = (*element)->item1; value_size++; } tmp = nih_realloc (struct_array_property, NULL, sizeof (MyStruct *) * (value_size + 1)); if (! tmp) goto error; struct_array_property = tmp; struct_array_property[value_size] = NULL; return 0; error: nih_error_raise_no_memory (); if (struct_array_property) { nih_free (struct_array_property); struct_array_property = NULL; } return -1; } MyStruct **dict_entry_array_property; int my_test_get_dict_entry_array (void * data, NihDBusMessage * message, MyTestDictEntryArrayElement ***value) { MyTestDictEntryArrayElement **tmp; size_t value_size; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! dict_entry_array_property[0]) { nih_dbus_error_raise ("com.netsplit.Nih.Test.DictEntryArray.Empty", "The property value was empty"); return -1; } else if (! dict_entry_array_property[1]) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } *value = NULL; value_size = 0; for (MyStruct **element = dict_entry_array_property; element && *element; element++) { tmp = nih_realloc (*value, message, sizeof (MyTestDictEntryArrayElement *) * (value_size + 1)); if (! tmp) goto error; *value = tmp; (*value)[value_size] = nih_new (*value, MyTestDictEntryArrayElement); if (! (*value)[value_size]) goto error; (*value)[value_size]->item0 = nih_strdup ((*value)[value_size], (*element)->item0); if (! (*value)[value_size]->item0) goto error; (*value)[value_size]->item1 = (*element)->item1; value_size++; } tmp = nih_realloc (*value, message, sizeof (MyTestDictEntryArrayElement *) * (value_size + 1)); if (! tmp) goto error; *value = tmp; (*value)[value_size] = NULL; return 0; error: nih_error_raise_no_memory (); if (*value) { nih_free (*value); *value = NULL; } return -1; } int my_test_set_dict_entry_array (void * data, NihDBusMessage *message, MyTestDictEntryArrayElement * const *value) { MyStruct **tmp; size_t value_size; TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (! value[0]) { nih_dbus_error_raise ("com.netsplit.Nih.Test.DictEntryArray.Empty", "The property value was empty"); return -1; } else if (! value[1]) { nih_error_raise (EINVAL, "Invalid argument"); return -1; } if (dict_entry_array_property) nih_free (dict_entry_array_property); dict_entry_array_property = NULL; value_size = 0; for (MyTestDictEntryArrayElement * const *element = value; element && *element; element++) { tmp = nih_realloc (dict_entry_array_property, NULL, sizeof (MyStruct *) * (value_size + 1)); if (! tmp) goto error; dict_entry_array_property = tmp; dict_entry_array_property[value_size] = nih_new (dict_entry_array_property, MyStruct); if (! dict_entry_array_property[value_size]) goto error; dict_entry_array_property[value_size]->item0 = nih_strdup (dict_entry_array_property[value_size], (*element)->item0); if (! dict_entry_array_property[value_size]->item0) goto error; dict_entry_array_property[value_size]->item1 = (*element)->item1; value_size++; } tmp = nih_realloc (dict_entry_array_property, NULL, sizeof (MyStruct *) * (value_size + 1)); if (! tmp) goto error; dict_entry_array_property = tmp; dict_entry_array_property[value_size] = NULL; return 0; error: nih_error_raise_no_memory (); if (dict_entry_array_property) { nih_free (dict_entry_array_property); dict_entry_array_property = NULL; } return -1; } int unix_fd_property; int my_test_get_unix_fd (void * data, NihDBusMessage *message, int * value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); TEST_NE_P (value, NULL); if (unix_fd_property < 0) { nih_dbus_error_raise ("com.netsplit.Nih.Test.UnixFd.Invalid", "The property value was invalid"); return -1; } *value = unix_fd_property; return 0; } int my_test_set_unix_fd (void * data, NihDBusMessage *message, int value) { TEST_ALLOC_SIZE (message, sizeof (NihDBusMessage)); TEST_NE_P (message->connection, NULL); TEST_NE_P (message->message, NULL); unix_fd_property = value; return 0; } libnih-1.0.3/nih-dbus-tool/tests/test_demarshal.c0000644000175000017500000040207111504710171016673 00000000000000/* nih-dbus-tool * * test_demarshal.c - test suite for nih-dbus-tool/demarshal.c * * Copyright © 2010 Scott James Remnant . * Copyright © 2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include "type.h" #include "demarshal.h" #include "tests/demarshal_code.h" void test_demarshal (void) { NihList outputs; NihList locals; NihList structs; TypeVar * var; TypeStruct * structure; DBusSignatureIter signature; DBusMessage * message = NULL; DBusMessageIter iter; DBusMessageIter subiter; DBusMessageIter subsubiter; char * str; int ret; uint8_t byte_value; int boolean_value; int16_t int16_value; uint16_t uint16_value; int32_t int32_value; uint32_t uint32_value; int64_t int64_value; uint64_t uint64_value; double double_value; char * str_value; int16_t * int16_array; size_t int16_array_len; int16_t ** int16_array_array; size_t * int16_array_array_len; char ** str_array; char *** str_array_array; MyStructValue * struct_value; MyStructArrayValueElement **struct_array; MyDictEntryArrayValueElement **dict_entry_array; int unix_fd_value; TEST_FUNCTION ("demarshal"); /* Check that the code to demarshal a D-Bus Byte into a uint8_t is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with byte"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_BYTE_AS_STRING); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "byte", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a uint8_t from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_BYTE) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&iter, &value);\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "uint8_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the D-Bus Byte * in the message we pass and stores it in the uint8_t pointer, which * should have the right value. */ TEST_FEATURE ("with byte (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); byte_value = 42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BYTE, &byte_value); } byte_value = 0; ret = my_byte_demarshal (NULL, message, &byte_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ (byte_value, 42); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a byte is expected, but a different type is * found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for byte (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } byte_value = 0; ret = my_byte_demarshal (NULL, message, &byte_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ (byte_value, FALSE); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus Boolean into an int is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with boolean"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_BOOLEAN_AS_STRING); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "boolean", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a int from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_BOOLEAN) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&iter, &value);\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the D-Bus * Boolean in the message we pass and stores it in the int pointer, * which should have the right value. */ TEST_FEATURE ("with boolean (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); boolean_value = TRUE; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &boolean_value); } boolean_value = FALSE; ret = my_boolean_demarshal (NULL, message, &boolean_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ (boolean_value, TRUE); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a boolean is expected, but a different type is * found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for boolean (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } boolean_value = FALSE; ret = my_boolean_demarshal (NULL, message, &boolean_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ (boolean_value, FALSE); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus Int16 into a int16_t is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with int16"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_INT16_AS_STRING); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "int16", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a int16_t from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT16) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&iter, &value);\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int16_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the D-Bus Int16 * in the message we pass and stores it in the uint8_t pointer, which * should have the right value. */ TEST_FEATURE ("with int16 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); int16_value = -42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT16, &int16_value); } int16_value = 0; ret = my_int16_demarshal (NULL, message, &int16_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ (int16_value, -42); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a int16 is expected, but a different type is * found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for int16 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } int16_value = 0; ret = my_int16_demarshal (NULL, message, &int16_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ (int16_value, 0); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus UInt16 into a uint16_t is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with uint16"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_UINT16_AS_STRING); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "uint16", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a uint16_t from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT16) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&iter, &value);\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "uint16_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the D-Bus UInt16 * in the message we pass and stores it in the uint8_t pointer, which * should have the right value. */ TEST_FEATURE ("with uint16 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); uint16_value = 42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT16, &uint16_value); } uint16_value = 0; ret = my_uint16_demarshal (NULL, message, &uint16_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ (uint16_value, 42); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a uint16 is expected, but a different type is * found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for uint16 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } uint16_value = 0; ret = my_uint16_demarshal (NULL, message, &uint16_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ (uint16_value, 0); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus Int32 into a int32_t is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with int32"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_INT32_AS_STRING); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "int32", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a int32_t from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&iter, &value);\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the D-Bus Int32 * in the message we pass and stores it in the uint8_t pointer, which * should have the right value. */ TEST_FEATURE ("with int32 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); int32_value = -42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &int32_value); } int32_value = 0; ret = my_int32_demarshal (NULL, message, &int32_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ (int32_value, -42); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a int32 is expected, but a different type is * found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for int32 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } int32_value = 0; ret = my_int32_demarshal (NULL, message, &int32_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ (int32_value, 0); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus UInt32 into a uint32_t is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with uint32"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_UINT32_AS_STRING); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "uint32", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a uint32_t from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&iter, &value);\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the D-Bus UInt32 * in the message we pass and stores it in the uint8_t pointer, which * should have the right value. */ TEST_FEATURE ("with uint32 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); uint32_value = 42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value); } uint32_value = 0; ret = my_uint32_demarshal (NULL, message, &uint32_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ (uint32_value, 42); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a uint32 is expected, but a different type is * found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for uint32 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } uint32_value = 0; ret = my_uint32_demarshal (NULL, message, &uint32_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ (uint32_value, 0); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus Int64 into a int64_t is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with int64"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_INT64_AS_STRING); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "int64", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a int64_t from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT64) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&iter, &value);\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int64_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the D-Bus Int64 * in the message we pass and stores it in the uint8_t pointer, which * should have the right value. */ TEST_FEATURE ("with int64 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); int64_value = -42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT64, &int64_value); } int64_value = 0; ret = my_int64_demarshal (NULL, message, &int64_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ (int64_value, -42); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a int64 is expected, but a different type is * found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for int64 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } int64_value = 0; ret = my_int64_demarshal (NULL, message, &int64_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ (int64_value, 0); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus UInt64 into a uint64_t is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with uint64"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_UINT64_AS_STRING); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "uint64", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a uint64_t from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT64) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&iter, &value);\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "uint64_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the D-Bus UInt64 * in the message we pass and stores it in the uint8_t pointer, which * should have the right value. */ TEST_FEATURE ("with uint64 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); uint64_value = 42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT64, &uint64_value); } uint64_value = 0; ret = my_uint64_demarshal (NULL, message, &uint64_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ (uint64_value, 42); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a uint64 is expected, but a different type is * found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for uint64 (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } uint64_value = 0; ret = my_uint64_demarshal (NULL, message, &uint64_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ (uint64_value, 0); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus Double into a double is * correctly generated and returned as an allocated string. */ TEST_FEATURE ("with double"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_DOUBLE_AS_STRING); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "double", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a double from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_DOUBLE) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&iter, &value);\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "double"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the D-Bus Double * in the message we pass and stores it in the double pointer, which * should have the right value. */ TEST_FEATURE ("with double (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 42; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } double_value = 0; ret = my_double_demarshal (NULL, message, &double_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ (double_value, 42); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a double is expected, but a different type is * found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for double (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); byte_value = TRUE; dbus_message_iter_append_basic (&iter, DBUS_TYPE_BYTE, &byte_value); } double_value = 0; ret = my_double_demarshal (NULL, message, &double_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ (double_value, 0); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus String into a char * * is correctly generated and returned as an allocated string. * This code differs from the other basic types in that it returns * an allocated copy of the string, so also requires a local variable * to hold the constant D-Bus version so appends an entry to the * list we pass. */ TEST_FEATURE ("with string"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_STRING_AS_STRING); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "string", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a char * from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&iter, &value_dbus);\n" "\n" "value = nih_strdup (parent, value_dbus);\n" "if (! value) {\n" "\treturn -1;\n" "}\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_dbus"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the D-Bus String * in the message we pass and stores it in the char * pointer, which * should have the right value. */ TEST_FEATURE ("with string (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); str_value = "hello there"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value); } str_value = NULL; ret = my_string_demarshal (NULL, message, &str_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "hello there"); TEST_ALLOC_PARENT (str_value, NULL); nih_free (str_value); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a string is expected, but a different type is * found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for string (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } str_value = NULL; ret = my_string_demarshal (NULL, message, &str_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (str_value, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus Object Path into a char * * is correctly generated and returned as an allocated string. * This code differs from the other basic types in that it returns * an allocated copy of the string, so also requires a local variable * to hold the constant D-Bus version so appends an entry to the * list we pass. */ TEST_FEATURE ("with object path"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_OBJECT_PATH_AS_STRING); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "object_path", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a char * from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_OBJECT_PATH) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&iter, &value_dbus);\n" "\n" "value = nih_strdup (parent, value_dbus);\n" "if (! value) {\n" "\treturn -1;\n" "}\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_dbus"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the D-Bus * Object Path in the message we pass and stores it in the * char * pointer, which should have the right value. */ TEST_FEATURE ("with object path (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); str_value = "/com/netsplit/Nih/Test"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH, &str_value); } str_value = NULL; ret = my_object_path_demarshal (NULL, message, &str_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "/com/netsplit/Nih/Test"); TEST_ALLOC_PARENT (str_value, NULL); nih_free (str_value); dbus_message_unref (message); dbus_shutdown (); } /* Check that when an object path is expected, but a different type * is found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for object path (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } str_value = NULL; ret = my_object_path_demarshal (NULL, message, &str_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (str_value, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus Signature into a char * * is correctly generated and returned as an allocated string. * This code differs from the other basic types in that it returns * an allocated copy of the string, so also requires a local variable * to hold the constant D-Bus version so appends an entry to the * list we pass. */ TEST_FEATURE ("with signature"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_SIGNATURE_AS_STRING); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "signature", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a char * from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_SIGNATURE) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&iter, &value_dbus);\n" "\n" "value = nih_strdup (parent, value_dbus);\n" "if (! value) {\n" "\treturn -1;\n" "}\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_dbus"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the D-Bus * Signature in the message we pass and stores it in the char * * pointer, which should have the right value. */ TEST_FEATURE ("with signature (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); str_value = "a(ii)"; dbus_message_iter_append_basic (&iter, DBUS_TYPE_SIGNATURE, &str_value); } str_value = NULL; ret = my_signature_demarshal (NULL, message, &str_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ_STR (str_value, "a(ii)"); TEST_ALLOC_PARENT (str_value, NULL); nih_free (str_value); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a signature is expected, but a different type is * found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for signature (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } str_value = NULL; ret = my_signature_demarshal (NULL, message, &str_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (str_value, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus Int16 Array into an * array of int16_t and a length is correctly generated and returned * as an allocated string. This differs from others in that it * actually returns two values, the array and the length of the * array. One local is required, the array iterator, and inside * the generated code should be the locals and inputs to the nested * marshalling code. */ TEST_FEATURE ("with int16 array"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING)); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "int16_array", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal an array from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_recurse (&iter, &value_iter);\n" "\n" "value_len = 0;\n" "value = NULL;\n" "\n" "while (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) {\n" "\tint16_t *value_tmp;\n" "\tint16_t value_element;\n" "\n" "\t/* Demarshal a int16_t from the message */\n" "\tif (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INT16) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_get_basic (&value_iter, &value_element);\n" "\n" "\tdbus_message_iter_next (&value_iter);\n" "\n" "\tif (value_len + 1 > SIZE_MAX / sizeof (int16_t)) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tvalue_tmp = nih_realloc (value, parent, sizeof (int16_t) * (value_len + 1));\n" "\tif (! value_tmp) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue = value_tmp;\n" "\tvalue[value_len] = value_element;\n" "\n" "\tvalue_len++;\n" "}\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int16_t *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "size_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_len"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the values from a D-Bus * Int16 Array in the message we pass and stores them in a newly * allocated int16_t * array, returned along with its length. */ TEST_FEATURE ("with int16 array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT16_AS_STRING, &subiter); int16_value = 4; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT16, &int16_value); int16_value = 8; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT16, &int16_value); int16_value = 15; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT16, &int16_value); int16_value = 16; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT16, &int16_value); int16_value = 23; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT16, &int16_value); int16_value = 42; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_INT16, &int16_value); dbus_message_iter_close_container (&iter, &subiter); } int16_array = NULL; int16_array_len = 0; ret = my_int16_array_demarshal (NULL, message, &int16_array, &int16_array_len); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_EQ (int16_array_len, 6); TEST_ALLOC_PARENT (int16_array, NULL); TEST_ALLOC_SIZE (int16_array, sizeof (int16_t) * 6); TEST_EQ (int16_array[0], 4); TEST_EQ (int16_array[1], 8); TEST_EQ (int16_array[2], 15); TEST_EQ (int16_array[3], 16); TEST_EQ (int16_array[4], 23); TEST_EQ (int16_array[5], 42); nih_free (int16_array); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a int16 array is expected, but a different type is * found at the top-level, the type error code is run and the function * returns without modifying the pointer. */ TEST_FEATURE ("with wrong type for int16 array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } int16_array = NULL; int16_array_len = 0; ret = my_int16_array_demarshal (NULL, message, &int16_array, &int16_array_len); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (int16_array, NULL); TEST_EQ (int16_array_len, 0); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a int16 array is expected, but a different type is * found inside the array, the type error code is run and the function * returns without modifying the pointer. */ TEST_FEATURE ("with wrong type inside int16 array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_value = 3.14; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); } int16_array = NULL; int16_array_len = 0; ret = my_int16_array_demarshal (NULL, message, &int16_array, &int16_array_len); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (int16_array, NULL); TEST_EQ (int16_array_len, 0); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus Int16 Array Array into an * array of int16_t arrays and a length array is correctly generated * and returned as an allocated string. This is even more complex * than the int16_t array case since the second value is now an * array of sizes, one for each of the int16 arrays in the first * argument. */ TEST_FEATURE ("with int16 array array"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING)); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "int16_array_array", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal an array from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_recurse (&iter, &value_iter);\n" "\n" "value_size = 0;\n" "value = NULL;\n" "value_len = NULL;\n" "\n" "value = nih_alloc (parent, sizeof (int16_t *));\n" "if (! value) {\n" "\treturn -1;\n" "}\n" "\n" "value[value_size] = NULL;\n" "\n" "while (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) {\n" "\tDBusMessageIter value_element_iter;\n" "\tint16_t ** value_tmp;\n" "\tint16_t * value_element;\n" "\tsize_t * value_len_tmp;\n" "\tsize_t value_element_len;\n" "\n" "\t/* Demarshal an array from the message */\n" "\tif (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_ARRAY) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_recurse (&value_iter, &value_element_iter);\n" "\n" "\tvalue_element_len = 0;\n" "\tvalue_element = NULL;\n" "\n" "\twhile (dbus_message_iter_get_arg_type (&value_element_iter) != DBUS_TYPE_INVALID) {\n" "\t\tint16_t *value_element_tmp;\n" "\t\tint16_t value_element_element;\n" "\n" "\t\t/* Demarshal a int16_t from the message */\n" "\t\tif (dbus_message_iter_get_arg_type (&value_element_iter) != DBUS_TYPE_INT16) {\n" "\t\t\tif (value_element)\n" "\t\t\t\tnih_free (value_element);\n" "\t\t\tif (value)\n" "\t\t\t\tnih_free (value);\n" "\t\t\treturn 1;\n" "\t\t}\n" "\n" "\t\tdbus_message_iter_get_basic (&value_element_iter, &value_element_element);\n" "\n" "\t\tdbus_message_iter_next (&value_element_iter);\n" "\n" "\t\tif (value_element_len + 1 > SIZE_MAX / sizeof (int16_t)) {\n" "\t\t\tif (value_element)\n" "\t\t\t\tnih_free (value_element);\n" "\t\t\tif (value)\n" "\t\t\t\tnih_free (value);\n" "\t\t\treturn 1;\n" "\t\t}\n" "\n" "\t\tvalue_element_tmp = nih_realloc (value_element, value, sizeof (int16_t) * (value_element_len + 1));\n" "\t\tif (! value_element_tmp) {\n" "\t\t\tif (value_element)\n" "\t\t\t\tnih_free (value_element);\n" "\t\t\tif (value)\n" "\t\t\t\tnih_free (value);\n" "\t\t\treturn -1;\n" "\t\t}\n" "\n" "\t\tvalue_element = value_element_tmp;\n" "\t\tvalue_element[value_element_len] = value_element_element;\n" "\n" "\t\tvalue_element_len++;\n" "\t}\n" "\n" "\tdbus_message_iter_next (&value_iter);\n" "\n" "\tif (value_size + 2 > SIZE_MAX / sizeof (int16_t *)) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tvalue_tmp = nih_realloc (value, parent, sizeof (int16_t *) * (value_size + 2));\n" "\tif (! value_tmp) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue = value_tmp;\n" "\tvalue[value_size] = value_element;\n" "\tvalue[value_size + 1] = NULL;\n" "\n" "\tif (value_size + 1 > SIZE_MAX / sizeof (size_t)) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tvalue_len_tmp = nih_realloc (value_len, value, sizeof (size_t) * (value_size + 1));\n" "\tif (! value_len_tmp) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue_len = value_len_tmp;\n" "\tvalue_len[value_size] = value_element_len;\n" "\n" "\tvalue_size++;\n" "}\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int16_t **"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "size_t *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_len"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "size_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the values from a D-Bus * Int16 Array Array in the message we pass and stores them as * allocated int16_t * arrays, inside their parent array along * with allocated size_t arrays for their lengths. The length * array must be a child of the main array. */ TEST_FEATURE ("with int16 array array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT16_AS_STRING, &subsubiter); int16_value = 4; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); int16_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); int16_value = 15; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); int16_value = 16; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); int16_value = 23; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); int16_value = 42; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT16_AS_STRING, &subsubiter); int16_value = 999; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); int16_value = 911; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); int16_value = 112; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); } int16_array_array = NULL; int16_array_array_len = NULL; ret = my_int16_array_array_demarshal (NULL, message, &int16_array_array, &int16_array_array_len); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_ALLOC_PARENT (int16_array_array, NULL); TEST_ALLOC_SIZE (int16_array_array, sizeof (int16_t *) * 3); TEST_ALLOC_PARENT (int16_array_array_len, int16_array_array); TEST_ALLOC_SIZE (int16_array_array_len, sizeof (size_t) * 2); TEST_EQ (int16_array_array_len[0], 6); TEST_ALLOC_PARENT (int16_array_array[0], int16_array_array); TEST_ALLOC_SIZE (int16_array_array[0], sizeof (int16_t) * 6); TEST_EQ (int16_array_array[0][0], 4); TEST_EQ (int16_array_array[0][1], 8); TEST_EQ (int16_array_array[0][2], 15); TEST_EQ (int16_array_array[0][3], 16); TEST_EQ (int16_array_array[0][4], 23); TEST_EQ (int16_array_array[0][5], 42); TEST_EQ (int16_array_array_len[1], 3); TEST_ALLOC_PARENT (int16_array_array[1], int16_array_array); TEST_ALLOC_SIZE (int16_array_array[1], sizeof (int16_t) * 3); TEST_EQ (int16_array_array[1][0], 999); TEST_EQ (int16_array_array[1][1], 911); TEST_EQ (int16_array_array[1][2], 112); nih_free (int16_array_array); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a int16 array array is expected, but a different * type is found at the top-level, the type error code is run and * the function returns without modifying the pointer. */ TEST_FEATURE ("with wrong type for int16 array array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } int16_array_array = NULL; int16_array_array_len = NULL; ret = my_int16_array_array_demarshal (NULL, message, &int16_array_array, &int16_array_array_len); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (int16_array_array, NULL); TEST_EQ_P (int16_array_array_len, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a int16 array array is expected, but a different * type is found inside the top array, the type error code is run and * the function returns without modifying the pointer. */ TEST_FEATURE ("with wrong type inside int16 array array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_value = 3.14; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); } int16_array_array = NULL; int16_array_array_len = NULL; ret = my_int16_array_array_demarshal (NULL, message, &int16_array_array, &int16_array_array_len); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (int16_array_array, NULL); TEST_EQ_P (int16_array_array_len, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a int16 array array is expected, but a different * type is found inside the second array, the type error code is run * and the function returns without modifying the pointer. */ TEST_FEATURE ("with wrong type deep inside int16 array array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_DOUBLE_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE_AS_STRING, &subsubiter); double_value = 3.14; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); } int16_array_array = NULL; int16_array_array_len = NULL; ret = my_int16_array_array_demarshal (NULL, message, &int16_array_array, &int16_array_array_len); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (int16_array_array, NULL); TEST_EQ_P (int16_array_array_len, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus String Array into an * array of char * is correctly generated and returned as an * allocated string. Two locals are required, the array iterator * and the length of the array. Inside the generated code should * be the locals and outputs from the nested marshalling code. */ TEST_FEATURE ("with string array"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "string_array", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal an array from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_recurse (&iter, &value_iter);\n" "\n" "value_size = 0;\n" "value = NULL;\n" "\n" "value = nih_alloc (parent, sizeof (char *));\n" "if (! value) {\n" "\treturn -1;\n" "}\n" "\n" "value[value_size] = NULL;\n" "\n" "while (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) {\n" "\tconst char *value_element_dbus;\n" "\tchar ** value_tmp;\n" "\tchar * value_element;\n" "\n" "\t/* Demarshal a char * from the message */\n" "\tif (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_STRING) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_get_basic (&value_iter, &value_element_dbus);\n" "\n" "\tvalue_element = nih_strdup (value, value_element_dbus);\n" "\tif (! value_element) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tdbus_message_iter_next (&value_iter);\n" "\n" "\tif (value_size + 2 > SIZE_MAX / sizeof (char *)) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tvalue_tmp = nih_realloc (value, parent, sizeof (char *) * (value_size + 2));\n" "\tif (! value_tmp) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue = value_tmp;\n" "\tvalue[value_size] = value_element;\n" "\tvalue[value_size + 1] = NULL;\n" "\n" "\tvalue_size++;\n" "}\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "char **"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "size_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the values from a D-Bus * String Array in the message we pass and stores them in a newly * allocated char * array, with each a child of the array itself. */ TEST_FEATURE ("with string array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); str_value = "this"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "is"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "a"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); str_value = "test"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&iter, &subiter); } str_array = NULL; ret = my_string_array_demarshal (NULL, message, &str_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_ALLOC_PARENT (str_array, NULL); TEST_ALLOC_SIZE (str_array, sizeof (char *) * 5); TEST_EQ_STR (str_array[0], "this"); TEST_ALLOC_PARENT (str_array[0], str_array); TEST_EQ_STR (str_array[1], "is"); TEST_ALLOC_PARENT (str_array[1], str_array); TEST_EQ_STR (str_array[2], "a"); TEST_ALLOC_PARENT (str_array[2], str_array); TEST_EQ_STR (str_array[3], "test"); TEST_ALLOC_PARENT (str_array[3], str_array); TEST_EQ_P (str_array[4], NULL); nih_free (str_array); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a string array is expected, but a different type is * found at the top-level, the type error code is run and the function * returns without modifying the pointer. */ TEST_FEATURE ("with wrong type for string array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } str_array = NULL; ret = my_string_array_demarshal (NULL, message, &str_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (str_array, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a string array is expected, but a different type is * found inside the array, the type error code is run and the function * returns without modifying the pointer. */ TEST_FEATURE ("with wrong type inside string array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_value = 3.14; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); } str_array = NULL; ret = my_string_array_demarshal (NULL, message, &str_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (str_array, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus String Array Array into * an array of arrays of char * is correctly generated and returned * as an allocated string. Two locals are required, the top-level * array iterator and the length of the top-level array. Inside the * generated code should be the locals and outputs from the nested * marshalling code. */ TEST_FEATURE ("with string array array"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "string_array_array", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal an array from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_recurse (&iter, &value_iter);\n" "\n" "value_size = 0;\n" "value = NULL;\n" "\n" "value = nih_alloc (parent, sizeof (char **));\n" "if (! value) {\n" "\treturn -1;\n" "}\n" "\n" "value[value_size] = NULL;\n" "\n" "while (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) {\n" "\tDBusMessageIter value_element_iter;\n" "\tsize_t value_element_size;\n" "\tchar *** value_tmp;\n" "\tchar ** value_element;\n" "\n" "\t/* Demarshal an array from the message */\n" "\tif (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_ARRAY) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_recurse (&value_iter, &value_element_iter);\n" "\n" "\tvalue_element_size = 0;\n" "\tvalue_element = NULL;\n" "\n" "\tvalue_element = nih_alloc (value, sizeof (char *));\n" "\tif (! value_element) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue_element[value_element_size] = NULL;\n" "\n" "\twhile (dbus_message_iter_get_arg_type (&value_element_iter) != DBUS_TYPE_INVALID) {\n" "\t\tconst char *value_element_element_dbus;\n" "\t\tchar ** value_element_tmp;\n" "\t\tchar * value_element_element;\n" "\n" "\t\t/* Demarshal a char * from the message */\n" "\t\tif (dbus_message_iter_get_arg_type (&value_element_iter) != DBUS_TYPE_STRING) {\n" "\t\t\tif (value_element)\n" "\t\t\t\tnih_free (value_element);\n" "\t\t\tif (value)\n" "\t\t\t\tnih_free (value);\n" "\t\t\treturn 1;\n" "\t\t}\n" "\n" "\t\tdbus_message_iter_get_basic (&value_element_iter, &value_element_element_dbus);\n" "\n" "\t\tvalue_element_element = nih_strdup (value_element, value_element_element_dbus);\n" "\t\tif (! value_element_element) {\n" "\t\t\tif (value_element)\n" "\t\t\t\tnih_free (value_element);\n" "\t\t\tif (value)\n" "\t\t\t\tnih_free (value);\n" "\t\t\treturn -1;\n" "\t\t}\n" "\n" "\t\tdbus_message_iter_next (&value_element_iter);\n" "\n" "\t\tif (value_element_size + 2 > SIZE_MAX / sizeof (char *)) {\n" "\t\t\tif (value_element)\n" "\t\t\t\tnih_free (value_element);\n" "\t\t\tif (value)\n" "\t\t\t\tnih_free (value);\n" "\t\t\treturn 1;\n" "\t\t}\n" "\n" "\t\tvalue_element_tmp = nih_realloc (value_element, value, sizeof (char *) * (value_element_size + 2));\n" "\t\tif (! value_element_tmp) {\n" "\t\t\tif (value_element)\n" "\t\t\t\tnih_free (value_element);\n" "\t\t\tif (value)\n" "\t\t\t\tnih_free (value);\n" "\t\t\treturn -1;\n" "\t\t}\n" "\n" "\t\tvalue_element = value_element_tmp;\n" "\t\tvalue_element[value_element_size] = value_element_element;\n" "\t\tvalue_element[value_element_size + 1] = NULL;\n" "\n" "\t\tvalue_element_size++;\n" "\t}\n" "\n" "\tdbus_message_iter_next (&value_iter);\n" "\n" "\tif (value_size + 2 > SIZE_MAX / sizeof (char **)) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tvalue_tmp = nih_realloc (value, parent, sizeof (char **) * (value_size + 2));\n" "\tif (! value_tmp) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue = value_tmp;\n" "\tvalue[value_size] = value_element;\n" "\tvalue[value_size + 1] = NULL;\n" "\n" "\tvalue_size++;\n" "}\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "char ***"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "size_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the values from a D-Bus * String Array Array in the message we pass and stores them in newly * allocated char * arrays in a newly allocated array, with each * a child of the parent array. */ TEST_FEATURE ("with string array array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subsubiter); str_value = "this"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "is"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "a"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "test"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subsubiter); str_value = "and"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "this"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "is"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); } str_array_array = NULL; ret = my_string_array_array_demarshal (NULL, message, &str_array_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_ALLOC_PARENT (str_array_array, NULL); TEST_ALLOC_SIZE (str_array_array, sizeof (char **) * 3); TEST_ALLOC_SIZE (str_array_array[0], sizeof (char *) * 5); TEST_ALLOC_PARENT (str_array_array[0], str_array_array); TEST_EQ_STR (str_array_array[0][0], "this"); TEST_ALLOC_PARENT (str_array_array[0][0], str_array_array[0]); TEST_EQ_STR (str_array_array[0][1], "is"); TEST_ALLOC_PARENT (str_array_array[0][1], str_array_array[0]); TEST_EQ_STR (str_array_array[0][2], "a"); TEST_ALLOC_PARENT (str_array_array[0][2], str_array_array[0]); TEST_EQ_STR (str_array_array[0][3], "test"); TEST_ALLOC_PARENT (str_array_array[0][3], str_array_array[0]); TEST_EQ_P (str_array_array[0][4], NULL); TEST_ALLOC_SIZE (str_array_array[1], sizeof (char *) * 4); TEST_ALLOC_PARENT (str_array_array[1], str_array_array); TEST_EQ_STR (str_array_array[1][0], "and"); TEST_ALLOC_PARENT (str_array_array[1][0], str_array_array[1]); TEST_EQ_STR (str_array_array[1][1], "this"); TEST_ALLOC_PARENT (str_array_array[1][1], str_array_array[1]); TEST_EQ_STR (str_array_array[1][2], "is"); TEST_ALLOC_PARENT (str_array_array[1][2], str_array_array[1]); TEST_EQ_P (str_array_array[1][3], NULL); TEST_EQ_P (str_array_array[2], NULL); nih_free (str_array_array); dbus_message_unref (message); dbus_shutdown (); } /* Check that when an array of string arrays is expected, but a * different type is found at the top-level, the type error code * is run and the function returns without modifying the pointer. */ TEST_FEATURE ("with wrong type for string array array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } str_array_array = NULL; ret = my_string_array_array_demarshal (NULL, message, &str_array_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (str_array_array, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that when an array of string arrays is expected, but a * different type is found inside the array, the type error code * is run and the function returns without modifying the pointer. */ TEST_FEATURE ("with wrong type inside string array array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_value = 3.14; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); } str_array_array = NULL; ret = my_string_array_array_demarshal (NULL, message, &str_array_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (str_array_array, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that when an array of string arrays is expected, but a * different type is found deep inside the array, the type error code * is run and the function returns without modifying the pointer. */ TEST_FEATURE ("with wrong type deep inside string array array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_DOUBLE_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE_AS_STRING, &subsubiter); double_value = 3.14; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); } str_array_array = NULL; ret = my_string_array_array_demarshal (NULL, message, &str_array_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (str_array_array, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus Structure members into * a newly allocated structure pointer is correctly generated and * returned as an allocated string. We expect a large number of * locals since this is all done at one level. */ TEST_FEATURE ("with structure"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT16_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING)); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "struct", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a structure from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRUCT) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_recurse (&iter, &value_iter);\n" "\n" "value = nih_new (parent, MyStructValue);\n" "if (! value) {\n" "\treturn -1;\n" "}\n" "\n" "/* Demarshal a char * from the message */\n" "if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_STRING) {\n" "\tnih_free (value);\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&value_iter, &value_item0_dbus);\n" "\n" "value_item0 = nih_strdup (value, value_item0_dbus);\n" "if (! value_item0) {\n" "\tnih_free (value);\n" "\treturn -1;\n" "}\n" "\n" "dbus_message_iter_next (&value_iter);\n" "\n" "value->item0 = value_item0;\n" "\n" "/* Demarshal a uint32_t from the message */\n" "if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_UINT32) {\n" "\tnih_free (value);\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&value_iter, &value_item1);\n" "\n" "dbus_message_iter_next (&value_iter);\n" "\n" "value->item1 = value_item1;\n" "\n" "/* Demarshal an array from the message */\n" "if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_ARRAY) {\n" "\tnih_free (value);\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_recurse (&value_iter, &value_item2_iter);\n" "\n" "value_item2_size = 0;\n" "value_item2 = NULL;\n" "\n" "value_item2 = nih_alloc (value, sizeof (char *));\n" "if (! value_item2) {\n" "\tnih_free (value);\n" "\treturn -1;\n" "}\n" "\n" "value_item2[value_item2_size] = NULL;\n" "\n" "while (dbus_message_iter_get_arg_type (&value_item2_iter) != DBUS_TYPE_INVALID) {\n" "\tconst char *value_item2_element_dbus;\n" "\tchar ** value_item2_tmp;\n" "\tchar * value_item2_element;\n" "\n" "\t/* Demarshal a char * from the message */\n" "\tif (dbus_message_iter_get_arg_type (&value_item2_iter) != DBUS_TYPE_STRING) {\n" "\t\tif (value_item2)\n" "\t\t\tnih_free (value_item2);\n" "\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_get_basic (&value_item2_iter, &value_item2_element_dbus);\n" "\n" "\tvalue_item2_element = nih_strdup (value_item2, value_item2_element_dbus);\n" "\tif (! value_item2_element) {\n" "\t\tif (value_item2)\n" "\t\t\tnih_free (value_item2);\n" "\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tdbus_message_iter_next (&value_item2_iter);\n" "\n" "\tif (value_item2_size + 2 > SIZE_MAX / sizeof (char *)) {\n" "\t\tif (value_item2)\n" "\t\t\tnih_free (value_item2);\n" "\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tvalue_item2_tmp = nih_realloc (value_item2, value, sizeof (char *) * (value_item2_size + 2));\n" "\tif (! value_item2_tmp) {\n" "\t\tif (value_item2)\n" "\t\t\tnih_free (value_item2);\n" "\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue_item2 = value_item2_tmp;\n" "\tvalue_item2[value_item2_size] = value_item2_element;\n" "\tvalue_item2[value_item2_size + 1] = NULL;\n" "\n" "\tvalue_item2_size++;\n" "}\n" "\n" "dbus_message_iter_next (&value_iter);\n" "\n" "value->item2 = value_item2;\n" "\n" "/* Demarshal an array from the message */\n" "if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_ARRAY) {\n" "\tnih_free (value);\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_recurse (&value_iter, &value_item3_iter);\n" "\n" "value_item3_len = 0;\n" "value_item3 = NULL;\n" "\n" "while (dbus_message_iter_get_arg_type (&value_item3_iter) != DBUS_TYPE_INVALID) {\n" "\tint16_t *value_item3_tmp;\n" "\tint16_t value_item3_element;\n" "\n" "\t/* Demarshal a int16_t from the message */\n" "\tif (dbus_message_iter_get_arg_type (&value_item3_iter) != DBUS_TYPE_INT16) {\n" "\t\tif (value_item3)\n" "\t\t\tnih_free (value_item3);\n" "\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_get_basic (&value_item3_iter, &value_item3_element);\n" "\n" "\tdbus_message_iter_next (&value_item3_iter);\n" "\n" "\tif (value_item3_len + 1 > SIZE_MAX / sizeof (int16_t)) {\n" "\t\tif (value_item3)\n" "\t\t\tnih_free (value_item3);\n" "\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tvalue_item3_tmp = nih_realloc (value_item3, value, sizeof (int16_t) * (value_item3_len + 1));\n" "\tif (! value_item3_tmp) {\n" "\t\tif (value_item3)\n" "\t\t\tnih_free (value_item3);\n" "\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue_item3 = value_item3_tmp;\n" "\tvalue_item3[value_item3_len] = value_item3_element;\n" "\n" "\tvalue_item3_len++;\n" "}\n" "\n" "dbus_message_iter_next (&value_iter);\n" "\n" "value->item3 = value_item3;\n" "value->item3_len = value_item3_len;\n" "\n" "if (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) {\n" "\tnih_free (value);\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "MyStructValue *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "const char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item0_dbus"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item2_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "size_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item2_size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "char **"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item2"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item3_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int16_t *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item3"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "size_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_item3_len"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyStructValue"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char **"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item2"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "int16_t *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item3"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "size_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item3_len"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes each of the values from the * D-Bus Struct in the message we pass and stores them in a newly * allocated structure in the pointer we provide. */ TEST_FEATURE ("with structure (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "hello there"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 1818118181; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subsubiter); str_value = "premium"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "economy"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); str_value = "only"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT16_AS_STRING, &subsubiter); int16_value = 4; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); int16_value = 8; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); int16_value = 15; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); int16_value = 16; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); int16_value = 23; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); int16_value = 42; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_INT16, &int16_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); } struct_value = NULL; ret = my_struct_demarshal (NULL, message, &struct_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_ALLOC_PARENT (struct_value, NULL); TEST_ALLOC_SIZE (struct_value, sizeof (MyStructValue)); TEST_EQ_STR (struct_value->item0, "hello there"); TEST_ALLOC_PARENT (struct_value->item0, struct_value); TEST_EQ (struct_value->item1, 1818118181); TEST_ALLOC_SIZE (struct_value->item2, sizeof (char *) * 4); TEST_ALLOC_PARENT (struct_value->item2, struct_value); TEST_EQ_STR (struct_value->item2[0], "premium"); TEST_ALLOC_PARENT (struct_value->item2[0], struct_value->item2); TEST_EQ_STR (struct_value->item2[1], "economy"); TEST_ALLOC_PARENT (struct_value->item2[1], struct_value->item2); TEST_EQ_STR (struct_value->item2[2], "only"); TEST_ALLOC_PARENT (struct_value->item2[2], struct_value->item2); TEST_EQ_P (struct_value->item2[3], NULL); TEST_EQ (struct_value->item3_len, 6); TEST_ALLOC_SIZE (struct_value->item3, sizeof (int16_t) * 6); TEST_ALLOC_PARENT (struct_value->item3, struct_value); TEST_EQ (struct_value->item3[0], 4); TEST_EQ (struct_value->item3[1], 8); TEST_EQ (struct_value->item3[2], 15); TEST_EQ (struct_value->item3[3], 16); TEST_EQ (struct_value->item3[4], 23); TEST_EQ (struct_value->item3[5], 42); nih_free (struct_value); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a structure is expected, but a different type * is found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for structure (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } struct_value = NULL; ret = my_struct_demarshal (NULL, message, &struct_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (struct_value, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a structure member is expected, but a different * member type is found, the type error code is run and the function * returns without modifying the pointer. */ TEST_FEATURE ("with wrong type for structure member (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "hello there"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 1818118181; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); double_value = 3.14; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); } struct_value = NULL; ret = my_struct_demarshal (NULL, message, &struct_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (struct_value, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that when an item inside a complex structure member is * expected, but a different type is found, the type error code * is run and the function returns without modifying the pointer. */ TEST_FEATURE ("with wrong type inside structure member (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &subiter); str_value = "hello there"; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value); uint32_value = 1818118181; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_open_container (&subiter, DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE_AS_STRING, &subsubiter); double_value = 3.14; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); } struct_value = NULL; ret = my_struct_demarshal (NULL, message, &struct_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (struct_value, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus Structure Array into * a newly allocated structure array pointer is correctly generated * and returned as an allocated string. All of the struct locals * should be internalised and just the array iterator and length * as locals. */ TEST_FEATURE ("with structure array"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_TYPE_ARRAY_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING)); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "struct_array", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal an array from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_recurse (&iter, &value_iter);\n" "\n" "value_size = 0;\n" "value = NULL;\n" "\n" "value = nih_alloc (parent, sizeof (MyStructArrayValueElement *));\n" "if (! value) {\n" "\treturn -1;\n" "}\n" "\n" "value[value_size] = NULL;\n" "\n" "while (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) {\n" "\tDBusMessageIter value_element_iter;\n" "\tconst char * value_element_item0_dbus;\n" "\tchar * value_element_item0;\n" "\tuint32_t value_element_item1;\n" "\tMyStructArrayValueElement **value_tmp;\n" "\tMyStructArrayValueElement * value_element;\n" "\n" "\t/* Demarshal a structure from the message */\n" "\tif (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_STRUCT) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_recurse (&value_iter, &value_element_iter);\n" "\n" "\tvalue_element = nih_new (value, MyStructArrayValueElement);\n" "\tif (! value_element) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\t/* Demarshal a char * from the message */\n" "\tif (dbus_message_iter_get_arg_type (&value_element_iter) != DBUS_TYPE_STRING) {\n" "\t\tnih_free (value_element);\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_get_basic (&value_element_iter, &value_element_item0_dbus);\n" "\n" "\tvalue_element_item0 = nih_strdup (value_element, value_element_item0_dbus);\n" "\tif (! value_element_item0) {\n" "\t\tnih_free (value_element);\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tdbus_message_iter_next (&value_element_iter);\n" "\n" "\tvalue_element->item0 = value_element_item0;\n" "\n" "\t/* Demarshal a uint32_t from the message */\n" "\tif (dbus_message_iter_get_arg_type (&value_element_iter) != DBUS_TYPE_UINT32) {\n" "\t\tnih_free (value_element);\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_get_basic (&value_element_iter, &value_element_item1);\n" "\n" "\tdbus_message_iter_next (&value_element_iter);\n" "\n" "\tvalue_element->item1 = value_element_item1;\n" "\n" "\tif (dbus_message_iter_get_arg_type (&value_element_iter) != DBUS_TYPE_INVALID) {\n" "\t\tnih_free (value_element);\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_next (&value_iter);\n" "\n" "\tif (value_size + 2 > SIZE_MAX / sizeof (MyStructArrayValueElement *)) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tvalue_tmp = nih_realloc (value, parent, sizeof (MyStructArrayValueElement *) * (value_size + 2));\n" "\tif (! value_tmp) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue = value_tmp;\n" "\tvalue[value_size] = value_element;\n" "\tvalue[value_size + 1] = NULL;\n" "\n" "\tvalue_size++;\n" "}\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "MyStructArrayValueElement **"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "size_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyStructArrayValueElement"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes each of the members of the * D-Bus Struct Array in the message we pass and stores them in a * newly allocated structure array in the pointer we provide. */ TEST_FEATURE ("with structure array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_STRUCT, NULL, &subsubiter); str_value = "hello there"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); uint32_value = 1818118181; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_STRUCT, NULL, &subsubiter); str_value = "goodbye world"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); uint32_value = 12345; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); } struct_array = NULL; ret = my_struct_array_demarshal (NULL, message, &struct_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_ALLOC_PARENT (struct_array, NULL); TEST_ALLOC_SIZE (struct_array, sizeof (MyStructArrayValueElement *) * 3); TEST_ALLOC_PARENT (struct_array[0], struct_array); TEST_ALLOC_SIZE (struct_array[0], sizeof (MyStructArrayValueElement)); TEST_EQ_STR (struct_array[0]->item0, "hello there"); TEST_ALLOC_PARENT (struct_array[0]->item0, struct_array[0]); TEST_EQ (struct_array[0]->item1, 1818118181); TEST_ALLOC_PARENT (struct_array[1], struct_array); TEST_ALLOC_SIZE (struct_array[1], sizeof (MyStructArrayValueElement)); TEST_EQ_STR (struct_array[1]->item0, "goodbye world"); TEST_ALLOC_PARENT (struct_array[1]->item0, struct_array[1]); TEST_EQ (struct_array[1]->item1, 12345); TEST_EQ_P (struct_array[2], NULL); nih_free (struct_array); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a structure array is expected, but a different * type is found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for structure array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } struct_array = NULL; ret = my_struct_array_demarshal (NULL, message, &struct_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (struct_array, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a structure array is expected, but a different * type is found in the array, the type error code is run and * the function returns without modifying the pointer. */ TEST_FEATURE ("with wrong array member type for structure array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_value = 3.14; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); } struct_array = NULL; ret = my_struct_array_demarshal (NULL, message, &struct_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (struct_array, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a structure array member is expected, but a * different member type is found, the type error code is run * and the function returns without modifying the pointer. */ TEST_FEATURE ("with wrong type for structure member (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_DOUBLE_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_STRUCT, NULL, &subsubiter); str_value = "hello there"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); double_value = 3.14; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); } struct_array = NULL; ret = my_struct_array_demarshal (NULL, message, &struct_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (struct_array, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus DictEntry Array into * a newly allocated dict entry array pointer is correctly generated * and returned as an allocated string. All of the struct locals * should be internalised and just the array iterator and length * as locals. */ TEST_FEATURE ("with dict entry array"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, (DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING)); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "dict_entry_array", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal an array from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_recurse (&iter, &value_iter);\n" "\n" "value_size = 0;\n" "value = NULL;\n" "\n" "value = nih_alloc (parent, sizeof (MyDictEntryArrayValueElement *));\n" "if (! value) {\n" "\treturn -1;\n" "}\n" "\n" "value[value_size] = NULL;\n" "\n" "while (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_INVALID) {\n" "\tDBusMessageIter value_element_iter;\n" "\tconst char * value_element_item0_dbus;\n" "\tchar * value_element_item0;\n" "\tuint32_t value_element_item1;\n" "\tMyDictEntryArrayValueElement **value_tmp;\n" "\tMyDictEntryArrayValueElement * value_element;\n" "\n" "\t/* Demarshal a structure from the message */\n" "\tif (dbus_message_iter_get_arg_type (&value_iter) != DBUS_TYPE_DICT_ENTRY) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_recurse (&value_iter, &value_element_iter);\n" "\n" "\tvalue_element = nih_new (value, MyDictEntryArrayValueElement);\n" "\tif (! value_element) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\t/* Demarshal a char * from the message */\n" "\tif (dbus_message_iter_get_arg_type (&value_element_iter) != DBUS_TYPE_STRING) {\n" "\t\tnih_free (value_element);\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_get_basic (&value_element_iter, &value_element_item0_dbus);\n" "\n" "\tvalue_element_item0 = nih_strdup (value_element, value_element_item0_dbus);\n" "\tif (! value_element_item0) {\n" "\t\tnih_free (value_element);\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tdbus_message_iter_next (&value_element_iter);\n" "\n" "\tvalue_element->item0 = value_element_item0;\n" "\n" "\t/* Demarshal a uint32_t from the message */\n" "\tif (dbus_message_iter_get_arg_type (&value_element_iter) != DBUS_TYPE_UINT32) {\n" "\t\tnih_free (value_element);\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_get_basic (&value_element_iter, &value_element_item1);\n" "\n" "\tdbus_message_iter_next (&value_element_iter);\n" "\n" "\tvalue_element->item1 = value_element_item1;\n" "\n" "\tif (dbus_message_iter_get_arg_type (&value_element_iter) != DBUS_TYPE_INVALID) {\n" "\t\tnih_free (value_element);\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tdbus_message_iter_next (&value_iter);\n" "\n" "\tif (value_size + 2 > SIZE_MAX / sizeof (MyDictEntryArrayValueElement *)) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn 1;\n" "\t}\n" "\n" "\tvalue_tmp = nih_realloc (value, parent, sizeof (MyDictEntryArrayValueElement *) * (value_size + 2));\n" "\tif (! value_tmp) {\n" "\t\tif (value)\n" "\t\t\tnih_free (value);\n" "\t\treturn -1;\n" "\t}\n" "\n" "\tvalue = value_tmp;\n" "\tvalue[value_size] = value_element;\n" "\tvalue[value_size + 1] = NULL;\n" "\n" "\tvalue_size++;\n" "}\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "MyDictEntryArrayValueElement **"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "DBusMessageIter"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_iter"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&locals); var = (TypeVar *)locals.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "size_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value_size"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&locals); TEST_LIST_NOT_EMPTY (&structs); structure = (TypeStruct *)structs.next; TEST_ALLOC_SIZE (structure, sizeof (TypeStruct)); TEST_ALLOC_PARENT (structure, str); TEST_EQ_STR (structure->name, "MyDictEntryArrayValueElement"); TEST_ALLOC_PARENT (structure->name, structure); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "char *"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item0"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_NOT_EMPTY (&structure->members); var = (TypeVar *)structure->members.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, structure); TEST_EQ_STR (var->type, "uint32_t"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "item1"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&structure->members); nih_free (structure); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes each of the members of the * D-Bus DictEntry Array in the message we pass and stores them in a * newly allocated dict entry array in the pointer we provide. */ TEST_FEATURE ("with dict entry array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_DICT_ENTRY, NULL, &subsubiter); str_value = "hello there"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); uint32_value = 1818118181; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_DICT_ENTRY, NULL, &subsubiter); str_value = "goodbye world"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); uint32_value = 12345; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_UINT32, &uint32_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); } dict_entry_array = NULL; ret = my_dict_entry_array_demarshal (NULL, message, &dict_entry_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_ALLOC_PARENT (dict_entry_array, NULL); TEST_ALLOC_SIZE (dict_entry_array, sizeof (MyDictEntryArrayValueElement *) * 3); TEST_ALLOC_PARENT (dict_entry_array[0], dict_entry_array); TEST_ALLOC_SIZE (dict_entry_array[0], sizeof (MyDictEntryArrayValueElement)); TEST_EQ_STR (dict_entry_array[0]->item0, "hello there"); TEST_ALLOC_PARENT (dict_entry_array[0]->item0, dict_entry_array[0]); TEST_EQ (dict_entry_array[0]->item1, 1818118181); TEST_ALLOC_PARENT (dict_entry_array[1], dict_entry_array); TEST_ALLOC_SIZE (dict_entry_array[1], sizeof (MyDictEntryArrayValueElement)); TEST_EQ_STR (dict_entry_array[1]->item0, "goodbye world"); TEST_ALLOC_PARENT (dict_entry_array[1]->item0, dict_entry_array[1]); TEST_EQ (dict_entry_array[1]->item1, 12345); TEST_EQ_P (dict_entry_array[2], NULL); nih_free (dict_entry_array); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a dict entry array is expected, but a different * type is found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for dict entry array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } dict_entry_array = NULL; ret = my_dict_entry_array_demarshal (NULL, message, &dict_entry_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (dict_entry_array, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a dict entry array is expected, but a different * type is found in the array, the type error code is run and * the function returns without modifying the pointer. */ TEST_FEATURE ("with wrong array member type for dict entry array (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE_AS_STRING, &subiter); double_value = 3.14; dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&iter, &subiter); } dict_entry_array = NULL; ret = my_dict_entry_array_demarshal (NULL, message, &dict_entry_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (dict_entry_array, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that when a dict entry array member is expected, but a * different member type is found, the type error code is run * and the function returns without modifying the pointer. */ TEST_FEATURE ("with wrong type for dict entry member (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_DOUBLE_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &subiter); dbus_message_iter_open_container (&subiter, DBUS_TYPE_DICT_ENTRY, NULL, &subsubiter); str_value = "hello there"; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_STRING, &str_value); double_value = 3.14; dbus_message_iter_append_basic (&subsubiter, DBUS_TYPE_DOUBLE, &double_value); dbus_message_iter_close_container (&subiter, &subsubiter); dbus_message_iter_close_container (&iter, &subiter); } dict_entry_array = NULL; ret = my_dict_entry_array_demarshal (NULL, message, &dict_entry_array); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ_P (dict_entry_array, NULL); dbus_message_unref (message); dbus_shutdown (); } /* Check that the code to demarshal a D-Bus file descriptor into an * int is correctly generated and returned as an allocated string. */ TEST_FEATURE ("with file descriptor"); TEST_ALLOC_FAIL { nih_list_init (&outputs); nih_list_init (&locals); nih_list_init (&structs); dbus_signature_iter_init (&signature, DBUS_TYPE_UNIX_FD_AS_STRING); str = demarshal (NULL, &signature, "parent", "iter", "value", "return -1;\n", "return 1;\n", &outputs, &locals, "my", NULL, "unix_fd", "value", &structs); if (test_alloc_failed) { TEST_EQ_P (str, NULL); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); continue; } TEST_EQ_STR (str, ("/* Demarshal a int from the message */\n" "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UNIX_FD) {\n" "\treturn 1;\n" "}\n" "\n" "dbus_message_iter_get_basic (&iter, &value);\n" "\n" "dbus_message_iter_next (&iter);\n")); TEST_LIST_NOT_EMPTY (&outputs); var = (TypeVar *)outputs.next; TEST_ALLOC_SIZE (var, sizeof (TypeVar)); TEST_ALLOC_PARENT (var, str); TEST_EQ_STR (var->type, "int"); TEST_ALLOC_PARENT (var->type, var); TEST_EQ_STR (var->name, "value"); TEST_ALLOC_PARENT (var->name, var); nih_free (var); TEST_LIST_EMPTY (&outputs); TEST_LIST_EMPTY (&locals); TEST_LIST_EMPTY (&structs); nih_free (str); } /* Check that the generated code takes the value from the D-Bus * file descriptor in the message we pass and stores it in the int * pointer, which should have the right value. */ TEST_FEATURE ("with file descriptor (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); unix_fd_value = 1; dbus_message_iter_append_basic (&iter, DBUS_TYPE_UNIX_FD, &unix_fd_value); } unix_fd_value = -1; ret = my_unix_fd_demarshal (NULL, message, &unix_fd_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_EQ (ret, 0); TEST_GT (unix_fd_value, 2); // duplicated by dbus dbus_message_unref (message); close (unix_fd_value); dbus_shutdown (); } /* Check that when a file descriptor is expected, but a different * type is found, the type error code is run and the function returns * without modifying the pointer. */ TEST_FEATURE ("with wrong type for file descriptor (generated code)"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append (message, &iter); double_value = 3.14; dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE, &double_value); } unix_fd_value = -1; ret = my_unix_fd_demarshal (NULL, message, &unix_fd_value); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_message_unref (message); dbus_shutdown (); continue; } TEST_GT (ret, 0); TEST_EQ (unix_fd_value, -1); dbus_message_unref (message); dbus_shutdown (); } } int main (int argc, char *argv[]) { test_demarshal (); return 0; } libnih-1.0.3/nih-dbus-tool/type.c0000644000175000017500000006434411504702561013526 00000000000000/* nih-dbus-tool * * type.c - type handling * * Copyright © 2010 Scott James Remnant . * Copyright © 2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include "symbol.h" #include "indent.h" #include "type.h" /** * type_const: * @dbus_type: D-Bus type constant. * * Converts an integer D-Bus type constant into the string name of the * constant, used when generating code. * * Returns: constant string. **/ const char * type_const (int dbus_type) { switch (dbus_type) { case DBUS_TYPE_BYTE: return "DBUS_TYPE_BYTE"; case DBUS_TYPE_BOOLEAN: return "DBUS_TYPE_BOOLEAN"; case DBUS_TYPE_INT16: return "DBUS_TYPE_INT16"; case DBUS_TYPE_UINT16: return "DBUS_TYPE_UINT16"; case DBUS_TYPE_INT32: return "DBUS_TYPE_INT32"; case DBUS_TYPE_UINT32: return "DBUS_TYPE_UINT32"; case DBUS_TYPE_INT64: return "DBUS_TYPE_INT64"; case DBUS_TYPE_UINT64: return "DBUS_TYPE_UINT64"; case DBUS_TYPE_DOUBLE: return "DBUS_TYPE_DOUBLE"; case DBUS_TYPE_STRING: return "DBUS_TYPE_STRING"; case DBUS_TYPE_OBJECT_PATH: return "DBUS_TYPE_OBJECT_PATH"; case DBUS_TYPE_SIGNATURE: return "DBUS_TYPE_SIGNATURE"; case DBUS_TYPE_ARRAY: return "DBUS_TYPE_ARRAY"; case DBUS_TYPE_STRUCT: return "DBUS_TYPE_STRUCT"; case DBUS_TYPE_DICT_ENTRY: return "DBUS_TYPE_DICT_ENTRY"; case DBUS_TYPE_UNIX_FD: return "DBUS_TYPE_UNIX_FD"; default: nih_assert_not_reached (); } } /** * type_of: * @parent: parent object for new string, * @iter: D-Bus signature iterator. * * Converts the D-Bus basic type at the current element of the iterator * @iter into an appropriate C type to hold it. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if allocation failed. **/ char * type_of (const void * parent, DBusSignatureIter *iter) { int dbus_type; nih_assert (iter != NULL); dbus_type = dbus_signature_iter_get_current_type (iter); switch (dbus_type) { case DBUS_TYPE_BYTE: return nih_strdup (parent, "uint8_t"); case DBUS_TYPE_BOOLEAN: return nih_strdup (parent, "int"); case DBUS_TYPE_INT16: return nih_strdup (parent, "int16_t"); case DBUS_TYPE_UINT16: return nih_strdup (parent, "uint16_t"); case DBUS_TYPE_INT32: return nih_strdup (parent, "int32_t"); case DBUS_TYPE_UINT32: return nih_strdup (parent, "uint32_t"); case DBUS_TYPE_INT64: return nih_strdup (parent, "int64_t"); case DBUS_TYPE_UINT64: return nih_strdup (parent, "uint64_t"); case DBUS_TYPE_DOUBLE: return nih_strdup (parent, "double"); case DBUS_TYPE_STRING: return nih_strdup (parent, "char *"); case DBUS_TYPE_OBJECT_PATH: return nih_strdup (parent, "char *"); case DBUS_TYPE_SIGNATURE: return nih_strdup (parent, "char *"); case DBUS_TYPE_UNIX_FD: return nih_strdup (parent, "int"); default: nih_assert_not_reached (); } } /** * type_var_new: * @parent: parent object for new structure, * @type: C type, * @name: variable name. * * Allocates and returns a new TypeVar structure with the C type @type * and variable name @name, the strucure is not placed into any linked * list but will be removed from its containing list when freed. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned structure. When all parents * of the returned structure are freed, the returned structure will also be * freed. * * Returns: the new TypeVar structure or NULL if insufficient memory. **/ TypeVar * type_var_new (const void *parent, const char *type, const char *name) { TypeVar *var; nih_assert (type != NULL); nih_assert (name != NULL); var = nih_new (parent, TypeVar); if (! var) return NULL; nih_list_init (&var->entry); var->type = nih_strdup (var, type); if (! var->type) { nih_free (var); return NULL; } var->name = nih_strdup (var, name); if (! var->name) { nih_free (var); return NULL; } var->array = FALSE; nih_alloc_set_destructor (var, nih_list_destroy); return var; } /** * type_var_to_string: * @parent: parent object for new string, * @var: variable to convert. * * Returns a string for the given variable @var, consisting of the type * and variable name separated by a space if appropriate. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: the newly allocated string or NULL if insufficient memory. **/ char * type_var_to_string (const void *parent, TypeVar * var) { char *str; nih_assert (var != NULL); if (strchr (var->type, '*')) { str = nih_sprintf (parent, "%s%s", var->type, var->name); } else { str = nih_sprintf (parent, "%s %s", var->type, var->name); } if (! str) return NULL; if (var->array) { if (! nih_strcat (&str, parent, "[]")) { nih_free (str); return NULL; } } return str; } /** * type_var_layout: * @parent: parent object for new string, * @vars: list of variables to convert. * * Returns a string for the list of variables @vars, each of which should * be a TypeVar structure. Each variable is declared on a new line, * with the names lined up to the longest type length. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: the newly allocated string or NULL if insufficient memory. **/ char * type_var_layout (const void *parent, NihList * vars) { size_t max; size_t len; char * str; nih_assert (vars != NULL); /* Work out how much space to have for the types */ max = 0; NIH_LIST_FOREACH (vars, iter) { TypeVar *var = (TypeVar *)iter; size_t this_len; this_len = strlen (var->type); if (! strchr (var->type, '*')) this_len++; if (this_len > max) max = this_len; } /* Allocate a string with each of the variables on each line. */ len = 0; str = nih_strdup (parent, ""); if (! str) return NULL; NIH_LIST_FOREACH (vars, iter) { TypeVar *var = (TypeVar *)iter; char * new_str; new_str = nih_realloc (str, parent, (len + max + strlen (var->name) + (var->array ? 2 : 0) + 3)); if (! new_str) { nih_free (str); return NULL; } str = new_str; memset (str + len, ' ', max); memcpy (str + len, var->type, strlen (var->type)); len += max; memcpy (str + len, var->name, strlen (var->name)); len += strlen (var->name); if (var->array) { memcpy (str + len, "[]", 2); len += 2; } memcpy (str + len, ";\n", 2); len += 2; str[len] = '\0'; } return str; } /** * type_func_new: * @parent: parent object for new structure, * @type: C return type, * @name: function name. * * Allocates and returns a new TypeFunc structure with the * C return type @type and function name @name, the structure is not placed * into any linked list but will be removed from its containing list when * freed. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned structure. When all parents * of the returned structure are freed, the returned structure will also be * freed. * * Returns: the new TypeFunc structure or NULL if insufficient memory. **/ TypeFunc * type_func_new (const void *parent, const char *type, const char *name) { TypeFunc *func; nih_assert (type != NULL); nih_assert (name != NULL); func = nih_new (parent, TypeFunc); if (! func) return NULL; nih_list_init (&func->entry); func->type = nih_strdup (func, type); if (! func->type) { nih_free (func); return NULL; } func->name = nih_strdup (func, name); if (! func->name) { nih_free (func); return NULL; } nih_list_init (&func->args); nih_list_init (&func->attribs); nih_alloc_set_destructor (func, nih_list_destroy); return func; } /** * type_func_to_string: * @parent: parent object for new string, * @func: function to convert. * * Returns a string for the given function @func for use as the function * declaration header. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: the newly allocated string or NULL if insufficient memory. **/ char * type_func_to_string (const void *parent, TypeFunc * func) { char * str; size_t max; size_t len; nih_assert (func != NULL); /* Type goes on a separate line to the name */ str = nih_sprintf (parent, "%s\n%s (", func->type, func->name); if (! str) return NULL; /* If no arguments, should be just void */ if (NIH_LIST_EMPTY (&func->args)) { if (! nih_strcat (&str, parent, "void)\n")) { nih_free (str); return NULL; } return str; } /* Figure out the longest type name */ max = 0; NIH_LIST_FOREACH (&func->args, iter) { TypeVar *arg = (TypeVar *)iter; size_t this_len; this_len = strlen (arg->type); if (! strchr (arg->type, '*')) this_len++; if (this_len > max) max = this_len; } /* Append each argument with all the types and names lined up */ len = strlen (str); NIH_LIST_FOREACH (&func->args, iter) { TypeVar *arg = (TypeVar *)iter; char * new_str; /* Each additional argument goes onto a new line, indented * by the length of the function name plus the usual * punctuation */ if (iter != func->args.next) { new_str = nih_realloc (str, parent, len + strlen (func->name) + 5); if (! new_str) { nih_free (str); return NULL; } str = new_str; memcpy (str + len, ",\n", 2); len += 2; memset (str + len, ' ', strlen (func->name) + 2); len += strlen (func->name) + 2; str[len] = '\0'; } /* Append the argument so that the names line up */ new_str = nih_realloc (str, parent, len + max + strlen (arg->name) + 1); if (! new_str) { nih_free (str); return NULL; } str = new_str; memset (str + len, ' ', max); memcpy (str + len, arg->type, strlen (arg->type)); len += max; memcpy (str + len, arg->name, strlen (arg->name)); len += strlen (arg->name); str[len] = '\0'; } if (! nih_strcat (&str, parent, ")\n")) { nih_free (str); return NULL; } return str; } /** * type_func_to_typedef: * @parent: parent object for new string, * @func: function to convert. * * Returns a string for the given function typedef @func for use as the * typedef declaration. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: the newly allocated string or NULL if insufficient memory. **/ char * type_func_to_typedef (const void *parent, TypeFunc * func) { char *str; nih_assert (func != NULL); str = nih_sprintf (parent, "%s %s (", func->type, func->name); if (! str) return NULL; /* If no arguments, should be just void */ if (NIH_LIST_EMPTY (&func->args)) { if (! nih_strcat (&str, parent, "void")) { nih_free (str); return NULL; } } /* Append the arguments */ NIH_LIST_FOREACH (&func->args, iter) { TypeVar * arg = (TypeVar *)iter; nih_local char *arg_str = NULL; if (iter != func->args.next) { if (! nih_strcat (&str, parent, ", ")) { nih_free (str); return NULL; } } arg_str = type_var_to_string (NULL, arg); if (! arg_str) { nih_free (str); return NULL; } if (! nih_strcat (&str, parent, arg_str)) { nih_free (str); return NULL; } } if (! nih_strcat (&str, parent, ");\n")) { nih_free (str); return NULL; } return str; } /** * type_func_layout: * @parent: parent object for new string, * @funcs: list of functions to convert. * * Returns a string for the list of functions @funcs, each of which should * be a TypeFunc structure. Each function is declared on a new line, * with the names lined up to the longest type length and the arguments * list lined up to the longest name length. Attributes follow on the next * line. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: the newly allocated string or NULL if insufficient memory. **/ char * type_func_layout (const void *parent, NihList * funcs) { size_t type_max; size_t name_max; char * str; nih_assert (funcs != NULL); /* Work out how much space to have for the types and the names */ type_max = 0; name_max = 0; NIH_LIST_FOREACH (funcs, iter) { TypeFunc *func = (TypeFunc *)iter; size_t this_type_len; size_t this_name_len; this_type_len = strlen (func->type); if (! strchr (func->type, '*')) this_type_len++; this_name_len = strlen (func->name); if (this_type_len > type_max) type_max = this_type_len; if (this_name_len > name_max) name_max = this_name_len; } /* Allocate a string with each of the functions on each line. */ str = nih_strdup (parent, ""); if (! str) return NULL; NIH_LIST_FOREACH (funcs, iter) { TypeFunc *func = (TypeFunc *)iter; char * new_str; size_t len; len = strlen (str); new_str = nih_realloc (str, parent, len + type_max + name_max + 3); if (! new_str) { nih_free (str); return NULL; } str = new_str; memset (str + len, ' ', type_max); memcpy (str + len, func->type, strlen (func->type)); len += type_max; memset (str + len, ' ', name_max + 1); memcpy (str + len, func->name, strlen (func->name)); len += name_max + 1; str[len] = '('; len++; str[len] = '\0'; /* If no arguments, should be just void */ if (NIH_LIST_EMPTY (&func->args)) { if (! nih_strcat (&str, parent, "void")) { nih_free (str); return NULL; } } /* Append the arguments */ NIH_LIST_FOREACH (&func->args, iter) { TypeVar * arg = (TypeVar *)iter; nih_local char *arg_str = NULL; if (iter != func->args.next) { if (! nih_strcat (&str, parent, ", ")) { nih_free (str); return NULL; } } arg_str = type_var_to_string (NULL, arg); if (! arg_str) { nih_free (str); return NULL; } if (! nih_strcat (&str, parent, arg_str)) { nih_free (str); return NULL; } } /* If there are no attributes, that's it */ if (NIH_LIST_EMPTY (&func->attribs)) { if (! nih_strcat (&str, parent, ");\n")) { nih_free (str); return NULL; } continue; } /* Append the attributes indented on the next line */ if (! nih_strcat (&str, parent, ")\n\t__attribute__ ((")) { nih_free (str); return NULL; } NIH_LIST_FOREACH (&func->attribs, iter) { NihListEntry *attrib = (NihListEntry *)iter; if (iter != func->attribs.next) { if (! nih_strcat (&str, parent, ", ")) { nih_free (str); return NULL; } } if (! nih_strcat (&str, parent, attrib->str)) { nih_free (str); return NULL; } } if (! nih_strcat (&str, parent, "));\n")) { nih_free (str); return NULL; } } return str; } /** * type_struct_new: * @parent: parent object for new structure, * @name: structure name. * * Allocates and returns a new TypeStruct structure with the structure * name @name, the structure is not placed into any linked list but will * be removed from its containing list when freed. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned structure. When all parents * of the returned structure are freed, the returned structure will also be * freed. * * Returns: the new TypeStruct structure or NULL if insufficient memory. **/ TypeStruct * type_struct_new (const void *parent, const char *name) { TypeStruct *structure; nih_assert (name != NULL); structure = nih_new (parent, TypeStruct); if (! structure) return NULL; nih_list_init (&structure->entry); structure->name = nih_strdup (structure, name); if (! structure->name) { nih_free (structure); return NULL; } nih_list_init (&structure->members); nih_alloc_set_destructor (structure, nih_list_destroy); return structure; } /** * type_struct_to_string: * @parent: parent object for new string, * @structure: structure to convert. * * Returns a string for the given @structure declaring it both as a C * structure and as a shorter typedef. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: the newly allocated string or NULL if insufficient memory. **/ char * type_struct_to_string (const void *parent, TypeStruct *structure) { nih_local char *symbol = NULL; nih_local char *block = NULL; char * str; nih_assert (structure != NULL); /* Generate a lowercase structure symbol */ symbol = symbol_from_name (NULL, structure->name); if (! symbol) return NULL; /* Line up the members and indent */ block = type_var_layout (NULL, &structure->members); if (! block) return NULL; if (! NIH_LIST_EMPTY (&structure->members)) if (! indent (&block, NULL, 1)) return NULL; /* Output */ str = nih_sprintf (parent, "typedef struct %s {\n" "%s" "} %s;\n", symbol, block, structure->name); return str; } /** * type_to_const: * @type: C type, * @parent: parent object for original string. * * Converts the C type @type into a constant form if it's a pointer type. * * Only the first level of pointer is made constant, this is consistent * with C99 only allowing one level of type-compatibility in this regard. * i.e.: * char * becomes const char * * char ** becomes char * const * * * This has no effect if the first level of pointer is already constant, * if other levels are constant, the pointer will become more constant. * * @type is modified directly, the returned string is simply a pointer to * it, thus @parent is actually ignored though it usual to pass the parent * of @type for style reasons. * * Returns: modified @type or NULL if insufficient memory. **/ char * type_to_const (char ** type, const void *parent) { char * ptr; char * ret; size_t len; nih_assert (type != NULL); nih_assert (*type != NULL); len = strlen (*type); nih_assert (len > 0); /* If this is a pointer, the final character will be the operator; * if not, we can return now. */ ptr = *type + len - 1; if (*ptr != '*') return *type; /* Check whether this is the sole pointer operator, if not we need * to insert "const" before this one - otherwise we simply prepend * the declaration with "const". In both cases, check it's not * already there. (This still allows us to const-up a pointer). */ if (strchr (*type, '*') != ptr) { if ((len > 8) && (! strncmp (*type + len - 8, " const *", 8))) return *type; ret = nih_realloc (*type, parent, len + 8); if (! ret) return NULL; *type = ret; memcpy (*type + len - 1, " const *", 9); } else if (strncmp (*type, "const ", 6)) { ret = nih_realloc (*type, parent, len + 7); if (! ret) return NULL; *type = ret; memmove (*type + 6, *type, len + 1); memcpy (*type, "const ", 6); } return *type; } /** * type_to_pointer: * @type: C type, * @parent: parent object for original string. * * Covnerts the C type @type into a type containing a pointer to the * original type. If the type in @type is already a pointer, a further * level of indirection is added. * * This has a special behaviour in the case of constant pointers, the * constantness is moved from the previous top level to the new top * level. * i.e.: * const char * becomes char * const * * char * const * becomes char ** const * * * This is to allow for arrays to pointerify their elements whilst * preserving the "I don't modify this" flag use of const. We can't * just add another const becuse C99 only allows one level of * type-compatibility. * * @type is modified directly, the returned string is simply a pointer to * it, thus @parent is actually ignored though it usual to pass the parent * of @type for style reasons. * * Returns: modified @type or NULL if insufficient memory. **/ char * type_to_pointer (char ** type, const void *parent) { char * ptr; char * ret; size_t len; nih_assert (type != NULL); nih_assert (*type != NULL); len = strlen (*type); nih_assert (len > 0); ptr = *type + len - 1; /* If the string is a single-level constant pointer, we have to * shuffle it all around to make it a two-level pointer with the * new first-level constant. * * If the string is a nth-level constant pointer, we just insert * a pointer in before the const part. * * If the string is any kind of pointer, we append another pointer. * * Otherwise we add a pointer and a space to keep everything * separate. */ if ((strchr (*type, '*') == ptr) && (! strncmp (*type, "const ", 6))) { ret = nih_realloc (*type, parent, len + 3); if (! ret) return NULL; *type = ret; memmove (*type, *type + 6, len - 6); memcpy (*type + len - 6, " const *", 9); } else if ((len > 8) && (! strncmp (*type + len - 8, " const *", 8))) { ret = nih_realloc (*type, parent, len + 2); if (! ret) return NULL; *type = ret; memcpy (*type + len - 8, "* const *", 10); } else if (*ptr == '*') { ret = nih_realloc (*type, parent, len + 2); if (! ret) return NULL; *type = ret; memcpy (*type + len, "*", 2); } else { ret = nih_realloc (*type, parent, len + 3); if (! ret) return NULL; *type = ret; memcpy (*type + len, " *", 3); } return *type; } /** * type_to_static: * @type: C type, * @parent: parent object for original string. * * Converts the C type @type into a static form. * * This has no effect if the type is already static. * * @type is modified directly, the returned string is simply a pointer to * it, thus @parent is actually ignored though it usual to pass the parent * of @type for style reasons. * * Returns: modified @type or NULL if insufficient memory. **/ char * type_to_static (char ** type, const void *parent) { char * ret; size_t len; nih_assert (type != NULL); nih_assert (*type != NULL); len = strlen (*type); nih_assert (len > 0); if (strncmp (*type, "static ", 7)) { ret = nih_realloc (*type, parent, len + 8); if (! ret) return NULL; *type = ret; memmove (*type + 7, *type, len + 1); memcpy (*type, "static ", 7); } return *type; } /** * type_to_extern: * @type: C type, * @parent: parent object for original string. * * Converts the C type @type into an extern form. * * This has no effect if the type is already extern. * * @type is modified directly, the returned string is simply a pointer to * it, thus @parent is actually ignored though it usual to pass the parent * of @type for style reasons. * * Returns: modified @type or NULL if insufficient memory. **/ char * type_to_extern (char ** type, const void *parent) { char * ret; size_t len; nih_assert (type != NULL); nih_assert (*type != NULL); len = strlen (*type); nih_assert (len > 0); if (strncmp (*type, "extern ", 7)) { ret = nih_realloc (*type, parent, len + 8); if (! ret) return NULL; *type = ret; memmove (*type + 7, *type, len + 1); memcpy (*type, "extern ", 7); } return *type; } /** * type_strcat_assert: * @block: code block to append to, * @parent: parent object for @block, * @var: variable to append assert block for, * @prev: prev variable in list or NULL, * @next: next variable in list or NULL. * * If @var is a pointer variable, appends a line of code to @block that * asserts that the variable is not NULL. If @var is not a pointer variable, * this function has no effect. * * This function handles the case of @var being an array and @next * being its size member, in which case @var may be NULL if its size member * is zero. * * This function also handles the case of @var being an array of size * members and @prev being the array, in which case @var may be NULL if the * first member of @prev is NULL. * * @block is modified directly, the returned string is simply a pointer to * it, thus @parent is actually ignored though it usual to pass the parent * of @block for style reasons. * * Note that @block may be returned unmodified, therefore it is not * permitted to pass NULL for @block as this would be indistinguishable from * insufficient memory. * * Returns: modified @block or NULL if insufficient memory. **/ char * type_strcat_assert (char ** block, const void *parent, TypeVar * var, TypeVar * prev, TypeVar * next) { nih_assert (block != NULL); nih_assert (var != NULL); if (! strchr (var->type, '*')) return *block; if (next && (! strcmp (next->type, "size_t"))) { if (! nih_strcat_sprintf (block, parent, "nih_assert ((%s == 0) || (%s != NULL));\n", next->name, var->name)) return NULL; } else if (prev && strstr (var->type, "size_t")) { if (! nih_strcat_sprintf (block, parent, "nih_assert ((*%s == NULL) || (%s != NULL));\n", prev->name, var->name)) return NULL; } else { if (! nih_strcat_sprintf (block, parent, "nih_assert (%s != NULL);\n", var->name)) return NULL; } return *block; } libnih-1.0.3/nih-dbus-tool/node.h0000644000175000017500000000455011445765555013510 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_NODE_H #define NIH_DBUS_TOOL_NODE_H #include #include #include #include "interface.h" /** * Node: * @path: D-Bus path of node, * @interfaces: interfaces the node implements. * * A node is the top-level tag in D-Bus introspection data and represents * a specific D-Bus object with the path given in @path. **/ typedef struct node { char * path; NihList interfaces; } Node; NIH_BEGIN_EXTERN int node_path_valid (const char *name); Node * node_new (const void *parent, const char *path) __attribute__ ((warn_unused_result, malloc)); int node_start_tag (XML_Parser xmlp, const char *tag, char * const *attr) __attribute__ ((warn_unused_result)); int node_end_tag (XML_Parser xmlp, const char *tag) __attribute__ ((warn_unused_result)); Interface *node_lookup_interface (Node *node, const char *symbol); char * node_interfaces_array (const void *parent, const char *prefix, Node *node, int object, NihList *prototypes) __attribute__ ((warn_unused_result, malloc)); char * node_object_functions (const void *parent, const char *prefix, Node *node, NihList *prototypes, NihList *handlers, NihList *structs, NihList *externs) __attribute__ ((warn_unused_result, malloc)); char * node_proxy_functions (const void *parent, const char *prefix, Node *node, NihList *prototypes, NihList *structs, NihList *typedefs, NihList *externs) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_NODE_H */ libnih-1.0.3/nih-dbus-tool/argument.c0000644000175000017500000003057111445765555014402 00000000000000/* nih-dbus-tool * * argument.c - argument parsing and handling * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include "symbol.h" #include "argument.h" #include "parse.h" #include "errors.h" /** * argument_name_valid: * @name: Member name to verify. * * Verifies whether @name matches the specification for a D-Bus interface * member name, and thus is valid for a argument. * * Returns: TRUE if valid, FALSE if not. **/ int argument_name_valid (const char *name) { nih_assert (name != NULL); /* We can get away with just using strlen() here even through name * is in UTF-8 because all the valid characters are ASCII. */ for (size_t i = 0; i < strlen (name); i++) { /* Names may contain digits, but not at the beginning. */ if ((name[i] >= '0') && (name[i] <= '9')) { if (i == 0) return FALSE; continue; } /* Valid characters anywhere are [A-Za-z_] */ if ( ((name[i] < 'A') || (name[i] > 'Z')) && ((name[i] < 'a') || (name[i] > 'z')) && (name[i] != '_')) return FALSE; } /* Name must be at least 1 character */ if (strlen (name) < 1) return FALSE; return TRUE; } /** * argument_new: * @parent: parent object for new argument, * @name: D-Bus name of argument, * @type: D-Bus type argument, * @direction: argument direction. * * Allocates a new D-Bus object Argument data structure, with the D-Bus name * optionally set to @name and the D-Bus type signature set to @type. The * returned structure is not placed into any list. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned argument. When all parents * of the returned argument are freed, the returned argument will also be * freed. * * Returns: the new argument or NULL if the allocation failed. **/ Argument * argument_new (const void * parent, const char * name, const char * type, NihDBusArgDir direction) { Argument *argument; nih_assert (type != NULL); argument = nih_new (parent, Argument); if (! argument) return NULL; nih_list_init (&argument->entry); nih_alloc_set_destructor (argument, nih_list_destroy); if (name) { argument->name = nih_strdup (argument, name); if (! argument->name) { nih_free (argument); return NULL; } } else { argument->name = NULL; } argument->symbol = NULL; argument->type = nih_strdup (argument, type); if (! argument->type) { nih_free (argument); return NULL; } argument->direction = direction; return argument; } /** * argument_start_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed, * @attr: NULL-terminated array of attribute name and value pairs. * * This function is called by parse_start_tag() for an "argument" * start tag, which may be a child of either the "method" or "signal" tags * defining an argument for the method or signal. * * If the argument does not appear within a method or signal tag a warning * is emitted and the tag will be ignored. * * Arguments must have a "type" attribute containing the D-Bus type * signature, they usually have a "name" attribute specifying the D-Bus name * but it's technically optional and they may also have a "direction" * attribute specifying whether the argument is input (default for methods) * or output (default for signals). * * Any unknown attributes result in a warning and will be ignored. * * An Argument object will be allocated and pushed onto the stack, this is * not added to the method or signal until the end tag is found. * * Returns: zero on success, negative value on raised error. **/ int argument_start_tag (XML_Parser xmlp, const char * tag, char * const *attr) { ParseContext * context; ParseStack * parent; nih_local Argument *argument = NULL; char * const * key; char * const * value; const char * name = NULL; const char * type = NULL; const char * direction_str = NULL; NihDBusArgDir direction; DBusError error; nih_assert (xmlp != NULL); nih_assert (tag != NULL); nih_assert (attr != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); /* Arguments should only appear inside methods or signals. */ parent = parse_stack_top (&context->stack); if ((! parent) || ((parent->type != PARSE_METHOD) && (parent->type != PARSE_SIGNAL))) { nih_warn ("%s:%zu:%zu: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unexpected tag")); if (! parse_stack_push (NULL, &context->stack, PARSE_IGNORED, NULL)) nih_return_system_error (-1); return 0; } /* Retrieve the name, type and direction from the attributes */ for (key = attr; key && *key; key += 2) { value = key + 1; nih_assert (value && *value); if (! strcmp (*key, "name")) { name = *value; } else if (! strcmp (*key, "type")) { type = *value; } else if (! strcmp (*key, "direction")) { direction_str = *value; } else { nih_warn ("%s:%zu:%zu: %s: %s", context->filename, (size_t)XML_GetCurrentLineNumber (xmlp), (size_t)XML_GetCurrentColumnNumber (xmlp), _("Ignored unknown attribute"), *key); } } /* Check we have a type and that it's valid (name and direction * are optional). We also check the name is valid according to * member rules, strictly speaking there is no such restriction, * but we hereby invent one. */ if (name && (! argument_name_valid (name))) nih_return_error (-1, ARGUMENT_INVALID_NAME, _(ARGUMENT_INVALID_NAME_STR)); if (! type) nih_return_error (-1, ARGUMENT_MISSING_TYPE, _(ARGUMENT_MISSING_TYPE_STR)); dbus_error_init (&error); if (! dbus_signature_validate_single (type, &error)) { nih_error_raise_printf (ARGUMENT_INVALID_TYPE, "%s: %s", _(ARGUMENT_INVALID_TYPE_STR), error.message); dbus_error_free (&error); return -1; } switch (parent->type) { case PARSE_METHOD: if (! direction_str) { direction = NIH_DBUS_ARG_IN; } else if (! strcmp (direction_str, "in")) { direction = NIH_DBUS_ARG_IN; } else if (! strcmp (direction_str, "out")) { direction = NIH_DBUS_ARG_OUT; } else { nih_return_error (-1, ARGUMENT_ILLEGAL_METHOD_DIRECTION, _(ARGUMENT_ILLEGAL_METHOD_DIRECTION_STR)); } break; case PARSE_SIGNAL: if (! direction_str) { direction = NIH_DBUS_ARG_OUT; } else if (! strcmp (direction_str, "out")) { direction = NIH_DBUS_ARG_OUT; } else { nih_return_error (-1, ARGUMENT_ILLEGAL_SIGNAL_DIRECTION, _(ARGUMENT_ILLEGAL_SIGNAL_DIRECTION_STR)); } break; default: nih_assert_not_reached (); } /* Allocate an Argument object and push onto the stack */ argument = argument_new (NULL, name, type, direction); if (! argument) nih_return_system_error (-1); if (! parse_stack_push (NULL, &context->stack, PARSE_ARGUMENT, argument)) { nih_error_raise_system (); return -1; } return 0; } /** * argument_end_tag: * @xmlp: XML parser, * @tag: name of XML tag being parsed. * * This function is called by parse_end_tag() for an "argument" end * tag, and matches a call to argument_start_tag() made at the same * parsing level. * * The argument is added to the list of arguments for the parent method * or signal. * * Returns: zero on success, negative value on raised error. **/ int argument_end_tag (XML_Parser xmlp, const char *tag) { ParseContext *context; ParseStack * entry; ParseStack * parent; Argument * argument; Argument * conflict; Method * method; Signal * signal; nih_assert (xmlp != NULL); nih_assert (tag != NULL); context = XML_GetUserData (xmlp); nih_assert (context != NULL); entry = parse_stack_top (&context->stack); nih_assert (entry != NULL); nih_assert (entry->type == PARSE_ARGUMENT); argument = entry->argument; /* Generate a symbol from the name if we have one */ if (argument->name && (! argument->symbol)) { argument->symbol = symbol_from_name (argument, argument->name); if (! argument->symbol) nih_return_no_memory_error (-1); } nih_list_remove (&entry->entry); parent = parse_stack_top (&context->stack); nih_assert (parent != NULL); switch (parent->type) { case PARSE_METHOD: method = parent->method; /* Otherwise generate a symbol from the argument count */ if (! argument->symbol) { size_t count = 0; NIH_LIST_FOREACH (&method->arguments, iter) count++; argument->symbol = nih_sprintf (argument, "arg%zu", ++count); if (! argument->symbol) { nih_list_add_after (&context->stack, &entry->entry); nih_return_no_memory_error (-1); } } /* Make sure there's not a conflict before adding the arg */ conflict = method_lookup_argument (method, argument->symbol); if (conflict) { nih_error_raise_printf (ARGUMENT_DUPLICATE_SYMBOL, _(ARGUMENT_DUPLICATE_SYMBOL_STR), argument->symbol, conflict->name); return -1; } nih_debug ("Add %s argument to %s method", argument->name ?: "(unknown)", method->name); nih_list_add (&method->arguments, &argument->entry); nih_ref (argument, method); break; case PARSE_SIGNAL: signal = parent->signal; /* Otherwise generate a symbol from the argument count */ if (! argument->symbol) { size_t count = 0; NIH_LIST_FOREACH (&signal->arguments, iter) count++; argument->symbol = nih_sprintf (argument, "arg%zu", ++count); if (! argument->symbol) { nih_list_add_after (&context->stack, &entry->entry); nih_return_no_memory_error (-1); } } /* Make sure there's not a conflict before adding the arg */ conflict = signal_lookup_argument (signal, argument->symbol); if (conflict) { nih_error_raise_printf (ARGUMENT_DUPLICATE_SYMBOL, _(ARGUMENT_DUPLICATE_SYMBOL_STR), argument->symbol, conflict->name); return -1; } nih_debug ("Add %s argument to %s signal", argument->name ?: "(unknown)", signal->name); nih_list_add (&signal->arguments, &argument->entry); nih_ref (argument, signal); break; default: nih_assert_not_reached (); } nih_free (entry); return 0; } /** * argument_annotation: * @argument: argument object annotation applies to, * @name: annotation name, * @value: annotation value. * * Handles applying the annotation @name with value @value to the argument * @argument. While the D-Bus Introspection specification does not permit * annotations for arguments, this is an nih-dbus-tool extension. Arguments * may be annotated with an alternate symbol name specified. * * Unknown annotations or illegal values to the known annotations result * in an error being raised. * * Returns: zero on success, negative value on raised error. **/ int argument_annotation (Argument * argument, const char *name, const char *value) { nih_assert (argument != NULL); nih_assert (name != NULL); nih_assert (value != NULL); if (! strcmp (name, "com.netsplit.Nih.Symbol")) { if (symbol_valid (value)) { if (argument->symbol) nih_unref (argument->symbol, argument); argument->symbol = nih_strdup (argument, value); if (! argument->symbol) nih_return_no_memory_error (-1); nih_debug ("Set %s argument symbol to %s", argument->name ?: "(unknown)", argument->symbol); } else { nih_return_error (-1, ARGUMENT_INVALID_SYMBOL, _(ARGUMENT_INVALID_SYMBOL_STR)); } } else { nih_error_raise_printf (ARGUMENT_UNKNOWN_ANNOTATION, "%s: %s: %s", _(ARGUMENT_UNKNOWN_ANNOTATION_STR), argument->name ?: "(unnamed)", name); return -1; } return 0; } libnih-1.0.3/nih-dbus-tool/method.h0000644000175000017500000000752111445765555014044 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_METHOD_H #define NIH_DBUS_TOOL_METHOD_H #include #include #include #include "interface.h" #include "argument.h" /** * Method: * @entry: list header, * @name: D-Bus name of method, * @symbol: name used when constructing C name, * @deprecated: whether this method is deprecated, * @async: whether the object implementation should be asynchronous, * @no_reply: TRUE if no reply should be expected or generated, * @arguments: arguments accepted by the method. * * D-Bus interfaces specify zero or more methods, which are selected by * @name over the bus and may have zero or more @arguments. * * When generating the C symbol names @symbol will be used. If @symbol * is NULL, @name will be converted into the usual C lowercase and underscore * style and used instead. **/ typedef struct method { NihList entry; char * name; char * symbol; int deprecated; int async; int no_reply; NihList arguments; } Method; NIH_BEGIN_EXTERN int method_name_valid (const char *name); Method * method_new (const void *parent, const char *name) __attribute__ ((warn_unused_result, malloc)); int method_start_tag (XML_Parser xmlp, const char *tag, char * const *attr) __attribute__ ((warn_unused_result)); int method_end_tag (XML_Parser xmlp, const char *tag) __attribute__ ((warn_unused_result)); int method_annotation (Method *method, const char *name, const char *value) __attribute__ ((warn_unused_result)); Method * method_lookup (Interface *interface, const char *symbol); Argument *method_lookup_argument (Method *method, const char *symbol); char * method_object_function (const void *parent, const char *prefix, Interface *interface, Method *method, NihList *prototypes, NihList *handlers, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * method_reply_function (const void *parent, const char *prefix, Interface *interface, Method *method, NihList *prototypes, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * method_proxy_function (const void *parent, const char *prefix, Interface *interface, Method *method, NihList *prototypes, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * method_proxy_notify_function (const void *parent, const char *prefix, Interface *interface, Method *method, NihList *prototypes, NihList *typedefs, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * method_proxy_sync_function (const void *parent, const char *prefix, Interface *interface, Method *method, NihList *prototypes, NihList *structs) __attribute__ ((warn_unused_result, malloc)); char * method_args_array (const void *parent, const char *prefix, Interface *interface, Method *method, NihList *prototypes) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_METHOD_H */ libnih-1.0.3/nih-dbus-tool/marshal.c0000644000175000017500000006734511445765555014220 00000000000000/* nih-dbus-tool * * marshal.c - type marshalling * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include "indent.h" #include "symbol.h" #include "type.h" #include "marshal.h" /* Prototypes for static functions */ static char *marshal_basic (const void *parent, DBusSignatureIter *iter, const char *iter_name, const char *name, const char *oom_error_code, NihList *inputs, NihList *locals, const char *prefix, const char *interface_symbol, const char *member_symbol, const char *symbol, NihList *structs) __attribute__ ((warn_unused_result, malloc)); static char *marshal_array (const void *parent, DBusSignatureIter *iter, const char *iter_name, const char *name, const char *oom_error_code, NihList *inputs, NihList *locals, const char *prefix, const char *interface_symbol, const char *member_symbol, const char *symbol, NihList *structs) __attribute__ ((warn_unused_result, malloc)); static char *marshal_struct (const void *parent, DBusSignatureIter *iter, const char *iter_name, const char *name, const char *oom_error_code, NihList *inputs, NihList *locals, const char *prefix, const char *interface_symbol, const char *member_symbol, const char *symbol, NihList *structs) __attribute__ ((warn_unused_result, malloc)); /** * marshal: * @parent: parent object for new string, * @signature: signature of type, * @iter_name: name of iterator variable, * @name: name of variable, * @oom_error_code: code to execute on OOM Error, * @inputs: list to append input variables to, * @locals: list to append local variables to, * @prefix: prefix for structure names, * @interface_symbol: symbol of interface for structure names, * @member_symbol: symbol of interface member for structure names, * @symbol: symbol of argument or variable for structure names, * @structs: list to append structure definitions to. * * Generates C code to marshal any D-Bus type from an appropriately typed * variable named @name into the D-Bus iterator variable named @iter_name. * * The type should be the current element of the signature iterator @iter. * This then simply calls marshal_fixed(), marshal_string(), * marshal_fixed_array(), marshal_flexible_array() or marshal_struct() * as appropriate. * * The generated code detects out-of-memory conditions but does not know * how to handle them, therefore you need to pass the appropriate handling * code in @oom_error_code. This code will be inserted wherever an OOM * condition is detected. * * The expected input variable types and names are given as TypeVar objects * appended to the @inputs list, each name is guaranteed to begin with @name * and the first member will always be @name itself. Should the C code * require local variables, similar TypeVar objects will be appended to * the @locals list. * * If the variable requires a structure to be defined, the definition is * returned as a TypeStruct object appended to the @structs list. The name * is generated from @prefix, @interface_symbol, @member_symbol and @symbol. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * marshal (const void * parent, DBusSignatureIter *iter, const char * iter_name, const char * name, const char * oom_error_code, NihList * inputs, NihList * locals, const char * prefix, const char * interface_symbol, const char * member_symbol, const char * symbol, NihList * structs) { int dbus_type; nih_assert (iter != NULL); nih_assert (iter_name != NULL); nih_assert (name != NULL); nih_assert (oom_error_code != NULL); nih_assert (inputs != NULL); nih_assert (locals != NULL); nih_assert (prefix != NULL); nih_assert (member_symbol != NULL); nih_assert (structs != NULL); dbus_type = dbus_signature_iter_get_current_type (iter); if (dbus_type_is_basic (dbus_type)) { return marshal_basic (parent, iter, iter_name, name, oom_error_code, inputs, locals, prefix, interface_symbol, member_symbol, symbol, structs); } else if (dbus_type == DBUS_TYPE_ARRAY) { return marshal_array (parent, iter, iter_name, name, oom_error_code, inputs, locals, prefix, interface_symbol, member_symbol, symbol, structs); } else if ((dbus_type == DBUS_TYPE_STRUCT) || (dbus_type == DBUS_TYPE_DICT_ENTRY)) { return marshal_struct (parent, iter, iter_name, name, oom_error_code, inputs, locals, prefix, interface_symbol, member_symbol, symbol, structs); } else { nih_assert_not_reached (); } } /** * marshal_basic: * @parent: parent object for new string, * @iter: D-Bus signature iterator, * @iter_name: name of iterator variable, * @name: name of variable, * @oom_error_code: code to execute on OOM Error, * @inputs: list to append input variables to, * @locals: list to append local variables to, * @interface_symbol: symbol of interface for structure names, * @member_symbol: symbol of interface member for structure names, * @symbol: symbol of argument or variable for structure names, * @structs: list to append structure definitions to. * * Generates C code to marshal a D-Bus basic type (ie. numerics and strings) * from an appropriately typed variable named @name into the D-Bus iterator * variable named @iter_name. * * The type should be the current element of the signature iterator @iter. * * The generated code detects out-of-memory conditions but does not know * how to handle them, therefore you need to pass the appropriate handling * code in @oom_error_code. This code will be inserted wherever an OOM * condition is detected. * * The expected input variable types and names are given as TypeVar objects * appended to the @inputs list, each name is guaranteed to begin with @name * and the first member will always be @name itself. Should the C code * require local variables, similar TypeVar objects will be appended to * the @locals list. * * If the variable requires a structure to be defined, the definition is * returned as a TypeStruct object appended to the @structs list. The name * is generated from @prefix, @interface_symbol, @member_symbol and @symbol. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ static char * marshal_basic (const void * parent, DBusSignatureIter *iter, const char * iter_name, const char * name, const char * oom_error_code, NihList * inputs, NihList * locals, const char * prefix, const char * interface_symbol, const char * member_symbol, const char * symbol, NihList * structs) { int dbus_type; const char * dbus_const; nih_local char *oom_error_block = NULL; nih_local char *c_type = NULL; char * code = NULL; TypeVar * var; nih_assert (iter != NULL); nih_assert (iter_name != NULL); nih_assert (name != NULL); nih_assert (oom_error_code != NULL); nih_assert (inputs != NULL); nih_assert (locals != NULL); nih_assert (prefix != NULL); nih_assert (member_symbol != NULL); nih_assert (structs != NULL); dbus_type = dbus_signature_iter_get_current_type (iter); dbus_const = type_const (dbus_type); oom_error_block = nih_strdup (NULL, oom_error_code); if (! oom_error_block) return NULL; if (! indent (&oom_error_block, NULL, 1)) return NULL; c_type = type_of (NULL, iter); if (! c_type) return NULL; if (! nih_strcat_sprintf (&code, parent, "/* Marshal a %s onto the message */\n" "if (! dbus_message_iter_append_basic (&%s, %s, &%s)) {\n" "%s" "}\n", c_type, iter_name, dbus_const, name, oom_error_block)) return NULL; /* Append our required input variable */ var = type_var_new (code, c_type, name); if (! var) { nih_free (code); return NULL; } nih_list_add (inputs, &var->entry); return code; } /** * marshal_array: * @parent: parent object for new string, * @iter: D-Bus signature iterator, * @iter_name: name of iterator variable, * @name: name of variable, * @oom_error_code: code to execute on OOM Error, * @inputs: list to append input variables to, * @locals: list to append local variables to, * @interface_symbol: symbol of interface for structure names, * @member_symbol: symbol of interface member for structure names, * @symbol: symbol of argument or variable for structure names, * @structs: list to append structure definitions to. * * Generates C code to marshal a D-Bus array type from an appropriately * typed, NULL-terminated, array variable named @name into the D-Bus * iterator variable named @iter_name. In the case of arrays (of any * number of levels) ultimately to a fixed type, an additional input * named "@name"_len is required of size_t type or an appropriate number * of pointers to it. * * The type should be the current element of the signature iterator @iter. * * The generated code detects out-of-memory conditions but does not know * how to handle them, therefore you need to pass the appropriate handling * code in @oom_error_code. This code will be inserted wherever an OOM * condition is detected. * * The expected input variable types and names are given as TypeVar objects * appended to the @inputs list, each name is guaranteed to begin with @name * and the first member will always be @name itself. Should the C code * require local variables, similar TypeVar objects will be appended to * the @locals list. * * If the variable requires a structure to be defined, the definition is * returned as a TypeStruct object appended to the @structs list. The name * is generated from @prefix, @interface_symbol, @member_symbol and @symbol. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ static char * marshal_array (const void * parent, DBusSignatureIter *iter, const char * iter_name, const char * name, const char * oom_error_code, NihList * inputs, NihList * locals, const char * prefix, const char * interface_symbol, const char * member_symbol, const char * symbol, NihList * structs) { nih_local char * array_iter_name = NULL; nih_local char * loop_name = NULL; nih_local char * element_name = NULL; nih_local char * element_symbol = NULL; nih_local char * len_name = NULL; nih_local char * oom_error_block = NULL; nih_local char * child_oom_error_code = NULL; nih_local char * child_oom_error_block = NULL; DBusSignatureIter subiter; int element_type; char * signature; char * code = NULL; TypeVar * array_iter_var; NihList element_inputs; NihList element_locals; NihList element_structs; nih_local char * element_block = NULL; nih_local char * element_c_type = NULL; nih_local TypeVar *element_var = NULL; nih_local TypeVar *element_len_var = NULL; nih_local char * block = NULL; nih_local char * vars_block = NULL; nih_assert (iter != NULL); nih_assert (iter_name != NULL); nih_assert (name != NULL); nih_assert (oom_error_code != NULL); nih_assert (inputs != NULL); nih_assert (locals != NULL); nih_assert (prefix != NULL); nih_assert (member_symbol != NULL); nih_assert (structs != NULL); array_iter_name = nih_sprintf (NULL, "%s_iter", name); if (! array_iter_name) return NULL; loop_name = nih_sprintf (NULL, "%s_i", name); if (! loop_name) return NULL; element_name = nih_sprintf (NULL, "%s_element", name); if (! element_name) return NULL; element_symbol = (symbol ? nih_sprintf (NULL, "%s_element", symbol) : nih_strdup (NULL, "element")); if (! element_symbol) return NULL; len_name = nih_sprintf (NULL, "%s_len", name); if (! len_name) return NULL; oom_error_block = nih_strdup (NULL, oom_error_code); if (! oom_error_block) return NULL; if (! indent (&oom_error_block, NULL, 1)) return NULL; child_oom_error_code = nih_sprintf (NULL, ("dbus_message_iter_abandon_container (&%s, &%s);\n" "%s"), iter_name, array_iter_name, oom_error_code); if (! child_oom_error_code) return NULL; child_oom_error_block = nih_strdup (NULL, child_oom_error_code); if (! child_oom_error_block) return NULL; if (! indent (&child_oom_error_block, NULL, 1)) return NULL; /* Open the array container, we need to give D-Bus the container * signature to do this and we need a local variable for the * recursed iterator. */ dbus_signature_iter_recurse (iter, &subiter); element_type = dbus_signature_iter_get_current_type (&subiter); signature = dbus_signature_iter_get_signature (&subiter); if (! nih_strcat_sprintf (&code, parent, "/* Marshal an array onto the message */\n" "if (! dbus_message_iter_open_container (&%s, DBUS_TYPE_ARRAY, \"%s\", &%s)) {\n" "%s" "}\n" "\n", iter_name, signature, array_iter_name, oom_error_block)) { dbus_free (signature); return NULL; } dbus_free (signature); array_iter_var = type_var_new (code, "DBusMessageIter", array_iter_name); if (! array_iter_var) { nih_free (code); return NULL; } nih_list_add (locals, &array_iter_var->entry); if (dbus_type_is_fixed (element_type)) { if (! nih_strcat_sprintf (&code, parent, "for (size_t %s = 0; %s < %s; %s++) {\n", loop_name, loop_name, len_name, loop_name)) { nih_free (code); return NULL; } } else { if (! nih_strcat_sprintf (&code, parent, "for (size_t %s = 0; %s[%s]; %s++) {\n", loop_name, name, loop_name, loop_name)) { nih_free (code); return NULL; } } /* Get the code that will marshal the individual elements, the * inputs that we need to give and any local variables we have * to declare. */ nih_list_init (&element_inputs); nih_list_init (&element_locals); nih_list_init (&element_structs); element_block = marshal (NULL, &subiter, array_iter_name, element_name, child_oom_error_code, &element_inputs, &element_locals, prefix, interface_symbol, member_symbol, element_symbol, &element_structs); if (! element_block) { nih_free (code); return NULL; } /* Each of the inputs of the marshalling code equates to one of our * own inputs, except that we add another level of pointers for the * array; at the same time, we keep the suffix and append it to our * own name. Instead of mucking around with pointers and structure * members, we also append the inputs onto the local lists (making it * const in the process) for the value to be marshalled into this * variable. */ NIH_LIST_FOREACH_SAFE (&element_inputs, iter) { TypeVar * input_var = (TypeVar *)iter; nih_local char *var_type = NULL; char * suffix; nih_local char *var_name = NULL; TypeVar * var; var_type = nih_strdup (NULL, input_var->type); if (! var_type) { nih_free (code); return NULL; } if (! type_to_pointer (&var_type, NULL)) { nih_free (code); return NULL; } nih_assert (! strncmp (input_var->name, element_name, strlen (element_name))); suffix = input_var->name + strlen (element_name); var_name = nih_sprintf (NULL, "%s%s", name, suffix); if (! var_name) { nih_free (code); return NULL; } var = type_var_new (code, var_type, var_name); if (! var) { nih_free (code); return NULL; } nih_list_add (inputs, &var->entry); if (! nih_strcat_sprintf (&block, NULL, "%s = %s[%s];\n", input_var->name, var_name, loop_name)) { nih_free (code); return NULL; } if (! type_to_const (&input_var->type, input_var)) { nih_free (code); return NULL; } nih_list_add (&element_locals, &input_var->entry); } vars_block = type_var_layout (NULL, &element_locals); if (! vars_block) { nih_free (code); return NULL; } NIH_LIST_FOREACH_SAFE (&element_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } /* Lay all that out in an indented block inside the for loop. * Make sure that we initialise the individual elements from the * pointer. */ if (! indent (&vars_block, NULL, 1)) { nih_free (code); return NULL; } if (! indent (&block, NULL, 1)) { nih_free (code); return NULL; } if (! indent (&element_block, NULL, 1)) { nih_free (code); return NULL; } if (! nih_strcat_sprintf (&code, parent, "%s" "\n" "%s" "\n" "%s", vars_block, block, element_block)) { nih_free (code); return NULL; } /* Close the container again */ if (! nih_strcat_sprintf (&code, parent, "}\n" "\n" "if (! dbus_message_iter_close_container (&%s, &%s)) {\n" "%s" "}\n", iter_name, array_iter_name, oom_error_block)) { nih_free (code); return NULL; } /* When iterating a fixed type, we get an extra length input */ if (dbus_type_is_fixed (element_type)) { TypeVar *var; var = type_var_new (code, "size_t", len_name); if (! var) { nih_free (code); return NULL; } nih_list_add (inputs, &var->entry); } return code; } /** * marshal_struct: * @parent: parent object for new string, * @iter: D-Bus signature iterator, * @iter_name: name of iterator variable, * @name: name of variable, * @oom_error_code: code to execute on OOM Error, * @inputs: list to append input variables to, * @locals: list to append local variables to, * @interface_symbol: symbol of interface for structure names, * @member_symbol: symbol of interface member for structure names, * @symbol: symbol of argument or variable for structure names, * @structs: list to append structure definitions to. * * Generates C code to marshal a D-Bus structure type, and its members, * from an appropriately typed variable named @name into the D-Bus iterator * variable named @iter_name. * * The type should be the current element of the signature iterator @iter. * * The generated code detects out-of-memory conditions but does not know * how to handle them, therefore you need to pass the appropriate handling * code in @oom_error_code. This code will be inserted wherever an OOM * condition is detected. * * The expected input variable types and names are given as TypeVar objects * appended to the @inputs list, each name is guaranteed to begin with @name * and the first member will always be @name itself. Should the C code * require local variables, similar TypeVar objects will be appended to * the @locals list. * * If the variable requires a structure to be defined, the definition is * returned as a TypeStruct object appended to the @structs list. The name * is generated from @prefix, @interface_symbol, @member_symbol and @symbol. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ static char * marshal_struct (const void * parent, DBusSignatureIter *iter, const char * iter_name, const char * name, const char * oom_error_code, NihList * inputs, NihList * locals, const char * prefix, const char * interface_symbol, const char * member_symbol, const char * symbol, NihList * structs) { int dbus_type; const char * dbus_const; nih_local char * struct_iter_name = NULL; nih_local char * oom_error_block = NULL; nih_local char * child_oom_error_code = NULL; nih_local char * child_oom_error_block = NULL; nih_local char * c_type = NULL; TypeStruct * structure; DBusSignatureIter subiter; char * code = NULL; TypeVar * struct_iter_var; size_t count = 0; TypeVar * var; nih_assert (iter != NULL); nih_assert (iter_name != NULL); nih_assert (name != NULL); nih_assert (oom_error_code != NULL); nih_assert (inputs != NULL); nih_assert (locals != NULL); nih_assert (prefix != NULL); nih_assert (member_symbol != NULL); nih_assert (structs != NULL); dbus_type = dbus_signature_iter_get_current_type (iter); dbus_const = type_const (dbus_type); struct_iter_name = nih_sprintf (NULL, "%s_iter", name); if (! struct_iter_name) return NULL; oom_error_block = nih_strdup (NULL, oom_error_code); if (! oom_error_block) return NULL; if (! indent (&oom_error_block, NULL, 1)) return NULL; child_oom_error_code = nih_sprintf (NULL, ("dbus_message_iter_abandon_container (&%s, &%s);\n" "%s"), iter_name, struct_iter_name, oom_error_code); if (! child_oom_error_code) return NULL; child_oom_error_block = nih_strdup (NULL, child_oom_error_code); if (! child_oom_error_block) return NULL; if (! indent (&child_oom_error_block, NULL, 1)) return NULL; /* Open the struct container, for that we need to know whether this * is a struct or a dictionary entry even though we handle the two * identically. We'll obviously need a local variable for the * recursed iterator. */ dbus_signature_iter_recurse (iter, &subiter); if (! nih_strcat_sprintf (&code, parent, "/* Marshal a structure onto the message */\n" "if (! dbus_message_iter_open_container (&%s, %s, NULL, &%s)) {\n" "%s" "}\n" "\n", iter_name, dbus_const, struct_iter_name, oom_error_block)) return NULL; struct_iter_var = type_var_new (code, "DBusMessageIter", struct_iter_name); if (! struct_iter_var) { nih_free (code); return NULL; } nih_list_add (locals, &struct_iter_var->entry); /* FIXME there should be a way to override this to a different type * name by annotation. */ c_type = symbol_typedef (NULL, prefix, interface_symbol, NULL, member_symbol, symbol); if (! c_type) { nih_free (code); return NULL; } structure = type_struct_new (code, c_type); if (! structure) { nih_free (code); return NULL; } nih_list_add (structs, &structure->entry); if (! type_to_pointer (&c_type, NULL)) { nih_free (code); return NULL; } /* Deal with each structure element individually, however we have * to end up with just one set of locals and one block so we * append directly onto our locals. */ do { nih_local char *item_member = NULL; nih_local char *item_name = NULL; nih_local char *item_symbol = NULL; NihList item_inputs; NihList item_locals; NihList item_structs; nih_local char *item_code = NULL; /* FIXME there should be a way to override the item names * via an annotation, which would also show up in the * structure definition itself. */ item_member = nih_sprintf (NULL, "item%zu", count); if (! item_member) { nih_free (code); return NULL; } item_name = nih_sprintf (NULL, "%s_%s", name, item_member); if (! item_name) { nih_free (code); return NULL; } item_symbol = (symbol ? nih_sprintf (NULL, "%s_%s", symbol, item_member) : nih_strdup (NULL, item_member)); if (! item_symbol) { nih_free (code); return NULL; } /* Get the code to do the marshalling of this item */ nih_list_init (&item_inputs); nih_list_init (&item_locals); nih_list_init (&item_structs); item_code = marshal (NULL, &subiter, struct_iter_name, item_name, child_oom_error_code, &item_inputs, &item_locals, prefix, interface_symbol, member_symbol, item_symbol, structs); if (! item_code) { nih_free (code); return NULL; } /* Append the item locals onto our locals list, we have * to reference these as we go. */ NIH_LIST_FOREACH_SAFE (&item_locals, iter) { TypeVar *local_var = (TypeVar *)iter; nih_list_add (locals, &local_var->entry); nih_ref (local_var, code); } /* Instead of mucking around with pointers and structure * members, each of the marshalling code inputs is appended * onto the local list (and made const) and we copy the * value from the array into this variable. */ NIH_LIST_FOREACH_SAFE (&item_inputs, iter) { TypeVar * input_var = (TypeVar *)iter; char * suffix; nih_local char *member_name = NULL; TypeVar * member_var; nih_assert (! strncmp (input_var->name, item_name, strlen (item_name))); suffix = input_var->name + strlen (item_name); /* Create the structure member entry */ member_name = nih_sprintf (NULL, "%s%s", item_member, suffix); if (! member_name) { nih_free (code); return NULL; } member_var = type_var_new (structure, input_var->type, member_name); if (! member_var) { nih_free (code); return NULL; } nih_list_add (&structure->members, &member_var->entry); /* Add code to copy into local variable */ if (! nih_strcat_sprintf (&code, parent, "%s = %s->%s;\n", input_var->name, name, member_name)) { nih_free (code); return NULL; } /* Make the input variable const and add to locals */ if (! type_to_const (&input_var->type, input_var)) { nih_free (code); return NULL; } nih_list_add (locals, &input_var->entry); nih_ref (input_var, code); } NIH_LIST_FOREACH_SAFE (&item_structs, iter) { TypeStruct *structure = (TypeStruct *)iter; nih_ref (structure, code); nih_list_add (structs, &structure->entry); } /* Append item marshalling code block */ if (! nih_strcat_sprintf (&code, parent, "\n" "%s" "\n", item_code)) { nih_free (code); return NULL; } nih_assert (++count > 0); } while (dbus_signature_iter_next (&subiter)); /* Close the container again */ if (! nih_strcat_sprintf (&code, parent, "if (! dbus_message_iter_close_container (&%s, &%s)) {\n" "%s" "}\n", iter_name, struct_iter_name, oom_error_block)) { nih_free (code); return NULL; } /* Append our required input variable */ var = type_var_new (code, c_type, name); if (! var) { nih_free (code); return NULL; } nih_list_add (inputs, &var->entry); return code; } libnih-1.0.3/nih-dbus-tool/type.h0000644000175000017500000001055111445765555013542 00000000000000/* nih-dbus-tool * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_TOOL_TYPE_H #define NIH_DBUS_TOOL_TYPE_H #include #include #include /** * TypeVar: * @entry: list entry, * @type: C type, * @name: variable name, * @array: TRUE of the variable is an array. * * This structure represents a C variable declaration, containing both * the type and name of the variable. They are returned by the marshal() * and demarshal() functions via the locals list. **/ typedef struct type_var { NihList entry; char * type; char * name; int array; } TypeVar; /** * TypeFunc: * @entry: list entry, * @type: C function return type, * @name: function name, * @args: function arguments, * @attribs: attributes. * * This structure represents a C function definition or prototype, * containing its return type, name, arguments and any function attributes * for compiler hints. They are returned by the various function * generators via the prototypes or externs lists. * * @args is a list of TypeVar entries, @attribs is a list of NihListEntry * entries with strings as the data pointer. **/ typedef struct type_func { NihList entry; char * type; char * name; NihList args; NihList attribs; } TypeFunc; /** * TypeStruct: * @entry: list entry, * @name: structure name, * @members: structure members. * * This structure represents a C structure definition, defined as a * typedef called @name with an actual structure name converted from * that. * * @members is a list of TypeVar entries. **/ typedef struct type_struct { NihList entry; char * name; NihList members; } TypeStruct; NIH_BEGIN_EXTERN const char *type_const (int dbus_type); const char *type_basic_type (int dbus_type); char * type_of (const void * parent, DBusSignatureIter *iter) __attribute__ ((warn_unused_result, malloc)); TypeVar * type_var_new (const void *parent, const char *type, const char *name) __attribute__ ((warn_unused_result, malloc)); char * type_var_to_string (const void *parent, TypeVar *var) __attribute__ ((warn_unused_result, malloc)); char * type_var_layout (const void *parent, NihList *vars) __attribute__ ((warn_unused_result, malloc)); TypeFunc * type_func_new (const void *parent, const char *type, const char *name) __attribute__ ((warn_unused_result, malloc)); char * type_func_to_string (const void *parent, TypeFunc *func) __attribute__ ((warn_unused_result, malloc)); char * type_func_to_typedef (const void *parent, TypeFunc *func) __attribute__ ((warn_unused_result, malloc)); char * type_func_layout (const void *parent, NihList *funcs) __attribute__ ((warn_unused_result, malloc)); TypeStruct *type_struct_new (const void *parent, const char *name) __attribute__ ((warn_unused_result, malloc)); char * type_struct_to_string (const void *parent, TypeStruct *structure) __attribute__ ((warn_unused_result, malloc)); char * type_to_const (char **type, const void *parent) __attribute__ ((warn_unused_result, malloc)); char * type_to_pointer (char **type, const void *parent) __attribute__ ((warn_unused_result, malloc)); char * type_to_static (char **type, const void *parent) __attribute__ ((warn_unused_result, malloc)); char * type_to_extern (char **type, const void *parent) __attribute__ ((warn_unused_result, malloc)); char * type_strcat_assert (char **block, const void *parent, TypeVar *var, TypeVar *prev, TypeVar *next) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_TOOL_TYPE_H */ libnih-1.0.3/nih-dbus-tool/indent.c0000644000175000017500000000772111445765555014042 00000000000000/* nih-dbus-tool * * indent.c - indentation and other code-style string changes * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include "indent.h" /** * indent: * @str: pointer to string to be indented, * @parent: parent object of returned string, * @level: number of indents to add. * * Indents the given string @str with @level tab characters preceding * each non-empty line, including the last even if that has no terminating * newline. * * @str is modified directly, the returned string is simply a pointer to * it, thus @parent is actually ignored though it usual to pass the parent * of @str for style reasons. * * Returns: modified @str or NULL if insufficient memory. **/ char * indent (char ** str, const void *parent, int level) { char * s; char * ret; size_t len; nih_assert (str != NULL); nih_assert (*str != NULL); nih_assert (level > 0); /* First figure out how many tab characters we have to insert */ len = strlen (*str); if (**str != '\n') len += level; for (s = *str; *s; s++) if ((*s == '\n') && (s[1] != '\0') && (s[1] != '\n')) len += level; /* Increase the length of the string to fit */ ret = nih_realloc (*str, parent, len + 1); if (! ret) return NULL; /* Now put the tab characters in */ *str = ret; if (**str != '\n') { memmove (*str + level, *str, len + 1 - level); memset (*str, '\t', level); } for (s = *str; *s; s++) { if ((*s == '\n') && (s[1] != '\0') && (s[1] != '\n')) { memmove (s + level + 1, s + 1, *str + len + 1 - level - s - 1); memset (s + 1, '\t', level); } } return *str; } /** * comment: * @str: pointer to string to be commented, * @parent: parent object of returned string. * * Applies commenting to the given @str, prefixing " * " onto each line * including the first and last. * * @str is modified directly, the returned string is simply a pointer to * it, thus @parent is actually ignored though it usual to pass the parent * of @str for style reasons. * * Returns: modified @str or NULL if insufficient memory. **/ char * comment (char ** str, const void *parent) { char * s; char * ret; size_t len; nih_assert (str != NULL); nih_assert (*str != NULL); /* First figure out how many characters we have to insert */ len = strlen (*str); if (**str == '\n') { len += 2; } else { len += 3; } for (s = *str; *s; s++) { if ((*s == '\n') && (s[1] != '\0')) { if (s[1] == '\n') { len += 2; } else { len += 3; } } } /* Increase the length of the string to fit */ ret = nih_realloc (*str, parent, len + 1); if (! ret) return NULL; /* Now put the comment characters in */ *str = ret; if (**str == '\n') { memmove (*str + 2, *str, len + 1 - 2); memcpy (*str, " *", 2); } else { memmove (*str + 3, *str, len + 1 - 3); memcpy (*str, " * ", 3); } for (s = *str; *s; s++) { if ((*s == '\n') && (s[1] != '\0')) { if (s[1] == '\n') { memmove (s + 2 + 1, s + 1, *str + len + 1 - 2 - s - 1); memcpy (s + 1, " *", 2); } else { memmove (s + 3 + 1, s + 1, *str + len + 1 - 3 - s - 1); memcpy (s + 1, " * ", 3); } } } return *str; } libnih-1.0.3/po/0000755000175000017500000000000011504742363010404 500000000000000libnih-1.0.3/po/remove-potcdate.sin0000644000175000017500000000066011461165271014136 00000000000000# Sed script that remove the POT-Creation-Date line in the header entry # from a POT file. # # The distinction between the first and the following occurrences of the # pattern is achieved by looking at the hold space. /^"POT-Creation-Date: .*"$/{ x # Test if the hold space is empty. s/P/P/ ta # Yes it was empty. First occurrence. Remove the line. g d bb :a # The hold space was nonempty. Following occurrences. Do nothing. x :b } libnih-1.0.3/po/boldquot.sed0000644000175000017500000000033111461165270012645 00000000000000s/"\([^"]*\)"/“\1”/g s/`\([^`']*\)'/‘\1’/g s/ '\([^`']*\)' / ‘\1’ /g s/ '\([^`']*\)'$/ ‘\1’/g s/^'\([^`']*\)' /‘\1’ /g s/“”/""/g s/“/“/g s/”/”/g s/‘/‘/g s/’/’/g libnih-1.0.3/po/en@boldquot.header0000644000175000017500000000247111461165271013755 00000000000000# All this catalog "translates" are quotation characters. # The msgids must be ASCII and therefore cannot contain real quotation # characters, only substitutes like grave accent (0x60), apostrophe (0x27) # and double quote (0x22). These substitutes look strange; see # http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html # # This catalog translates grave accent (0x60) and apostrophe (0x27) to # left single quotation mark (U+2018) and right single quotation mark (U+2019). # It also translates pairs of apostrophe (0x27) to # left single quotation mark (U+2018) and right single quotation mark (U+2019) # and pairs of quotation mark (0x22) to # left double quotation mark (U+201C) and right double quotation mark (U+201D). # # When output to an UTF-8 terminal, the quotation characters appear perfectly. # When output to an ISO-8859-1 terminal, the single quotation marks are # transliterated to apostrophes (by iconv in glibc 2.2 or newer) or to # grave/acute accent (by libiconv), and the double quotation marks are # transliterated to 0x22. # When output to an ASCII terminal, the single quotation marks are # transliterated to apostrophes, and the double quotation marks are # transliterated to 0x22. # # This catalog furthermore displays the text between the quotation marks in # bold face, assuming the VT100/XTerm escape sequences. # libnih-1.0.3/po/en@quot.header0000644000175000017500000000226311461165271013113 00000000000000# All this catalog "translates" are quotation characters. # The msgids must be ASCII and therefore cannot contain real quotation # characters, only substitutes like grave accent (0x60), apostrophe (0x27) # and double quote (0x22). These substitutes look strange; see # http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html # # This catalog translates grave accent (0x60) and apostrophe (0x27) to # left single quotation mark (U+2018) and right single quotation mark (U+2019). # It also translates pairs of apostrophe (0x27) to # left single quotation mark (U+2018) and right single quotation mark (U+2019) # and pairs of quotation mark (0x22) to # left double quotation mark (U+201C) and right double quotation mark (U+201D). # # When output to an UTF-8 terminal, the quotation characters appear perfectly. # When output to an ISO-8859-1 terminal, the single quotation marks are # transliterated to apostrophes (by iconv in glibc 2.2 or newer) or to # grave/acute accent (by libiconv), and the double quotation marks are # transliterated to 0x22. # When output to an ASCII terminal, the single quotation marks are # transliterated to apostrophes, and the double quotation marks are # transliterated to 0x22. # libnih-1.0.3/po/insert-header.sin0000644000175000017500000000124011461165271013565 00000000000000# Sed script that inserts the file called HEADER before the header entry. # # At each occurrence of a line starting with "msgid ", we execute the following # commands. At the first occurrence, insert the file. At the following # occurrences, do nothing. The distinction between the first and the following # occurrences is achieved by looking at the hold space. /^msgid /{ x # Test if the hold space is empty. s/m/m/ ta # Yes it was empty. First occurrence. Read the file. r HEADER # Output the file's contents by reading the next line. But don't lose the # current line while doing this. g N bb :a # The hold space was nonempty. Following occurrences. Do nothing. x :b } libnih-1.0.3/po/POTFILES.in0000644000175000017500000000151311445765555012115 00000000000000# List of source files which contain translatable strings. nih/alloc.c nih/child.c nih/command.c nih/config.c nih/error.c nih/file.c nih/hash.c nih/io.c nih/list.c nih/logging.c nih/main.c nih/option.c nih/signal.c nih/string.c nih/timer.c nih/tree.c nih/watch.c nih/errors.h nih-dbus/dbus_connection.c nih-dbus/dbus_error.c nih-dbus/dbus_message.c nih-dbus/dbus_object.c nih-dbus/dbus_pending_data.c nih-dbus/dbus_proxy.c nih-dbus/dbus_util.c nih-dbus/errors.h nih-dbus-tool/annotation.c nih-dbus-tool/argument.c nih-dbus-tool/demarshal.c nih-dbus-tool/indent.c nih-dbus-tool/interface.c nih-dbus-tool/main.c nih-dbus-tool/marshal.c nih-dbus-tool/method.c nih-dbus-tool/node.c nih-dbus-tool/output.c nih-dbus-tool/parse.c nih-dbus-tool/property.c nih-dbus-tool/signal.c nih-dbus-tool/symbol.c nih-dbus-tool/type.c nih-dbus-tool/errors.h libnih-1.0.3/po/LINGUAS0000644000175000017500000000032611445765555011366 00000000000000# This file contains the list of available translations. # # Each should be prefixed with the English name for the language and # the current maintainer's name in their preferred form and contact # e-mail address. libnih-1.0.3/po/ChangeLog0000644000175000017500000000326711445765555012122 000000000000002009-08-11 Scott James Remnant * libnih.pot: Distribute the pot file 2009-06-17 Scott James Remnant * POTFILES.in: Add nih-dbus/dbus_pending_data.c and nih-dbus-tool * POTFILES.in: Drop the auto-generated test output 2009-06-10 Scott James Remnant * POTFILES.in: Add the proxy output too. 2009-01-29 Scott James Remnant * POTFILES.in: Update for new libnih-dbus path 2008-06-11 Scott James Remnant * POTFILES.in: Add the generated test D-Bus object code, more to test the build system than anything else. 2008-04-29 Scott James Remnant * POTFILES.in: Add dbus.c 2007-03-09 Scott James Remnant * POTFILES.in: Add tree.c 2007-02-05 Scott James Remnant * POTFILES.in: Add watch.c 2007-01-06 Scott James Remnant * POTFILES.in: Add config.c * POTFILES.in: Add command.c 2006-08-24 Scott James Remnant * POTFILES.in: Add file.c 2006-08-19 Scott James Remnant * POTFILES.in: option.c has translatable strings 2006-08-18 Scott James Remnant * POTFILES.in: errors.h can have translatable strings. * POTFILES.in: Add the list of current source files. 2005-08-21 Scott James Remnant * LINGUAS: Created file to hold language list once we have some translations. * POTFILES.in: Created file to hold list of source files which contain translations. * Makevars: Created file from Makevars.template and filled in fields. * ChangeLog: Initial gettext infrastructure from gettext 0.14.5. libnih-1.0.3/po/stamp-po0000644000175000017500000000001211504742363012000 00000000000000timestamp libnih-1.0.3/po/Makefile.in.in0000644000175000017500000003552411461165270013005 00000000000000# Makefile for PO directory in any package using GNU gettext. # Copyright (C) 1995-1997, 2000-2007 by Ulrich Drepper # # This file can be copied and used freely without restrictions. It can # be used in projects which are not available under the GNU General Public # License but which still want to provide support for the GNU gettext # functionality. # Please note that the actual code of GNU gettext is covered by the GNU # General Public License and is *not* in the public domain. # # Origin: gettext-0.17 GETTEXT_MACRO_VERSION = 0.17 PACKAGE = @PACKAGE@ VERSION = @VERSION@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ SHELL = /bin/sh @SET_MAKE@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ VPATH = @srcdir@ prefix = @prefix@ exec_prefix = @exec_prefix@ datarootdir = @datarootdir@ datadir = @datadir@ localedir = @localedir@ gettextsrcdir = $(datadir)/gettext/po INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ # We use $(mkdir_p). # In automake <= 1.9.x, $(mkdir_p) is defined either as "mkdir -p --" or as # "$(mkinstalldirs)" or as "$(install_sh) -d". For these automake versions, # @install_sh@ does not start with $(SHELL), so we add it. # In automake >= 1.10, @mkdir_p@ is derived from ${MKDIR_P}, which is defined # either as "/path/to/mkdir -p" or ".../install-sh -c -d". For these automake # versions, $(mkinstalldirs) and $(install_sh) are unused. mkinstalldirs = $(SHELL) @install_sh@ -d install_sh = $(SHELL) @install_sh@ MKDIR_P = @MKDIR_P@ mkdir_p = @mkdir_p@ GMSGFMT_ = @GMSGFMT@ GMSGFMT_no = @GMSGFMT@ GMSGFMT_yes = @GMSGFMT_015@ GMSGFMT = $(GMSGFMT_$(USE_MSGCTXT)) MSGFMT_ = @MSGFMT@ MSGFMT_no = @MSGFMT@ MSGFMT_yes = @MSGFMT_015@ MSGFMT = $(MSGFMT_$(USE_MSGCTXT)) XGETTEXT_ = @XGETTEXT@ XGETTEXT_no = @XGETTEXT@ XGETTEXT_yes = @XGETTEXT_015@ XGETTEXT = $(XGETTEXT_$(USE_MSGCTXT)) MSGMERGE = msgmerge MSGMERGE_UPDATE = @MSGMERGE@ --update MSGINIT = msginit MSGCONV = msgconv MSGFILTER = msgfilter POFILES = @POFILES@ GMOFILES = @GMOFILES@ UPDATEPOFILES = @UPDATEPOFILES@ DUMMYPOFILES = @DUMMYPOFILES@ DISTFILES.common = Makefile.in.in remove-potcdate.sin \ $(DISTFILES.common.extra1) $(DISTFILES.common.extra2) $(DISTFILES.common.extra3) DISTFILES = $(DISTFILES.common) Makevars POTFILES.in \ $(POFILES) $(GMOFILES) \ $(DISTFILES.extra1) $(DISTFILES.extra2) $(DISTFILES.extra3) POTFILES = \ CATALOGS = @CATALOGS@ # Makevars gets inserted here. (Don't remove this line!) .SUFFIXES: .SUFFIXES: .po .gmo .mo .sed .sin .nop .po-create .po-update .po.mo: @echo "$(MSGFMT) -c -o $@ $<"; \ $(MSGFMT) -c -o t-$@ $< && mv t-$@ $@ .po.gmo: @lang=`echo $* | sed -e 's,.*/,,'`; \ test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \ echo "$${cdcmd}rm -f $${lang}.gmo && $(GMSGFMT) -c --statistics -o $${lang}.gmo $${lang}.po"; \ cd $(srcdir) && rm -f $${lang}.gmo && $(GMSGFMT) -c --statistics -o t-$${lang}.gmo $${lang}.po && mv t-$${lang}.gmo $${lang}.gmo .sin.sed: sed -e '/^#/d' $< > t-$@ mv t-$@ $@ all: check-macro-version all-@USE_NLS@ all-yes: stamp-po all-no: # Ensure that the gettext macros and this Makefile.in.in are in sync. check-macro-version: @test "$(GETTEXT_MACRO_VERSION)" = "@GETTEXT_MACRO_VERSION@" \ || { echo "*** error: gettext infrastructure mismatch: using a Makefile.in.in from gettext version $(GETTEXT_MACRO_VERSION) but the autoconf macros are from gettext version @GETTEXT_MACRO_VERSION@" 1>&2; \ exit 1; \ } # $(srcdir)/$(DOMAIN).pot is only created when needed. When xgettext finds no # internationalized messages, no $(srcdir)/$(DOMAIN).pot is created (because # we don't want to bother translators with empty POT files). We assume that # LINGUAS is empty in this case, i.e. $(POFILES) and $(GMOFILES) are empty. # In this case, stamp-po is a nop (i.e. a phony target). # stamp-po is a timestamp denoting the last time at which the CATALOGS have # been loosely updated. Its purpose is that when a developer or translator # checks out the package via CVS, and the $(DOMAIN).pot file is not in CVS, # "make" will update the $(DOMAIN).pot and the $(CATALOGS), but subsequent # invocations of "make" will do nothing. This timestamp would not be necessary # if updating the $(CATALOGS) would always touch them; however, the rule for # $(POFILES) has been designed to not touch files that don't need to be # changed. stamp-po: $(srcdir)/$(DOMAIN).pot test ! -f $(srcdir)/$(DOMAIN).pot || \ test -z "$(GMOFILES)" || $(MAKE) $(GMOFILES) @test ! -f $(srcdir)/$(DOMAIN).pot || { \ echo "touch stamp-po" && \ echo timestamp > stamp-poT && \ mv stamp-poT stamp-po; \ } # Note: Target 'all' must not depend on target '$(DOMAIN).pot-update', # otherwise packages like GCC can not be built if only parts of the source # have been downloaded. # This target rebuilds $(DOMAIN).pot; it is an expensive operation. # Note that $(DOMAIN).pot is not touched if it doesn't need to be changed. $(DOMAIN).pot-update: $(POTFILES) $(srcdir)/POTFILES.in remove-potcdate.sed if LC_ALL=C grep 'GNU @PACKAGE@' $(top_srcdir)/* 2>/dev/null | grep -v 'libtool:' >/dev/null; then \ package_gnu='GNU '; \ else \ package_gnu=''; \ fi; \ if test -n '$(MSGID_BUGS_ADDRESS)' || test '$(PACKAGE_BUGREPORT)' = '@'PACKAGE_BUGREPORT'@'; then \ msgid_bugs_address='$(MSGID_BUGS_ADDRESS)'; \ else \ msgid_bugs_address='$(PACKAGE_BUGREPORT)'; \ fi; \ case `$(XGETTEXT) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \ '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].* | 0.16 | 0.16.[0-1]*) \ $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \ --add-comments=TRANSLATORS: $(XGETTEXT_OPTIONS) @XGETTEXT_EXTRA_OPTIONS@ \ --files-from=$(srcdir)/POTFILES.in \ --copyright-holder='$(COPYRIGHT_HOLDER)' \ --msgid-bugs-address="$$msgid_bugs_address" \ ;; \ *) \ $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \ --add-comments=TRANSLATORS: $(XGETTEXT_OPTIONS) @XGETTEXT_EXTRA_OPTIONS@ \ --files-from=$(srcdir)/POTFILES.in \ --copyright-holder='$(COPYRIGHT_HOLDER)' \ --package-name="$${package_gnu}@PACKAGE@" \ --package-version='@VERSION@' \ --msgid-bugs-address="$$msgid_bugs_address" \ ;; \ esac test ! -f $(DOMAIN).po || { \ if test -f $(srcdir)/$(DOMAIN).pot; then \ sed -f remove-potcdate.sed < $(srcdir)/$(DOMAIN).pot > $(DOMAIN).1po && \ sed -f remove-potcdate.sed < $(DOMAIN).po > $(DOMAIN).2po && \ if cmp $(DOMAIN).1po $(DOMAIN).2po >/dev/null 2>&1; then \ rm -f $(DOMAIN).1po $(DOMAIN).2po $(DOMAIN).po; \ else \ rm -f $(DOMAIN).1po $(DOMAIN).2po $(srcdir)/$(DOMAIN).pot && \ mv $(DOMAIN).po $(srcdir)/$(DOMAIN).pot; \ fi; \ else \ mv $(DOMAIN).po $(srcdir)/$(DOMAIN).pot; \ fi; \ } # This rule has no dependencies: we don't need to update $(DOMAIN).pot at # every "make" invocation, only create it when it is missing. # Only "make $(DOMAIN).pot-update" or "make dist" will force an update. $(srcdir)/$(DOMAIN).pot: $(MAKE) $(DOMAIN).pot-update # This target rebuilds a PO file if $(DOMAIN).pot has changed. # Note that a PO file is not touched if it doesn't need to be changed. $(POFILES): $(srcdir)/$(DOMAIN).pot @lang=`echo $@ | sed -e 's,.*/,,' -e 's/\.po$$//'`; \ if test -f "$(srcdir)/$${lang}.po"; then \ test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \ echo "$${cdcmd}$(MSGMERGE_UPDATE) $${lang}.po $(DOMAIN).pot"; \ cd $(srcdir) && $(MSGMERGE_UPDATE) $${lang}.po $(DOMAIN).pot; \ else \ $(MAKE) $${lang}.po-create; \ fi install: install-exec install-data install-exec: install-data: install-data-@USE_NLS@ if test "$(PACKAGE)" = "gettext-tools"; then \ $(mkdir_p) $(DESTDIR)$(gettextsrcdir); \ for file in $(DISTFILES.common) Makevars.template; do \ $(INSTALL_DATA) $(srcdir)/$$file \ $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ for file in Makevars; do \ rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ else \ : ; \ fi install-data-no: all install-data-yes: all $(mkdir_p) $(DESTDIR)$(datadir) @catalogs='$(CATALOGS)'; \ for cat in $$catalogs; do \ cat=`basename $$cat`; \ lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \ dir=$(localedir)/$$lang/LC_MESSAGES; \ $(mkdir_p) $(DESTDIR)$$dir; \ if test -r $$cat; then realcat=$$cat; else realcat=$(srcdir)/$$cat; fi; \ $(INSTALL_DATA) $$realcat $(DESTDIR)$$dir/$(DOMAIN).mo; \ echo "installing $$realcat as $(DESTDIR)$$dir/$(DOMAIN).mo"; \ for lc in '' $(EXTRA_LOCALE_CATEGORIES); do \ if test -n "$$lc"; then \ if (cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc 2>/dev/null) | grep ' -> ' >/dev/null; then \ link=`cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc | sed -e 's/^.* -> //'`; \ mv $(DESTDIR)$(localedir)/$$lang/$$lc $(DESTDIR)$(localedir)/$$lang/$$lc.old; \ mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \ (cd $(DESTDIR)$(localedir)/$$lang/$$lc.old && \ for file in *; do \ if test -f $$file; then \ ln -s ../$$link/$$file $(DESTDIR)$(localedir)/$$lang/$$lc/$$file; \ fi; \ done); \ rm -f $(DESTDIR)$(localedir)/$$lang/$$lc.old; \ else \ if test -d $(DESTDIR)$(localedir)/$$lang/$$lc; then \ :; \ else \ rm -f $(DESTDIR)$(localedir)/$$lang/$$lc; \ mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \ fi; \ fi; \ rm -f $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \ ln -s ../LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo 2>/dev/null || \ ln $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo 2>/dev/null || \ cp -p $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \ echo "installing $$realcat link as $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo"; \ fi; \ done; \ done install-strip: install installdirs: installdirs-exec installdirs-data installdirs-exec: installdirs-data: installdirs-data-@USE_NLS@ if test "$(PACKAGE)" = "gettext-tools"; then \ $(mkdir_p) $(DESTDIR)$(gettextsrcdir); \ else \ : ; \ fi installdirs-data-no: installdirs-data-yes: $(mkdir_p) $(DESTDIR)$(datadir) @catalogs='$(CATALOGS)'; \ for cat in $$catalogs; do \ cat=`basename $$cat`; \ lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \ dir=$(localedir)/$$lang/LC_MESSAGES; \ $(mkdir_p) $(DESTDIR)$$dir; \ for lc in '' $(EXTRA_LOCALE_CATEGORIES); do \ if test -n "$$lc"; then \ if (cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc 2>/dev/null) | grep ' -> ' >/dev/null; then \ link=`cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc | sed -e 's/^.* -> //'`; \ mv $(DESTDIR)$(localedir)/$$lang/$$lc $(DESTDIR)$(localedir)/$$lang/$$lc.old; \ mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \ (cd $(DESTDIR)$(localedir)/$$lang/$$lc.old && \ for file in *; do \ if test -f $$file; then \ ln -s ../$$link/$$file $(DESTDIR)$(localedir)/$$lang/$$lc/$$file; \ fi; \ done); \ rm -f $(DESTDIR)$(localedir)/$$lang/$$lc.old; \ else \ if test -d $(DESTDIR)$(localedir)/$$lang/$$lc; then \ :; \ else \ rm -f $(DESTDIR)$(localedir)/$$lang/$$lc; \ mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \ fi; \ fi; \ fi; \ done; \ done # Define this as empty until I found a useful application. installcheck: uninstall: uninstall-exec uninstall-data uninstall-exec: uninstall-data: uninstall-data-@USE_NLS@ if test "$(PACKAGE)" = "gettext-tools"; then \ for file in $(DISTFILES.common) Makevars.template; do \ rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ else \ : ; \ fi uninstall-data-no: uninstall-data-yes: catalogs='$(CATALOGS)'; \ for cat in $$catalogs; do \ cat=`basename $$cat`; \ lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \ for lc in LC_MESSAGES $(EXTRA_LOCALE_CATEGORIES); do \ rm -f $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \ done; \ done check: all info dvi ps pdf html tags TAGS ctags CTAGS ID: mostlyclean: rm -f remove-potcdate.sed rm -f stamp-poT rm -f core core.* $(DOMAIN).po $(DOMAIN).1po $(DOMAIN).2po *.new.po rm -fr *.o clean: mostlyclean distclean: clean rm -f Makefile Makefile.in POTFILES *.mo maintainer-clean: distclean @echo "This command is intended for maintainers to use;" @echo "it deletes files that may require special tools to rebuild." rm -f stamp-po $(GMOFILES) distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) dist distdir: $(MAKE) update-po @$(MAKE) dist2 # This is a separate target because 'update-po' must be executed before. dist2: stamp-po $(DISTFILES) dists="$(DISTFILES)"; \ if test "$(PACKAGE)" = "gettext-tools"; then \ dists="$$dists Makevars.template"; \ fi; \ if test -f $(srcdir)/$(DOMAIN).pot; then \ dists="$$dists $(DOMAIN).pot stamp-po"; \ fi; \ if test -f $(srcdir)/ChangeLog; then \ dists="$$dists ChangeLog"; \ fi; \ for i in 0 1 2 3 4 5 6 7 8 9; do \ if test -f $(srcdir)/ChangeLog.$$i; then \ dists="$$dists ChangeLog.$$i"; \ fi; \ done; \ if test -f $(srcdir)/LINGUAS; then dists="$$dists LINGUAS"; fi; \ for file in $$dists; do \ if test -f $$file; then \ cp -p $$file $(distdir) || exit 1; \ else \ cp -p $(srcdir)/$$file $(distdir) || exit 1; \ fi; \ done update-po: Makefile $(MAKE) $(DOMAIN).pot-update test -z "$(UPDATEPOFILES)" || $(MAKE) $(UPDATEPOFILES) $(MAKE) update-gmo # General rule for creating PO files. .nop.po-create: @lang=`echo $@ | sed -e 's/\.po-create$$//'`; \ echo "File $$lang.po does not exist. If you are a translator, you can create it through 'msginit'." 1>&2; \ exit 1 # General rule for updating PO files. .nop.po-update: @lang=`echo $@ | sed -e 's/\.po-update$$//'`; \ if test "$(PACKAGE)" = "gettext-tools"; then PATH=`pwd`/../src:$$PATH; fi; \ tmpdir=`pwd`; \ echo "$$lang:"; \ test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \ echo "$${cdcmd}$(MSGMERGE) $$lang.po $(DOMAIN).pot -o $$lang.new.po"; \ cd $(srcdir); \ if $(MSGMERGE) $$lang.po $(DOMAIN).pot -o $$tmpdir/$$lang.new.po; then \ if cmp $$lang.po $$tmpdir/$$lang.new.po >/dev/null 2>&1; then \ rm -f $$tmpdir/$$lang.new.po; \ else \ if mv -f $$tmpdir/$$lang.new.po $$lang.po; then \ :; \ else \ echo "msgmerge for $$lang.po failed: cannot move $$tmpdir/$$lang.new.po to $$lang.po" 1>&2; \ exit 1; \ fi; \ fi; \ else \ echo "msgmerge for $$lang.po failed!" 1>&2; \ rm -f $$tmpdir/$$lang.new.po; \ fi $(DUMMYPOFILES): update-gmo: Makefile $(GMOFILES) @: Makefile: Makefile.in.in Makevars $(top_builddir)/config.status @POMAKEFILEDEPS@ cd $(top_builddir) \ && $(SHELL) ./config.status $(subdir)/$@.in po-directories force: # Tell versions [3.59,3.63) of GNU make not to export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: libnih-1.0.3/po/quot.sed0000644000175000017500000000023111461165271012004 00000000000000s/"\([^"]*\)"/“\1”/g s/`\([^`']*\)'/‘\1’/g s/ '\([^`']*\)' / ‘\1’ /g s/ '\([^`']*\)'$/ ‘\1’/g s/^'\([^`']*\)' /‘\1’ /g s/“”/""/g libnih-1.0.3/po/Makevars0000644000175000017500000000346111445765555012040 00000000000000# Makefile variables for PO directory in any package using GNU gettext. # Usually the message domain is the same as the package name. DOMAIN = $(PACKAGE) # These two variables depend on the location of this directory. subdir = po top_builddir = .. # These options get passed to xgettext. XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ # This is the copyright holder that gets inserted into the header of the # $(DOMAIN).pot file. Set this to the copyright holder of the surrounding # package. (Note that the msgstr strings, extracted from the package's # sources, belong to the copyright holder of the package.) Translators are # expected to transfer the copyright for their translations to this person # or entity, or to disclaim their copyright. The empty string stands for # the public domain; in this case the translators are expected to disclaim # their copyright. COPYRIGHT_HOLDER = Scott James Remnant # This is the email address or URL to which the translators shall report # bugs in the untranslated strings: # - Strings which are not entire sentences, see the maintainer guidelines # in the GNU gettext documentation, section 'Preparing Strings'. # - Strings which use unclear terms or require additional context to be # understood. # - Strings which make invalid assumptions about notation of date, time or # money. # - Pluralisation problems. # - Incorrect English spelling. # - Incorrect formatting. # It can be your email address, or a mailing list address where translators # can write to without being subscribed, or the URL of a web page through # which the translators can contact you. MSGID_BUGS_ADDRESS = libnih-bugs@netsplit.com # This is the list of locale categories, beyond LC_MESSAGES, for which the # message catalogs shall be used. It is usually empty. EXTRA_LOCALE_CATEGORIES = libnih-1.0.3/po/Rules-quot0000644000175000017500000000337611461165270012336 00000000000000# Special Makefile rules for English message catalogs with quotation marks. DISTFILES.common.extra1 = quot.sed boldquot.sed en@quot.header en@boldquot.header insert-header.sin Rules-quot .SUFFIXES: .insert-header .po-update-en en@quot.po-create: $(MAKE) en@quot.po-update en@boldquot.po-create: $(MAKE) en@boldquot.po-update en@quot.po-update: en@quot.po-update-en en@boldquot.po-update: en@boldquot.po-update-en .insert-header.po-update-en: @lang=`echo $@ | sed -e 's/\.po-update-en$$//'`; \ if test "$(PACKAGE)" = "gettext"; then PATH=`pwd`/../src:$$PATH; GETTEXTLIBDIR=`cd $(top_srcdir)/src && pwd`; export GETTEXTLIBDIR; fi; \ tmpdir=`pwd`; \ echo "$$lang:"; \ ll=`echo $$lang | sed -e 's/@.*//'`; \ LC_ALL=C; export LC_ALL; \ cd $(srcdir); \ if $(MSGINIT) -i $(DOMAIN).pot --no-translator -l $$ll -o - 2>/dev/null | sed -f $$tmpdir/$$lang.insert-header | $(MSGCONV) -t UTF-8 | $(MSGFILTER) sed -f `echo $$lang | sed -e 's/.*@//'`.sed 2>/dev/null > $$tmpdir/$$lang.new.po; then \ if cmp $$lang.po $$tmpdir/$$lang.new.po >/dev/null 2>&1; then \ rm -f $$tmpdir/$$lang.new.po; \ else \ if mv -f $$tmpdir/$$lang.new.po $$lang.po; then \ :; \ else \ echo "creation of $$lang.po failed: cannot move $$tmpdir/$$lang.new.po to $$lang.po" 1>&2; \ exit 1; \ fi; \ fi; \ else \ echo "creation of $$lang.po failed!" 1>&2; \ rm -f $$tmpdir/$$lang.new.po; \ fi en@quot.insert-header: insert-header.sin sed -e '/^#/d' -e 's/HEADER/en@quot.header/g' $(srcdir)/insert-header.sin > en@quot.insert-header en@boldquot.insert-header: insert-header.sin sed -e '/^#/d' -e 's/HEADER/en@boldquot.header/g' $(srcdir)/insert-header.sin > en@boldquot.insert-header mostlyclean: mostlyclean-quot mostlyclean-quot: rm -f *.insert-header libnih-1.0.3/po/libnih.pot0000644000175000017500000002622511504742363012324 00000000000000# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR Scott James Remnant # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: libnih 1.0.3\n" "Report-Msgid-Bugs-To: libnih-bugs@netsplit.com\n" "POT-Creation-Date: 2010-12-23 21:53+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: nih/command.c:61 msgid "display list of commands" msgstr "" #: nih/command.c:139 #, c-format msgid "For a list of commands, try `%s help'." msgstr "" #: nih/command.c:143 msgid "COMMAND [OPTION]... [ARG]..." msgstr "" #: nih/command.c:158 #, c-format msgid "%s: missing command\n" msgstr "" #: nih/command.c:166 #, c-format msgid "%s: invalid command: %s\n" msgstr "" #: nih/command.c:177 #, c-format msgid "%s [OPTION]..." msgstr "" #: nih/command.c:403 #, c-format msgid "For more information on a command, try `%s COMMAND --help'.\n" msgstr "" #: nih/command.c:426 #, c-format msgid "%s commands:\n" msgstr "" #: nih/command.c:428 #, c-format msgid "Other commands:\n" msgstr "" #: nih/command.c:430 #, c-format msgid "Commands:\n" msgstr "" #: nih/io.c:1199 msgid "Error while reading from descriptor" msgstr "" #: nih/main.c:233 #, c-format msgid "Try `%s --help' for more information.\n" msgstr "" #: nih/main.c:255 msgid "" "This is free software; see the source for copying conditions. There is NO " "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." msgstr "" #: nih/main.c:318 msgid "Unable to write pid file" msgstr "" #: nih/option.c:95 msgid "reduce output to errors only" msgstr "" #: nih/option.c:98 msgid "increase output to include informational messages" msgstr "" #: nih/option.c:105 msgid "display this help and exit" msgstr "" #: nih/option.c:108 msgid "output version information and exit" msgstr "" #: nih/option.c:302 #, c-format msgid "%s: invalid option: -%c\n" msgstr "" #: nih/option.c:395 #, c-format msgid "%s: invalid option: --%s\n" msgstr "" #: nih/option.c:411 #, c-format msgid "%s: unexpected argument: --%s\n" msgstr "" #: nih/option.c:467 #, c-format msgid "%s: missing argument: %s\n" msgstr "" #: nih/option.c:667 #, c-format msgid "%s: illegal argument: %s\n" msgstr "" #: nih/option.c:860 msgid "Usage" msgstr "" #: nih/option.c:864 msgid "[OPTION]..." msgstr "" #: nih/option.c:912 #, c-format msgid "Report bugs to <%s>\n" msgstr "" #: nih/option.c:914 #, c-format msgid "Report bugs at <%s>\n" msgstr "" #: nih/option.c:939 #, c-format msgid "%s options:\n" msgstr "" #: nih/option.c:941 #, c-format msgid "Other options:\n" msgstr "" #: nih/option.c:943 #, c-format msgid "Options:\n" msgstr "" #: nih/watch.c:550 msgid "Unable to watch directory" msgstr "" #: nih/errors.h:56 msgid "Expected token" msgstr "" #: nih/errors.h:57 msgid "Unexpected token" msgstr "" #: nih/errors.h:58 msgid "Trailing slash in file" msgstr "" #: nih/errors.h:59 msgid "Unterminated quoted string" msgstr "" #: nih/errors.h:60 msgid "Unterminated block" msgstr "" #: nih/errors.h:61 msgid "Unknown stanza" msgstr "" #: nih/errors.h:63 msgid "Directory loop detected" msgstr "" #: nih-dbus/dbus_object.c:311 msgid "Invalid arguments to Introspect method" msgstr "" #: nih-dbus/dbus_object.c:547 msgid "Invalid arguments to Get method" msgstr "" #: nih-dbus/dbus_object.c:632 #, c-format msgid "The %s property is write-only" msgstr "" #: nih-dbus/dbus_object.c:688 msgid "Invalid arguments to GetAll method" msgstr "" #: nih-dbus/dbus_object.c:889 msgid "Invalid arguments to Set method" msgstr "" #: nih-dbus/dbus_object.c:969 #, c-format msgid "The %s property is read-only" msgstr "" #: nih-dbus/errors.h:38 msgid "Invalid arguments received in reply" msgstr "" #: nih-dbus-tool/annotation.c:94 msgid "Ignored unexpected tag" msgstr "" #: nih-dbus-tool/annotation.c:116 msgid "Ignored unknown attribute" msgstr "" #: nih-dbus-tool/annotation.c:159 msgid "Ignored unknown interface annotation" msgstr "" #: nih-dbus-tool/annotation.c:166 msgid "Ignored unknown method annotation" msgstr "" #: nih-dbus-tool/annotation.c:173 msgid "Ignored unknown signal annotation" msgstr "" #: nih-dbus-tool/annotation.c:180 msgid "Ignored unknown property annotation" msgstr "" #: nih-dbus-tool/annotation.c:187 msgid "Ignored unknown argument annotation" msgstr "" #: nih-dbus-tool/argument.c:201 msgid "Ignored unexpected tag" msgstr "" #: nih-dbus-tool/argument.c:225 msgid "Ignored unknown attribute" msgstr "" #: nih-dbus-tool/interface.c:214 msgid "Ignored unexpected tag" msgstr "" #: nih-dbus-tool/interface.c:234 msgid "Ignored unknown attribute" msgstr "" #: nih-dbus-tool/main.c:88 #, c-format msgid "%s: illegal output mode: %s\n" msgstr "" #: nih-dbus-tool/main.c:307 msgid "output mode: object, or proxy [default: proxy]" msgstr "" #: nih-dbus-tool/main.c:309 msgid "prefix for C functions [default: dbus]" msgstr "" #: nih-dbus-tool/main.c:311 msgid "interface name not included in symbols" msgstr "" #: nih-dbus-tool/main.c:313 msgid "write C source to FILENAME, header alongside" msgstr "" #: nih-dbus-tool/main.c:315 msgid "name of software source being created for" msgstr "" #: nih-dbus-tool/main.c:336 msgid "[XMLFILE]" msgstr "" #: nih-dbus-tool/main.c:337 msgid "Generate C bindings for D-Bus objects" msgstr "" #: nih-dbus-tool/main.c:338 msgid "Fill this in later" msgstr "" #: nih-dbus-tool/main.c:353 #, c-format msgid "%s: --output must be specified when using standard input\n" msgstr "" #: nih-dbus-tool/main.c:416 msgid "No such interface" msgstr "" #: nih-dbus-tool/method.c:185 msgid "Ignored unexpected tag" msgstr "" #: nih-dbus-tool/method.c:205 msgid "Ignored unknown attribute" msgstr "" #: nih-dbus-tool/method.c:302 msgid "Ignored NoReply annotation for method with output arguments" msgstr "" #: nih-dbus-tool/method.c:314 msgid "Ignored Async annotation for NoReply method" msgstr "" #: nih-dbus-tool/node.c:185 msgid "Ignored unexpected tag" msgstr "" #: nih-dbus-tool/node.c:206 msgid "Ignored unknown attribute" msgstr "" #: nih-dbus-tool/parse.c:206 msgid "Ignored unknown tag" msgstr "" #: nih-dbus-tool/parse.c:335 msgid "Unable to create XML Parser" msgstr "" #: nih-dbus-tool/parse.c:354 msgid "Unable to allocate parsing buffer" msgstr "" #: nih-dbus-tool/parse.c:362 msgid "Read error" msgstr "" #: nih-dbus-tool/parse.c:384 msgid "XML parse error" msgstr "" #: nih-dbus-tool/parse.c:396 msgid "No node present" msgstr "" #: nih-dbus-tool/property.c:202 msgid "Ignored unexpected tag" msgstr "" #: nih-dbus-tool/property.c:226 msgid "Ignored unknown attribute" msgstr "" #: nih-dbus-tool/signal.c:183 msgid "Ignored unexpected tag" msgstr "" #: nih-dbus-tool/signal.c:203 msgid "Ignored unknown attribute" msgstr "" #: nih-dbus-tool/errors.h:81 msgid "Unable to generate unique name for symbol" msgstr "" #: nih-dbus-tool/errors.h:83 msgid "Invalid object path in name attribute" msgstr "" #: nih-dbus-tool/errors.h:85 msgid " missing required name attribute" msgstr "" #: nih-dbus-tool/errors.h:86 msgid "Invalid interface name in name attribute" msgstr "" #: nih-dbus-tool/errors.h:87 msgid "" "Illegal value for org.freedesktop.DBus.Deprecated interface annotation, " "expected 'true' or 'false'" msgstr "" #: nih-dbus-tool/errors.h:88 msgid "Invalid C symbol for interface" msgstr "" #: nih-dbus-tool/errors.h:89 msgid "Unknown annotation for interface" msgstr "" #: nih-dbus-tool/errors.h:90 #, c-format msgid "Symbol '%s' already assigned to %s interface" msgstr "" #: nih-dbus-tool/errors.h:92 msgid " missing required name attribute" msgstr "" #: nih-dbus-tool/errors.h:93 msgid "Invalid method name in name attribute" msgstr "" #: nih-dbus-tool/errors.h:94 msgid "" "Illegal value for org.freedesktop.DBus.Deprecated method annotation, " "expected 'true' or 'false'" msgstr "" #: nih-dbus-tool/errors.h:95 msgid "" "Illegal value for org.freedesktop.DBus.Method.NoReply method annotation, " "expected 'true' or 'false'" msgstr "" #: nih-dbus-tool/errors.h:96 msgid "Invalid C symbol for method" msgstr "" #: nih-dbus-tool/errors.h:97 msgid "" "Illegal value for com.netsplit.Nih.Method.Async method annotation, expected " "'true' or 'false'" msgstr "" #: nih-dbus-tool/errors.h:98 msgid "Unknown annotation for method" msgstr "" #: nih-dbus-tool/errors.h:99 #, c-format msgid "Symbol '%s' already assigned to %s method" msgstr "" #: nih-dbus-tool/errors.h:101 msgid " missing required name attribute" msgstr "" #: nih-dbus-tool/errors.h:102 msgid "Invalid signal name in name attribute" msgstr "" #: nih-dbus-tool/errors.h:103 msgid "" "Illegal value for org.freedesktop.DBus.Deprecated signal annotation, " "expected 'true' or 'false'" msgstr "" #: nih-dbus-tool/errors.h:104 msgid "Invalid C symbol for signal" msgstr "" #: nih-dbus-tool/errors.h:105 msgid "Unknown annotation for signal" msgstr "" #: nih-dbus-tool/errors.h:106 #, c-format msgid "Symbol '%s' already assigned to %s signal" msgstr "" #: nih-dbus-tool/errors.h:108 msgid " missing required name attribute" msgstr "" #: nih-dbus-tool/errors.h:109 msgid "Invalid property name in name attribute" msgstr "" #: nih-dbus-tool/errors.h:110 msgid " missing required type attribute" msgstr "" #: nih-dbus-tool/errors.h:111 msgid "Invalid D-Bus type in type attribute" msgstr "" #: nih-dbus-tool/errors.h:112 msgid " missing required access attribute" msgstr "" #: nih-dbus-tool/errors.h:113 msgid "" "Illegal value for access attribute, expected 'read', 'write' or " "'readwrite'" msgstr "" #: nih-dbus-tool/errors.h:114 msgid "" "Illegal value for org.freedesktop.DBus.Deprecated property annotation, " "expected 'true' or 'false'" msgstr "" #: nih-dbus-tool/errors.h:115 msgid "Invalid C symbol for property" msgstr "" #: nih-dbus-tool/errors.h:116 msgid "Unknown annotation for property" msgstr "" #: nih-dbus-tool/errors.h:117 #, c-format msgid "Symbol '%s' already assigned to %s property" msgstr "" #: nih-dbus-tool/errors.h:119 msgid "Invalid C symbol for argument" msgstr "" #: nih-dbus-tool/errors.h:120 msgid "Unknown annotation for argument" msgstr "" #: nih-dbus-tool/errors.h:121 msgid "Invalid argument name in name attribute" msgstr "" #: nih-dbus-tool/errors.h:122 msgid " missing required type attribute" msgstr "" #: nih-dbus-tool/errors.h:123 msgid "Invalid D-Bus type in type attribute" msgstr "" #: nih-dbus-tool/errors.h:124 msgid "Illegal value for direction attribute, expected 'in' or 'out'" msgstr "" #: nih-dbus-tool/errors.h:125 msgid "Illegal value for direction attribute, expected 'out'" msgstr "" #: nih-dbus-tool/errors.h:126 #, c-format msgid "Symbol '%s' already assigned to %s argument" msgstr "" #: nih-dbus-tool/errors.h:128 msgid " missing required name attribute" msgstr "" #: nih-dbus-tool/errors.h:129 msgid " missing required value attribute" msgstr "" libnih-1.0.3/Makefile.in0000644000175000017500000006213611503251220011745 00000000000000# Makefile.in generated by automake 1.11.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, # 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, # Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ subdir = . DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in $(srcdir)/config.h.in \ $(top_srcdir)/configure $(top_srcdir)/intl/Makefile.in \ ABOUT-NLS AUTHORS COPYING ChangeLog INSTALL NEWS TODO compile \ config.guess config.rpath config.sub depcomp install-sh \ ltmain.sh missing ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/codeset.m4 \ $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/glibc2.m4 \ $(top_srcdir)/m4/glibc21.m4 $(top_srcdir)/m4/iconv.m4 \ $(top_srcdir)/m4/intdiv0.m4 $(top_srcdir)/m4/intl.m4 \ $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/intmax.m4 \ $(top_srcdir)/m4/inttypes-pri.m4 \ $(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/lcmessage.m4 \ $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libnih.m4 \ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/lock.m4 \ $(top_srcdir)/m4/longlong.m4 $(top_srcdir)/m4/ltoptions.m4 \ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \ $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/m4/po.m4 \ $(top_srcdir)/m4/printf-posix.m4 $(top_srcdir)/m4/progtest.m4 \ $(top_srcdir)/m4/size_max.m4 $(top_srcdir)/m4/stdint_h.m4 \ $(top_srcdir)/m4/uintmax_t.m4 $(top_srcdir)/m4/visibility.m4 \ $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/m4/wint_t.m4 \ $(top_srcdir)/m4/xsize.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d CONFIG_HEADER = config.h CONFIG_CLEAN_FILES = intl/Makefile CONFIG_CLEAN_VPATH_FILES = AM_V_GEN = $(am__v_GEN_$(V)) am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) am__v_GEN_0 = @echo " GEN " $@; AM_V_at = $(am__v_at_$(V)) am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) am__v_at_0 = @ SOURCES = DIST_SOURCES = RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ html-recursive info-recursive install-data-recursive \ install-dvi-recursive install-exec-recursive \ install-html-recursive install-info-recursive \ install-pdf-recursive install-ps-recursive install-recursive \ installcheck-recursive installdirs-recursive pdf-recursive \ ps-recursive uninstall-recursive RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ distclean-recursive maintainer-clean-recursive AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \ distdir dist dist-all distcheck ETAGS = etags CTAGS = ctags DIST_SUBDIRS = $(SUBDIRS) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) am__remove_distdir = \ { test ! -d "$(distdir)" \ || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \ && rm -fr "$(distdir)"; }; } am__relativize = \ dir0=`pwd`; \ sed_first='s,^\([^/]*\)/.*$$,\1,'; \ sed_rest='s,^[^/]*/*,,'; \ sed_last='s,^.*/\([^/]*\)$$,\1,'; \ sed_butlast='s,/*[^/]*$$,,'; \ while test -n "$$dir1"; do \ first=`echo "$$dir1" | sed -e "$$sed_first"`; \ if test "$$first" != "."; then \ if test "$$first" = ".."; then \ dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ else \ first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ if test "$$first2" = "$$first"; then \ dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ else \ dir2="../$$dir2"; \ fi; \ dir0="$$dir0"/"$$first"; \ fi; \ fi; \ dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ done; \ reldir="$$dir2" DIST_ARCHIVES = $(distdir).tar.gz GZIP_ENV = --best distuninstallcheck_listfiles = find . -type f -print distcleancheck_listfiles = find . -type f -print ACLOCAL = @ACLOCAL@ ALLOCA = @ALLOCA@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@ CATOBJEXT = @CATOBJEXT@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CFLAG_VISIBILITY = @CFLAG_VISIBILITY@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DATADIRNAME = @DATADIRNAME@ DBUS_CFLAGS = @DBUS_CFLAGS@ DBUS_LIBS = @DBUS_LIBS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ EXPAT_LIBS = @EXPAT_LIBS@ FGREP = @FGREP@ GENCAT = @GENCAT@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ GLIBC2 = @GLIBC2@ GLIBC21 = @GLIBC21@ GMSGFMT = @GMSGFMT@ GMSGFMT_015 = @GMSGFMT_015@ GREP = @GREP@ HAVE_ASPRINTF = @HAVE_ASPRINTF@ HAVE_POSIX_PRINTF = @HAVE_POSIX_PRINTF@ HAVE_SNPRINTF = @HAVE_SNPRINTF@ HAVE_VISIBILITY = @HAVE_VISIBILITY@ HAVE_WPRINTF = @HAVE_WPRINTF@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INSTOBJEXT = @INSTOBJEXT@ INTLBISON = @INTLBISON@ INTLLIBS = @INTLLIBS@ INTLOBJS = @INTLOBJS@ INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@ INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBMULTITHREAD = @LIBMULTITHREAD@ LIBOBJS = @LIBOBJS@ LIBPTH = @LIBPTH@ LIBPTH_PREFIX = @LIBPTH_PREFIX@ LIBS = @LIBS@ LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBC = @LTLIBC@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ LTLIBMULTITHREAD = @LTLIBMULTITHREAD@ LTLIBOBJS = @LTLIBOBJS@ LTLIBPTH = @LTLIBPTH@ LTLIBTHREAD = @LTLIBTHREAD@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ NIH_DBUS_TOOL = @NIH_DBUS_TOOL@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_COPYRIGHT = @PACKAGE_COPYRIGHT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ POSUB = @POSUB@ PRI_MACROS_BROKEN = @PRI_MACROS_BROKEN@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@ USE_NLS = @USE_NLS@ VERSION = @VERSION@ VERSION_SCRIPT_ARG = @VERSION_SCRIPT_ARG@ WINDRES = @WINDRES@ WOE32 = @WOE32@ WOE32DLL = @WOE32DLL@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ SUBDIRS = m4 intl nih nih-dbus nih-dbus-tool po EXTRA_DIST = HACKING ACLOCAL_AMFLAGS = --install -I m4 all: config.h $(MAKE) $(AM_MAKEFLAGS) all-recursive .SUFFIXES: am--refresh: @: $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ echo ' cd $(srcdir) && $(AUTOMAKE) --gnu'; \ $(am__cd) $(srcdir) && $(AUTOMAKE) --gnu \ && exit 0; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ echo ' $(SHELL) ./config.status'; \ $(SHELL) ./config.status;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \ cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) $(SHELL) ./config.status --recheck $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) $(am__cd) $(srcdir) && $(AUTOCONF) $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) $(am__aclocal_m4_deps): config.h: stamp-h1 @if test ! -f $@; then \ rm -f stamp-h1; \ $(MAKE) $(AM_MAKEFLAGS) stamp-h1; \ else :; fi stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status @rm -f stamp-h1 cd $(top_builddir) && $(SHELL) ./config.status config.h $(srcdir)/config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) rm -f stamp-h1 touch $@ distclean-hdr: -rm -f config.h stamp-h1 intl/Makefile: $(top_builddir)/config.status $(top_srcdir)/intl/Makefile.in cd $(top_builddir) && $(SHELL) ./config.status $@ mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs distclean-libtool: -rm -f libtool config.lt # This directory's subdirectories are mostly independent; you can cd # into them and run `make' without going through this Makefile. # To change the values of `make' variables: instead of editing Makefiles, # (1) if the variable is set in `config.status', edit `config.status' # (which will cause the Makefiles to be regenerated when you run `make'); # (2) otherwise, pass the desired values on the `make' command line. $(RECURSIVE_TARGETS): @fail= failcom='exit 1'; \ for f in x $$MAKEFLAGS; do \ case $$f in \ *=* | --[!k]*);; \ *k*) failcom='fail=yes';; \ esac; \ done; \ dot_seen=no; \ target=`echo $@ | sed s/-recursive//`; \ list='$(SUBDIRS)'; for subdir in $$list; do \ echo "Making $$target in $$subdir"; \ if test "$$subdir" = "."; then \ dot_seen=yes; \ local_target="$$target-am"; \ else \ local_target="$$target"; \ fi; \ ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ || eval $$failcom; \ done; \ if test "$$dot_seen" = "no"; then \ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ fi; test -z "$$fail" $(RECURSIVE_CLEAN_TARGETS): @fail= failcom='exit 1'; \ for f in x $$MAKEFLAGS; do \ case $$f in \ *=* | --[!k]*);; \ *k*) failcom='fail=yes';; \ esac; \ done; \ dot_seen=no; \ case "$@" in \ distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ *) list='$(SUBDIRS)' ;; \ esac; \ rev=''; for subdir in $$list; do \ if test "$$subdir" = "."; then :; else \ rev="$$subdir $$rev"; \ fi; \ done; \ rev="$$rev ."; \ target=`echo $@ | sed s/-recursive//`; \ for subdir in $$rev; do \ echo "Making $$target in $$subdir"; \ if test "$$subdir" = "."; then \ local_target="$$target-am"; \ else \ local_target="$$target"; \ fi; \ ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ || eval $$failcom; \ done && test -z "$$fail" tags-recursive: list='$(SUBDIRS)'; for subdir in $$list; do \ test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ done ctags-recursive: list='$(SUBDIRS)'; for subdir in $$list; do \ test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ done ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS TAGS: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) set x; \ here=`pwd`; \ if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ include_option=--etags-include; \ empty_fix=.; \ else \ include_option=--include; \ empty_fix=; \ fi; \ list='$(SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ test ! -f $$subdir/TAGS || \ set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ fi; \ done; \ list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: CTAGS CTAGS: ctags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(DISTFILES) @case `sed 15q $(srcdir)/NEWS` in \ *"$(VERSION)"*) : ;; \ *) \ echo "NEWS not updated; not releasing" 1>&2; \ exit 1;; \ esac $(am__remove_distdir) test -d "$(distdir)" || mkdir "$(distdir)" @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ test -d "$(distdir)/$$subdir" \ || $(MKDIR_P) "$(distdir)/$$subdir" \ || exit 1; \ fi; \ done @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ $(am__relativize); \ new_distdir=$$reldir; \ dir1=$$subdir; dir2="$(top_distdir)"; \ $(am__relativize); \ new_top_distdir=$$reldir; \ echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ ($(am__cd) $$subdir && \ $(MAKE) $(AM_MAKEFLAGS) \ top_distdir="$$new_top_distdir" \ distdir="$$new_distdir" \ am__remove_distdir=: \ am__skip_length_check=: \ am__skip_mode_fix=: \ distdir) \ || exit 1; \ fi; \ done -test -n "$(am__skip_mode_fix)" \ || find "$(distdir)" -type d ! -perm -755 \ -exec chmod u+rwx,go+rx {} \; -o \ ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ || chmod -R a+r "$(distdir)" dist-gzip: distdir tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz $(am__remove_distdir) dist-bzip2: distdir tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2 $(am__remove_distdir) dist-lzma: distdir tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma $(am__remove_distdir) dist-xz: distdir tardir=$(distdir) && $(am__tar) | xz -c >$(distdir).tar.xz $(am__remove_distdir) dist-tarZ: distdir tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z $(am__remove_distdir) dist-shar: distdir shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz $(am__remove_distdir) dist-zip: distdir -rm -f $(distdir).zip zip -rq $(distdir).zip $(distdir) $(am__remove_distdir) dist dist-all: distdir tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz $(am__remove_distdir) # This target untars the dist file and tries a VPATH configuration. Then # it guarantees that the distribution is self-contained by making another # tarfile. distcheck: dist case '$(DIST_ARCHIVES)' in \ *.tar.gz*) \ GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ *.tar.bz2*) \ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ *.tar.lzma*) \ lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\ *.tar.xz*) \ xz -dc $(distdir).tar.xz | $(am__untar) ;;\ *.tar.Z*) \ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ *.shar.gz*) \ GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\ *.zip*) \ unzip $(distdir).zip ;;\ esac chmod -R a-w $(distdir); chmod a+w $(distdir) mkdir $(distdir)/_build mkdir $(distdir)/_inst chmod a-w $(distdir) test -d $(distdir)/_build || exit 0; \ dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ && am__cwd=`pwd` \ && $(am__cd) $(distdir)/_build \ && ../configure --srcdir=.. --prefix="$$dc_install_base" \ --with-included-gettext \ $(DISTCHECK_CONFIGURE_FLAGS) \ && $(MAKE) $(AM_MAKEFLAGS) \ && $(MAKE) $(AM_MAKEFLAGS) dvi \ && $(MAKE) $(AM_MAKEFLAGS) check \ && $(MAKE) $(AM_MAKEFLAGS) install \ && $(MAKE) $(AM_MAKEFLAGS) installcheck \ && $(MAKE) $(AM_MAKEFLAGS) uninstall \ && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \ distuninstallcheck \ && chmod -R a-w "$$dc_install_base" \ && ({ \ (cd ../.. && umask 077 && mkdir "$$dc_destdir") \ && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \ && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \ && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \ distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \ } || { rm -rf "$$dc_destdir"; exit 1; }) \ && rm -rf "$$dc_destdir" \ && $(MAKE) $(AM_MAKEFLAGS) dist \ && rm -rf $(DIST_ARCHIVES) \ && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \ && cd "$$am__cwd" \ || exit 1 $(am__remove_distdir) @(echo "$(distdir) archives ready for distribution: "; \ list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' distuninstallcheck: @$(am__cd) '$(distuninstallcheck_dir)' \ && test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \ || { echo "ERROR: files left after uninstall:" ; \ if test -n "$(DESTDIR)"; then \ echo " (check DESTDIR support)"; \ fi ; \ $(distuninstallcheck_listfiles) ; \ exit 1; } >&2 distcleancheck: distclean @if test '$(srcdir)' = . ; then \ echo "ERROR: distcleancheck can only run from a VPATH build" ; \ exit 1 ; \ fi @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \ || { echo "ERROR: files left in build directory after distclean:" ; \ $(distcleancheck_listfiles) ; \ exit 1; } >&2 check-am: all-am check: check-recursive all-am: Makefile config.h installdirs: installdirs-recursive installdirs-am: install: install-recursive install-exec: install-exec-recursive install-data: install-data-recursive uninstall: uninstall-recursive install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-recursive install-strip: $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ `test -z '$(STRIP)' || \ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install mostlyclean-generic: clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-recursive clean-am: clean-generic clean-libtool mostlyclean-am distclean: distclean-recursive -rm -f $(am__CONFIG_DISTCLEAN_FILES) -rm -f Makefile distclean-am: clean-am distclean-generic distclean-hdr \ distclean-libtool distclean-tags dvi: dvi-recursive dvi-am: html: html-recursive html-am: info: info-recursive info-am: install-data-am: install-dvi: install-dvi-recursive install-dvi-am: install-exec-am: install-html: install-html-recursive install-html-am: install-info: install-info-recursive install-info-am: install-man: install-pdf: install-pdf-recursive install-pdf-am: install-ps: install-ps-recursive install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-recursive -rm -f $(am__CONFIG_DISTCLEAN_FILES) -rm -rf $(top_srcdir)/autom4te.cache -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-recursive mostlyclean-am: mostlyclean-generic mostlyclean-libtool pdf: pdf-recursive pdf-am: ps: ps-recursive ps-am: uninstall-am: .MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) all \ ctags-recursive install-am install-strip tags-recursive .PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ all all-am am--refresh check check-am clean clean-generic \ clean-libtool ctags ctags-recursive dist dist-all dist-bzip2 \ dist-gzip dist-lzma dist-shar dist-tarZ dist-xz dist-zip \ distcheck distclean distclean-generic distclean-hdr \ distclean-libtool distclean-tags distcleancheck distdir \ distuninstallcheck dvi dvi-am html html-am info info-am \ install install-am install-data install-data-am install-dvi \ install-dvi-am install-exec install-exec-am install-html \ install-html-am install-info install-info-am install-man \ install-pdf install-pdf-am install-ps install-ps-am \ install-strip installcheck installcheck-am installdirs \ installdirs-am maintainer-clean maintainer-clean-generic \ mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \ ps ps-am tags tags-recursive uninstall uninstall-am # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: libnih-1.0.3/ChangeLog0000644000175000017500000120013411504742356011463 000000000000002010-12-23 Scott James Remnant * NEWS: Release 1.0.3 * nih-dbus-tool/type.c (type_const, type_of): Add support for the DBUS_TYPE_UNIX_FD type, with a C type of "int". * nih-dbus-tool/tests/test_type.c (test_const, test_of): Check the types are correct. * nih-dbus-tool/tests/marshal_factory.c: Generate function for unix_fd testing * nih-dbus-tool/tests/marshal_code.h: Add header for generated function * nih-dbus-tool/tests/test_marshal.c (test_marshal): Test the generator and the generated function * nih-dbus-tool/tests/demarshal_factory.c: Generate function for unix_fd testing * nih-dbus-tool/tests/demarshal_code.h: Add header for generated function * nih-dbus-tool/tests/test_demarshal.c (test_demarshal): Test the generator and the generated code * nih-dbus-tool/tests/com.netsplit.Nih.Test.xml: Add methods, signal and properties for testing. * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.h: Add property definition * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.c (my_test_unix_fd_to_str) (my_test_str_to_unix_fd, my_test_get_unix_fd) (my_test_set_unix_fd): Test implementation. * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c (test_unix_fd_to_str) (test_str_to_unix_fd, test_new_unix_fd, test_get_unix_fd) (test_set_unix_fd): Add methods to test the object implementation. * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c (test_unix_fd_to_str) (test_unix_fd_to_str_sync, test_str_to_unix_fd) (test_str_to_unix_fd_sync, test_new_unix_fd, test_get_unix_fd) (test_get_unix_fd_sync, test_set_unix_fd, test_set_unix_fd_sync): Add tests for unix fds. (test_get_all, test_get_all_sync): Add unix fd to tests. * NEWS: Update 2010-04-27 Scott James Remnant * configure.ac: Bump version to 1.0.3 * NEWS: Begin new release * NEWS: Release 1.0.2 2010-04-24 Scott James Remnant * m4/libnih.m4 (NIH_WITH_LOCAL_LIBNIH): Add macro cribbed from the Upstart configure.ac 2010-03-04 Scott James Remnant * nih-dbus-tool/Makefile.am (tests/marshal_code.c) (tests/demarshal_code.c, tests/interface_code.c) (tests/method_code.c, tests/signal_code.c) (tests/property_code.c): Support silent rules by using $(AM_V_GEN) 2010-02-26 Scott James Remnant * configure.ac: Use NIH_COPYRIGHT instead of AC_COPYRIGHT * m4/libnih.m4: Add a serial header and a comment reminding us to increment it each time, otherwise aclocal can overwrite the copy in the source tree with an older installed copy. 2010-02-09 Scott James Remnant * m4/libnih.m4 (AC_COPYRIGHT): Rename to NIH_COPYRIGHT, since this macro file is installed globally we don't want to muck around like we were when it was copied in. 2010-02-04 Scott James Remnant * configure.ac: Bump version to 1.0.2 * NEWS: Begin new release * NEWS: Release 1.0.1 * nih/logging.c (__abort_msg): Make a weak symbol reference. (nih_log_abort_message): Check whether __abort_msg has an address before saving. * nih/tests/test_logging.c (__abort_msg): Make a weak symbol reference. (test_log_message): Skip __abort_msg tests if there is no address for it. 2010-02-03 Scott James Remnant * nih/libnih.ver: Add missing export for __nih_* so you can build test cases; not bumping the library age here since this isn't an API change but a bug. * nih-dbus-tool/Makefile.am ($(com_netsplit_Nih_Test_object_OUTPUTS)): ($(com_netsplit_Nih_Test_proxy_OUTPUTS)): Make compatible with am-silent-rules by using $(AM_V_GEN) and combining the mkdir and nih-dbus-tool lines. * configure.ac: Bump copyright year to 2010. * NEWS: Begin new release. 2009-11-29 Scott James Remnant * configure.ac (AM_INIT_AUTOMAKE): Drop dist-bzip2, since we don't use them. * configure.ac: Bump version to 1.0.1 2009-11-28 Scott James Remnant * NEWS: Release 1.0.0 * nih-dbus-tool/main.c (source_file_path, header_file_path): Use a not reached assertion rather than an initial one, to avoid gcc warnings. * nih/tests/test_string.c (test_array_addp), * nih/tests/test_logging.c (test_log_message): Add a couple more initialisations for gcc, found with -O2 * TODO: Update. * nih/tests/test_error.c (test_raise_error, test_pop_context): Also unlink core.PID form of core file, and unlink a valgrind core of the same name as well while we're in there. * nih/tests/test_child.c (test_poll): Do the same here, except it turns out that under valgrind we might still have NIH_CHILD_KILLED but a core file - always clean up core files anyway. * nih/libnih.supp, nih-dbus/libnih-dbus.supp: Valgrind got a whole bunch more strict in the 3.5 release. That's a good thing because we catch more errors, but it means it's somewhat picker about things like our reference allocations. Redo the suppressions against 3.5, taking an opportunity to clean up the files and insert documentation as to why they are there. * nih/tests/test_signal.c (test_poll): The two signal structures allocated in this function were not being freed at the end. * nih/tests/test_watch.c (test_reader): On termination of this test we were not freeing the last path copied. * nih-dbus/tests/test_dbus_connection.c (test_connect, test_bus) (test_setup): Free signal handlers before exiting the child, unlike other test cases we can't make these children of any other object since we don't actually have one! * nih-dbus-tool/tests/test_annotation.c (test_start_tag) (test_end_tag): Missing call to discard the NULL reference from the various objects after pushing onto the stack. * nih-dbus-tool/tests/test_parse.c (test_stack_push): Thanks to the updated valgrind, I can now see that this test case wasn't updated for the new nih_alloc() behaviour. We now need to free the object even after it's been referenced, because it still has our NULL reference. (test_start_tag, test_end_tag): Also need to discard the NULL reference in each of these cases. 2009-11-24 Scott James Remnant * nih/logging.c (nih_log_message): Split the abort message saving out into its own function. (nih_log_abort_message): This makes it easier to suppress. * nih/libnih.supp: Add suppressions. * NEWS: Update. * nih/libnih.supp: Add new tmpfile suppression * nih-dbus-tool/interface.c (interface_proxy_get_all_function), * nih-dbus-tool/method.c (method_proxy_function), * nih-dbus-tool/property.c (property_proxy_get_function) (property_proxy_set_function): The dbus_connection_send_with_reply() function can return TRUE without setting a pending_call in the case of a non-connected connection. Convert this into the DBUS_ERROR_DISCONNECTED error to match send_with_reply_and_block * nih-dbus-tool/tests/test_interface.c (test_proxy_get_all_function), * nih-dbus-tool/tests/test_method.c (test_proxy_function), * nih-dbus-tool/tests/test_property.c (test_proxy_get_function) (test_proxy_set_function), * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c (test_ordinary_method) (test_nameless_method, test_async_method, test_byte_to_str) (test_str_to_byte, test_boolean_to_str, test_str_to_boolean) (test_int16_to_str, test_str_to_int16, test_uint16_to_str) (test_str_to_uint16, test_int32_to_str, test_str_to_int32) (test_uint32_to_str, test_str_to_uint32, test_int64_to_str) (test_str_to_int64, test_uint64_to_str, test_str_to_uint64) (test_double_to_str, test_str_to_double) (test_object_path_to_str, test_str_to_object_path) (test_signature_to_str, test_str_to_signature) (test_struct_to_str, test_str_to_struct) (test_int32_array_to_str, test_str_to_int32_array) (test_str_array_to_str, test_str_to_str_array) (test_int32_array_array_to_str, test_str_to_int32_array_array) (test_struct_array_to_str, test_str_to_struct_array) (test_dict_entry_array_to_str, test_str_to_dict_entry_array) (test_get_byte, test_set_byte, test_get_boolean) (test_set_boolean, test_get_int16, test_set_int16) (test_get_uint16, test_set_uint16, test_get_int32) (test_set_int32, test_get_uint32, test_set_uint32) (test_get_int64, test_set_int64, test_get_uint64) (test_set_uint64, test_get_double, test_set_double) (test_get_string, test_set_string, test_get_object_path) (test_set_object_path, test_get_signature, test_set_signature) (test_get_structure, test_set_structure, test_get_int32_array) (test_set_int32_array, test_get_str_array, test_set_str_array) (test_get_int32_array_array, test_set_int32_array_array) (test_get_struct_array, test_set_struct_array) (test_get_dict_entry_array, test_set_dict_entry_array) (test_get_all): Add test cases for sending to a disconnected connection and getting the error reply back straight away. * nih-dbus-tool/tests/expected/test_interface_proxy_get_all_function_standard.c, * nih-dbus-tool/tests/expected/test_method_proxy_function_standard.c, * nih-dbus-tool/tests/expected/test_method_proxy_function_structure.c, * nih-dbus-tool/tests/expected/test_method_proxy_function_array.c, * nih-dbus-tool/tests/expected/test_method_proxy_function_no_args.c, * nih-dbus-tool/tests/expected/test_method_proxy_function_deprecated.c, * nih-dbus-tool/tests/expected/test_property_proxy_get_function_standard.c, * nih-dbus-tool/tests/expected/test_property_proxy_get_function_deprecated.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_function_standard.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_function_structure.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_function_array.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_function_deprecated.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_standard.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_structure.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_no_methods.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_no_signals.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_no_properties.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_only_properties.c: Update expected function output to match. * nih-dbus-tool/tests/test_interface.c (test_proxy_get_all_sync_function), * nih-dbus-tool/tests/test_method.c (test_proxy_sync_function), * nih-dbus-tool/tests/test_property.c (test_proxy_get_sync_function) (test_proxy_set_sync_function), * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c (test_ordinary_method_sync) (test_nameless_method_sync, test_async_method_sync) (test_byte_to_str_sync, test_str_to_byte_sync) (test_boolean_to_str_sync, test_str_to_boolean_sync) (test_int16_to_str_sync, test_str_to_int16_sync) (test_uint16_to_str_sync, test_str_to_uint16_sync) (test_int32_to_str_sync, test_str_to_int32_sync) (test_uint32_to_str_sync, test_str_to_uint32_sync) (test_int64_to_str_sync, test_str_to_int64_sync) (test_uint64_to_str_sync, test_str_to_uint64_sync) (test_double_to_str_sync, test_str_to_double_sync) (test_object_path_to_str_sync, test_str_to_object_path_sync) (test_signature_to_str_sync, test_str_to_signature_sync) (test_struct_to_str_sync, test_str_to_struct_sync) (test_int32_array_to_str_sync, test_str_to_int32_array_sync) (test_str_array_to_str_sync, test_str_to_str_array_sync) (test_int32_array_array_to_str_sync) (test_str_to_int32_array_array_sync) (test_struct_array_to_str_sync, test_str_to_struct_array_sync) (test_dict_entry_array_to_str_sync) (test_str_to_dict_entry_array_sync, test_get_byte_sync) (test_set_byte_sync, test_get_boolean_sync) (test_set_boolean_sync, test_get_int16_sync) (test_set_int16_sync, test_get_uint16_sync) (test_set_uint16_sync, test_get_int32_sync, test_set_int32_sync) (test_get_uint32_sync, test_set_uint32_sync) (test_get_int64_sync, test_set_int64_sync, test_get_uint64_sync) (test_set_uint64_sync, test_get_double_sync) (test_set_double_sync, test_get_string_sync) (test_set_string_sync, test_get_object_path_sync) (test_set_object_path_sync, test_get_signature_sync) (test_set_signature_sync, test_get_structure_sync) (test_set_structure_sync, test_get_int32_array_sync) (test_set_int32_array_sync, test_get_str_array_sync) (test_set_str_array_sync, test_get_int32_array_array_sync) (test_set_int32_array_array_sync, test_get_struct_array_sync) (test_set_struct_array_sync, test_get_dict_entry_array_sync) (test_set_dict_entry_array_sync, test_get_all_sync): Add test cases for a sync() function on a disconnected connection, which should return the same error internally inside D-Bus. * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c: These tests weren't passing under valgrind, because I got lazy and gave up. Most of the reason was that the main signal handler wasn't freed; fix that by attaching the signal to the D-Bus object. * nih/test_process.h (TEST_CHILD, TEST_CHILD_WAIT): Flush standard output and error before forking, to avoid the typical strange buffering issues when piping to less. * nih/alloc.c (NihAllocCtx): The recent alignment changes mean there's always 4 bytes of spare space in this structure, use those to remember the allocation size rather than relying on malloc() to do it. This makes us more portable to alternative (and debugging) malloc implementations. (nih_alloc, nih_realloc): Update the size field (nih_alloc_size): Just return the size field. * TODO: Update. 2009-11-21 Scott James Remnant * nih/option.c: Add a note that --debug is deliberately hidden. * nih/macros.h (NIH_ALIGN_SIZE): Fix rounding to be twice size of size_t, or alignment of long long - which is what we decided in the bug. * nih/alloc.c (NIH_ALLOC_SIZE): Formatting. * nih/Makefile.am (libnih_la_LDFLAGS): Bump version * nih-dbus/Makefile.am (libnih_dbus_la_LDFLAGS): Bump version * configure.ac (AC_PRERQ): Update to 2.62 (AM_INIT_AUTOMAKE): Update to 1.11, add color-tests and silent-rules to the options (AM_SILENT_RULES): Explicitly make silent rules the default (AM_MAINTAINER_MODE): Add, but with "enable" as the default, so distributions may turn it off with --disable-maintainer-mode (AM_GNU_GETTEXT_VERSION): Update to 0.17 * HACKING: Update requirements; document that we support the standard options. 2009-11-21 John Cater * nih/macros.h (NIH_ALIGN_SIZE): Add macro to guess at the maximum alignment of a type * nih/alloc.c (NIH_ALLOC_SIZE): Define the size of the context based off its size and the maximum alignment macro, thus hopefully ensuring the following pointer is generically aligned (NIH_ALLOC_CTX, NIH_ALLOC_PTR): Redefine based on NIH_ALLOC_SIZE (nih_alloc, nih_realloc, nih_alloc_size): Use NIH_ALLOC_SIZE instead of sizeof (NihAllocCtx) 2009-11-21 Scott James Remnant * NEWS: Update * nih-dbus-tool/main.c: Add option to supply the package name and store in a global variable for the output code to access. * nih-dbus-tool/output.c (output_preamble): Use the supplied package name in preference to "libnih" when generating preamble comments. (output_sentinel): Use the supplied package name in preference to "libnih" when generating header sentinels. * nih-dbus-tool/output.h: Add variable declaration * m4/Makefile.am (nih_dbus_tool_LDADD): Turns out that this doesn't link with libnih-dbus at all * nihify: Remove the script to copy into other source directories * nih/libnih.ver, nih-dbus/libnih-dbus.ver: Update versions * nih-dbus-tool/Makefile.am (bin_PROGRAMS): Always install the tool (dist_man_MANS): Always install the manual page (EXTRA_DIST): We don't need to distribute the manual page with this now * nih/libnih.pc.in, nih-dbus/libnih-dbus.pc.in: Source to pkg-config data files * configure.ac: Generate the actual pkg-config files from the sources * nih/Makefile.am (lib_LTLIBRARIES): Always install libnih.la (include_HEADERS): Always install the header files (pkgconfig_DATA): Install the pkg-config file (EXTRA_DIST): Distribute the source to it * nih-dbus/Makefile.am (lib_LTLIBRARIES): Always install libnih-dbus.la (include_HEADERS): Always install the header files (pkgconfig_DATA): Install the pkg-config file (EXTRA_DIST): Distribute the source to it * Makefile.am: Always build libnih-dbus and nih-dbus-tool * m4/misc.m4, m4/compiler.m4, m4/linker.m4: Merge together into a single libnih.m4 file for easier aclocal inclusion. * m4/libnih.m4 (NIH_INIT): Drop this macro, libnih shouldn't need software to call any special macros other than the ones they probably need anyway. * m4/libs.m4: Drop this source and the NIH_LIB_DBUS macro, since we'll always build this * m4/Makefile.am: Unconditionally install the new macro file * configure.ac: Replace NIH_INIT with the bits we actually want to check for here. * README: Remove the usage instructions, since this is going to be an ordinary shared library; rewrite the Dependencies section language to be better; add a Cross-compiling section. * configure.ac: Since this library is now being used in several places, it's time to start caring about API and stop compiling it statically into things. Bump version to 1.0.0. Bug fixes without any API changes will be named 1.0.x; backwards compatible API changes 1.x.0, etc. * NEWS: Bump version to 1.0.0 * TODO: Update with missing bits for 1.0 and plans for 1.1/2.0 2009-10-03 Scott James Remnant * m4/libs.m4 (NIH_LIB_DBUS): Allow an external nih-dbus-tool to be used by setting NIH_DBUS_TOOL when calling configure; when cross-compiling, if this is not set, look for it in the PATH and warn if we fall back to using our built copy. * nih-dbus-tool/Makefile.am ($(com_netsplit_Nih_Test_object_OUTPUTS)): ($(com_netsplit_Nih_Test_proxy_OUTPUTS)): Use an externally built nih-dbus-tool for the tests if given, not strictly right but the best we can do when cross-compiling (when we probably won't run "make check" anyway) * nih/file.c (nih_dir_walk_sort): Add static function to replace alphasort() which we can't call anymore. It would be deeply ironic to bitch about glibc breaking API in the libnih changelog. (nih_dir_walk_scan): Replace alphasort() with nih_dir_walk_sort() 2009-08-11 Johan Kiviniemi * nih/logging.c: Expose the glibc-internal __abort_msg symbol so that we can set it. (nih_log_message): Save a copy of any fatal or higher log message into this variable; assuming that abort() is the next function call as is the case for nih_assert() 2009-08-11 Scott James Remnant * nih/test_alloc.h (TEST_ALLOC_NOT_PARENT): Add the opposite test for a known parent, making sure that something is not a parent. 2009-08-04 Scott James Remnant * nih/tests/test_alloc.c (test_ref, test_unref): Add tests for multiple identical parents. * nih/alloc.h: Document that we specifically permit multiple references between two objects. * configure.ac: 0.4.0 is a bit far, and the nih_alloc() changes are largely minor in effect outside the library; let's call this 0.3.5 * NEWS: Change version * nih-dbus-tool/node.c (node_start_tag): Make node object local. (node_end_tag): Replace use of nih_unref_only with a simple nih_ref()/nih_unref() pair * nih-dbus-tool/interface.c (interface_start_tag): Make interface object local * nih-dbus-tool/method.c (method_start_tag): Make method object local. * nih-dbus-tool/signal.c (signal_start_tag): Make signal object local. * nih-dbus-tool/argument.c (argument_start_tag): Make argument object local. * nih-dbus-tool/property.c (property_start_tag): Make property object local. * nih-dbus-tool/tests/test_type.c (test_of): Replace TEST_ALLOC_ORPHAN(ptr) with TEST_ALLOC_PARENT(ptr, NULL) * nih-dbus-tool/tests/test_demarshal.c (test_demarshal): Replace TEST_ALLOC_ORPHAN(ptr) with TEST_ALLOC_PARENT(ptr, NULL) * nih-dbus-tool/tests/test_node.c (test_end_tag): Replace TEST_ALLOC_ORPHAN(ptr) with TEST_ALLOC_PARENT(ptr, NULL) (test_start_tag, test_end_tag): Discard stack objects after pushing * nih-dbus-tool/tests/test_interface.c (test_start_tag) (test_end_tag): Discard stack objects after pushing * nih-dbus-tool/tests/test_method.c (test_start_tag) (test_end_tag): Discard stack objects after pushing * nih-dbus-tool/tests/test_signal.c (test_start_tag) (test_end_tag): Discard stack objects after pushing * nih-dbus-tool/tests/test_property.c (test_start_tag) (test_end_tag): Discard stack objects after pushing * nih-dbus-tool/tests/test_argument.c (test_start_tag) (test_end_tag): Discard stack objects after pushing * nih/io.c (nih_io_read_message): Replace use of nih_unref_only with a simple nih_ref()/nih_unref() pair (nih_io_write): Use nih_local for the message, we either reference it when we send or we throw it away on returning. * nih/tests/test_io.c (test_watcher): After sending the message we need to discard it, it's only referenced not stolen now. (test_read_message): Replace TEST_ALLOC_ORPHAN(msg) with TEST_ALLOC_PARENT(msg, NULL) * nih/tests/test_string.c (test_sprintf, test_vsprintf) (test_strdup, test_strndup): Replace TEST_ALLOC_ORPHAN(ptr) checks with TEST_ALLOC_PARENT(ptr, NULL) (test_array_addp): Fix bad uses of TEST_ALLOC_FAIL on data allocated outside of the loop, necessary now that the pointer won't be "stolen" by the function merely referenced * nih/alloc.c (nih_alloc_ref_new): Allow parent to be NULL, when it is we store NULL in ref->parent and leave the children_entry as an empty list node. (NIH_ALLOC_CTX): Context for a NULL pointer is NULL (nih_alloc): Always allocate a reference, even when the parent is NULL creating a NULL ref (nih_discard): Lookup a NULL reference and free that before checking for existing references. (nih_ref, nih_unref, nih_alloc_ref_lookup): Allow parent to be NULL (nih_unref_only): We don't need this function anymore so drop (nih_alloc_parent): Since NULL can be a parent, this now looks that up - there's no function for "has a parent" * nih/alloc.h: Remove nih_unref_only prototype, update documentation * nih/test_alloc.h (TEST_ALLOC_PARENT): Update documentation to reflect that NULL is valid again (TEST_ALLOC_ORPHAN): Drop this macro. * nih/tests/test_alloc.c (test_new, test_alloc, test_realloc): Replace TEST_ALLOC_ORPHAN checks with TEST_ALLOC_PARENT (ptr, NULL) (test_ref): Make sure that the NULL reference is not removed by adding another; add new test for adding a new NULL reference. (test_unref): Add tests for removing the NULL reference and freeing or leaving the object. (test_parent): Add test for looking up NULL Parent * nih/libnih.supp: Add suppressions for nih_alloc_ref_new in the appropriate places. * NEWS: Update 2009-08-03 Scott James Remnant * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c (test_set_string_sync) (test_set_object_path_sync, test_set_signature_sync): Fix the incorrect parent tests to actually check for the specific parent rather than just a parent. 2009-08-02 Scott James Remnant * configure.ac: Bump version to 0.4.0 * NEWS: Begin new release * NEWS: Release 0.3.2 2009-07-29 Michael Biebl * nih/child.h: Remove unnecessary sys/ptrace.h and linux/ptrace.h headers, that prevent compilation on ia64. 2009-07-22 Michael Biebl * nih-dbus-tool/Makefile.am (dist_man_MANS): Don't install the manpages unless INSTALL_NIH, take care to make sure they're still distributed. 2009-07-15 Scott James Remnant * m4/libs.m4 (NIH_LIB_DBUS): Now that D-Bus 1.2.16 proper has been released, update our version requirements to that. * README: Update documentation. 2009-07-14 Scott James Remnant * nih/tests/test_main.c (test_init): Add a test for being called as a login shell. * nih/main.c (nih_main_init_full): Check for and skip initial dash. 2009-07-11 Scott James Remnant * configure.ac: Bump version to 0.3.2 * NEWS: Begin new release 2009-07-09 Scott James Remnant * NEWS: Release 0.3.1 * m4/libs.m4 (NIH_LIB_DBUS): Increase D-Bus dependency to current GIT HEAD (1.2.15) * README: Update documentation. * NEWS: Note the change. * nih-dbus-tool/demarshal.c (demarshal_array): Always initialise all arrays to NULL first, and then only allocate the arrays after to avoid gcc's uninitialised warnings. * nih-dbus-tool/tests/test_demarshal.c (test_demarshal): Update expected output to match * nih-dbus-tool/tests/expected/test_method_proxy_notify_function_standard.c, * nih-dbus-tool/tests/expected/test_method_proxy_notify_function_array.c, * nih-dbus-tool/tests/expected/test_method_proxy_sync_function_standard.c, * nih-dbus-tool/tests/expected/test_method_proxy_sync_function_no_input.c: Update the method tests expected output too * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c (test_new_struct_array) (test_new_dict_entry_array): Initialise alloc-safe variables to NULL to avoid gcc warning * nih-dbus/dbus_connection.c (nih_dbus_timeout_toggled): Use the monotonic clock to recalculate the timer * nih-dbus/Makefile.am (libnih_dbus_la_LIBS): Rename to _LIBADD (libnih_dbus_la_LIBADD): Link with librt * nih/timer.c (nih_timer_add_timeout, nih_timer_add_periodic) (nih_timer_poll): Use a monotonic clock for timers, not the realtime clock. * nih/main.c (nih_main_loop): Calculate select time based on the monotonic clock. * nih/Makefile.am (libnih_la_LIBADD): Link with librt * README: Bump the recommended D-Bus 2009-07-08 Scott James Remnant * nih/file.c (nih_dir_walk_scan): Should compare against DT_DIR not use S_ISDIR * NEWS: Update. * nih/file.h (NihFileFilter): Add an is_dir argument * nih/file.c (nih_dir_walk_scan): Pass the new argument * nih/watch.c (nih_watch_handle): Pass the extra argument * nih/tests/test_file.c (my_filter): Add the extra argument but ignore * nih/tests/test_watch.c (my_filter): Add here too 2009-07-03 Scott James Remnant * nih/error.h (NihError): Declare this a slightly odd way to permit the members to be directly embedded in sub-classes rather than referring back through an accessor variable. * nih-dbus/dbus_error.h (nih_dbus_error): Embed the NihError members directly using the new macro. * nih-dbus/dbus_error.c (nih_dbus_error_raise) (nih_dbus_error_raise_printf): Just set number and message directly; cast before raising. * nih-dbus/dbus_object.c (nih_dbus_object_property_get) (nih_dbus_object_property_get_all, nih_dbus_object_property_set): Access message through the dbus_err cast. * nih-dbus/tests/test_dbus_error.c (test_error_raise) (test_error_raise_printf): Test directly accessing the number and message. 2009-07-02 Scott James Remnant * nih-dbus/tests/test_dbus_proxy.c (test_connect): We can end up with a lot of stray signals with these tests, so open and close the connections for each one. * NEWS: Update. * TODO: Update. * nih-dbus-tool/interface.c (interface_proxy_get_all_function) (interface_proxy_get_all_sync_function), * nih-dbus-tool/method.c (method_proxy_function) (method_proxy_sync_function), * nih-dbus-tool/property.c (property_proxy_get_function) (property_proxy_set_function, property_proxy_get_sync_function) (property_proxy_set_sync_function): Set the auto_start flag in new method calls that we create. * tests/expected/test_interface_proxy_get_all_function_standard.c, * tests/expected/test_interface_proxy_get_all_sync_function_standard.c, * tests/expected/test_interface_proxy_get_all_sync_function_structure.c, * tests/expected/test_method_proxy_function_array.c, * tests/expected/test_method_proxy_function_deprecated.c, * tests/expected/test_method_proxy_function_no_args.c, * tests/expected/test_method_proxy_function_standard.c, * tests/expected/test_method_proxy_function_structure.c, * tests/expected/test_method_proxy_sync_function_array_input.c, * tests/expected/test_method_proxy_sync_function_deprecated.c, * tests/expected/test_method_proxy_sync_function_no_args.c, * tests/expected/test_method_proxy_sync_function_no_input.c, * tests/expected/test_method_proxy_sync_function_no_output.c, * tests/expected/test_method_proxy_sync_function_standard.c, * tests/expected/test_method_proxy_sync_function_structure_input.c, * tests/expected/test_method_proxy_sync_function_structure_output.c, * tests/expected/test_property_proxy_get_function_standard.c, * tests/expected/test_property_proxy_get_function_deprecated.c, * tests/expected/test_property_proxy_get_sync_function_standard.c, * tests/expected/test_property_proxy_get_sync_function_structure.c, * tests/expected/test_property_proxy_get_sync_function_deprecated.c, * tests/expected/test_property_proxy_set_function_standard.c, * tests/expected/test_property_proxy_set_function_structure.c, * tests/expected/test_property_proxy_set_function_array.c, * tests/expected/test_property_proxy_set_function_deprecated.c, * tests/expected/test_property_proxy_set_sync_function_standard.c, * tests/expected/test_property_proxy_set_sync_function_structure.c, * tests/expected/test_property_proxy_set_sync_function_array.c, * tests/expected/test_property_proxy_set_sync_function_deprecated.c, * tests/expected/test_node_proxy_functions_standard.c, * tests/expected/test_node_proxy_functions_no_methods.c, * tests/expected/test_node_proxy_functions_no_signals.c, * tests/expected/test_node_proxy_functions_no_properties.c, * tests/expected/test_node_proxy_functions_only_properties.c, * tests/expected/test_node_proxy_functions_structure.c, * tests/expected/test_output_proxy_standard.c: Update expected output. * nih-dbus/dbus_proxy.h (NihDBusProxy): Add an auto_start member * nih-dbus/dbus_proxy.c (nih_dbus_proxy_new): Initialise auto_start member to TRUE (the D-Bus default). * nih-dbus/tests/test_dbus_proxy.c (test_new): Add checks for auto-start being TRUE. * nih-dbus-tool/signal.c (signal_proxy_function): Look up connection and path through the proxy object; if the proxy object has a name, compare the signal sender against the OWNER of that name, not the name. * nih-dbus-tool/tests/test_signal.c (test_proxy_function): Drop parent argument from calls to nih_dbus_proxy_connect. Add test cases for signal catching on peer-to-peer and well-known name (we were previously just using unique). * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c (test_new_byte) (test_new_boolean, test_new_int16, test_new_uint16) (test_new_int32, test_new_uint32, test_new_int64) (test_new_uint64, test_new_double, test_new_string) (test_new_object_path, test_new_signature, test_new_struct) (test_new_int32_array, test_new_str_array) (test_new_int32_array_array, test_new_struct_array) (test_new_dict_entry_array): Drop the parent argument from calls to nih_dbus_proxy_connect * nih-dbus-tool/tests/expected/test_signal_proxy_function_standard.c, * nih-dbus-tool/tests/expected/test_signal_proxy_function_no_args.c, * nih-dbus-tool/tests/expected/test_signal_proxy_function_structure.c, * nih-dbus-tool/tests/expected/test_signal_proxy_function_deprecated.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_standard.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_no_methods.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_no_properties.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_structure.c, * nih-dbus-tool/tests/expected/test_output_proxy_standard.c: Update expected output * nih-dbus/dbus_proxy.c (nih_dbus_proxy_new): Track the name whenever one is given, not just when we have a lost handler. (nih_dbus_proxy_name_track): lost_handler is not compulsory (nih_dbus_proxy_name_owner_changed): Make the lost handler optional (nih_dbus_proxy_destroy): name tracking must be cleaned up when there's a name, not a lost handler * nih-dbus/tests/test_dbus_proxy.c (test_name_owner_changed): Add tests for both well-known and unique names with both being tracked. (test_name_owner_changed): Add a test case for tracking a unique name. * nih-dbus/dbus_proxy.h (NihDBusProxySignal): Go back to just holding a reference to the proxy in the connected signal, we need its name owner tracking. * nih-dbus/dbus_proxy.c (nih_dbus_proxy_connect): Keep a reference to the proxy, don't copy the members in; be allocated as a child of the proxy. * nih-dbus/tests/test_dbus_proxy.c (test_connect): Add a test case for connecting to a signal by well-known name, rather than just unique name * nih-dbus-tool/output.c (output): Don't know where the word "Forward" came from in this comment, delete it. * nih-dbus-tool/tests/expected/test_output_proxy_standard.c, * nih-dbus-tool/tests/expected/test_output_object_standard.c: Delete from the expected output as well. * nih-dbus-tool/main.c: Add a --default-interface argument that takes the place of setting the Symbol annotation to "". This is much cleaner, and allows the user of the code to decide, not the author of the interface. * nih-dbus-tool/interface.c (interface_annotation): Don't allow the symbol annotation to be empty again. (interface_end_tag): Which means that the symbol can never be empty when we get to here. * nih-dbus-tool/tests/test_interface.c (test_annotation): Drop the test case for the empty annotation. (test_end_tag): And drop the empty string test case. * nih-dbus/tests/test_dbus_object.c (test_object_property_get) (test_object_property_set): We actually want "Access Denied" returned instead of "No Such Method". * nih-dbus/dbus_object.c (nih_dbus_object_property_get) (nih_dbus_object_property_set): Rework so that we can return "access denied". * nih-dbus/tests/test_dbus_object.c (test_object_property_get) (test_object_property_set, test_object_property_get): Add some test cases for property access. * TODO: Update. * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c (test_get_all) (test_get_all_sync): End-to-end test of the proxy get_all functions. * nih-dbus-tool/interface.c (interface_proxy_get_all_notify_function) (interface_proxy_get_all_sync_function): We can't use continue to repeat the loop, because there might be inner loops. Use the local label trick. * nih-dbus-tool/tests/expected/test_interface_proxy_get_all_notify_function_standard.c, * nih-dbus-tool/tests/expected/test_interface_proxy_get_all_notify_function_structure.c, * nih-dbus-tool/tests/expected/test_interface_proxy_get_all_sync_function_standard.c, * nih-dbus-tool/tests/expected/test_interface_proxy_get_all_sync_function_structure.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_standard.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_no_methods.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_no_signals.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_only_properties.c, * nih-dbus-tool/tests/expected/test_output_proxy_standard.c: Update expected output for test cases 2009-07-01 Scott James Remnant * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c (test_struct_to_str) (test_struct_to_str_sync, test_str_to_struct) (test_str_to_struct_sync, test_struct_array_to_str) (test_struct_array_to_str_sync, test_str_to_struct_array) (test_str_to_struct_array_sync, test_dict_entry_array_to_str) (test_dict_entry_array_to_str_sync) (test_str_to_dict_entry_array) (test_str_to_dict_entry_array_sync, test_new_struct) (test_new_struct_array, test_new_dict_entry_array) (test_get_structure, test_get_structure_sync) (test_set_structure, test_set_structure_sync) (test_get_struct_array, test_get_struct_array_sync) (test_set_struct_array, test_set_struct_array_sync) (test_get_dict_entry_array, test_get_dict_entry_array_sync) (test_set_dict_entry_array, test_set_dict_entry_array_sync): Proxy test functions for structures, arrays of structures, and arrays of dictionary entries in converstion, signal and property get/set form. * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.c (my_test_get_struct_array) (my_test_get_dict_entry_array): Be consistent about what generates a D-Bus error and what generates a generic error. * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c (test_get_struct_array) (test_get_dict_entry_array): Update to match. * nih-dbus-tool/tests/com.netsplit.Nih.Test.xml: Add methods, signals and properties that take a structure, an array of structures and an array of dictionary entries to the tests. * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.h: Add structure definition for the property we store behind the scenes, add extern variables for the structure and structure/dictionary array properties * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.c (my_test_struct_to_str) (my_test_str_to_struct, my_test_struct_array_to_str) (my_test_str_to_struct_array, my_test_dict_entry_array_to_str) (my_test_str_to_dict_entry_array, my_test_get_structure) (my_test_set_structure, my_test_get_struct_array) (my_test_set_struct_array, my_test_get_dict_entry_array) (my_test_set_dict_entry_array): Add implementation for the structure and structure/dictionary array conversion functions and property get/set functions. Signal emission is implemented entirely by the binding tool. * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c (test_struct_to_str) (test_str_to_struct, test_struct_array_to_str) (test_str_to_struct_array, test_dict_entry_array_to_str) (test_str_to_dict_entry_array, test_new_struct) (test_new_struct_array, test_new_dict_entry_array) (test_get_structure, test_set_structure, test_get_struct_array) (test_set_struct_array, test_get_dict_entry_array) (test_set_dict_entry_array): Add new test cases for structures, structure arrays and dictionaries. 2009-06-30 Scott James Remnant * nih-dbus-tool/tests/test_node.c (test_proxy_functions): Structures of readable properties come after all writable ones * nih-dbus-tool/tests/com.netsplit.Nih.Test.xml: Can't just call the property "double" now it ends up in a structure, apply an annotation to change the symbol. * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.c (my_test_get_double) (my_test_set_double): Rename * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c (test_get_double) (test_get_double_sync, test_set_double, test_set_double_sync): Call the renamed functions. * nih-dbus-tool/tests/test_marshal.c (test_marshal): Add missing test cases for arrays of dictionary entries. * nih-dbus-tool/tests/marshal_factory.c: Generate a dict entry test * nih-dbus-tool/tests/marshal_code.h: Add the expected structure type and prototypes. * nih-dbus-tool/tests/test_demarshal.c (test_demarshal): Add missing test cases for arrays of dictionary entries. * nih-dbus-tool/tests/demarshal_code.h: Add the expected structure type and prototypes. * nih-dbus-tool/tests/demarshal_factory.c: Generate a dict entry test * nih-dbus-tool/marshal.c, nih-dbus-tool/demarshal.c, * nih-dbus-tool/node.c, nih-dbus-tool/method.c, nih-dbus-tool/signal.c, * nih-dbus-tool/property.c: Add missing mention of @structs in function documentation. * nih-dbus-tool/tests/test_interface.c (test_proxy_get_all_function) (test_proxy_get_all_notify_function) (test_proxy_get_all_sync_function): Include a mix of readwrite, read and writable properties in the test - only the first two should appear in the output. * nih-dbus-tool/output.c (output): Source should include string.h and stdint.h for the following code, header should include stdint.h * nih-dbus-tool/tests/expected/test_output_proxy_standard.c: Add the headers and the get_all functions to the expected output * nih-dbus-tool/tests/expected/test_output_proxy_standard.h: Add the headers, properties structure and get_all function prototypes to the expected output * nih-dbus-tool/tests/expected/test_output_object_standard.c, * nih-dbus-tool/tests/expected/test_output_object_standard.h, * nih-dbus-tool/tests/expected/test_output_object_no_interfaces.c, * nih-dbus-tool/tests/expected/test_output_object_no_interfaces.h, * nih-dbus-tool/tests/expected/test_output_proxy_no_interfaces.c: * nih-dbus-tool/tests/expected/test_output_proxy_no_interfaces.h: Add the headers to the expected output * nih/test_files.h (TEST_EXPECTED_STR): Don't just compare the start of the string, make sure we compare the whole string - easiest way is to check the length first (TEST_EXPECTED_FILE): Make sure the files are the same length * nih-dbus-tool/node.c (node_proxy_functions): If there are properties, include the async and sync versions of the get_all function. These define all the property structs, so the only ones we need are the write-only ones. * nih-dbus-tool/tests/test_node.c (test_proxy_functions): Add the expected externs, prototypes, typedefs and structs for the get_all function. * nih-dbus-tool/tests/expected/test_node_proxy_functions_standard.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_no_methods.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_no_signals.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_only_properties.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_structure.c: Add the "get_all" function expected output. 2009-06-29 Scott James Remnant * nih/test_files.h (TEST_EXPECTED_STR): Display the full original string, not just the first part. * nih-dbus-tool/interface.c (interface_proxy_get_all_function) (interface_proxy_get_all_notify_function) (interface_proxy_get_all_sync_function): Add functions to generate proxy methods that get all of the properties of the given interface, returned as members of a structure. * nih-dbus-tool/interface.h: Add prototypes. * nih-dbus-tool/tests/interface_factory.c: Call the new functions to generate other functions that we can test * nih-dbus-tool/tests/interface_code.h: Expected structure definitions, typedefs and prototypes for generated code. * nih-dbus-tool/tests/test_interface.c (test_proxy_get_all_function) (test_proxy_get_all_notify_function) (test_proxy_get_all_sync_function): Test both the generator functions themselves and the code that they generate. * nih-dbus-tool/tests/expected/test_interface_proxy_get_all_function_standard.c, * nih-dbus-tool/tests/expected/test_interface_proxy_get_all_notify_function_standard.c, * nih-dbus-tool/tests/expected/test_interface_proxy_get_all_notify_function_structure.c, * nih-dbus-tool/tests/expected/test_interface_proxy_get_all_sync_function_standard.c, * nih-dbus-tool/tests/expected/test_interface_proxy_get_all_sync_function_structure.c: Expected output from generators * nih-dbus-tool/Makefile.am (check_PROGRAMS): Build the interface factory binary (test_interface_SOURCES): Depend on the header file (nodist_test_interface_SOURCES): Build and link the generated source (test_interface_LDADD): Need to link to libnih-dbus.la (interface_factory_SOURCES, interface_factory_LDFLAGS) (interface_factory_LDADD, tests/interface_code.c): Details to build interface factory binary (CLEANFILES): Make sure we clean up (EXTRA_DIST): Distribute expected files 2009-06-28 Scott James Remnant * nih/test_files.h (TEST_EXPECTED_STR, TEST_EXPECTED_FILE): It's getting increasingly annoying to have very large strings containing C source which we compare, add a couple of macros to let us compare a string or file against the contents of a file under tests/expected * nih-dbus-tool/tests/test_method.c, * nih-dbus-tool/tests/test_signal.c, * nih-dbus-tool/tests/test_property.c, * nih-dbus-tool/tests/test_node.c, * nih-dbus-tool/tests/test_output.c: Cut out the embedded C source into separate files * nih-dbus-tool/tests/expected/test_method_object_function_standard.c, * nih-dbus-tool/tests/expected/test_method_object_function_no_input.c, * nih-dbus-tool/tests/expected/test_method_object_function_no_output.c, * nih-dbus-tool/tests/expected/test_method_object_function_structure_input.c, * nih-dbus-tool/tests/expected/test_method_object_function_structure_output.c, * nih-dbus-tool/tests/expected/test_method_object_function_no_args.c, * nih-dbus-tool/tests/expected/test_method_object_function_async.c, * nih-dbus-tool/tests/expected/test_method_object_function_deprecated.c, * nih-dbus-tool/tests/expected/test_method_reply_function_standard.c, * nih-dbus-tool/tests/expected/test_method_reply_function_no_args.c, * nih-dbus-tool/tests/expected/test_method_reply_function_structure.c, * nih-dbus-tool/tests/expected/test_method_reply_function_array.c, * nih-dbus-tool/tests/expected/test_method_reply_function_deprecated.c, * nih-dbus-tool/tests/expected/test_method_proxy_function_standard.c, * nih-dbus-tool/tests/expected/test_method_proxy_function_no_args.c, * nih-dbus-tool/tests/expected/test_method_proxy_function_structure.c, * nih-dbus-tool/tests/expected/test_method_proxy_function_array.c, * nih-dbus-tool/tests/expected/test_method_proxy_function_deprecated.c, * nih-dbus-tool/tests/expected/test_method_proxy_notify_function_standard.c, * nih-dbus-tool/tests/expected/test_method_proxy_notify_function_no_args.c, * nih-dbus-tool/tests/expected/test_method_proxy_notify_function_structure.c, * nih-dbus-tool/tests/expected/test_method_proxy_notify_function_array.c, * nih-dbus-tool/tests/expected/test_method_proxy_sync_function_standard.c, * nih-dbus-tool/tests/expected/test_method_proxy_sync_function_no_input.c, * nih-dbus-tool/tests/expected/test_method_proxy_sync_function_no_output.c, * nih-dbus-tool/tests/expected/test_method_proxy_sync_function_no_args.c, * nih-dbus-tool/tests/expected/test_method_proxy_sync_function_structure_input.c, * nih-dbus-tool/tests/expected/test_method_proxy_sync_function_structure_output.c, * nih-dbus-tool/tests/expected/test_method_proxy_sync_function_array_input.c, * nih-dbus-tool/tests/expected/test_method_proxy_sync_function_deprecated.c, * nih-dbus-tool/tests/expected/test_signal_object_function_standard.c, * nih-dbus-tool/tests/expected/test_signal_object_function_no_args.c, * nih-dbus-tool/tests/expected/test_signal_object_function_structure.c, * nih-dbus-tool/tests/expected/test_signal_object_function_array.c, * nih-dbus-tool/tests/expected/test_signal_object_function_deprecated.c, * nih-dbus-tool/tests/expected/test_signal_proxy_function_standard.c, * nih-dbus-tool/tests/expected/test_signal_proxy_function_no_args.c, * nih-dbus-tool/tests/expected/test_signal_proxy_function_structure.c, * nih-dbus-tool/tests/expected/test_signal_proxy_function_deprecated.c, * nih-dbus-tool/tests/expected/test_property_object_get_function_standard.c, * nih-dbus-tool/tests/expected/test_property_object_get_function_structure.c, * nih-dbus-tool/tests/expected/test_property_object_get_function_deprecated.c, * nih-dbus-tool/tests/expected/test_property_object_set_function_standard.c, * nih-dbus-tool/tests/expected/test_property_object_set_function_structure.c, * nih-dbus-tool/tests/expected/test_property_object_set_function_deprecated.c, * nih-dbus-tool/tests/expected/test_property_proxy_get_function_standard.c, * nih-dbus-tool/tests/expected/test_property_proxy_get_function_deprecated.c, * nih-dbus-tool/tests/expected/test_property_proxy_get_notify_function_standard.c, * nih-dbus-tool/tests/expected/test_property_proxy_get_notify_function_structure.c, * nih-dbus-tool/tests/expected/test_property_proxy_get_notify_function_deprecated.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_function_standard.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_function_structure.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_function_array.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_function_deprecated.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_notify_function_standard.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_notify_function_deprecated.c, * nih-dbus-tool/tests/expected/test_property_proxy_get_sync_function_standard.c, * nih-dbus-tool/tests/expected/test_property_proxy_get_sync_function_structure.c, * nih-dbus-tool/tests/expected/test_property_proxy_get_sync_function_deprecated.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_sync_function_standard.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_sync_function_structure.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_sync_function_array.c, * nih-dbus-tool/tests/expected/test_property_proxy_set_sync_function_deprecated.c, * nih-dbus-tool/tests/expected/test_node_interfaces_array_object.c, * nih-dbus-tool/tests/expected/test_node_interfaces_array_proxy.c, * nih-dbus-tool/tests/expected/test_node_interfaces_array_none.c, * nih-dbus-tool/tests/expected/test_node_object_functions_standard.c, * nih-dbus-tool/tests/expected/test_node_object_functions_no_methods.c, * nih-dbus-tool/tests/expected/test_node_object_functions_no_signals.c, * nih-dbus-tool/tests/expected/test_node_object_functions_no_properties.c, * nih-dbus-tool/tests/expected/test_node_object_functions_only_properties.c, * nih-dbus-tool/tests/expected/test_node_object_functions_structure.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_standard.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_no_methods.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_no_signals.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_no_properties.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_only_properties.c, * nih-dbus-tool/tests/expected/test_node_proxy_functions_structure.c, * nih-dbus-tool/tests/expected/test_output_proxy_standard.c, * nih-dbus-tool/tests/expected/test_output_proxy_standard.h, * nih-dbus-tool/tests/expected/test_output_proxy_no_interfaces.c, * nih-dbus-tool/tests/expected/test_output_proxy_no_interfaces.h, * nih-dbus-tool/tests/expected/test_output_object_standard.c, * nih-dbus-tool/tests/expected/test_output_object_standard.h, * nih-dbus-tool/tests/expected/test_output_object_no_interfaces.c, * nih-dbus-tool/tests/expected/test_output_object_no_interfaces.h: Expected output texts * nih-dbus-tool/Makefile.am (EXTRA_DIST): Distribute the expected source files * nih-dbus-tool/output.c (output): Pass a structs list to calls to node_output_functions() and node_proxy_functions() and place the formatted output in the header file before the typedefs. * nih-dbus-tool/tests/test_output.c (test_output): Make sure we test having a structure in both proxy and object mode. * nih-dbus-tool/node.c (node_object_functions) (node_proxy_functions): Call the various function generators with a structs list, which we copy up into our own new structs argument. * nih-dbus-tool/node.h: Add structs arguments to prototypes * nih-dbus-tool/tests/test_node.c (test_object_functions) (test_proxy_functions): Pass the structs argument in; make sure the structures are passed back as well without duplicating the definitions when we have multiple functions that declare them. 2009-06-26 Scott James Remnant * nih-dbus-tool/property.c (property_object_get_function) (property_object_set_function) (property_proxy_get_notify_function) (property_proxy_set_function, property_proxy_get_sync_function) (property_proxy_set_sync_function): Call marshal() and demarshal() with the extra arguments, obtaining most of them from our arguments including the Interface and Property structures. Copy back the list of structures returned into a new structs argument that these functions accept. (property_proxy_get_function) (property_proxy_set_notify_function): Add the extra structs argument for consistency, though we don't do anything with it * nih-dbus-tool/property.h: Update prototypes to add new argument * nih-dbus-tool/tests/test_property.c (test_object_get_function) (test_object_set_function, test_proxy_get_notify_function) (test_proxy_set_function, test_proxy_get_sync_function) (test_proxy_set_sync_function): Pass in the structs array, add tests to make sure that members of this array are passed back when the property is a structure (test_proxy_get_function, test_proxy_set_notify_function): Pass in the structs array, no need to tests passing back because none ever will be, * nih-dbus-tool/tests/property_factory.c: Pass expected structs list when generating the code. * nih-dbus-tool/symbol.c (symbol_typedef): Allow the postfix to be NULL (property structures) * nih-dbus-tool/tests/test_symbol.c (test_typedef): Add tests for without postfix with/without other arguments. * nih-dbus-tool/signal.c (signal_object_function) (signal_proxy_function): Call marshal() and demarshal() with the extra arguments, obtaining most of them from our arguments including the Interface and Signal structures. Copy back the list of structures returned into a new structs argument that these functions accept. * nih-dbus-tool/signal.h: Update prototypes to add new argument * nih-dbus-tool/tests/test_signal.c (test_object_function) (test_proxy_function): Pass in the structs array, add tests to make sure that members of this array are passed back when the signal has structure arguments * nih-dbus-tool/tests/signal_factory.c: Pass expected structs list when generating the code. * nih-dbus-tool/method.c (method_object_function) (method_reply_function, method_proxy_function) (method_proxy_notify_function, method_proxy_sync_function): Call marshal() and demarshal() with the extra arguments, obtaining most of them from our arguments including the Interface and Method structures. Copy back the list of structures returned into a new structs argument that these functions accept. * nih-dbus-tool/method.h: Update prototypes to add new argument * nih-dbus-tool/tests/test_method.c (test_object_function) (test_reply_function, test_proxy_function) (test_proxy_notify_function, test_proxy_sync_function): Pass in the structs array, add tests to make sure that members of this array are passed back when the method has array arguments * nih-dbus-tool/tests/method_factory.c: Pass expected structs list when generating the code. * nih-dbus-tool/demarshal.c (demarshal_struct): Generate the structure name using symbol_typedef() rather than expecting type_of() to do it for us. To do this we need extra arguments giving us the interface, member and variable symbol names. Create a TypeStruct for it, adding members as we go, and return it via the extra structs list. (demarshal_array): Take the same extra arguments as demarshal_struct() so we can support arrays of structures, pass them to our recursive demarshal() call and make sure we pass structs back up. Create a custom symbol for the structure array, so that it becomes "PrefixInterfaceMemberArgElement". (demarshal_basic): Take the extra arguments for consistency, though we don't do anything with them. (demarshal): Take the extra arguments, pass down to the static functions. * nih-dbus-tool/demarshal.h: Update prototypes. * nih-dbus-tool/tests/test_demarshal.c (test_demarshal): Pass in strings and structs list, check the structs list contents on the way out * nih-dbus-tool/tests/demarshal_factory.c (demarshal_function): Pass expected structs and structs list when generating the code. * nih-dbus-tool/tests/demarshal_code.h: Changes required in the name of the expected structures * nih-dbus-tool/Makefile.am (demarshal_factory_LDADD): Link to symbol * nih-dbus-tool/marshal.c (marshal_struct): Generate the structure name using symbol_typedef() rather than expecting type_of() to do it for us. To do this we need extra arguments giving us the interface, member and variable symbol names. Create a TypeStruct for it, adding members as we go, and return it via the extra structs list. (marshal_array): Take the same extra arguments as marshal_struct() so we can support arrays of structures, pass them to our recursive marshal() call and make sure we pass structs back up. Create a custom symbol for the structure array, so that it becomes "PrefixInterfaceMemberArgElement". (marshal_basic): Take the extra arguments for consistency, though we don't do anything with them. (marshal): Take the extra arguments, pass down to the static functions. * nih-dbus-tool/marshal.h: Update prototypes. * nih-dbus-tool/tests/test_marshal.c (test_marshal): Pass in strings and structs list, check the structs list contents on the way out * nih-dbus-tool/tests/marshal_factory.c (marshal_function): Pass expected structs and structs list when generating the code. * nih-dbus-tool/tests/marshal_code.h: Changes required in the name of the expected structures * nih-dbus-tool/Makefile.am (marshal_factory_LDADD): Link to symbol * nih-dbus-tool/type.c (type_of): Simplify type_of() so that it only works for basic types. * nih-dbus-tool/tests/test_type.c (test_of): Remove complex types * nih-dbus-tool/type.h (TypeStruct): Add another type for structure definitions, we need to know the name and a list of members. * nih-dbus-tool/type.c (type_struct_new, type_struct_to_string): Function to allocate the new type and convert it to a string definition. * nih-dbus-tool/tests/test_type.c (test_struct_new) (test_struct_to_string): Add tests for the two new functions. * nih-dbus-tool/Makefile.am (test_type_LDADD): Link to indent & symbol (test_marshal_LDADD, test_demarshal_LDADD): These need to link to symbol as well. * nih-dbus/dbus_proxy.h: Since we use INT_MAX in a macro, we need to include limits.h 2009-06-23 Scott James Remnant * COPYING: Change licence to version 2 of the GNU GPL. All files have been updated to reflect this. 2009-06-21 Scott James Remnant * configure.ac: Bump version to 0.3.1 * NEWS: Begin new release. 2009-06-17 Scott James Remnant * NEWS: Release 0.3.0 * nih-dbus-tool/tests/test_interface.c (test_annotation): Add test case for an empty symbol annotation * nih-dbus-tool/interface.c (interface_annotation): Explicitly allow the symbol to be empty * configure.ac: Bump version up to 0.3.0, I think the nih-dbus-tool changes are enough to warrant it * nih/tests/test_error.c (test_pop_context): Initialise pid to avoid gcc issue where it believes the value can be uninitialised (test_raise_error): Initialise errors and pid. * nih-dbus/tests/test_dbus_connection.c (test_connect): Initialise variables allocated inside test constructs. * nih-dbus/tests/test_dbus_message.c (test_message_error): Initialise variables * nih-dbus/tests/test_dbus_proxy.c (test_name_owner_changed): More initialisation * nih-dbus-tool/tests/test_main.c (test_mode_option): Have to initialise ret. * nih-dbus-tool/tests/test_node.c (test_start_tag): And another * nih-dbus-tool/tests/test_interface.c (test_start_tag): One more * nih-dbus-tool/tests/test_method.c (test_start_tag) (test_end_tag, test_annotation): Bunch more ret initialises. (test_object_function, test_reply_function, test_proxy_function) (test_proxy_notify_function): Various other variables * nih-dbus-tool/tests/test_signal.c (test_start_tag): Another ret * nih-dbus-tool/tests/test_property.c (test_object_get_function) (test_object_set_function, test_proxy_get_notify_function) (test_proxy_set_notify_function): More miscellaneous ones * nih-dbus-tool/tests/test_argument.c (test_start_tag): Another ret * nih-dbus-tool/tests/test_annotation.c (test_start_tag): Yet another * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c: Even more in this one. * nih-dbus-tool/method.c (method_object_function): Don't translate the string we return to the caller. * nih-dbus-tool/property.c (property_object_set_function): Likewise don't translate. * nih-dbus-tool/tests/test_method.c (test_object_function): Update expected output in tests. * nih-dbus-tool/tests/test_property.c (test_object_set_function): Likewise * nih-dbus-tool/tests/test_node.c (test_object_functions): Likewise * nih-dbus-tool/tests/test_output.c (test_output): Likewise. * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c: Too many to count in this source file * nih-dbus-tool/Makefile.am (test_com_netsplit_Nih_Test_object_SOURCES) (test_com_netsplit_Nih_Test_proxy_SOURCES): Finally decided that we're not going to ship these built sources, we'd just regenerate them every build anyway because nih-dbus-tool will have changed. Make them nodist. (AM_CPPFLAGS): Which means we also need to include files from the build directory, as well as the source directory (BUILT_SOURCES): Change explanation of why it's in built sources (CLEANFILES): Clean after build. * nih/tests/test_error.c (test_raise_error, test_pop_context): Unlink the core file after the assert tests. * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.c, * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c, * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c: #include quoted paths will only look in the source directory or current working directory, for out of tree builds the current working directory won't contain the header so we need to prefix with tests/ so we can lookup from the source directory * nih-dbus-tool/tests/marshal_factory.c, * nih-dbus-tool/tests/demarshal_factory.c, * nih-dbus-tool/tests/method_factory.c, * nih-dbus-tool/tests/signal_factory.c, * nih-dbus-tool/tests/property_factory.c: Update generated code to prefix includes with tests/ * nih/tests/test_error.c (test_raise_error, test_pop_context): Make sure we don't expect the filename to be always relative, e.g. out-of-tree builds. 2009-06-16 Scott James Remnant * nih-dbus-tool/marshal.c (marshal_array, marshal_struct): In the array of structures situation, we can't just close the container because it's not been completed - instead we use the new abandon function to free the resources while hosing the message. * nih-dbus-tool/property.c (property_object_get_function) (property_proxy_set_function, property_proxy_set_sync_function): Likewise abandon the variant container, strictly speaking probably not required but worthwhile for consistenc * nih-dbus-tool/tests/test_marshal.c (test_marshal): Update the output checks to match * nih-dbus-tool/tests/test_method.c (test_object_function) (test_proxy_function, test_proxy_sync_function): More output updates * nih-dbus-tool/tests/test_signal.c (test_object_function): Update the output check * nih-dbus-tool/tests/test_property.c (test_object_get_function) (test_proxy_set_function, test_proxy_set_sync_function): Yet more * nih-dbus-tool/tests/test_node.c (test_object_functions) (test_proxy_functions): More output updates. * nih-dbus-tool/tests/test_output.c (test_output): Also update the top-level output * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.c: Update the property functions to raise the no memory error where appropriate, also include code to return D-Bus and generic errors for testing. * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c (test_get_byte) (test_get_boolean, test_get_int16, test_get_uint16) (test_get_int32, test_get_uint32, test_get_int64) (test_get_uint64, test_get_string, test_get_object_path) (test_get_signature, test_get_int32_array, test_get_str_array) (test_get_int32_array_array): Add tests for the get function returning an D-Bus error and a generic error. * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c (test_get_byte) (test_get_boolean, test_get_int16, test_get_uint16, test_get_int32) (test_get_uint32, test_get_int64, test_get_uint64, test_get_double) (test_get_string, test_get_object_path, test_get_signature) (test_get_int32_array, test_get_int32_array_array): Add D-Bus error and generic error test cases to the async functions, making sure that the error handler is raised. (test_get_byte_sync, test_get_boolean_sync, test_get_int16_sync) (test_get_uint16_sync, test_get_int32_sync) (test_get_uint32_sync, test_get_int64_sync) (test_get_uint64_sync, test_get_double_sync, test_get_string_sync) (test_get_object_path_sync, test_get_signature_sync) (test_get_int32_array_sync, test_get_str_array_sync) (test_get_int32_array_array_sync): Also add D-Bus and generic error test cases to the sync functions, which are slightly harder to test because of the need for a separate server process; still, this tests the error return code. * nih-dbus-tool/tests/test_node.c (test_object_functions): Update the output tests to expect the error raises. * nih-dbus-tool/tests/test_output.c (test_output): Update the output tests to match as well. * nih-dbus-tool/property.c (property_object_get_function): Raise the no memory error when we return. * nih-dbus-tool/tests/test_property.c (test_object_get_function): Make sure that the output matches, and test the generated function with normal output, out of memory, dbus error and generic error returns. * nih-dbus/dbus_object.c (nih_dbus_object_property_get): It makes sense to be able to return an error when getting a property, at the very least it might be a PolicyKit authorisation error. (nih_dbus_object_property_get_all): If we get an error while getting any property, we have to return that error to the user, such is the manner in which D-Bus messages have to be built. * nih-dbus/tests/test_dbus_object.c (test_object_property_get): Update function to test for property getter functions returning errors. (test_object_property_get_all): Include a couple of test cases here too. * TODO (dbus): Update on no_reply, still not completely clear what we should do with this annotation as the results are surprising * nih-dbus-tool/method.c (method_end_tag): Ignore the NoReply annotation if the method has output arguments; ignore the Async annotation if the method is NoReply. * nih-dbus-tool/tests/test_method.c (test_end_tag): Make sure the annotations are amended and warnings emitted as appropriate. * nih-dbus-tool/node.c (node_object_functions): Don't generate reply functions for non-async method implementations * nih-dbus-tool/tests/test_node.c (test_object_functions): Make the peek method async so that's the only one that should have a reply function. Also add an output value to another method to check ordinary return values. * nih-dbus-tool/tests/test_output.c (test_output): Apply the same changes to this test as well. * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c: Turns out I was using the wrong timeout value everywhere, this is why macros are useful -- replace the wrong "0" with NIH_DBUS_TIMEOUT_DEFAULT * nih-dbus/dbus_proxy.h (NIH_DBUS_TIMEOUT_DEFAULT) (NIH_DBUS_TIMEOUT_NEVER): Add macros so we don't have to remember what the timeout magic numbers are * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c: Use TEST_FUNCTION with proper function names instead of TEST_GROUP 2009-06-15 Scott James Remnant * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.h, * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.c, * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c, * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c: Completely rewrite these tests using TEST_DBUS, making sure we test as much of the newly generated code as possible. * nih-dbus-tool/tests/com.netsplit.Nih.Test.xml: Various slight updates to better test the newer code; add arrays of arrays to the tests; rename "data" to "value" to avoid clash with data argument; remove the glue we won't use it anymore. * nih-dbus-tool/Makefile.am ($(com_netsplit_Nih_Test_proxy_OUTPUTS)): Use "proxy" as the prefix again, "your" just looks silly. * nih-dbus-tool/type.c (type_strcat_assert): And now the other corner case we found, size arrays can be NULL if the first element of the array is NULL. * nih-dbus-tool/tests/test_type.c (test_strcat_assert): Add tests * nih-dbus-tool/method.c (method_reply_function) (method_proxy_function, method_proxy_sync_function), * nih-dbus-tool/signal.c (signal_object_function), * nih-dbus-tool/property.c (property_proxy_set_function) (property_proxy_set_sync_function): Think-o, we can't look at the previous iterated we have to look at the last function argument * nih-dbus-tool/type.c (type_strcat_assert): We're starting to get a lot of corner cases in that simple assert block, separate it out so we don't have to repeatedly get it wrong. * nih-dbus-tool/type.h: Add prototype * nih-dbus-tool/tests/test_type.c (test_strcat_assert): The all important tests. * nih-dbus-tool/method.c (method_reply_function) (method_proxy_function, method_proxy_sync_function): Use the new function. * nih-dbus-tool/signal.c (signal_object_function): Likewise. * nih-dbus-tool/property.c (property_proxy_set_function) (property_proxy_set_sync_function): Likewise. * nih-dbus-tool/method.c (method_reply_function) (method_proxy_function, method_proxy_sync_function): Input array arguments of basic types (those with a size_t argument following) may be NULL if that size_t argument is zero. Check for this when adding asserts. * nih-dbus-tool/tests/test_method.c (test_reply_function) (test_proxy_function, test_proxy_sync_function): Add test cases for an array input argument to make sure we generate the right assert * nih-dbus-tool/signal.c (signal_object_function): Needs exactly the same patch * nih-dbus-tool/tests/test_signal.c (test_object_function): Add the test case for this one too. * nih-dbus-tool/property.c (property_proxy_set_function) (property_proxy_set_sync_function): We also need the same patch for this one too. * nih-dbus-tool/tests/test_property.c (test_proxy_set_function) (test_proxy_set_sync_function): And test as well 2009-06-14 Scott James Remnant * nih-dbus/dbus_proxy.c (nih_dbus_proxy_connect): Total thinko with the API; I'd expected the signal structures to be public, but we don't generally want that. Better just to take a signal name. * nih-dbus/dbus_proxy.h: Update prototype. * nih-dbus/tests/test_dbus_proxy.c (test_connect): Update tests (test_signal_destroy): Also update this one * nih-dbus-tool/tests/test_signal.c (test_proxy_function): Also update 2009-06-13 Scott James Remnant * nih-dbus-tool/output.c (output): Need dbus_pending_data.h in the header too for the error handler typedef. * nih-dbus-tool/tests/test_output.c (test_output): Add to tests 2009-06-11 Scott James Remnant * nih-dbus-tool/tests/test_output.c (test_output): We want an extra line between extern variables and functions, but only when there are both. * nih-dbus-tool/output.c (output): Adjust the code to make that so * nih/child.h, * nih/io.h, * nih/logging.h, * nih/main.h, * nih/signal.h: Make sure we prefix variables with "extern" * nih-dbus-tool/node.c (node_interfaces_array): Make the structure prototypes that we export "extern", since they go in the header file. * nih-dbus-tool/tests/test_node.c (test_interfaces_array): Make sure that the returned variable types all include "extern" in the lists, but not in the output. * nih-dbus-tool/tests/test_output.c (test_output): Update the output checks of the headers to expect extern in front of variables. 2009-06-10 Scott James Remnant * nih-dbus-tool/signal.c (signal_proxy_function): Eliminate the proxy passthrough and use proxied members directly. * nih-dbus-tool/tests/test_signal.c (test_proxy_function): Update expected output of tests to match. * nih-dbus-tool/tests/test_node.c (test_proxy_functions): Update expected output. * nih-dbus-tool/tests/test_output.c (test_output): Update as well * nih-dbus-tool/tests/test_signal.c (test_proxy_function): Pass the extra arguments to nih_dbus_proxy_connect(), which means we actually move the data pointer to the connect call now. * nih-dbus/dbus_proxy.h (NihDBusProxySignal): Rather than reference the proxy itself, copy the members that we want out of it. * nih-dbus/dbus_proxy.c (nih_dbus_proxy_connect): Accept a parent argument, as well as a separate data argument, copy the members from proxy into the object, taking a reference to the connection as we do so. (nih_dbus_proxy_signal_destroy): Don't forget to unref the connection (nih_dbus_proxy_signal_rule): Take members directly * nih-dbus/tests/test_dbus_proxy.c (test_connect): Call the function with the two new arguments, update tests to check for the new members (test_signal_destroy): Call with the two new arguments. * nih-dbus-tool/property.c (property_proxy_set_sync_function): Add a parent argument to the methods, even though we never use it; otherwise it's irritatingly inconsistent with methods and property get functions. * nih-dbus-tool/tests/property_code.h: Adjust the expected prototype * nih-dbus-tool/tests/test_property.c (test_proxy_set_sync_function): Adjust expected output to include the parent argument * nih-dbus-tool/tests/test_node.c (test_proxy_functions): Update expected output to match * nih-dbus-tool/tests/test_output.c (test_output): Update as well * nih-dbus/dbus_proxy.h (NihDBusSignalhandler): Remove the proxy argument. * nih-dbus/tests/test_dbus_proxy.c (my_signal_handler): Remove the argument from here too * nih-dbus-tool/signal.c (signal_proxy_function): Don't pass the proxy to the signal handler function; we don't pass it for method or property reply handlers because we don't have it, it's inconsitent to pass it here as well - we can always make a new proxy for the origin after all. * nih-dbus-tool/tests/signal_code.h: Update typedef * nih-dbus-tool/tests/test_signal.c (test_proxy_function): Update the tests * nih-dbus-tool/tests/test_node.c (test_proxy_functions): Update expected output * nih-dbus-tool/tests/test_output.c (test_output): Update expected output. * nih-dbus-tool/method.c (method_proxy_notify_function): Symbol name for a notify function should be implementation, it's static (method_proxy_function): Call with the implementation name * nih-dbus-tool/tests/method_code.h: Update name of notify function we expect to be generated * nih-dbus-tool/tests/method_factory.c: Updadate the name of the notify function we'll supply in the test * nih-dbus-tool/tests/test_method.c (test_proxy_notify_function): Rename notify function in output and when we call it (test_proxy_function): Rename notify function in output * nih-dbus-tool/tests/test_node.c (test_proxy_functions): Update expected output * nih-dbus-tool/tests/test_output.c (test_output): Update expected output * NEWS: Update * TODO: Update * nih-dbus-tool/tests/com.netsplit.Nih.Test.xml: Update to newer XML format, using annotations instead of namespaces. Add a couple of extra tests cases, and in particular add properties. * nih-dbus-tool/Makefile.am ($(com_netsplit_Nih_Test_object_OUTPUTS)): ($(com_netsplit_Nih_Test_proxy_OUTPUTS)): Use the C version of the nih-dbus-tool to generate the output; currently not compatible with the tests, but should generate good code. Be sure to make the output directory first (out of tree builds) (nodist_test_marshal_SOURCES, nodist_test_demarshal_SOURCES) (nodist_test_method_SOURCES, nodist_test_signal_SOURCES) (nodist_test_property_SOURCES): We don't want to distribute the *_code.c files so move them into a nodist prefixed (MAINTAINERCLEANFILES): BUILT_SOURCES are always maintainer-clean, so drop this (EXTRA_DIST): Sources are always distributed, so drop the outputs from this leaving only the XML (tests/marshal_code.c, tests/demarshal_code.c) (tests/method_code.c, tests/signal_code.c) (tests/property_code.c): Drop the temporary output, no need for it (CLEANFILES): Specify by expanding the nodist_*_SOURCES variables * nih-dbus-tool/nih_dbus_tool.py: Drop the python version * TODO: Update. * nih-dbus-tool/main.c: Actually output the source and header files * nih-dbus-tool/main.c: Generate the source and header paths earlier, using an nih_local string so we don't have to free. Make sure we close the input file descriptor. Don't put meaningless content into the errors we output. * nih-dbus-tool/main.c (mode_option): Rather than set a random enum, just use TRUE/FALSE as the output and node methods do. * nih-dbus-tool/tests/test_main.c (test_mode_option): Update. * nih-dbus-tool/man/nih-dbus-tool.1: Make a start on a man page for the tool. * nih-dbus-tool/output.c (output): Primary function to output C source and header files for a node in either object or proxy mode. (output_preamble): Support function to generate the preamble comment (output_sentinel): Support function to generate the header sentinel (output_write): Support file to write out to the file descriptor * nih-dbus-tool/output.h: Headers * nih-dbus-tool/tests/test_output.c: Tests for the code * nih-dbus-tool/Makefile.am (nih_dbus_tool_SOURCES): Compile and link the new source file (TESTS): Run the new tests (test_output_SOURCES, test_output_LDFLAGS, test_output_LDADD): Details for the new tests * nih-dbus-tool/type.c (type_func_to_typedef, type_func_layout): Use type_var_to_string instead of doing things by hand. * nih-dbus-tool/tests/test_type.c (test_func_layout): Noticed that I have no test cases for no arguments or returning void, extend the existing cases. * nih-dbus-tool/type.c (type_func_layout): Glad I did that - I didn't cope with no arguments. * nih-dbus-tool/type.c (type_func_to_typedef): We need to be able to lay typedefs out individually, thus add this function. * nih-dbus-tool/type.h: Add prototype * nih-dbus-tool/tests/test_type.c (test_func_to_typedef): Add tests 2009-06-09 Scott James Remnant * nih-dbus-tool/node.c (node_object_functions) (node_proxy_functions): Implement functions that call all the necessary other functions to return C code for a node's object or proxy implementations. * nih-dbus-tool/node.h: Add prototypes. * nih-dbus-tool/tests/test_node.c (test_object_functions) (test_proxy_functions): Test cases for the functions. 2009-06-04 Scott James Remnant * nih-dbus-tool/main.c: Change the default output mode to proxy, which makes a bit more sense for the majority case. * nih-dbus-tool/signal.c (signal_proxy_function): Name the signal functions _signal to match _method * nih-dbus-tool/tests/signal_code.h: Update to match * nih-dbus-tool/tests/test_signal.c (test_proxy_function): Update * nih-dbus-tool/node.c (node_interfaces_array): The last member should be just NULL, it's an array of pointers. * nih-dbus-tool/tests/test_node.c (test_interfaces_array): Adjust test case output to match. * nih-dbus/dbus_object.c (nih_dbus_object_introspect): Cope with name-less arguments. * nih-dbus/tests/test_dbus_object.c (test_object_introspect): Update input and expected return string. * nih-dbus-tool/interface.c (interface_end_tag): If the symbol is given as "", set it to NULL. * nih-dbus-tool/tests/test_interface.c (test_end_tag): Add a test case for the empty symbol. * nih-dbus-tool/node.c (node_interfaces_array): Generate the array of interfaces for a given node. * nih-dbus-tool/node.h: Add prototype. * nih-dbus-tool/tests/test_node.c (test_interfaces_array): Add tests for the new function * nih-dbus-tool/interface.c (interface_methods_array) (interface_signals_array, interface_properties_array): Return the prototype with the name set, and thus don't return a static argument array. (interface_struct): Rewrite to reuse the name and insert the static * nih-dbus-tool/interface.h: Update prototypes * nih-dbus-tool/tests/test_interface.c (test_methods_array) (test_signals_array, test_properties_array): Adjust to match * nih-dbus-tool/interface.c (interface_methods_array) (interface_signals_array): Restructure to expect prototypes to be returned from the args array functions, using that to get the name of those and generally making things a bit more readable. Make static along the way too. * nih-dbus-tool/tests/test_interface.c (test_struct): Make sure the returned items aren't arrays. * nih-dbus-tool/signal.c (signal_args_array): Return the prototype with the name set, and thus don't return a static argument array. * nih-dbus-tool/signal.h: Update prototype * nih-dbus-tool/tests/test_signal.c (test_args_array): Adjust to match * nih-dbus-tool/method.c (method_args_array): Return the prototype with the name set, and thus don't return a static argument array. * nih-dbus-tool/method.h: Update prototype * nih-dbus-tool/tests/test_method.c (test_args_array): Adjust to match * nih-dbus-tool/type.h (type_var): Add an array member. * nih-dbus-tool/type.c (type_var_new): Initialise array to FALSE. (type_var_to_string, type_var_layout): Append [] if the var is an array * nih-dbus-tool/tests/test_type.c (test_var_new): Check array is FALSE (test_var_to_string, test_var_layout): Add checks for array * nih-dbus-tool/interface.c (interface_struct): Generate a structure variable for an interface, along with the members code. * nih-dbus-tool/interface.h: Add prototype * nih-dbus-tool/tests/test_interface.c (test_struct): Tests. 2009-06-03 Scott James Remnant * nih-dbus-tool/method.c (method_args_array): Add missing NihDBusArg * nih-dbus-tool/tests/test_method.c (test_args_array): Update expected test output * nih-dbus-tool/signal.c (signal_args_array): Add missing NihDBusArg * nih-dbus-tool/tests/test_signal.c (test_args_array): Update expected test output * nih-dbus-tool/interface.c (interface_methods_array) (interface_signals_array, interface_properties_array): Add missing NihDBusMethod, NihDBusSignal and NihDBusProperty type names. * nih-dbus-tool/tests/test_interface.c (test_methods_array) (test_signals_array, test_properties_array): Update expected test output * nih-dbus-tool/interface.c (interface_properties_array): Generate the array of properties for an interface * nih-dbus-tool/interface.h: Add prototype * nih-dbus-tool/tests/test_interface.c (test_properties_array): Tests * nih-dbus-tool/method.c (method_args_array): Use method_args instead of args to distinguish from signals. * nih-dbus-tool/tests/test_method.c (test_args_array): Update. * nih-dbus-tool/signal.c (signal_args_array): Use signal_args instead of args to distinguish from methods. * nih-dbus-tool/tests/test_signal.c (test_args_array): Update. * nih-dbus-tool/interface.c (interface_methods_array) (interface_signals_array): Update to match * nih-dbus-tool/tests/test_interface.c (test_methods_array) (test_signals_array): Also update. * nih-dbus-tool/interface.c (interface_signals_array): Generate the array of signals for an interface, including the arguments. * nih-dbus-tool/interface.h: Add prototype * nih-dbus-tool/tests/test_interface.c (test_signals_array): Tests. * nih-dbus-tool/interface.c (interface_methods_array): Generate the array of methods for an interface, including the arguments. * nih-dbus-tool/interface.h: Add prototype * nih-dbus-tool/tests/test_interface.c (test_methods_array): Tests. * nih-dbus-tool/signal.c (signal_args_array): Generate the array of arguments for a signal. * nih-dbus-tool/signal.h: Add prototype. * nih-dbus-tool/tests/test_signal.c (test_args_array): Tests. * nih-dbus-tool/method.c (method_args_array): Generate the array of arguments for a method. * nih-dbus-tool/method.h: Add prototype. * nih-dbus-tool/tests/test_method.c (test_args_array): Tests. * nih-dbus-tool/symbol.c (symbol_impl): Allow the symbol name and postfix to be NULL, as is the case for structure definitions. * nih-dbus-tool/tests/test_symbol.c (test_impl): Extend test cases to cover new cases. 2009-06-02 Scott James Remnant * nih-dbus-tool/property.c (property_object_get_function) (property_object_set_function, property_proxy_get_function) (property_proxy_get_notify_function) (property_proxy_set_function) (property_proxy_set_notify_function) (property_proxy_get_sync_function) (property_proxy_set_sync_function): Rather than accepting precanned names, accept prefix, interface and property and generate them every time. * nih-dbus-tool/property.h: Update prototypes. * nih-dbus-tool/tests/property_factory.c: Create an interface and pass it to the functions. * nih-dbus-tool/tests/property_code.h: Prototypes all change * nih-dbus-tool/tests/test_property.c: Update tests. * nih-dbus-tool/signal.c (signal_object_function) (signal_proxy_function): Rather than accepting precanned names, accept prefix, interface and signal and generate them every time * nih-dbus-tool/signal.h: Update prototypes. * nih-dbus-tool/tests/signal_factory.c: Create an interface and pass it to the functions * nih-dbus-tool/tests/signal_code.h: Filter function name changes as a result. * nih-dbus-tool/tests/test_signal.c: Update tests. * nih-dbus-tool/method.c (method_object_function) (method_reply_function, method_proxy_function) (method_proxy_notify_function, method_proxy_sync_function): Rather than accepting precanned names, accept prefix, interface and method and generate them every time. * nih-dbus-tool/method.h: Update prototypes. * nih-dbus-tool/tests/method_factory.c: Create an interface and pass it to the functions * nih-dbus-tool/tests/method_code.h: A couple of names of generated functions change as a result (becoming proper) * nih-dbus-tool/tests/test_method.c: Update tests * nih-dbus-tool/interface.c (interface_lookup_method): Move to method.c (interface_lookup_signal): Move to signal.c (interface_lookup_property): Move to property.c * nih-dbus-tool/interface.h: Also move prototypes * nih-dbus-tool/tests/test_interface.c: Also move test cases * nih-dbus-tool/method.c (interface_lookup_method): Rename to method_lookup * nih-dbus-tool/method.h: Update prototype. * nih-dbus-tool/tests/test_method.c (test_lookup_method): Rename to test_lookup * nih-dbus-tool/signal.c (interface_lookup_signal): Rename to signal_lookup * nih-dbus-tool/signal.h: Update prototype. * nih-dbus-tool/tests/test_signal.c (test_lookup_signal): Rename to test_lookup * nih-dbus-tool/property.c (interface_lookup_property): Rename to property_lookup * nih-dbus-tool/property.h: Update prototype * nih-dbus-tool/tests/test_property.c (test_lookup_property): Rename to test_lookup * nih-dbus/dbus_proxy.c (nih_dbus_proxy_name_owner_changed): Add missing DBUS_TYPE_INVALID sentinel to the dbus_message_get_args() call. 2009-05-29 Scott James Remnant * nih-dbus-tool/tests/test_node.c (test_lookup_interface): Extend test case to look for NULL * nih-dbus-tool/node.c (node_lookup_interface): Allow NULL symbol lookup, which returns an Interface with a NULL symbol (ie. the default). * nih-dbus-tool/symbol.c (symbol_impl, symbol_extern) (symbol_typedef): Name generation functions (symbol_strcat_interface, symbol_strcat_title): Utility functions used for the above * nih-dbus-tool/symbol.h: Add prototypes * nih-dbus-tool/tests/test_symbol.c (test_impl, test_extern) (test_typedef): Test cases for the new functions 2009-05-27 Scott James Remnant * nih-dbus-tool/method.c (method_proxy_sync_function): sync function returns an integer, so should not be malloc * nih-dbus-tool/tests/test_method.c (test_proxy_sync_function): Remove from tests as well * nih-dbus-tool/tests/test_method.c (test_proxy_sync_function): Do the child process stuff before creating the proxy, otherwise it holds a reference to the connection. * nih-dbus-tool/tests/test_property.c (test_proxy_get_sync_function) (test_proxy_set_sync_function): Likewise. 2009-05-26 Scott James Remnant * nih-dbus-tool/nih_dbus_tool.py: Rename conn to connection * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.c: Update conn to connection here too * nih-dbus-tool/tests/test_method.c, * nih-dbus-tool/tests/test_signal.c, * nih-dbus-tool/tests/test_property.c: Update variable names in test cases too * nih-dbus-tool/method.c, * nih-dbus-tool/signal.c, * nih-dbus-tool/property.c: Update accessor of message, proxy and object functions * nih-dbus/tests/test_dbus_message.c, * nih-dbus/tests/test_dbus_object.c, * nih-dbus/tests/test_dbus_pending_data.c, * nih-dbus/tests/test_dbus_proxy.c: Update to match conn/connection * nih-dbus/dbus_proxy.c: rename conn to connection * nih-dbus/dbus_proxy.h (NihDBusProxy): rename conn to connection * nih-dbus/dbus_object.c: rename conn to connection * nih-dbus/dbus_object.h (NihDBusObject): rename conn to connection * nih-dbus/dbus_pending_data.c: rename conn to connection * nih-dbus/dbus_pending_data.h (NihDBusPendingData): rename conn to connection * nih-dbus/dbus_message.c: rename conn to connection * nih-dbus/dbus_message.h (NihDBusMessage): rename conn to connection * nih-dbus/dbus_interface.h: Rename conn arguments to connection. * nih-dbus/dbus_connection.c: Rename conn arguments/variables to connection, for style-wise stuff * nih-dbus/dbus_connection.h: Update prototypes * nih-dbus-tool/signal.c (signal_proxy_function): Function to generate D-Bus connection filter functions to catch signal messages and pass them to a handler * nih-dbus-tool/signal.h: Add prototype * nih-dbus-tool/tests/signal_factory.c: Call the function to generate a filter function for testing * nih-dbus-tool/tests/signal_code.h: Expected prototype for generated function, and the typedef it casts handler functions to * nih-dbus-tool/tests/test_signal.c (test_proxy_function): Test cases for the function and the generated function * nih-dbus/dbus_interface.h (NihDBusSignalFilter): Rename the message argument to signal, since we use message for the context 2009-05-25 Scott James Remnant * nih-dbus/dbus_interface.h (NihDBusSignal): Add filter function member, which is a D-Bus connection filter that will call a proxied handler function. (NihDBusProxySignal): add advanced typedef (NihDBusSignalFilter): typedef for signal filter function * nih-dbus/dbus_proxy.c (nih_dbus_proxy_connect): Function to connect a signal handler to a proxy using the filter function defined in the NihDBusSignal structure. (nih_dbus_proxy_signal_destroy): Destructor for a proxied signal that removes the match on the bus daemon and the filter (nih_dbus_proxy_signal_rule): Function to generate signal rule * nih-dbus/dbus_proxy.h (NihDBusProxySignal): Structure with the information we need about a connected signal. (NihDBusSignalHandler): Typedef for signal handler function we accept for nih_dbus_proxy_connect() * nih-dbus/tests/test_dbus_proxy.c (test_connect) (test_signal_destroy): Test the new functions * nih-dbus/dbus_proxy.c (nih_dbus_proxy_destroy) (nih_dbus_proxy_name_track): If we don't pass a DBusError to dbus_bus_remove_match() then it won't wait for the reply, which leaks a method call reply elsewhere. 2009-05-24 Scott James Remnant * nih-dbus-tool/tests/test_method.c (test_proxy_function) (test_proxy_sync_function), * nih-dbus-tool/tests/test_property.c (test_proxy_get_function) (test_proxy_set_function, test_proxy_get_sync_function) (test_proxy_set_sync_function), * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c (test_method_dispatch): Update arguments to nih_dbus_proxy_new() calls * nih-dbus/dbus_proxy.h (NihDBusProxy): Add owner member to store the unique name of the proxied object, also add a handler function for the owner dropping off the bus and a data pointer to pass to it. (NihDBusLostHandler): typedef for lost handler function * nih-dbus/dbus_proxy.c (nih_dbus_proxy_new): Accept the lost handler and data members, setting in the function. If the lost handler is passed (which may only be passed if name is not NULL) then we'll track that name on the bus. (nih_dbus_proxy_destroy): We need a destructor to tear down and remove bus matches and connection filters, and also unreference the connection. (nih_dbus_proxy_name_track): Set up tracking for a name, which is far more complicated than it needs to be; arranges for the NameOwnerChanged signal to be received, and obtains the current owner of the name. (nih_dbus_proxy_name_rule): Function to generate the match rule used for the NameOwnerChanged signal. (nih_dbus_proxy_name_owner_changed): Handle the NameOwnerChanged rule, updating the owner member of the proxy and calling the lost handler if the name becomes NULL. * nih-dbus/dbus_interface.h: Add a pre-declaration for the NihDBusProxy typedef since we'll need to pass this to signal filter functions defined here later on 2009-05-22 Scott James Remnant * nih/inotify.h: Remove this wrapper, we require a libc with inotify support. * m4/misc.m4 (NIH_INIT): Remove the check for sys/inotify.h * nih/watch.c, * nih/watch.h, * nih/tests/test_watch.c: Update includes. * nih/Makefile.am (nihinclude_HEADERS): Remove inotify.h * COPYING: Change licence from GPL-2+ to MIT. All files have been updated to reflect this. 2009-05-21 Scott James Remnant * nih-dbus/dbus_object.h: Separate out the actual structure definitions for an interface, the overlap is getting difficult to manage and they're shared with proxies anyway. * nih-dbus/dbus_interface.h: File for the separated out interfaces * nih-dbus/libnih-dbus.h: Include new header * nih-dbus/Makefile.am (nihdbusinclude_HEADERS): Ship and install it 2009-05-19 Scott James Remnant * nih-dbus-tool/signal.c (signal_emit_function): Rename to signal_object_function for consistency * nih-dbus-tool/signal.h: Update header * nih-dbus-tool/tests/signal_factory.c: Update. * nih-dbus-tool/tests/test_signal.c (test_emit_function): Rename to test_object_function to match; update * nih-dbus-tool/method.c (method_proxy_sync_function): Also following the property code, rework method calls to return an integer as well - which means some tricksy cleanup code in the case of argument errors now we don't have a top-level message to free. * nih-dbus-tool/tests/method_code.h: Update the expected prototype * nih-dbus-tool/tests/test_method.c (test_proxy_sync_function): Update the tests to match * nih-dbus-tool/method.c (method_proxy_notify_function): Of course, that's only useful if the notify function handles there being no reply handler, so put an if around the calling of it. * nih-dbus-tool/tests/test_method.c (test_proxy_notify_function): Update the output tests to look for the if. Add test cases for that as well. * nih-dbus-tool/method.c (method_proxy_function): Make the same modification that we made to the property functions, allowing the reply handler to be NULL as long as the error handler isn't * nih-dbus-tool/tests/test_method.c (test_proxy_function): Adjust the output test functions, and also add a test in for no reply handler but an error handler * nih-dbus-tool/property.c (property_proxy_set_function) (property_proxy_set_notify_function): Functions to generate functions to make an asynchronous method call to set the value of a property. * nih-dbus-tool/property.h: Add prototypes * nih-dbus-tool/tests/property_factory.c: Use the functions to generate functions for testing purposes * nih-dbus-tool/tests/property_code.h: Expected prototypes of generated functions, along with the handler typedef that we need * nih-dbus-tool/tests/test_property.c (test_proxy_set_function) (test_proxy_set_notify_function): Test the functions and the generated code 2009-05-18 Scott James Remnant * nih-dbus/dbus_pending_data.c (nih_dbus_pending_data_new): Allow handler to be NULL. * nih-dbus/tests/test_dbus_pending_data.c (test_new): Make sure that NULL is permitted. * nih-dbus-tool/property.c (property_proxy_get_function) (property_proxy_get_notify_function): Functions to generate functions to make an asynchronous method call to get the value of a property. * nih-dbus-tool/property.h: Add prototypes * nih-dbus-tool/tests/property_factory.c: Use the functions to generate functions for testing purposes * nih-dbus-tool/tests/property_code.h: Expected prototypes of generated functions, along with the handler typedef that we need * nih-dbus-tool/tests/test_property.c (test_proxy_get_function) (test_proxy_get_notify_function): Test the functions and the generated code * nih-dbus-tool/property.c (property_proxy_get_sync_function) (property_proxy_set_sync_function): Make sure we clean up in cases of out-of-memory for the interface name and property name arguments. * nih-dbus-tool/tests/test_property.c (test_proxy_get_sync_function) (test_proxy_set_sync_function): Adjust test cases to match * nih-dbus-tool/method.c (method_proxy_notify_function): No need to use NIH_MUST when we're in an emomem loop. * nih-dbus-tool/tests/test_method.c (test_proxy_notify_function): Update output tests to match. * nih-dbus-tool/property.c (property_proxy_get_sync_function) (property_proxy_set_sync_function): Functions to generate functions to make a synchronous method call to get or set the value of a property respectively. * nih-dbus-tool/property.h: Add prototypes * nih-dbus-tool/tests/property_factory.c: Call the two functions to generate functions for testing * nih-dbus-tool/tests/property_code.h: Prototypes for expected generated functions * nih-dbus-tool/tests/test_property.c (test_proxy_get_sync_function) (test_proxy_set_sync_function): Test the code generator and the generated code. 2009-05-17 Scott James Remnant * NEWS: Add entry for move of nih-dbus errors 2009-05-15 Scott James Remnant * nih/tests/test_error.c (test_raise_no_memory): Fix missing nih_error_get () (test_raise_error): Free the second error * nih/libnih.supp: Suppress the abort()-related leak * nih-dbus-tool/method.c (method_object_function): Rename externs to handlers * nih-dbus-tool/method.h: Update prototype * nih-dbus-tool/tests/method_factory.c: Update calls * nih-dbus-tool/tests/test_method.c (test_object_function): Update variable names in tests * nih-dbus-tool/method.c (method_reply_function) (method_proxy_sync_function): Remove the unused externs parameters * nih-dbus-tool/method.h: Update prototypes * nih-dbus-tool/tests/method_factory.c: Don't pass when we don't use them * nih-dbus-tool/tests/test_method.c (test_reply_function) (test_proxy_sync_function): Remove the empty list checks * nih-dbus-tool/property.c (property_object_get_function) (property_object_set_function): Rename externs to handlers * nih-dbus-tool/property.h: Update prototypes * nih-dbus-tool/tests/property_factory.c: Update calls * nih-dbus-tool/tests/test_property.c (test_object_get_function) (test_object_set_function): Update variable names in tests. * nih-dbus-tool/signal.c (signal_emit_function): Remove the externs parameter, which is not used. * nih-dbus-tool/signal.h: Update prototype * nih-dbus-tool/tests/signal_factory.c: Drop externs handling * nih-dbus-tool/tests/test_signal.c (test_emit_function): Drop tests for empty externs list * nih/errors.h: Remove the D-Bus errors from this file * nih-dbus/errors.h: Place them in a new file. * nih-dbus/libnih-dbus.h: Include the new header * nih-dbus/Makefile.am (nihdbusinclude_HEADERS): Install the new header. * nih-dbus/dbus_error.c, * nih-dbus/dbus_object.c: * nih-dbus/tests/test_dbus_connection.c, * nih-dbus/tests/test_dbus_error.c, * nih-dbus-tool/tests/method_factory.c, * nih-dbus-tool/tests/signal_factory.c, * nih-dbus-tool/tests/property_factory.c, * nih-dbus-tool/tests/test_method.c, * nih-dbus-tool/tests/test_property.c, * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c: Update headers included * nih-dbus-tool/nih_dbus_tool.py (Output.sourceFile): Update generated includes. * nih-dbus/dbus_object.h (NihDBusPropertySetter): Change prototype to return an int, instead of a handler result. This allows us to introduce interesting new SetMany-like methods later. * nih-dbus/dbus_object.c (nih_dbus_object_property_set): Expand the function to do the reply handling here, this actually makes things much better for the ENOMEM case. * nih-dbus/tests/test_dbus_object.c (test_object_property_set): Adjust test cases to match * nih-dbus-tool/property.c (property_object_set_function): Rework the prototype of property setter functions, we just want to return int and have the nih-dbus core deal with sending the reply. * nih-dbus-tool/tests/property_code.h: Update prototype. * nih-dbus-tool/tests/test_property.c (test_object_set_function): Update tests to match * nih-dbus-tool/method.c (method_object_function): Push an error context around the handler call * nih-dbus-tool/tests/test_method.c (test_object_function): Adjust tests to expect the error context * nih-dbus-tool/tests/test_method.c (test_proxy_sync_function): Make sure the methods aren't marked to expect no reply (completeness) * nih-dbus-tool/method.c (method_proxy_sync_function): Fix nih_strcat call to not overwrite variable with return value * nih-dbus-tool/method.c (method_proxy_function) (method_proxy_notify_function): Functions to generate the two functions required for an asynchronous method call, the first makes the call and the second is the pending call notify function for it that calls the reply handler. * nih-dbus-tool/method.h: Prototypes. * nih-dbus-tool/tests/method_factory.c: Call both functions to generate functions for testing * nih-dbus-tool/tests/method_code.h: Expected prototypes for the generated functions. * nih-dbus-tool/tests/test_method.c (test_proxy_function) (test_proxy_notify_function): Test the code generator and the generated code. 2009-05-14 Scott James Remnant * nih-dbus/dbus_pending_data.c (nih_dbus_pending_data_new): Allocate a new NihDBusPendingData structure, referencing the D-Bus connection. (nih_dbus_pending_data_destroy): Unreference the attached connection. * nih-dbus/dbus_pending_data.h: Function typedefs, structure and function prototype. * nih-dbus/tests/test_dbus_pending_data.c: Test suite. * nih-dbus/libnih-dbus.h: Include the header * nih-dbus/Makefile.am (libnih_dbus_la_SOURCES): Build and link the new source file (nihdbusinclude_HEADERS): Install the header (TESTS): Run the test suite (test_dbus_pending_data_SOURCES, test_dbus_pending_data_LDFLAGS) (test_dbus_pending_data_LDADD): Test suite details. * nih-dbus/dbus_object.c (nih_dbus_object_new): Add a comment to explain why we don't reference the connection in NihDBusObject. * nih-dbus/dbus_object.h (NihDBusObject): Document that no reference is held on @conn 2009-05-13 Scott James Remnant * nih-dbus-tool/method.c (method_proxy_sync_function): Rename the message local to method_call and the msg local to message to match other functions. * nih-dbus-tool/tests/test_method.c (test_proxy_sync_function): Update tests to match * nih-dbus-tool/method.c (method_proxy_sync_function): Unreference the D-Bus method call we're building, not the message we'll return. * nih-dbus-tool/tests/test_method.c (test_proxy_sync_function): Adjust output functions to account for the change. * nih-dbus-tool/method.c (method_object_function): We can't just use a do { .. } while (0) loop and continue in the case of ENOMEM because that won't work for arrays. Instead use a local label to goto the continuation of an outer loop like we do in method_proxy_sync_function() * nih-dbus-tool/tests/test_method.c (test_object_function): Adjust output tests to account for the change. * nih-dbus-tool/tests/test_method.c (test_object_function) (test_reply_function): Add tests for argument-less methods. * nih-dbus-tool/tests/test_signal.c (test_emit_function): Add test for argument-less signal, and missing test for deprecated signals. * nih-dbus-tool/tests/test_property.c (test_object_get_function) (test_object_set_function): Add missing tests for deprecated properties. * nih-dbus-tool/method.c (method_object_function) (method_reply_function): Build the assert block up as we go * nih-dbus-tool/signal.c (signal_emit_function): Build up the assert block as we go. * nih-dbus-tool/method.c (method_proxy_sync_function): Generate a function to make a synchronous method call to a remote D-Bus object. * nih-dbus-tool/method.h: Prototype. * nih-dbus-tool/tests/method_factory.c: Use the function to generate a function for testing * nih-dbus-tool/tests/method_code.h: Add expected prototype of generated function. * nih-dbus-tool/tests/test_method.c (test_proxy_sync_function): Test the generator function and the generated function. * nih-dbus/dbus_message.c (nih_dbus_message_new): Pass parent to nih_new() not NULL. * nih/error.h (nih_error_raise_no_memory): Finally succum and add this macro. (nih_return_no_memory_error): Use that macro in this. * nih/tests/test_error.c (test_raise_no_memory): Add test case. 2009-05-12 Scott James Remnant * nih-dbus-tool/tests/method_factory.c, * nih-dbus-tool/tests/signal_factory.c, * nih-dbus-tool/tests/property_factory.c: Use the returned externs list for the prototypes, rather than hard-coding them. * nih-dbus-tool/type.c (type_to_static, type_to_extern): Methods to prepend "static" and "extern" onto a type. * nih-dbus-tool/type.h: Prototypes. * nih-dbus-tool/tests/test_type.c (test_to_static) (test_to_extern): Test the methods. * nih-dbus-tool/tests/test_parse.c (test_parse_xml): Update due to change in error from D-Bus 1.2.14 * nih-dbus-tool/method.c (method_object_function) (method_reply_function): Replace the hand-coded function layout code with a call to type_func_to_string() * nih-dbus-tool/tests/test_method.c (test_object_function) (test_reply_function): Adjust tests to account for the indentation differences. * nih-dbus-tool/signal.c (signal_emit_function): Replace code * nih-dbus-tool/tests/test_signal.c (test_emit_function): Adjust tests * nih-dbus-tool/property.c (property_object_get_function) (property_object_set_function): Replace code * nih-dbus-tool/tests/test_property.c (test_object_get_function) (test_object_set_function): Adjust tests 2009-05-11 Scott James Remnant * nih-dbus-tool/property.c (property_get_function, property_set_function): Accept list arguments for prototypes and externs, filling them in. * nih-dbus-tool/property.h: Adjust prototypes. * nih-dbus-tool/tests/property_factory.c: Pass in the prototypes and extern lists, but don't actually use them just yet. * nih-dbus-tool/tests/test_property.c (test_get_function) (test_set_function): Add tests for returned prototype, including a test for not having a deprecated attribute. * nih-dbus-tool/signal.c (signal_reply_function): Accept list arguments for prototypes and externs, filling in the prototypes one. * nih-dbus-tool/signal.h: Adjust prototype. * nih-dbus-tool/tests/signal_factory.c: Pass in the prototypes and extern lists, but don't actually use them just yet. * nih-dbus-tool/tests/test_signal.c (test_reply_function): Add tests for returned prototype, including a test for not having a deprecated attribute. * nih-dbus-tool/demarshal.c (demarshal_array), * nih-dbus-tool/marshal.c (marshal_array), * nih-dbus-tool/method.c (method_object_function) (method_reply_function), * nih-dbus-tool/signal.c (signal_emit_function), * nih-dbus-tool/property.c (property_object_get_function) (property_object_set_function): Line-up variable blocks. * nih-dbus-tool/tests/test_demarshal.c (test_demarshal), * nih-dbus-tool/tests/test_marshal.c (test_marshal), * nih-dbus-tool/tests/test_method.c (test_object_function) (test_reply_function): * nih-dbus-tool/tests/test_signal.c (test_emit_function): * nih-dbus-tool/tests/test_property.c (test_object_get_function): Adjust string output checks for the slight difference in indentation * nih-dbus-tool/type.c (type_func_to_string, type_func_layout): Functions to convert TypeFunc entries into strings. * nih-dbus-tool/type.h: Add prototypes. * nih-dbus-tool/tests/test_type.c (test_func_to_string) (test_func_layout): Test cases for the functions. 2009-05-10 Scott James Remnant * nih-dbus-tool/type.c (type_var_to_string, type_var_layout): Functions to convert TypeVar entries into strings. * nih-dbus-tool/type.h: Prototypes. * nih-dbus-tool/tests/test_type.c (test_var_to_string) (test_var_layout): Test cases. * nih-dbus-tool/tests/test_marshal.c (test_marshal): Make sure the input and local variable parents are correct, and make sure the lists are empty in case of memory error. * nih-dbus-tool/tests/test_demarshal.c (test_demarshal): Make sure the output and local variable parents are correct, and make sure the lists are empty in case of memory error. * nih-dbus-tool/method.c (method_reply_function): Accept list arguments for prototypes and externs, filling in the prototypes one. * nih-dbus-tool/method.h: Adjust prototype. * nih-dbus-tool/tests/method_factory.c: Pass in the prototypes and extern lists, but don't actually use them just yet. * nih-dbus-tool/tests/test_method.c (test_reply_function): Add tests for returned prototype, including a test for not having a deprecated attribute. * nih-dbus-tool/method.c (method_object_function): Accept list arguments for prototypes and externs. * nih-dbus-tool/method.h: Add prototype. * nih-dbus-tool/tests/method_factory.c: Pass in the prototypes and extern lists, but don't actually use them just yet.x * nih-dbus-tool/tests/test_method.c (test_object_function): Add tests for returned prototype, and add a test for not having a deprecated attribute * nih-dbus-tool/type.h (TypeFunc): Structure to represent a function definition. * nih-dbus-tool/type.c (type_func_new): Function to create a new TypeFunc structure. * nih-dbus-tool/tests/test_type.c (test_func_new): Test for the function. 2009-05-09 Scott James Remnant * nih/error.c (nih_error_steal): Add a new function to get an error and remove it from the context, needed for stashing errors while trying something else - or raising an error outside of a context. * nih/error.h: Add prototype. * nih/tests/test_error.c (test_steal): Add test cases. * nih/error.h: Update documentation. * TODO: Update. * nih/main.c (nih_main_daemonise): Don't just ignore the raised error when we fail to write the pid file, at least warn about it. * nih/tests/test_main.c (test_daemonise): Hide the output from nih_main_daemonise() which will usually bitch about permissions * nih/tests/test_io.c (test_watcher): In various tests, we close the file descriptor when reading or writing and check for an error being raised - but had forgotten that we'd get the error again when the structure is closed as it tries to close the descriptor (test_message_recv, test_message_send, test_reopen) (test_destroy): Add a few contexts around critical bits to make sure we're not leaking any other errors. * nih/error.c (nih_error_clear): Make an unhandled error an assertion failure * nih/tests/test_error.c (test_pop_context): Make sure the unhandled error is asserted (test_raise_error): Make sure a double-raise is asserted. * nih/error.c (nih_error_clear): Allow the function to be called when there is no current error in the context (nih_error_init): Register as an atexit() function so that unhandled errors are caught when the process exits. (_nih_error_raise_error, nih_error_pop_context): Don't double check, just call the function to clear the context. * nih/error.c (_nih_error_raise_error): Don't allow the same error to be raised twice anymore. * nih/tests/test_error.c (test_pop_context): No need to raise the error twice. * nih/io.c (nih_io_watcher): Don't double-raise the error. * nih/watch.c (nih_watch_add): Again, don't double-raise the error * nih/tests/test_file.c (my_error_handler): No need to double-raise * nih-dbus-tool/annotation.c (annotation_start_tag): Don't need to double-raise either * nih/error.h (NIH_SHOULD): We don't need to raise the error again, simply don't free it. * nih/error.c (_nih_error_raise_error): Don't accept a NULL filename anymore. * nih/error.c (_nih_error_raise, _nih_error_raise_printf) (_nih_error_raise_system): Don't make the error a child of the context. * nih/error.h (NihError): Add filename, line and function members set when the error is raised. (NIH_SHOULD): Re-raise using _nih_error_raise_error() directly passing NULL for the filename and such so it's not overwritten (this is a temporary hack) (nih_error_raise, nih_error_raise_printf) (nih_error_raise_system, nih_error_raise_error): Macros to wrap the underlying functions passing the filename, line and function name in which they were expanded. * nih/error.c (nih_error_raise, nih_error_raise_printf) (nih_error_raise_system, nih_error_raise_error): Rename to have an initial underscore, accepting filename, line and function arguments from the wrapping macros. (_nih_error_raise_error): Set the filename, line and function members of the raised error (we just overwrite these). (nih_error_clear): Report where the unhandled error came from. * nih/error.c (nih_error_destroy): Add destructor functions for error messages, this clears the error from the current error context. (nih_error_raise_error): Set the destructor. (nih_error_clear): Assert that the destructor frees the error, don't do it ourselves. (nih_error_get): Do not clear the error from the context. (nih_error_raise_error): Check for the error being double-raised which is currently permitted. 2009-05-07 Scott James Remnant * nih-dbus-tool/annotation.c (annotation_start_tag): Update error call to nih_error_raise_error(). * nih/tests/test_error.c (test_raise_error): Use TEST_ALLOC_FAIL and a separate error context for each test. * nih/error.c (nih_error_raise_again): Rename to nih_error_raise_error() (nih_error_raise, nih_error_raise_printf) (nih_error_raise_system): Update calling. * nih/error.h (NIH_SHOULD): Update calling. Update prototype. * nih/tests/test_error.c (test_raise_again): Rename and change calls. * nih/io.c (nih_io_watcher): Update call. * nih/watch.c (nih_watch_add): Update call. * nih/tests/test_file.c (my_error_handler): Update call. * nih-dbus/dbus_error.c (nih_dbus_error_raise) (nih_dbus_error_raise_printf): Update calls. 2009-04-28 Scott James Remnant * nih-dbus-tool/marshal.c (marshal_array, marshal_struct): We have to close a container in out-of-memory situations, unrefing the message isn't sufficient. * nih-dbus-tool/tests/test_marshal.c (test_marshal): Make sure all those containers are closed. * nih-dbus-tool/tests/test_method.c (test_object_function) (test_reply_function): Make sure containers called from method functions are closed on error too * nih-dbus-tool/property.c (property_object_get_function): Close containers in case of out-of-memory error. * nih-dbus-tool/tests/test_property.c (test_object_get_function): Make sure the close container code is added. * nih-dbus/tests/test_dbus_object.c (test_object_message): Add a test where the first handler declines (test_object_property_set): Make sure that the Set handler cannot decline, as we can't do the same for the Get handler. * nih-dbus/dbus_object.c (nih_dbus_object_message): Move onto the next handler if the handler declines. * nih-dbus-tool/Makefile.am (nih_dbus_tool_LDADD) (test_method_LDADD, test_signal_LDADD) (test_com_netsplit_Nih_Test_object_LDADD) (test_com_netsplit_Nih_Test_proxy_LDADD): Always put libnih.la after libnih-dbus.la * nih-dbus/dbus_object.h (NihDBusMethod): Move the method handler to be the last member. * nih-dbus/tests/test_dbus_object.c: Update. * nih-dbus-tool/nih_dbus_tool.py (Interface.methodsArray): Update. * nih-dbus/Makefile.am (libnih_dbus_la_LIBS): Include libnih.la as it's a dependency. (test_dbus_error_LDADD, test_dbus_connection_LDADD) (test_dbus_message_LDADD, test_dbus_object_LDADD) (test_dbus_proxy_LDADD, test_dbus_util_LDADD): Specify libnih-dbus.la first since it's what we're testing, and deps go the other way * nih-dbus/tests/test_dbus_object.c (test_object_introspect): Add a missing test case for too many arguments to the Introspect call. * nih-dbus/dbus_object.c (nih_dbus_object_introspect): Which reveals we didn't catch this. * nih-dbus/tests/test_dbus_object.c (test_object_property_get) (test_object_property_get_all, test_object_property_set): Add missing test cases for argument errors. * nih-dbus/dbus_object.c (nih_dbus_object_property_get_all): Add function to retrieve all properties at once. (nih_dbus_object_message): Call out to it. * nih-dbus/tests/test_dbus_object.c (test_object_property_get_all): Test the new function. * nih-dbus/dbus_object.h (NihDBusPropertyGetter) (NihDBusPropertySetter): Add function typedefs for property get and set functions. (NihDBusProperty): Add getter and setter members. * nih-dbus/dbus_object.c (nih_dbus_object_property_get) (nih_dbus_object_property_set): Functions to handle calling the getter and setter functions for a single property Get or Set method. (nih_dbus_object_message): Call out to the new functions. * nih-dbus/tests/test_dbus_object.c (test_object_property_get) (test_object_property_set): Test the new single property get/set functions. * nih-dbus/dbus_object.h (NihDBusMarshaller): Rename to NihDBusMethodHandler, since this prototype only applies to methods and not to properties. (nih_dbus_method): Change type and name of marshaller member to handler. * nih-dbus/dbus_object.c (nih_dbus_object_message): Update name of function pointer member we use. * nih-dbus/tests/test_dbus_object.c: Avoid using the word "marshal" and use "handler" instead. * nih-dbus/dbus_object.c (nih_dbus_object_introspect): Put the Introspect interface last, since it's the least important one; we always want the object's own interfaces first, followed by properties, followed by introspection, followed by children nodes. * nih-dbus/tests/test_dbus_object.c (test_object_introspect): Update tests to match. * nih-dbus/tests/test_dbus_object.c (test_object_message): Split out the introspection test cases into a new function. (test_object_introspect): Add a test for having no properties. * nih-dbus/tests/test_dbus_object.c (test_object_new) (test_object_destroy, test_object_unregister) (test_object_message): Convert to test using TEST_DBUS rather than a hodge-podge of different buses and servers. * nih-dbus/test_dbus.h (TEST_DBUS_DISPATCH): Equivalent to TEST_DBUS_MESSAGE but dispatches the message internally rather than stealing it. * nih-dbus/tests/test_dbus_connection.c (test_connect): Add tests for a fake disconnected signal (as much as we can test anyway). 2009-04-27 Scott James Remnant * nih-dbus/dbus_connection.h: Note on allocation. * nih-dbus/dbus_message.h: Add documentation string. * nih-dbus/tests/test_dbus_message.c (test_message_new): Add missing call to dbus_shutdown() after test case. (test_message_error): Rewrite using TEST_DBUS and using TEST_ALLOC_FAIL to check for memory issues. * nih-dbus/dbus_connection.h: Add documentation. * nih-dbus/dbus_connection.c (nih_dbus_setup): We actually want to attempt to setup the watch, timeout and wake-up functions each time through nih_dbus_setup() so it can be called in a loop in cases of out-of-memory so do this first before setting the main loop function, and unwind in case of error. (nih_dbus_watch_toggled): D-Bus could try and change the flags with a toggle? * nih-dbus/dbus_connection.h (NihDBusConnectHandler): Add missing Returns to documentation string. * nih-dbus/dbus_error.h: Add documentation string. * nih-dbus/dbus_connection.c (nih_dbus_connect, nih_dbus_bus): Clarify that it's ok to unreference a connection obtained with these functions - indeed we do so everywhere in the test suite. * nih-dbus/dbus_connection.c (nih_dbus_connect, nih_dbus_bus) (nih_dbus_server): Return ENOMEM raised on insufficient memory rather than the D-Bus equivalent; we don't just convert these everywhere because sometimes we want to know that it's the remote side that's out of memory and we don't want to use ENOMEM for that. * nih-dbus/tests/test_dbus_connection.c: Various cleanup fixes, making sure we unref everything that we use. Increase timeout for method calls since things get slower when under valgrind. * nih-dbus/dbus_connection.c (nih_dbus_connection_disconnected): Push an error context while calling the handler. (nih_dbus_new_connection): Push an error context while calling the handler. * nih/timer.c (nih_timer_poll): The timer callback can free the timer, so we need to adjust the due time before we call it. In the case of timeouts, we hold a reference while calling and always free after returning. Also push an error context during it so we don't leak errors. 2009-04-24 Scott James Remnant * nih-dbus/tests/test_dbus_connection.c (test_connect): Add tests for a method call being made and its reply received through the main loop, and for a method call timing out within the main loop. This exercises the watch and timeout functions. 2009-04-23 Scott James Remnant * nih-dbus/tests/test_dbus_connection.c (test_server): Add tests for address in use, * nih/tests/test_logging.c (my_logger): Safely strdup the message. (test_set_logger, test_set_priority, test_log_message): Make sure all calls are wrapped with TEST_ALLOC_FAIL (test_logger_printf): Call TEST_ALLOC_FAIL for everything. * nih/Makefile.am (.PHONY): Mark tests phony. * nih-dbus/Makefile.am (.PHONY): Mark tests phony. * nih-dbus-tool/Makefile.am (.PHONY): Mark tests phony. * nih-dbus/Makefile.am (libnih_dbus_la_CFLAGS, AM_CFLAGS): Replace the former with the latter. (test_dbus_error_CFLAGS, test_dbus_connection_LDFLAGS) (test_dbus_message_CFLAGS, test_dbus_object_CFLAGS) (test_dbus_proxy_CFLAGS, test_dbus_util_CFLAGS): Remove. * nih-dbus/tests/test_dbus_connection.c: Wrap every test in NIH_ALLOC_FAIL, to properly make sure that we handle failure cases properly. * nih-dbus/dbus_connection.c (nih_dbus_server): Disconnect the server before unreferencing it. 2009-04-22 Scott James Remnant * nih-dbus-tool/nih_dbus_tool.py (Method.marshalFunction): Also fix async method handler return to match. * nih-dbus-tool/tests/test_main.c, * nih-dbus-tool/tests/test_node.c, * nih-dbus-tool/tests/test_interface.c, * nih-dbus-tool/tests/test_method.c, * nih-dbus-tool/tests/test_signal.c, * nih-dbus-tool/tests/test_property.c, * nih-dbus-tool/tests/test_argument.c, * nih-dbus-tool/tests/test_annotation.c, * nih-dbus-tool/tests/test_parse.c: All tests cases should use TEST_ALLOC_FAIL, even the ones testing for errors. To get around situations where some allocations may be repeated, but others will fail, check the return value to see which happened. 2009-04-21 Scott James Remnant * nih-dbus/tests/test_dbus_message.c (my_return_error): Return DBUS_HANDLED_RESULT_HANDLED otherwise the message will be ignored. * nih-dbus-tool/property.c (property_object_get_function) (property_object_set_function): Generate code for functions to get and set, respectively, properties using a handler function. * nih-dbus-tool/property.h: Add prototypes. * nih-dbus-tool/tests/property_factory.c: Call the two functions to generate their resulting property get and set functions and place them in a C file for testing. * nih-dbus-tool/tests/property_code.h: Expected prototypes for generated functions. * nih-dbus-tool/tests/test_property.c (test_object_get_function) (test_object_set_function): Tests for the code, and for the resulting generated code. * nih-dbus-tool/Makefile.am (check_PROGRAMS): Run the program to generate the C code. (property_factory_SOURCES) (property_factory_LDFLAGS, property_factory_LDADD) (tests/property_code.c): Details for code generator. (CLEANFILES): Clean up after. (test_property_SOURCES): Link to the generated code. * nih-dbus/dbus_object.c: Add missing include for previous commit. 2009-04-20 Scott James Remnant * nih-dbus/dbus_object.c (nih_dbus_object_message): Call the marshaller function inside a context so that errors aren't leaked. * nih-dbus/dbus_object.c (nih_dbus_object_message): We don't need any special handling for async functions now we have nih_local, the function simply needs to reference the message. Drop the requirement that it returns DBUS_HANDLER_RESULT_NOT_YET_HANDLED. * nih-dbus-tool/method.c (method_object_function): Always return DBUS_HANDLER_RESULT_HANDLED, even for async methods. * nih-dbus-tool/tests/test_method.c (test_object_function): Replace tests for not yet handled with ones for the ordinary handled result. 2009-04-18 Scott James Remnant * nih-dbus-tool/signal.c (signal_emit_function): Generate code for a function that emits a signal. * nih-dbus-tool/signal.h: Add prototype. * nih-dbus-tool/tests/signal_factory.c: Call signal_emit_function() to generate a signal emission function and place it in a C file for testing. * nih-dbus-tool/tests/signal_code.h: Expected prototype for generated function. * nih-dbus-tool/tests/test_signal.c (test_emit_function): Test the generator function and generated function. * nih-dbus-tool/Makefile.am (check_PROGRAMS): Run the program to generate the C code. (signal_factory_SOURCES, signal_factory_LDFLAGS) (signal_factory_LDADD, tests/signal_code.c): Details for generator (CLEANFILES): Clean up after. (test_signal_SOURCES): Link to the generated code. * nih-dbus-tool/method.c (method_object_function) (method_reply_function): Add missing asserts. 2009-04-17 Scott James Remnant * nih-dbus-tool/tests/test_method.c: Oops, commented out the test. * nih-dbus-tool/tests/test_method.c (test_object_function): Add test cases for the no reply expected flag on an incoming message. * nih-dbus-tool/method.c (method_reply_function): Generate code for a function that sends a reply to an asynchronous method call. * nih-dbus-tool/method.h: Add prototype. * nih-dbus-tool/tests/method_factory.c: Call method_reply_function() to generate a reply function and place it in a C file for testing. * nih-dbus-tool/tests/method_code.h: Expected prototype. * nih-dbus-tool/tests/test_method.c (test_reply_function): Add test cases for the code, the generated code, and the no reply expected case. * nih-dbus-tool/tests/test_method.c (test_object_function): Add tests for too many arguments in method call * nih-dbus-tool/method.c (method_object_function): Add a block of code to check for extra function arguments. * nih-dbus-tool/method.c (method_object_function): When the method is marked async, ignore the output arguments and don't try and send any reply - instead returning the magic "not yet handled" code. * nih-dbus-tool/tests/method_factory.c: Generate an async version of the same function for testing. * nih-dbus-tool/tests/method_code.h: Add prototype * nih-dbus-tool/tests/test_method.c (test_object_function): Test code generation and the generated code for an asynchronous method. * nih-dbus-tool/method.c (method_object_function): Generate code for a function that handles an incoming method call, and calls a handler function for it. * nih-dbus-tool/method.h: Add prototype. * nih-dbus-tool/tests/test_method.c (test_object_function): Tests cases for the function and the function code it generates. * nih-dbus-tool/tests/method_factory.c: Call method_object_function() to generate a function, and place it in a C file for testing. * nih-dbus-tool/tests/method_code.h: Prototype for generated function. * nih-dbus-tool/Makefile.am (check_PROGRAMS): Build the method_factory program when running tests (nih_dbus_tool_SOURCES, TESTS): Marshalling/demarshalling code now has to come before parsing and method code since we use it. (method_factory_SOURCES, method_factory_LDFLAGS) (method_factory_LDADD, tests/method_code.c): Run the method_factory tool to generate tests/method_code.c (test_method_SOURCES, test_method_LDADD): Link to the output of the method_factory tool (CLEANFILES): Clean up (test_node_LDADD, test_interface_LDADD, test_signal_LDADD) (test_property_LDADD, test_argument_LDADD) (test_annotation_LDADD, test_parse_LDADD): Add marshal/demarshal object files 2009-04-16 Scott James Remnant * nih-dbus-tool/tests/marshal_factory.c (marshal_function): Remove code to get type which we never use now we have the demarshalling function outputs * nih-dbus-tool/tests/demarshal_factory.c (demarshal_function): Remove code to get type which we never use now we have the marshalling function inputs. * nih-dbus-tool/demarshal.c (demarshal_basic): Do not make the output variable a pointer, when used in method object/signal proxy mode we actually have this as a local variable and want the demarshalled value placed directly into it. (demarshal_array, demarshal_struct): Instead of making the output variable a pointer, demarshal into a local and copy that into the output variable. * nih-dbus-tool/tests/demarshal_factory.c (demarshal_function): Make passed in outputs pointers, copy into them after demarshalling * nih-dbus-tool/tests/test_demarshal.c (test_demarshal): Make sure that const does not appear in the inputs, or comments, but that all locals are still const (as they are only copies) even in source. 2009-04-15 Scott James Remnant * nih-dbus-tool/marshal.c (marshal_basic): Do not make the input variable const, when used in method object/signal proxy mode we might modify the local variable before passing it to the marshalling code so can't have it const. (marshal_array, marshal_struct): Instead of making the input variable const, make the local we copy into const. * nih-dbus-tool/tests/marshal_factory.c (marshal_function): Make passed-in inputs const. * nih-dbus-tool/tests/test_marshal.c (test_marshal): Make sure that const does not appear in the inputs, or comments, but that all locals are still const (as they are only copies) even in source. * nih-dbus-tool/type.c (type_of): can't pass a size_t to a format length, and don't want to cast down to int in case of underrun Continue porting the D-Bus binding tool from Python to C, this code implements the type marshalling and demarshalling with additional support for arrays of arrays of fixed types and structures that the Python code never had. * nih-dbus-tool/type.c, nih-dbus-tool/type.h: Functions to identify C types from D-Bus type signatures, and to handle variable declarations * nih-dbus-tool/test_type.c: Test cases * nih-dbus-tool/marshal.c, nih-dbus-tool/marshal.h: Generate code to marshal data from C standard types with given variable names into a D-Bus message. * nih-dbus-tool/tests/marshal_factory.c: Generate functions that contain the generated code for types that we test * nih-dbus-tool/tests/marshal_code.h: Header for generated code * nih-dbus-tool/tests/test_marshal.c: Test both the output strings and the behaviour of the generated code * nih-dbus-tool/demarshal.c, nih-dbus-tool/demarshal.h: Generate code to demarshal data from a D-Bus message into C standard types with requested variable names. * nih-dbus-tool/tests/demarshal_factory.c: Generate functions that contain the generated code for types that we test * nih-dbus-tool/tests/demarshal_code.h: Header for generated code * nih-dbus-tool/tests/test_demarshal.c: Test both the output strings and the behaviour of the generated code * nih-dbus-tool/Makefile.am (nih_dbus_tool_SOURCES): Build and link new source files (TESTS): Run test cases for new source files (test_type_SOURCES, test_type_LDFLAGS, test_type_LDADD) (test_marshal_SOURCES, test_marshal_LDFLAGS, test_marshal_LDADD) (test_demarshal_SOURCES, test_demarshal_LDFLAGS) (test_demarshal_LDADD): Details for test cases. (check_PROGRAMS, marshal_factory_SOURCES) (marshal_factory_LDFLAGS, marshal_factory_LDADD) (tests/marshal_code.c, demarshal_factory_SOURCES) (demarshal_factory_LDFLAGS, demarshal_factory_LDADD) (tests/demarshal_code.c, CLEANFILES): In order to test the output code, we generate a C file containing it and link it to the test cases. This gets cleaned up on "clean" rather than maintainer-clean 2009-04-04 Scott James Remnant * nih-dbus-tool/parse.c (parse_start_tag, parse_xml): Cast return value of XML_GetCurrentLineNumber and XML_GetCurrentColumnNumber to size_t and use %zu * nih-dbus-tool/node.c (node_start_tag): Likewise. * nih-dbus-tool/interface.c (interface_start_tag): Likewise. * nih-dbus-tool/method.c (method_start_tag): Likewise. * nih-dbus-tool/signal.c (signal_start_tag): Likewise. * nih-dbus-tool/property.c (property_start_tag): Likewise. * nih-dbus-tool/annotation.c (annotation_start_tag): Likewise. * nih-dbus-tool/argument.c (argument_start_tag): Likewise. (argument_end_tag): Use %zu for the unsigned count, not %zi 2009-03-30 Scott James Remnant * nih-dbus-tool/main.c (main): open() returns less-than-zero on error not zero, which is standard input! * nih-dbus-tool/Makefile.am (test_com_netsplit_Nih_Test_object_CFLAGS) (test_com_netsplit_Nih_Test_proxy_CFLAGS): Remove the CFLAGS overrides, we set this globally in the file. * nih-dbus-tool/indent.c (indent): Function to indent the lines in a string using the specified number of tabs. (comment): Function to prepend the traditional " * " comment prefix to the lines in a string. * nih-dbus-tool/indent.h: Prototypes. * nih-dbus-tool/tests/test_indent.c: Test cases. * nih-dbus-tool/Makefile.am (TESTS): Build the indent test cases (test_indent_SOURCES, test_indent_LDFLAGS, test_indent_LDADD): Details for indent test cases * nih-dbus-tool/main.c: Re-order so that the option variables, the options list and the main() function can be contained inside a #if directive so we can test the rest. (source_file_path, header_file_path): Factor out the code from main() that generated the source and header file paths so we can test; at the same time, fix them so they don't cast ptrdiff_t to int and always output to the current working directory unless output_path includes one. * nih-dbus-tool/tests/test_main.c: Which means we can test the mode_option(), source_file_path() and header_file_path() functions * nih-dbus-tool/Makefile.am (TESTS): Build and run test_main (test_main_SOURCES, test_main_LDFLAGS, test_main_LDADD): usual details for test_main, except we use main.c as a SOURCE rather than linking in LDADD like we normally do (test_main_CFLAGS): Override CFLAGS to set -DTEST, this causes us to recompile main.c specially for test_main with the main() function #ifdef'd out. * nih-dbus/Makefile.am (tests): Move to the bottom of the file * nih/Makefile.am (tests): Move to the bottom of the file * nih-dbus-tool/Makefile.am (tests): Move to the bottom of the file Begin replacing the old Python D-Bus bindings tool with one written in C, starting with the code that parses the introspection data. * nih-dbus-tool/Makefile.am (bin_SCRIPTS, noinst_SCRIPTS) (bin_PROGRAMS, noinst_PROGRAMS): Replace the nih-dbus-tool script with a program that we need to compile. (CLEANFILES, EXTRA_DIST, do_subst, nih-dbus-tool): Drop the rules to generate the script by replacing bits out of the Python source (nih_dbus_tool_SOURCES, nih_dbus_tool_LDADD): Instead build from C sources, and link to libnih, libnih-dbus, expat and libdbus (AM_CFLAGS): Require the D-Bus CFLAGS when compiling the tool (AM_CPPFLAGS): Include quoted headers from the source directory so the test suite can get at them (TESTS): Add tests for the various bits of the C tool (tests): Rule to generate binaries for the test suite (test_symbol_SOURCES, test_symbol_LDFLAGS, test_symbol_LDADD) (test_node_SOURCES, test_node_LDFLAGS, test_node_LDADD) (test_interface_SOURCES, test_interface_LDFLAGS) (test_interface_LDADD, test_method_SOURCES, test_method_LDFLAGS) (test_method_LDADD, test_signal_SOURCES, test_signal_LDFLAGS) (test_signal_LDADD, test_property_SOURCES) (test_property_LDFLAGS, test_property_LDADD) (test_argument_SOURCES, test_argument_LDFLAGS) (test_argument_LDADD, test_annotation_SOURCES) (test_annotation_LDFLAGS, test_annotation_LDADD) (test_parse_SOURCES, test_parse_LDFLAGS, test_parse_LDADD): Test suite details * nih-dbus-tool/main.c, nih-dbus-tool/symbol.c, nih-dbus-tool/symbol.h, nih-dbus-tool/tests/test_symbol.c, nih-dbus-tool/node.c, nih-dbus-tool/node.h, nih-dbus-tool/tests/test_node.c, nih-dbus-tool/interface.c, nih-dbus-tool/interface.h, nih-dbus-tool/tests/test_interface.c, nih-dbus-tool/method.c, nih-dbus-tool/method.h, nih-dbus-tool/tests/test_method.c, nih-dbus-tool/signal.c, nih-dbus-tool/signal.h, nih-dbus-tool/tests/test_signal.c, nih-dbus-tool/property.c, nih-dbus-tool/property.h, nih-dbus-tool/tests/test_property.c, nih-dbus-tool/argument.c, nih-dbus-tool/argument.h, nih-dbus-tool/tests/test_argument.c, nih-dbus-tool/annotation.c, nih-dbus-tool/annotation.h, nih-dbus-tool/tests/test_annotation.h, nih-dbus-tool/parse.c, nih-dbus-tool/parse.h, nih-dbus-tool/tests/test_parse.c, nih-dbus-tool/errors.h: Source for the tool * m4/misc.m4 (NIH_INIT): Explicitly check for pkg-config 0.22 * m4/libs.m4 (NIH_LIB_DBUS): Replace check for Python with a check for the expat library, removing the HAVE_PYTHON conditional entirely. Update required D-Bus version to 1.2.4 * README: Update dependencies documentation 2009-03-27 Scott James Remnant * nih/file.c (nih_file_read, nih_file_map): Cast to the bigger type. * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.c: Add missing signal.h include. * m4/compiler.m4: Add -Wextra, but turn off some of the silly ones. * nih/io.c (nih_io_buffer_resize): Remove unnecessary assert. * nih/file.c (nih_file_read, nih_file_map): Be explicit when comparing signed and unsigned types. * nih/option.c (nih_option_long): Cast pointer difference to size_t (nih_option_group_help): Use unsigned constant. * nih/command.c (nih_command_group_help): Use unsigned constant. * nih/tests/test_config.c (test_parse_stanza): Cast -1 to size_t to get the real number. * nih-dbus/dbus_object.c (nih_dbus_object_vtable): Move static to before const. * nih-dbus/tests/test_dbus_message.c (my_error_connect): Put static before const. 2009-03-22 Scott James Remnant * nih/Makefile.am (tests): Add rule to build all test cases without running them (useful when using valgrind). * nih-dbus/Makefile.am (tests): Add the same rule. * nih/test_values.h (TEST_EQ_STR, TEST_EQ_STRN, TEST_EQ_MEM) (TEST_NE_STR, TEST_NE_STRN, TEST_NE_MEM): Guard against NULL being parsed. * nih/test_alloc.h (TEST_ALLOC_SIZE, TEST_ALLOC_PARENT) (TEST_ALLOC_ORPHAN): Also guard against NULL for these. * nih/test_files.h (TEST_FILE_MATCH): Add test that lets us match the content of a file line against a wildcard pattern. 2009-02-20 Scott James Remnant * nih/option.c (nih_option_help), * nih/command.c (nih_command_help), * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.c (my_str_to_int32_array): No need for a new_* temporary variable when looping over nih_realloc with NIH_MUST. * nihify: Add nih-dbus-tool symlink too * nih/watch.c (nih_watch_new): Update to set variable outside of NIH_SHOULD and NIH_MUST macros. (nih_watch_add, nih_watch_handle), * nih/alloc.c (nih_alloc_ref_new), * nih/timer.c (nih_timer_init), * nih/signal.c (nih_signal_init), * nih/child.c (nih_child_init), * nih/io.c (nih_io_init), * nih/file.c (nih_dir_walk, nih_dir_walk_scan) (nih_dir_walk_visit), * nih/main.c (nih_main_init_full, nih_main_version) (nih_main_set_pidfile, nih_main_get_pidfile) (nih_main_write_pidfile, nih_main_loop_init), * nih/option.c (nih_option_parser, nih_option_handle_arg) (nih_option_join, nih_option_help, nih_option_group_help), * nih/command.c (nih_command_parser, nih_command_join) (nih_command_help, nih_command_group_help), * nih/logging.c (nih_log_message), * nih/error.c (nih_error_init, nih_error_raise) (nih_error_raise_printf, nih_error_raise_system) (nih_error_push_context), * nih/tests/test_string.c (test_array_copy, test_array_append), * nih/tests/test_watch.c (my_create_handler, my_modify_handler) (my_delete_handler), * nih-dbus/dbus_error.c (nih_dbus_error_raise) (nih_dbus_error_raise_printf), * nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.c () (my_test_async_method, my_str_to_int32_array): Update to set variable outside of NIH_MUST macro. 2009-02-20 Casey Dahlin * nih/macros.h (NIH_MUST, NIH_ZERO): Use the GCC statement expression extension (also used by nih_min and nih_max) to allow these macros to return the value of their expression. * nih/error.h (NIH_SHOULD): Also return its value. 2009-02-20 Scott James Remnant * nih-dbus-tool/Makefile.am (test_com_netsplit_Nih_Test_object_LDADD) (test_com_netsplit_Nih_Test_proxy_LDADD): Fix path to libnih-dbus.la * nih/option.c (nih_option_parser): Fix a bug where a lone dash would be eaten instead of treated as an argument * nih/tests/test_option.c (test_parser): Add test case * nih/option.c (nih_option_help): Support the bugs address being a URL, and slightly change the wording we use. * nih/libnih.ver: We have to export anything beginning _nih_* and the program_name and package_* variables. * configure.ac (AC_INIT): Give bugs address as a URL 2009-01-30 Scott James Remnant * Makefile.am (SUBDIRS): po needs to be last, so always append * configure.ac: Create nih-dbus-tool Makefile * Makefile.am (SUBDIRS): Add nih-dbus-tool sub-directory * nih-dbus-tool/Makefile.am: Include rules to create nih-dbus-tool and its tests * nih-dbus/Makefile.am: Remove those rules from here * nih-dbus/nih_dbus_tool.py: Move to nih-dbus-tool/nih_dbus_tool.py * nih-dbus/tests/com.netsplit.Nih.Test.xml, nih-dbus/tests/com.netsplit.Nih.Test_impl.c, nih-dbus/tests/com.netsplit.Nih.Test_impl.h, nih-dbus/tests/test_com.netsplit.Nih.Test_object.c, nih-dbus/tests/test_com.netsplit.Nih.Test_proxy.c: Move to nih-dbus-tool/tests * Makefile.am (SUBDIRS): conditionally add the nih-dbus directory depending on HAVE_DBUS * nih-dbus/Makefile.am: which means we don't have to conditionalise anything in this file, cleaning things up a bit. 2009-01-29 Scott James Remnant * nih-dbus/tests/test_com.netsplit.Nih.Test_proxy.c (test_method_dispatch): Fix the test case to not compare a void * with strcmp 2008-01-29 Casey Dahlin * nih/nih_dbus_tool.py (Method.asyncDispatchPrototype): Prototype for new asynchronous dispatch function, explained below. (Method.asyncDispatchFunction): The asynchronous dispatch function takes a proxy, the arguments to the given method, a callback and an "errback" function pointer, and a void pointer. It calls the DBus method, but does not wait for a reply. Instead it sets up the callback to be called upon reply. If an error occurs, the errback is called instead. Either function will recieve the proxy and the value in the void pointer as arguments. The normal callback also receives arguments for anything returned by the method. (Method.asyncNotifyPrototype): Prototype for new asynchronous notification function. See below. (Method.asyncNotifyFunction): When the asynchronous dispatch function sets up a method call, it specifies the function generated by this function as the callback, and passes it an NihAsyncNotifyData struct containing the user-provided callback and errback. The asynchronous notify function then sets up the error to be handled by the errback or marshalls the return values to the callback. (Generator.exportTypedefs): This function returns a list of tuples * nih-dbus/tests/test_com.netsplit.Nih.Test_proxy.c (test_method_dispatch): of (type, name, args) format for typedefs to be placed in the generated header file. Args is present for defining function arguments for function pointer typedefs. (lineup_typedefs): Works like the other lineup_*s. Outputs typedef text from (type, name, args) tuples (see above) in a prettified, well-spaced format. (typedef_lineup_prefix): Used to make names line up well in lineup_typedefs. If a string begins with (* it is returned as is. If it begins with * it is returned with one leading space. Otherwise it gets two leading spaces. * nih-dbus/tests/test_com.netsplit.Nih.Test_proxy.c (test_method_dispatch): Test asynchronous method dispatch 2009-01-29 Scott James Remnant * nih/alloc.c (nih_alloc_real_set_destructor): Does not modify the actual data, so the pointer can be const. (nih_ref): Does not modify the actual data, so the pointer can be const. (nih_unref_only): Does not modify the actual data, and unlike nih_unref(), does not free it; so the pointer can be const * nih/alloc.h: Update prototypes. * configure.ac: Bump version to 0.2.1 * NEWS: Begin 0.2.1 * NEWS: Update * nih/test_alloc.h (TEST_ALLOC_FAIL): Initialise the count in the loop pre-condition, still doesn't solve gcc's issues but I prefer it. * nih/tests/test_command.c (test_help): Array was too small, increase the size. * nih/tests/test_string.c (test_str_split): Oops, left some debugging in here. * nih/file.c (nih_file_read): Never trust a changelog entry that says "minor clean-up"; make sure we raise the error before returning NULL. * nih-dbus/dbus_connection.c (nih_dbus_setup) (nih_dbus_add_watch, nih_dbus_add_timeout): We should discard objects attached to the D-Bus connection since they're floating; nobody should take a reference, but good practice and all that. * nih/alloc.h: Document the different usage patterns * nih/io.c (nih_io_buffer_resize): Use nih_unref() instead of nih_free(), while nothing should have taken a reference, it's a good pattern to stick to. (nih_io_message_recv): Use nih_local for ctrl_buf (nih_io_message_send): Use nih_local for ctrl_buf (nih_io_send_message): Take a reference to messages on the send q (nih_io_watcher_write): Unreference the message from the NihIo object instead of freeing, in case a reference is used elsewhere (nih_io_read): Unreference instead of freeing (nih_io_get): Unreference instead of freeing (nih_io_message_new): Parent should not be the NihIo (nih_io_write): Obey that rule here * nih/tests/test_io.c (test_send_message): Make sure that a reference is taken after all. (test_watcher): Don't create object with parent as io * nih/file.c (nih_file_read): Minor clean-up * nih/main.c (nih_main_set_pidfile): Discard the pid file in case someone took a reference to it. * nih/main.c (nih_main_init_full): Discard the package string in case another part of the code has taken a reference to it; since it never changes unless this function is called, generate it here (nih_main_package_string): dropping this function (nih_main_version): Fetch package_string * nih/main.h: Add external package_string and drop function proto. * nih/tests/test_main.c (test_package_string): Fold these tests into (test_init): here. * nih/libnih.supp: Update suppression * nih/logging.c (nih_log_message): Use nih_local for message * nih/io.c (nih_io_printf): Use nih_local for str * nih/config.c (nih_config_parse_stanza): Use nih_local for name. 2009-01-28 Scott James Remnant * nih/file.c (nih_dir_walk_visit): Can't allocate nih_local var with a parent, otherwise it'll never be cleaned up. * nih/config.c (nih_config_parse): Initialise nih_local var to NULL. * nih/alloc.c (nih_alloc_context_free): After the destructor has been called, an object is dead. Attempting to reference it should fail, so we need to store a flag that this has happened. (nih_realloc, nih_free, nih_discard, nih_alloc_real_set_destructor) (nih_alloc_ref_new, nih_unref, nih_alloc_parent) (nih_alloc_ref_lookup, nih_alloc_size): Forbid operations on finalised objects. * nih/tests/test_alloc.c (test_free): Once again I've tripped over bugs where the ordering of allocations between siblings in a child matters if they refer to each other in their destructor (typical case, a hash table in a struct). * nih/alloc.c (nih_realloc, nih_alloc_ref_new): Reverse the free order, so that the last member allocated is the first one freed. This was the original fix for the above bug, but this just moves the problem without really fixing it. I do think it's generally correct that the order should be backwards though. (nih_free): Since this is the only function that needs to do it, take care of casting off parents here. (nih_unref): Again, since this is the only function that needs to free the context when there are no parents, do it here after freeing the reference. (nih_alloc_ref_free): Which means this function no longer needs to recurse; nih_free() and nih_discard() always directly free a context, and nih_unref() knows to if there are no parents left; nih_unref() explicitly doesn't free the context. (nih_unref_only): No need to pass FALSE to nih_alloc_ref_free() now. (nih_alloc_context_free): This gets the big rewrite; rather than just recursively freeing the heirarchy, finalise them first by calling destructors and then reparenting them to the context being freed. Only free the objects after all destructors are called. * nih/macros.h (MIN, MAX): Replace with newer evaluation-safe nih_min() and nih_max() * nih/io.c (nih_io_select_fds): Replace MAX with nih_max (nih_io_buffer_pop): Replace MIN with nih_min (nih_io_buffer_shrink): Replace MIN with nih_min * nih/command.c (nih_command_group_help): Replace MAX with nih_max, nicely avoiding multiple function call there. * nih/option.c (nih_option_group_help): Likewise. * nih/tests/test_io.c (test_select_fds): Replace MAX with nih_max * nih-dbus/nih_dbus_tool.py (Method.replyFunction): Don't free the message passed in to the function. Since we now require the handler function to take a reference to the message during async processing, we can't just go around freeing it. (Method.replyPrototype): Warn if the error from the reply function is ignored, since this is important. * nih-dbus/dbus_message.c (nih_dbus_message_error): Likewise we should not free the message when passed in for a caller either. * nih-dbus/tests/test_dbus_message.c (my_return_error_cb): Update to make sure the message is not freed. * nih-dbus/tests/com.netsplit.Nih.Test_impl.c (async_method_reply): Make sure message is not freed. * NEWS: Document the change 2009-01-26 Scott James Remnant * configure.ac: Officially mandate libtool 2.2 * HACKING: Bump dependency on libtool to 2.2.4 * NEWS: Document change. * configure.ac (AC_INIT): Bump version to 0.2.0 since we're making a number of large API changes. (AC_COPYRIGHT): Bump the copyright year too. * NEWS (0.1.0): Declare 0.1.0 to have happened at revision 600 before we started the most recent round of changes; this is the version shipped with Upstart 0.5 but with the fixed list iteration. (0.2.0): Begin documenting changes in the API since then; this file can therefore be used as a checklist for updating software. * nih-dbus/dbus.c, nih-dbus/dbus.h: Seperate out the code into separate files to make maintenance much easier. The new files are nih-dbus/dbus_error.c, nih-dbus/dbus_error.h, nih-dbus/dbus_connection.c, nih-dbus/dbus_connection.h, nih-dbus/dbus_message.c, nih-dbus/dbus_message.h, nih-dbus/dbus_object.c, nih-dbus/dbus_object.h, nih-dbus/dbus_proxy.c, nih-dbus/dbus_proxy.h, nih-dbus/dbus_util.c, nih-dbus/dbus_util.h. * nih-dbus/nih_dbus_tool.py (Output.sourceFile): Change include to separate ones for error, message, object and proxy. (Output.headerFile): Change include to separate ones for message, object and proxy. * nih-dbus/dbus_message.c (nih_dbus_message_new): New function separated out of nih_dbus_object_message(); also no need to cast the destructor. * nih-dbus/dbus_object.c (nih_dbus_object_message): Clean up to call new nih_dbus_message_new function. * nih-dbus/libnih-dbus.h: New top-level header to include everything * nih-dbus/tests/test_dbus.c: Separate out the tests into files to match the sources. The new files are nih-dbus/tests/test_dbus_error.c, nih-dbus/tests/test_dbus_connection.c, nih-dbus/tests/test_dbus_message.c, nih-dbus/tests/test_dbus_object.c, nih-dbus/tests/test_dbus_proxy.c, nih-dbus/tests/test_dbus_util.c. * nih-dbus/tests/test_dbus_error.c (test_error_raise_printf): Looks like this function was never run in the old test suite, oops. * nih-dbus/tests/test_dbus_message.c (test_message_new): Test the new function * nih-dbus/tests/test_com.netsplit.Nih.Test_object.c: Drop includes we don't actually seem to use the library! * nih-dbus/tests/test_com.netsplit.Nih.Test_proxy.c: Update includes to include proxy * nih-dbus/tests/com.netsplit.Nih.Test_impl.c: Replace includes with separate ones. * nih-dbus/tests/com.netsplit.Nih.Test_impl.h: Drop include. * nih-dbus/Makefile.am (include_HEADERS): Install the top-level header (nihdbusinclude_HEADERS): Update paths to new headers (libnih_dbus_la_SOURCES): Build from new sources (TESTS, test_dbus_error_SOURCES, test_dbus_error_CFLAGS) (test_dbus_error_LDFLAGS, test_dbus_error_LDADD) (test_dbus_connection_SOURCES, test_dbus_connection_CFLAGS) (test_dbus_connection_LDFLAGS, test_dbus_connection_LDADD) (test_dbus_message_SOURCES, test_dbus_message_CFLAGS) (test_dbus_message_LDFLAGS, test_dbus_message_LDADD) (test_dbus_object_SOURCES, test_dbus_object_CFLAGS) (test_dbus_object_LDFLAGS, test_dbus_object_LDADD) (test_dbus_proxy_SOURCES, test_dbus_proxy_CFLAGS) (test_dbus_proxy_LDFLAGS, test_dbus_proxy_LDADD) (test_dbus_util_SOURCES, test_dbus_util_CFLAGS) (test_dbus_util_LDFLAGS, test_dbus_util_LDADD): Add details for new tests, replacing old ones * nih/dbus.c, nih/dbus.h, nih/libnih-dbus.supp, nih/libnih-dbus.ver, nih/nih_dbus_tool.py, nih/test_dbus.h, nih/tests/com.netsplit.Nih.Test.xml, nih/tests/com.netsplit.Nih.Test_impl.c, nih/tests/com.netsplit.Nih.Test_impl.h, nih/tests/test_com.netsplit.Nih.Test_object.c, nih/tests/test_com.netsplit.Nih.Test_proxy.c, nih/tests/test_dbus.c: Move all D-Bus related code into a new sub-directory * nih/Makefile.am: Move D-Bus related rules into * nih-dbus/Makefile.am: here. * nih-dbus/tests/test_dbus.c: Update include path for D-Bus test macros and dbus.h * nih-dbus/tests/test_com.netsplit.Nih.Test_object.c: Update include path for dbus.h * nih-dbus/tests/test_com.netsplit.Nih.Test_proxy.c: Update include path for dbus.h * nih-dbus/tests/com.netsplit.Nih.Test_impl.c: Update include path for dbus.h * nih-dbus/tests/com.netsplit.Nih.Test_impl.h: Update include path for dbus.h * nih-dbus/nih_dbus_tool.py (Output.sourceFile, Output.headerFile): Generate includes with correct path for dbus.h * Makefile.am (SUBDIRS): Iterate into new sub-directory * configure.ac (AC_CONFIG_FILES): Generate new Makefile * nihify: Create symlink to nih-dbus as well * nih/tests/com.netsplit.Nih.Test_impl.c (my_test_async_method): Take a reference to the message * nih/libnih-dbus.supp: Update D-Bus suppressions. * TODO: Update * nih/libnih.supp: Update suppressions for new calling stack * nih/dbus.c (nih_dbus_object_new): Update documentation to match new nih_alloc(), no need to cast destructor (nih_dbus_proxy_new, nih_dbus_path): Update documentation to match new nih_alloc() (nih_dbus_object_message): Make the message nih_local, this means the handler must now reference the message otherwise it will be freed. (nih_dbus_object_introspect): Make the xml string nih_local (nih_dbus_message_error): Make the string nih_local * nih/tests/test_dbus.c (test_error_raise) (test_error_raise_printf): Don't check for no parent if we don't need to. (my_return_error): Must reference the message (test_error_raise, test_error_raise_printf): Must mean TEST_ALLOC_FAIL * nih/main.c (nih_main_loop_add_func): Update documentation to match new nih_alloc(), no need to cast destructor function. (nih_main_version): Use nih_local (nih_main_write_pidfile): Use nih_local * nih/tests/test_main.c: Include limits.h * nih/io.c (nih_io_watcher): Can't just break if we catch a free, we have to at least process errors first! * nih/watch.c (nih_watch_new): Update documentation to match new nih_alloc(), no need to cast destructor function. (nih_watch_add): No need to cast destructor function; free the not a directory error as well. (nih_watch_handle): Use nih_local on the path so it's always cleaned up if we don't reference it; reference it when delaying the create handler instead of reparenting * nih/tests/test_watch.c: Include limits.h (test_new): Free watch inside loop, don't select fds; no idea why this code is here. (test_reader): Can't just call select then handle, we actually have to wait for activity first. (my_create_handler, my_modify_handler, my_delete_handler): Loop over allocations, we can't use TEST_ALLOC_SAFE if we don't know we're in a TEST_ALLOC_FAIL. 2009-01-25 Scott James Remnant * nih/file.c (nih_file_read): Update documentation to match new nih_alloc() (nih_dir_walk, nih_dir_walk_visit): No need to cast destructor function, use nih_local to clean up code a little bit. (nih_dir_walk_scan): Use nih_local to make this easier. * nih/tests/test_file.c: Include limits.h (my_visitor): No need to cast destructor * nih/test.h: Include config.h since that defines _GNU_SOURCE * nih/tests/test_child.c, nih/tests/test_signal.c: Remove extra double include. * nih/test_alloc.h (TEST_FREE_TAG): Remove incorrect "extern" * nih/alloc.c (nih_unref_only): Add function to allow unreferencing without freeing, for example if we return something from our state and want to reparent but still allow NULL. * nih/alloc.h: Add prototype. * nih/io.c (nih_io_add_watch, nih_io_message_new, nih_io_reopen): Update documentation to match new nih_alloc(), no need to cast destructor function. (nih_io_buffer_new, nih_io_buffer_pop, nih_io_read, nih_io_get): Update documentation to match new nih_alloc() (nih_io_read_message): Update documentation to match new nih_alloc(), reparent message by referencing to parent before unreferencing from io structure. * nih/tests/test_io.c (test_read_message, test_send_message): Replace TEST_ALLOC_PARENT with NULL parent with TEST_ALLOC_OPRHAN (test_read_message): Message must reference the io watch (test_message_add_control): Remove strange allocator changing. (test_message_recv): Call nih_error_init to avoid valgrind issue * nih/child.c (nih_child_add_watch): Update documentation to match new nih_alloc(), no need to cast destructor function. * nih/tests/test_child.c: Include config.h * nih/signal.c (nih_signal_add_handler): Update documentation to match new nih_alloc(), no need to cast destructor function. * nih/tests/test_signal.c: Include config.h * nih/timer.c (nih_timer_add_timeout, nih_timer_add_periodic) (nih_timer_add_scheduled): Update documentation to match new nih_alloc(), no need to cast destructor function. * nih/alloc.c (nih_alloc_parent, nih_alloc_size): Pointer argument should be const since we don't modify it. * nih/alloc.h: Update prototype. * nih/error.h: Add documentation for header. (NIH_SHOULD): Much needed docstring. * nih/logging.c: Include nih/macros.h * nih/logging.h: Add documentation for header. * nih/config.c (nih_config_next_token, nih_config_next_arg) (nih_config_parse_args, nih_config_parse_command) (nih_config_parse_block): Update documentation to match new nih_alloc() (nih_config_parse): Rewrite to use nih_file_read() into an nih_local variable, instead of mmap which has strange behaviours in the face of updates. * nih/config.h: Add documentation header. * nih/tests/test_config.c: Include limits.h * nih/command.c (nih_command_parser): Update documentation to match new nih_alloc(), use nih_local where possible to clean up code. (nih_command_join): Update documentation to match new nih_alloc() (nih_command_handle): Update documentation to match new nih_alloc(), use nih_local where possible to clean up code. (nih_command_help): Use nih_local for groups array (nih_command_group_help): Use nih_local for wrapped string * nih/command.h: Add documentation string for header. * nih/option.c (nih_option_parser): Update documentation to match new nih_alloc(), should not use parent for any old allocation. (nih_option_join): Update documentation to match new nih_alloc() (nih_option_help): Use nih_local for temporary strings and groups (nih_option_group_help): Use nih_local for temporary string. * nih/option.h: Add documentation string for header. * nih/list.h, nih/hash.h: Provide a much better documentation string. * nih/tree.c (nih_tree_new, nih_tree_entry_new): Update documentation to match new nih_alloc(); no need to cast destructor function * nih/tree.h: Add documentation string for the header. * nih/hash.c (nih_hash_new): Update documentation to match new nih_alloc(); update comment to reflect what we actually do to pick a prime. (nih_hash_pointer_key, nih_hash_pointer_hash) (nih_hash_pointer_cmp): Drop these, we were looking at the raw bytes of a pointer, which is almost certainly naughty. * nih/hash.h: Add documentation string, remove prototypes. (NIH_HASH_FOREACH, NIH_HASH_FOREACH_SAFE): Update documentation in same manner as the list functions. (nih_hash_pointer_new): Drop, this is probably illegal C ;-) (nih_hash_string_new): Update documentation to match new nih_alloc() * nih/tests/test_hash.c (test_pointer_new, test_pointer_key): Drop. (test_lookup): Modify to use string hashes instead. (test_foreach, test_foreach_safe): Fix function name comment. * nih/list.c (nih_list_new, nih_list_entry_new): Update documentation to match new nih_alloc(); No need to cast the destructor function anymore. * nih/list.h: Add documentation string for the header. (NIH_LIST_FOREACH, NIH_LIST_FOREACH_SAFE): Improve documentation about which is best. (NIH_LIST_ITER): Add macro to make iterating a list with an offset head easier. * nih/macros.h: Add sorely-missed documentation strings, including one for the header itself. (NULL): Drop, NULL is defined by the C compiler. * nih/string.c: Update all documentation to match new nih_alloc() (nih_str_array_addp): Take a reference to the passed variable instead of reparenting (which isn't possible anymore). (nih_str_array_add, nih_str_array_addn): Since these just call nih_str_array_addp() which now takes a reference rather than reparents, we can change these functions to make new_str as a local variable. (nih_strv_free): Drop this function, it's not used and it's utterly inconsistent with the others as it expressly isn't used with nih_alloc(). (nih_strncat): This function worryingly did not work if NULL was passed, catch that and call nih_strndup() instead. * nih/string.h: Add a documentation string and drop prototype. * nih/tests/test_string.c (test_strv_free): Drop. (test_sprintf, test_vsprintf, test_strdup, test_strndup): Replace TEST_ALLOC_PARENT calls with NULL as the second argument with TEST_ALLOC_ORPHAN instead. (test_strcat, test_strncat, test_strcat_sprintf) (test_strcat_vsprintf): Strangely these test cases don't appear to have worked before, the functions return NULL in case of memory allocation failure so we need to check the string against a temporary copy stored before, and we need to free that string as well. Also add test cases for NULL being passed in as the source string. * nih/test_alloc.h: Expose references to nih_alloc()'s pointers to malloc, realloc and free so we can replace them for testing purposes. (TEST_ALLOC_SIZE): Since this returns the size of the allocated object, rather than the request, check that the block is at least as large as the argument given - not exactly as large. (TEST_ALLOC_PARENT): Call nih_alloc_parent directly with both arguments, since it's compatible with our calling - can't output the current parent now they're may be multiple though. When passed NULL this now checks if it *has* a parent (almost the exact inverse of the previous meaning). (TEST_ALLOC_ORPHAN): New test to make sure that an object does not have a parent. (_test_free_tag): Reimplement to lookup the tag block in a linked list, instead of a static array, and only return TRUE or FALSE. (_test_destructor): Drop, we can just use nih_list_destroy instead. (TEST_FREE_TAG): Reimplement to allocate the tag struct itself as the child, and place in a linked list. (_test_malloc): Add malloc wrapper. (_test_allocator): Rename to _test_realloc (TEST_ALLOC_FAIL, TEST_ALLOC_SAFE): Change allocator through the exposed variables. * nih/alloc.h (nih_local): Macro to add a variable attribute that calls a nih_discard() as a cleanup function when the variable goes out of scope. * nih/alloc.c (_nih_discard_local): gcc cleanup function wrapper that takes the address of the local variable, it gets the actual pointer out and passes it to nih_discard(). Unlike the other functions, this actually allows the pointer to be NULL. * nih/tests/test_alloc.c (test_local): Test local variables work! * nih/alloc.c (nih_alloc_has_ref): Rename back to nih_alloc_parent. (nih_alloc_parent): Accept NULL, if given returns TRUE if there are any parents. * nih/alloc.h: Update prototype. * nih/tests/test_alloc.c (test_parent): Since it's a bit more complex, we should probably explicitly test this ;-) * nih/test.h, nih/test_output.h, nih/test_values.h, nih/test_process.h, nih/test_divert.h, nih/test_files.h, nih/test_alloc.h, nih/test_list.h, nih/test_hash.h, nih/test_dbus.h: Split the test macros out into separate files to make maintaining them easier. None of them may be included directly, execept nih/test_dbus.h which is now no longer included by default. * nih/Makefile.am (nihinclude_HEADERS): Install new headers. * nih/alloc.c: Re-implement as a multi-reference allocator; an object may now have as many parents as you wish, each one holding its own reference to it. (NihAllocCtx): Restructure. (NihAllocRef): New object linked by context to hold a reference. (nih_alloc_init, nih_alloc_set_allocator, nih_alloc_using): Drop support for custom allocators, knowing that we always use malloc is useful for the implementation - we still allow the test suite to change them, but nothing else. (nih_alloc): Reimplement from original nih_alloc_using() function, now calls nih_alloc_ref_new() if parent is not NULL. (nih_realloc): Reimplement for multi-referenceness; much of the this remains the same. (nih_free): Reimplement as a wrap around nih_alloc_context_free(). (nih_discard): New function to discard an object if it has no parent references, used if you believe references may have been taken by functions you have called. (nih_alloc_context_free): Common function to free an object, calling its destructor after discarding parent references but before cleaning up children. (nih_alloc_reparent): Drop, it's no longer possible to simply reparent an object. Instead you should call the new functions: (nih_ref, nih_alloc_ref_new, nih_unref, nih_alloc_ref_free): Handle NihAllocRef objects, linking them to a context and removing them from a context; when the last reference to a child is removed, we automatically call nih_alloc_context_free(). (nih_alloc_parent, nih_alloc_has_ref): Replace the former function with the latter, it's no longer possible to query the exact parent since there isn't one. (nih_alloc_ref_lookup): Internal function to find a reference. (nih_alloc_size): Reimplement assuming malloc, which saves us some space in the context structure. * nih/alloc.h: Update all prototypes and documentation, including adding module documentation to the top of the header file. (NihAllocator): Drop typedef. (nih_alloc_set_destructor): Add casting macro with name of original function that calls nih_alloc_real_set_destructor(). * nih/tests/test_alloc.c (test_new, test_alloc): Fix to check for a reference rather than the explicit parent; also include a test for allocation failure using a malloc hook. (test_realloc): Fix to check for a reference rather than the explicit parent, change allocatil failure test to use a realloc hook instead of a different allocator. (test_free): Add a with parent test. (test_discard): New test, as test_free() but with different expected result for the parent test. (test_set_allocator): Drop test. (test_reparent, test_ref, test_unref): Drop the former test and replace with checking that referencing and unreferencing works. 2008-10-24 Scott James Remnant * nih/list.h (NIH_LIST_FOREACH_SAFE): Mark the cursor to be automatically cleaned up should we exit the loop; this somewhat simplifies the definition and allows returning from within the loop. * nih/list.h (NIH_LIST_FOREACH_SAFE): Fix a typo that caused only once cursor variable to be used, rather than one per iteration. * nih/main.h, nih/main.c, nih/dbus.c, nih/tests/test_dbus.c: Revert previous "delete" patch now that we can iterate linked lists without tripping over the bug we found here. * nih/libnih-dbus.supp: Update suppressions for newer glibc and D-Bus without debugging enabled. * nih/list.h (NIH_LIST_FOREACH_SAFE): Replace with a more ingenious version based on work by Casey Dahlin and myself; instead of caching the next pointer, place a cursor node in the list instead. This solves the issue where the next pointer may be changed or freed, and, in fact solves all issues of list rearrangement. * nih/tests/test_list.c (test_foreach_safe): Add test cases. * nih/hash.h (NIH_HASH_FOREACH_SAFE): Update comment to match. 2008-08-12 Casey Dahlin * nih/main.h (NihMainLoopFunc): Add delete member. * nih/main.c (nih_main_loop): Don't run the callback for any function marked for deletion, instead call nih_free on it. (nih_main_loop_add_func): Initialise delete to FALSE. * nih/dbus.c (nih_dbus_release_callback): Add function to mark a loop function as deleted. (nih_dbus_setup): and use it as the free function instead of nih_free. * nih/tests/test_dbus.c (test_connect, test_bus, test_setup): Check that the loop functions are marked for deletion instead of freed. * nih/nih_dbus_tool.py (Output.sourceFile): Include limits.h 2008-07-02 Scott James Remnant * nih/Makefile.am (test_com_netsplit_Nih_Test_object_SOURCES) (test_com_netsplit_Nih_Test_proxy_SOURCES): Add forgotten header. 2008-07-01 Scott James Remnant * TODO: Update. * nih/tests/test_com.netsplit.Nih.Test_proxy.c (test_method_dispatch): Add test cases for input and output arguments of various types. * nih/nih_dbus_tool.py (DBusArray.marshal): Add extra parens in array setting call for precedence reasons. * nih/tests/test_com.netsplit.Nih.Test_proxy.c (test_method_dispatch): Add basic tests of calls to synchronous and async methods, and the usual error returns. * nih/tests/com.netsplit.Nih.Test_impl.c (async_method_reply): Add replies that have the wrong combinations of arguments. * nih/tests/com.netsplit.Nih.Test_impl.c, * nih/tests/test_com.netsplit.Nih.Test_object.c (my_connect_handler) (my_setup, my_teardown): Move these functions across too. * nih/tests/com.netsplit.Nih.Test_impl.h: Add prototypes. * nih/dbus.c (nih_dbus_proxy_new): Allow name to be NULL. * nih/tests/test_dbus.c (test_proxy_new): Test without a name. * nih/tests/test_com.netsplit.Nih.Test_object.c, * nih/tests/com.netsplit.Nih.Test_impl.c: Separate out the server object implementation so that the proxy code could use it. * nih/tests/com.netsplit.Nih.Test_impl.h: Header for object definition * nih/Makefile.am (test_com_netsplit_Nih_Test_object_SOURCES) (test_com_netsplit_Nih_Test_proxy_SOURCES): Include the object implementation code. * nih/tests/test_com.netsplit.Nih.Test_proxy.c: Stub file for proxy test cases. * nih/Makefile.am (TESTS): Build the proxy test suite. (test_com_netsplit_Nih_Test_proxy_SOURCES) (test_com_netsplit_Nih_Test_proxy_CFLAGS) (test_com_netsplit_Nih_Test_proxy_LDFLAGS) (test_com_netsplit_Nih_Test_proxy_LDADD): Details for the proxy test suite, which actually includes the object code since it needs to implement objects too * nih/nih_dbus_tool.py (MemberWithArgs.variables): Only include arg array in object mode. * nih/Makefile.am ($(com_netsplit_Nih_Test_object_OUTPUTS)): ($(com_netsplit_Nih_Test_proxy_OUTPUTS)): Must be newer than the source for the python tool * nih/nih_dbus_tool.py (Interface.variables, Interface.exports): Only include the interface definition in object mode, we will need something for proxying signals later, but right now this means problems when building an object and its proxy together. * nih/Makefile.am (com_netsplit_Nih_Test_proxy_OUTPUTS) (com_netsplit_Nih_Test_proxy_XML) ($(com_netsplit_Nih_Test_proxy_OUTPUTS)): Generate sources in proxy mode for the test interfaces. (BUILT_SOURCES, MAINTAINERCLEANFILES, EXTRA_DIST): Build if necessary before anything else, clean in maintainer-clean and include in the distribution. 2008-06-30 Scott James Remnant * m4/libs.m4 (NIH_LIB_DBUS): Always check for Python, but don't error or disable D-Bus unless the install option is defined. Otherwise if we don't have it, don't define HAVE_PYTHON. * nih/Makefile.am (noinst_SCRIPTS): Only build if we have python. * nih/Makefile.am: Redress the Makefile such that the generated test sources are actually included in the distribution tarball. * nih/dbus.h (NihDDusProxy): Add definition for proxy structure and prototype for function to create one. * nih/nih_dbus_tool.py (Method.dispatchFunction): Adjust name of destination member in the proxy. * nih/dbus.c (nih_dbus_proxy_new): Simple function to create a new proxy object. * nih/tests/test_dbus.c (test_proxy_new): Add simple test for the simple function, which will get more complicated if we add signal filter registration later. * nih/errors.h (NIH_DBUS_INVALID_ARGS): Add error caused when the reply arguments on a method call were not what we expected. * nih/nih_dbus_tool.py: Implement the simplest of the method dispatch cases, a blocking method call with the reply data returned as arguments to the call. * nih/nih_dbus_tool.py: Allocate a copy of string arguments when passing, this makes them consistent with arrays, and also means that we can actually do method dispatching which requires the reply data to last longer than the underlying message. * nih/nih_dbus_tool.py: Add parent argument to marshal functions for when we need to allocate something (ie. arrays) * nih/nih_dbus_tool.py (DBusArray.marshal): Add extra parens around possible deferenced length variable, not needed for precedence but helps clarity in generated code. (DBusArray.dispatch): Increment the length inside the for loop, rather than always leaving it at zero, useful for debugging. * nih/nih_dbus_tool.py: Have a bash at sorting out the whole pointer and const problem again. Make them properties of a group, passed to type functions that can add * and const as appropriate, and allows DBusArray to be more clever about things. Works for the existing cases, anyway. * nih/nih_dbus_tool.py (Method.handlerPrototype): Only include function pointers when the mode is object. * nih/nih_dbus_tool.py: Allow mode to be changed to proxy, but don't specify anything to be generated for that mode yet. 2008-06-11 Scott James Remnant * Makefile.am (SUBDIRS): po has to come last to make sure we've built any auto-generated code before update-po * nih/nih_dbus_tool.py (Method.marshalFunction): Allow the message for the invalid args/type message to be translated. * nih/tests/test_child.c (test_poll): We end up creating a core file, so unlink it. * nih/Makefile.am (tests/com.netsplit.Nih.Test_object.c tests/com.netsplit.Nih.Test_object.h): Create the tests directory. 2008-06-08 Scott James Remnant * nih/Makefile.am (tests/com.netsplit.Nih.Test_object.c tests/com.netsplit.Nih.Test_object.h): Make the tests directory in the output. * nih/Makefile.am (EXTRA_DIST): Forgot to distribute the test XML * nih/file.c (nih_file_read): Implement a simpler function for reading a file into memory that does literally just that, better than map for various reasons. * nih/file.h: Add prototype. * nih/tests/test_file.c (test_read): Test it works. 2008-06-06 Scott James Remnant * nih/test.h (TEST_DBUS, TEST_DBUS_OPEN, TEST_DBUS_MESSAGE) (TEST_DBUS_CLOSE, TEST_DBUS_END): Various useful macros to set up, connect to, pop messages from, close and kill D-Bus connections to a private bus daemon. * nih/tests/test_string.c (test_array_copy): Add a test case for a zero-length array, which we need to be able to support. * nih/string.c (nih_str_array_copy): Fix it by always creating a new array to copy into, since array can't be NULL. 2008-06-04 Scott James Remnant * nih/tests/test_com.netsplit.Nih.Test_object.c (test_method_marshal): Why would I be allocating a string array using sizeof (int32_t), fix C&P error to make amd64 happy again. 2008-06-02 Scott James Remnant * nih/test.h (TEST_DBUS): Initialise _test_address to zeros so valgrind shuts up. * nih/test.h (TEST_DBUS, TEST_DBUS_END): Macros to set up a temporary D-Bus session bus for testing purposes. * nih/tests/test_dbus.c (test_object_new, test_object_destroy) (test_object_unregister): Use the system bus for testing, since there may be no session bus. * nih/tests/test_dbus.c (test_bus): We get an error when the session bus is not available, so we should eat that before skipping. 2008-06-01 Scott James Remnant * nih/dbus.c (nih_dbus_object_message): Keep a reference on the connection, as well as the message; otherwise if the connection is disconnected while handling a async method, we'll end up trying to send it to a freed connection instead of just a disconnected and forgotten one. (nih_dbus_message_destroy): Unreference the connection when freeing the message object. 2008-05-28 Scott James Remnant * TODO (main, timers): Update. * nih/nih_dbus_tool.py: The C type of string-like types should be just "char *"; instead we should add "const" when needed, such as in the prototype of handlers and in reply functions. This avoids some const-bending games. * nih/tests/test_com.netsplit.Nih.Test_object.c (my_emit_signal): Adjust type of string array to match. 2008-05-24 Scott James Remnant * HACKING: Changed branch location again. 2008-05-18 Scott James Remnant * nih/error.h (nih_return_no_memory_error): Add a convenience macro for raising the ENOMEM system error with the right string, rather than setting errno just do it directly. * nih/tests/test_error.c (test_return_no_memory_error): Make sure the macro is tested. * nih/dbus.c (nih_dbus_connect, nih_dbus_bus, nih_dbus_server): Use new macro to return ENOMEM when we're not sure that it's the current errno. 2008-05-14 Scott James Remnant * TODO: Update. * nih/tests/test_com.netsplit.Nih.Test_object.c (my_str_to_int32_array): Forgot to clean up parts after splitting. (test_method_marshal): Forgot to free self-allocated arrays, and we have to free a string array returned by D-Bus as well. (test_signal_dispatch): Another string array to be freed. * nih/tests/test_dbus.c (test_object_message): Don't use timeouts to guess when the reply should have arrived, just use a pending call notify function. This speeds the whole thing up a hundred fold and removes valgrind slowness issues. * nih/dbus.c (nih_dbus_message_error): Asynchronous messages need a way to return an error message to the sender after the handler function has terminated; this function fulfills that need * nih/dbus.h: Add prototype. * nih/tests/test_dbus.c (test_message_error): Add test case for replying to an asynchronous message with an error; this ends up somewhat evil since we're not using the bindings. * nih/nih_dbus_tool.py: Use a namespaced attribute to specify whether methods should be generated synchronous (reply generated after handler returns) or asynchronous (handler expected to keep the message object and call a reply function later). * nih/tests/com.netsplit.Nih.Test.xml: Add a test asynchronous method, the same basic method as the ordinary test method, but which is specified to generate an asynchronous call. * nih/tests/test_com.netsplit.Nih.Test_object.c: Add many tests for async calls, in fact, we pretty much just duplicate the sync tests but use a timer in the server to deliver the reply. * nih/dbus.c (nih_dbus_object_message): Set a destructor for the message that unreferences the attached D-Bus message when it is freed, and don't unreference it ourselves. Also allow the handler to return "not yet handled" to mean that the method has actually been handled, but the reply hasn't been sent yet. (nih_dbus_message_destroy): Destructor for the message. 2008-05-11 Scott James Remnant * nih/nih_dbus_tool.py: Implement handling for arrays of simple C types with an extra length variable, and handling for arrays of pointer types with an extra NULL element * nih/tests/com.netsplit.Nih.Test.xml: Add test methods with an int32 and string array as input and output, and test signals with both array types. * nih/tests/test_com.netsplit.Nih.Test_object.c: Add tests for the new methods and signals, testing the underlying automatic generation. 2008-05-10 Scott James Remnant * nih/string.c (nih_strncat, nih_strcat_vsprintf): Ok, there was a minor technical reason after all; don't strlen the string if we don't have it. * nih/string.c (nih_strcat, nih_strncat, nih_strcat_sprintf) (nih_strcat_vsprintf): Remove the restriction that the string must be pre-allocated, there's no technical reason for it, I was just trying to enforce a style. 2008-05-09 Scott James Remnant * nih/nih_dbus_tool.py: Drop the data type argument, and just pass around void *; we never have the types available, and since we have our own prototype anyway, we never upset gcc. * nih/dbus.c (nih_dbus_path): Empty path components are named as "_" instead. * nih/tests/test_dbus.c (test_path): Test the new functionality. 2008-05-08 Casey Dahlin * nih/file.c (nih_file_is_packaging): Add matches for various RPM temporary and atomicity files. 2008-05-08 Scott James Remnant * nih/dbus.c (nih_dbus_error_raise_printf): Add formatted error function, I held out as long as I could * nih/dbus.h: Add prototype. * nih/tests/test_dbus.c (test_error_raise_printf): And test for it. * nih/error.h: Add missing attribute * nih/Makefile.am: No need for version info if not installing 2008-05-06 Scott James Remnant * m4/compiler.m4: -Wformat is already in -Wall * nih/main.c (nih_main_daemonise): Deliberately ignore chdir return value, repeat the dup calls until they work. (nih_main_loop_interrupt): repeat write call until it succeeds. * nih/test.h (TEST_CHILD, TEST_CHILD_WAIT, TEST_CHILD_RELEASE): assert that pipe() returns zero and read() and write() both return 1. (TEST_DIVERT_STDOUT_FD, TEST_DIVERT_STDERR_FD): assert that dup2 returns a file descriptor. (TEST_FILE_RESET): assert ftruncate works. * nih/tests/test_io.c (test_add_watch, test_select_fds) (test_handle_fds, test_reopen, test_shutdown, test_destroy) (test_watcher, test_read_message, test_send_message, test_read) (test_write, test_get, test_printf, test_set_nonblock) (test_set_cloexec): assert that the pipe() calls work. (test_watcher): assert that write() returns expected number. * nih/tests/test_file.c (test_map): Check the fgets works. (test_dir_walk): assert that the symlink call works. * nih/tests/test_main.c (test_daemonise): assert pipe(), write() and getcwd() calls work. * nih/tests/test_com.netsplit.Nih.Test_object.c (my_setup): initialise wait_fd to get around gcc's blindness. (my_emit_signal): initialise ret. * m4/compiler.m4: Add -Wformat, -Wformat-security and -D_FORTIFY_SOURCE=2 to our default CFLAGS unless compiler warnings are disabled. 2008-04-29 Scott James Remnant * nih/tests/test_com.netsplit.Nih.Test_object.c (test_method_marshal) (test_signal_dispatch): For some reason valgrind needs some reassurance that it's ok to pass uninitialised data around in various cases; probably good for testing anyway. * nih/dbus.c (nih_dbus_path): Function to generate D-Bus paths with appropriate escaping of non-root elements. * nih/dbus.h: Add prototype. * nih/tests/test_dbus.c (test_path): Test the new function. * nih/dbus.c (nih_dbus_object_introspect): Free the introspection string after sending the message (oops!) 2008-04-27 Scott James Remnant * nih/tests/com.netsplit.Nih.Test.xml: Add signals to the test interface for the variety of basic argument types, we also need a glue function to make the server emit the signal. * nih/tests/test_com.netsplit.Nih.Test_object.c (my_emit_signal) (test_signal_dispatch): Test the signals are emitted and dispatched properly by catching them and checking them. 2008-04-26 Scott James Remnant * nih/test.h (TEST_GROUP): Add macro for when we don't test functions. * nih/tests/test_com.netsplit.Nih.Test_object.c (test_method_marshal): Use TEST_GROUP here. * nih/tests/com.netsplit.Nih.Test.xml: Add more methods to test, one generic method and two methods (in and out) for each basic type. * nih/tests/test_com.netsplit.Nih.Test_object.c: Slightly redo the way we do the tests, do the basic set of tests using a single method that can return cases such as errors, etc. Then have input and output marshal tests for each of the basic types. * nih/nih_dbus_tool.py (NAME_RE): Cope with numerics in member names, treat them the same as lowerspace characters. 2008-04-25 Scott James Remnant * TODO: Update, adding missing pieces for D-Bus support and an idea for changing the way that timers/signals/io/etc. work. * nih_dbus_tool.py: Handle the basic D-Bus types and generate marshalling functions for methods and dispatch functions for signals, along with all of the glue needed for nih_dbus_object_new() * nih/tests/com.netsplit.Nih.Test.xml: Interface to be used for testing of the generated code. * nih/tests/test_com.netsplit.Nih.Test_object.c: Test suite for the generated code (in object mode), so far this just tests a couple of methods but will be adding a lot more tests soon. * nih/Makefile.am (TESTS): Add the above test suite. (test_com_netsplit_Nih_Test_object_SOURCES) (test_com_netsplit_Nih_Test_object_CFLAGS) (test_com_netsplit_Nih_Test_object_LDFLAGS) (test_com_netsplit_Nih_Test_object_LDADD): Details for the test suite. (BUILT_SOURCES): Interface definitions are auto-generated and need to be done so at the start of the build so deps work properly. (CLEANFILES): All built sources need to be cleaned on "make clean" (tests/com.netsplit.Nih.Test_object.c tests/com.netsplit.Nih.Test_object.h): Generate the interface definitions with the binding tool, being sure to regenerate if the XML or binding tool change. * nih/dbus.c (nih_dbus_object_new): Register an object with D-Bus and hook it up to an internal message handling function that deals with introspection and the like, while passing off actual handling to marshaller functions for individual methods. (nih_dbus_object_destroy): When the object is freed, unregister it from the bus making sure that doing so doesn't try to free it a second time. (nih_dbus_object_unregister): When the bus connection is dropped or object otherwise unregistered, free it, making sure that doing so doesn't try to unregister it a second time. (nih_dbus_object_message): Handle messages for the object, locate the marshaller function in the interface structures or pass off to internal handler for introspection. (nih_dbus_object_introspect): Handle the Introspect method by generating XML which we return in a reply. * nih/dbus.h: Add prototype for new function. (NihDBusObject, NihDBusMessage, NihDBusMarshaller, NihDBusArgDir) (NihDBusArg, NihDBusMethod, NihDBusSignal, NihDBusAccess) (NihDBusProperty, NihDBusInterface): Add the truly insane number of structures and enums we need to fully specify the interfaces that a D-Bus object provides; you'll never do this by hand! :-) * nih/tests/test_dbus.c (test_object_new, test_object_destroy) (test_object_unregister, test_object_message): Test cases for new functions. (test_connect, test_bus): Check error messages using the macros rather than by name. 2008-04-23 Scott James Remnant * nih/tests/test_nih_dbus_tool.py: In hindsight, it's unnecessary to test the binding tool directly since the tests will basically just compare the output to an expected C file which will make maintaining it damned hard and doesn't actually guarantee it works; instead we'll test generated output. * nih/Makefile.am (TESTS): Remove the call to the Python test suite, and reverse the TESTS/check_PROGRAMS thing again to match. 2008-04-22 Scott James Remnant * nih/libnih-dbus.supp: D-Bus init_system_db() related leaks were likely a missing dbus_shutdown() since they've gone away now. * nih/dbus.c (nih_dbus_add_timeout, nih_dbus_timeout_toggled): Slightly adjust the millisecond to second conversion to always round up to the nearest whole second rather than down; that way we have a 1s minimum timeout instead of an immediate one. 2008-04-21 Scott James Remnant * nih/tests/test_dbus.c (test_bus): Cope when the session bus is not available. * nih/libnih-dbus.supp: Suppress annoying NSS problems on i686 as well (we did x86-64 last time). Also found that a couple of the suppressions were caused by failing to shutdown properly, so remove those (and uncover a D-Bus bug or two in the process). * nih/tests/test_dbus.c: Remove unnecessary SIGPIPE setting. * nih/libnih-dbus.supp: I keep finding ways in which D-Bus holds on to data, not to mention annoying NSS problems. * nih/libnih.supp: Add long-missing suppression for the main loop functions list, seems we've never actually tested that without freeing it manually. 2008-04-18 Scott James Remnant * nih/dbus.c (nih_dbus_connect, nih_dbus_bus): Functions to connect to an abitrary address or a well-known bus, calling our own handler on disconnect instead of exit() and setting things up in the main loop properly. (nih_dbus_setup): Function called by the above, and callable externally, to set up the disconnect handler and main loop hook-ups; deals with shared connections by checking the main loop slot. (nih_dbus_server): Similar function to create a listening server and hook it up to the main loop. (nih_dbus_add_watch, nih_dbus_remove_watch) (nih_dbus_watch_toggled, nih_dbus_watcher): Glue functions so that D-Bus can watch file descriptors using our main loop. (nih_dbus_add_timeout, nih_dbus_remove_timeout) (nih_dbus_timeout_toggled, nih_dbus_timer): Glue functions so that D-Bus can set timeouts using our main loop. (nih_dbus_wakeup_main): Glue function so that D-Bus can interrupt the main loop (I think this is really for multi-threaded apps, but it does no harm to force an iteration). (nih_dbus_callback): Glue function to dispatch D-Bus messages within the main loop. (nih_dbus_connection_disconnected): Filter function to catch the org.freedesktop.DBus.Local.Disconnected signal and call any disconnect handler before unreferencing the connection. (nih_dbus_new_connection): Handle new server connections by calling the connect handler if set, referencing the new connection then setting it up in the main loop. * nih/dbus.h (NihDBusDisconnectHandler, NihDBusConnectHandler): Function prototype typedefs for disconnect and connect handlers. * nih/tests/test_dbus.c (test_connect, test_bus, test_setup) (test_server): Test the new functions as best we can. * nih/libnih-dbus.supp: D-Bus slot allocator doesn't free memory. * nih/main.c (nih_main_loop_init): Make a non-static function. * nih/main.h: Add prototype. 2008-04-16 Scott James Remnant * nih/test.h (TEST_FILE_NE, TEST_FILE_NE_N): Fix logic of tests. 2008-04-12 Scott James Remnant * nih/Makefile.am: If we're not installing the library then we want to still make the script but don't want to install it. * nih/nih_dbus_tool.py: Skeleton code for the Python binding tool. * nih/tests/test_nih_dbus_tool.py: Test cases for the dbus tool. * nih/Makefile.am (TESTS): When building the dbus library, also run the Python test suite for the Python binding tool; this requires reversing the check_PROGRAMS/TESTS setting since it needs to only be in TESTS. * nih/libnih-dbus.supp, nih/libnih-dbus.ver: Library support files. * nih/dbus.c (nih_dbus_error_raise): Begin the D-Bus library with a function to raise an NihError that can be converted into a DBusError when necessary (to be used in function returns). * nih/dbus.h (NihDBusError): Type for the structure since we need to include a name member. * nih/tests/test_dbus.c (test_error_raise): Test case. * nih/errors.h: Add NIH_DBUS_ERROR error; no string for this since each individual error will have its own. 2008-04-11 Scott James Remnant * m4/misc.m4: Reverse the sense of the noinstall option, so that "install" needs to be present for libnih to be installed. * configure.ac: Install libnih when built from its own source. 2008-03-29 Scott James Remnant * nih/Makefile.am (libraries): Build optional libnih-dbus.la (libnih_dbus_la_SOURCES, libnih_dbus_la_CFLAGS) (libnih_dbus_la_LIBS, -version-info 0, libnih_dbus_la_LDFLAGS): Details for optional library. (EXTRA_DIST): Distribute the version script and suppressions files. (nihinclude_HEADERS): Install the optional libdbus header (bin_SCRIPTS): Build optional nih-dbus-tool binding tool script (CLEANFILES, EXTRA_DIST, do_subst, nih-dbus-tool): Create installed script by substituting in another, be sure to distribute the other and clean the intermediate file. (TESTS): Optional test suite (test_dbus_SOURCES, test_dbus_CFLAGS, test_dbus_LDFLAGS) (test_dbus_LDADD): Details for the optional dbus test suite. * m4/misc.m4 (AC_COPYRIGHT): Also add a Makefile PACKAGE_COPYRIGHT variable for substitution. (NIH_INIT): We have separate cflags for dbus-related tools, so we need to check that gcc supports -c and -o. * m4/libs.m4 (NIH_LIB_DBUS): Macro to detet whether pkg-config, D-Bus and Python are available and decide based on that whether or not we can build an optional D-Bus binding library; configure options and arguments determine whether being unable to is a warning or an error. * m4/misc.m4: Add the dbus option to the help and the call to check for the libraries. * README: Add a section on the dependencies this introduces. * m4/libs.m4: Add an empty file to hold macros relating to library detection. * m4/Makefile.am (dist_aclocal_DATA): Install and distribute the new macro file. * nihify: Symlink the new macro file across as well. 2008-03-19 Scott James Remnant * nih/hash.c (nih_hash_pointer_hash): Fix hash generation on 64-bit systems by using each byte rather than trying to be clever. 2008-03-14 Scott James Remnant * nih/hash.c (nih_hash_new): Also require hash and cmp functions and store in the structure. (nih_hash_add, nih_hash_add_unique, nih_hash_add_replace) (nih_hash_search, nih_hash_lookup): Change key type to void, use hash and cmp functions from the structure. (fnv_hash): Rename to nih_hash_string_key (nih_hash_string_cmp): String comparison function. (nih_hash_pointer_key, nih_hash_pointer_hash, nih_hash_pointer_cmp): Pointer hash functions. * nih/hash.h (NihHashFunction): Prototype for hash function. (NihCmpFunction): Prototype for key comparison function. (NihHash): Add hash_function and cmp_function members. (nih_hash_pointer_new, nih_hash_string_new): Macros to wrap function and pass in common key, hash and cmp functions. * nih/tests/test_hash.c: Update tests to include new functions and macros. * nih/watch.c: Use nih_hash_string_new() to create the hash table. * nih/command.c: Add const to local structures. (nih_command_join): Expect to not change the structures passed (nih_command_handle): Iterate structure as const. * nih/command.h: Add const to prototype. * nih/option.c: Add const to local structures. (nih_option_join): Expect to not change the structures passed * nih/option.h: Add const to prototype. * nih/error.c (nih_error_init): Make extern for consistency. * nih/error.h: Add prototype. * nih/logging.c (nih_log_init): Make extern for consistency. * nih/logging.h: Add prototype. * nih/child.c (child_watches): Rename to nih_child_watches and make extern. (nih_child_init): Make extern, update name of global. (nih_child_add_watch, nih_child_poll): Update name of global. * nih/child.h: Add prototypes. * nih/io.c (io_watches): Rename to nih_io_watches and make extern. (nih_io_init): Make extern, update name of global. (nih_io_add_watch, nih_io_select_fds, nih_io_handle_fds): Update name of global. * nih/io.h: Add prototypes. * nih/main.c (loop_functions): Rename to nih_main_loop_functions and make extern. (nih_main_loop_init, nih_main_loop, nih_main_loop_add_func): Update name of global. * nih/main.h: Add prototype. * nih/signal.c (signals): Rename to nih_signals and make extern. (nih_signal_init): Make extern, update name of global. (nih_signal_add_handler, nih_signal_poll): Update name of global. * nih/signal.h: Add prototypes. * nih/timer.c (timers): Rename to nih_timers and make extern. (nih_timer_init): Make extern, update name of global. (nih_timer_add_timeout, nih_timer_add_periodic) (nih_timer_add_scheduled, nih_timer_next_due, nih_timer_poll): Update name of global. * nih/timer.h: Add prototypes. * m4/misc.m4 (NIH_INIT): Allow the macro to take options, the first of which shall be "noinstall" which defines a Makefile conditional that prevents installation of files -- useful when embedded in things like Upstart. * m4/Makefile.am (dist_aclocal_DATA): Don't install if "noinstall" is defined. * nih/Makefile.am (lib_LTLIBRARIES): If "noinstall" is defined, still build the library but do not install it. (include_HEADERS): Don't install if "noinstall" is defined. 2008-03-08 Scott James Remnant * HACKING: Don't even need /product/ anymore. * HACKING: Terminology changes: Bazaar-NG is now just Bazaar; Malone is now just Launchpad's bug tracking system. 2008-03-07 Scott James Remnant * nih/error.h (NIH_SHOULD): We quite often need to loop while we get ENOMEM, but break on another error; this does that. * nih/watch.c (nih_watch_new): Use here, fixing a bug in the process where we didn't re-raise the error again. 2008-03-06 Scott James Remnant * nih/string.c (nih_strcat, nih_strncat, nih_strcat_sprintf) (nih_strcat_vsprintf): I'm needing to use realloc more than I should for string concatenation, so lets have some functions to do that. * nih/string.h: Prototypes for new functions. * nih/tests/test_string.c (test_strcat, test_strncat) (test_strcat_sprintf, test_strcat_vsprintf): Test the new functions. * TODO: Update. 2008-03-03 Scott James Remnant * nih/tests/test_config.c (test_token): Also check that backslashes can escape themselves; since you may want a literal one followed by whitespace or a newline. * nih/config.c (nih_config_token): Dequote blackslash following a blackslash. * nih/tests/test_config.c (test_token): We don't want to dequote anything other than newlines and whitespace, since the quote characters may be important for the value (e.g. \$FOO being different to $FOO). Add tests to make sure we don't. * nih/config.c (nih_config_token): After a slash, only dequote whitespace otherwise if we're copying, copy a literal slash character first. * nih/tests/test_string.c (test_array_append): Should work with a NULL array argument. * nih/string.c (nih_str_array_append): Make it work. (nih_str_array_copy): Which makes this function somewhat simpler. 2008-03-02 Scott James Remnant * nih/libnih.supp (nih-command-parser, nih-option-parser): Suppress leak of internal state during --help tests. (nih-main-package-string-test): Modify suppression to also catch when it's allocated within a test case. 2008-03-01 Scott James Remnant * nih/tree.h (NIH_TREE_FOREACH_FULL, NIH_TREE_FOREACH_PRE_FULL) (NIH_TREE_FOREACH_POST_FULL): The lack of these macros was silly. * nih/tests/test_tree.c (test_foreach_full) (test_foreach_pre_full, test_foreach_post_full): Add tests. * nih/tree.c (nih_tree_next, nih_tree_prev, nih_tree_next_pre) (nih_tree_prev_pre, nih_tree_next_post, nih_tree_prev_post): Rename these functions to *_full and add filter and data pointers, where the filter must return FALSE if given otherwise a node is ignored. * nih/tree.h: Update prototypes, and keep previous behaviour with the old names through the use of macros. Typedef the filter function pointer type. * nih/tests/test_tree.c (test_next_full, test_prev_full) (test_next_pre_full, test_prev_pre_full, text_next_post_full) (test_prev_post_full): Test iteration with filters. 2008-01-16 Scott James Remnant * nih/tree.c (nih_tree_next, nih_tree_prev, nih_tree_next_pre) (nih_tree_prev_pre, nih_tree_next_post, nih_tree_prev_post): It's never possible to break out of the loop since we always return inside it. * nih/tests/test_child.c (test_poll): Add test case for the watch being on the wrong event. * m4/compiler.m4 (NIH_COMPILER_COVERAGE): Allow this to disable use of -Os, which otherwise wouldn't be. * configure.ac (AC_COPYRIGHT): Update copyright to 2008. 2008-01-15 Scott James Remnant * nih/tests/test_child.c (test_poll): Don't run the ptrace tests under valgrind, since they upset it somewhat and return different things (I expect we end up tracing valgrind itself). * nih/main.c (nih_main_daemonise): Formatting fix. 2008-01-14 Scott James Remnant * HACKING: Correct bzr URL to trunk. 2007-12-06 Scott James Remnant * nih/child.c (nih_child_poll): I give up. The wait queue can change between an invocation of waitid with WNOWAIT and the invocation later to "remove" the entry. WNOWAIT is a waste of time, and no matter how useful it might have been, I just see no way of actually using it. * nih/child.h: Update documentation. 2007-12-02 Scott James Remnant * nih/signal.c (nih_signal_set_handler): Drop the SA_NOCLDSTOP flag from when we were setting SIGCHLD, I've no idea why this crept in and it now stops us doing things we want to. * nih/tests/test_signal.c (test_set_handler): Remove the test for it. * nih/tests/test_child.c (test_poll): Fix for AMD64, the data argument for PTRACE_GETEVENTMSG is unsigned long, which is larger than pid_t here. * nih/tests/test_child.c (test_poll): Fix up several race conditions in the ptrace test cases, there are a lot of quirks you have to remember when dealing this most insane of syscalls. (signal from traced child): Once we've finished the test we must detach from the child otherwise we'll trap our own SIGTERM and the child won't exit. Tthere's no need to send SIGCONT since this is an ordinary ptrace signal trap. (exec by traced child): Detach and send SIGCONT in case the process we run gets a signal delivered to it; if that happened, we'd trap that signal and the child would never exit. (fork by traced child): This is the most pathalogical. We had a race where nih_child_poll() was actually reaping the event for the child stopping. Change to get the child pid and wait for it before calling the poll function. Don't bother waiting for the child to terminate, we shouldn't ever find out if we've detached properly. 2007-11-29 Scott James Remnant * nih/main.c (nih_main_write_pidfile): Have to cast the difference in pointers to int, otherwise we get a compiler warning on amd64. * nih/child.c (nih_child_poll): Remove the hacks that shift the status information back now that we have a kernel patch in akpm's tree to fix it. 2007-11-15 Scott James Remnant * nih/child.c (nih_child_poll): I found out what was causing the signal information to be missing for CLD_STOPPED, a kernel bug; cope with it for now by shifting the status across 8 bits for CLD_TRAPPED and CLD_STOPPED until I get Roland to fix that bit. * nih/tests/test_child.c (test_poll): Replace sleeps with waitid WNOWAIT calls now that that particular kernel bug is fixed; add a couple of pauses so that the child doesn't exit and clean up the wait queue before we get a chance to look. Add a wait on the child stopping after fork to avoid a race condition where the child isn't actually running yet when we try and detach from it. * nih/child.h (NihChildWatch): Add events member and rename reaper to handler, since it can now be called for things like stop, trap and ptrace events. (NihReaper): Rename to NihChildHandler (NihChildEvents): Enumeration/bit flags for events member * nih/child.c (WAITOPTS): Define wait options in one place to make repeating them easier. (nih_child_add_watch): Add events argument and change type and name of function argument, set in the structure. (nih_child_poll): Rather than just working out a killed boolean (which was wrong anyway since it didn't take CLD_DUMPED into account), we store one of many events in the event argument and convert status if necessary (bit shifting for CLD_TRAPPED and ptrace events). Check this event against the events mask in the watch, and pass to the handler. * nih/tests/test_child.c (test_add_watch): Check that events and handler are initialised correctly. (test_poll): Many new test cases for exiting, killing, aborting, stopping, continuing, trapping and ptracing. 2007-11-03 Scott James Remnant * nih/watch.h (NihWatch): Add created hash table so we can easily delay the create_handler until the file is closed. * nih/watch.c (nih_watch_new): Initialise the created hash table. (nih_watch_handle): When a file is created, add an entry to the created hash table and return without calling a handler -- for all paths, check for and remove any remove any existing created entry; call create_handler instead of modify_handler if this exists, and don't call delete_handler at all. * nih/tests/test_watch.c (test_new): Check created is initialised. (test_reader): Test that creating a file doesn't trigger create until it's closed and that unlinking a file before it's been closed doesn't trigger at all. * nih/test.h (TEST_FREE_TAG): assert that we don't use this on a NULL pointer. 2007-11-02 Scott James Remnant * nih/test.h (TEST_FUNCTION_FEATURE): Add macro for when we're testing a specific feature of a function. 2007-10-27 Scott James Remnant * m4/compiler.m4 (NIH_COMPILER_OPTIMISATIONS): Add extra [...] * m4/compiler.m4 (NIH_COMPILER_WARNINGS): Add missing [...] around the second argument to AS_IF. (NIH_COMPILER_OPTIMISATIONS): Fix wrong use of [..][..] to [....] (NIH_COMPILER_COVERAGE): Remove extraneous comma * m4/linker.m4 (NIH_LINKER_VERSION_SCRIPT): Restore AM_CONDITIONAL that was mistakenly dropped. 2007-10-26 Scott James Remnant * m4/linker.m4 (NIH_LINKER_SYMBOLIC_FUNCTIONS): Test that checks for -Bsymbolic-functions * m4/linker.m4: Style fix. * m4/compiler.m4 (NIH_COMPILER_COVERAGE, NIH_COMPILER_OPTIMISATIONS) (NIH_COMPILER_WARNINGS): Update to use AS_IF. * m4/compiler.m4 (NIH_C_THREAD): Shell fix. * m4/linker.m4 (NIH_LINKER_OPTIMISATIONS): Update to use AS_IF. * m4/linker.m4 (NIH_LINKER_VERSION_SCRIPT): Update so it supports a config.cache 2007-10-24 Scott James Remnant * nih/file.c (nih_file_map): Catch a file larger than the length of size_t and raise the standard EFBIG error message. Noticed by Kees Cook. 2007-10-15 Scott James Remnant * nih/alloc.c (nih_alloc_using, nih_alloc_reparent, nih_realloc): Change the order in which children allocations are stored in the list such that the last allocation is freed first rather than the other way around. This solves issues of children being stored inside an allocated hash table which will be freed first. * m4/misc.m4 (NIH_INIT): Use AC_PROG_CC_C99 instead of NIH_C_C99 * configure.ac: Bump Autoconf dependency to 2.61 * HACKING: Likewise increase documentation * HACKING: Correct Bazaar branch now we're natively hosted on LP * nih/test.h (_test_allocator): Mark used in case it isn't. (_test_free_tag, _test_free_tags, _test_destructor) (TEST_FREE_TAG, TEST_FREE, TEST_NOT_FREE): Since destructors are now intended for internal use by an object, we shouldn't abuse them in test cases like we were doing - since we might not chain up properly and miss vital behaviour as a result. Instead implement some tests that use a destructor on an nih_alloc() child of the object to determine freeness. * nih/tests/test_watch.c (test_reader): Use TEST_FREE instead of a custom destructor, which are no longer favoured for this kind of work. * nih/tests/test_error.c (test_raise_again, test_pop_context): Use TEST_FREE instead of custom destructor. * nih/tests/test_timer.c (test_poll): Use TEST_FREE/TEST_NOT_FREE * nih/tests/test_child.c (test_poll): Use TEST_FREE, etc. * nih/tests/test_io.c (test_shutdown, test_watcher) (test_read_message, test_read, test_get): Use TEST_FREE, etc. * nih/hash.c, nih/timer.c, nih/signal.c, nih/child.c, nih/io.c, nih/watch.c: Document why non-allocated versions of functions are missing. * TODO: Update. 2007-10-14 Scott James Remnant * nih/alloc.c (nih_free): Call destructors before freeing children, this makes them more consistent with being structure clean-up functions rather than using them to detect a free. Don't return values from children destructors. * nih/tests/test_alloc.c (test_free): Adjust test, return values from children destructors are never returned. * nih/watch.c (nih_watch_new): Make the io structure an nih_alloc child of the watch, now that we don't perform any kind of lazy freeing or closing. (nih_watch_destroy): No need to close the io structure since it'll be automatically freed, just set the flag to be caught in the reader. * nih/tests/test_watch.c (test_new): Check parent of watch->io is watch, not NUL. (test_destroy): Don't use the destructor anymore, nih_alloc is tested elsewhere. (test_reader): Don't use destructor to test watch->io (my_destructor): Always call nih_watch_destroy since this is only used for that. * nih/io.c (nih_io_close): Rename to nih_io_destroy, setting a free flag in the structure if necessary before closing the descriptor and calling the error handler if there's a problem. (nih_io_reopen): Set destructor (nih_io_watcher): Rename lazy_close to caught_free and check its value after any calls to the reader, error handler or close handler functions; if true, simply bail out. Reorder leaving so that a shutdown check happens last (since this can free the structure). (nih_io_closed): Now simply calls the close handler if it exists, otherwise frees the structure. * nih/io.h (NihIo): Rename close member to free. Update prototypes. * nih/tests/test_io.c (my_reader, test_reopen): Use nih_free instead of nih_io_close. (test_reopen): Create new fds each time, since they are closed on free now. (destructor_called): Chain up to call nih_io_destroy (test_close): Rename to test_destroy and alter appropriately. (test_watcher): Adjust documentation to say we're checking that free is called in the reader. (test_send_message, test_write, test_printf): Open pipes rather than just stdout, because that will end up closed. 2007-10-12 Scott James Remnant * nih/watch.h (NihCreateHandler, NihModifyHandler, NihDeleteHandler): Modify doc strings to mention nih_free instead of nih_watch_free * nih/tests/test_file.c (my_visitor): Set destructor for the list entries we create as we go. * nih/watch.c (nih_watch_reader): Rework the function slightly, instead of using the free pointer to free at the end of the handler, use it to detect the free after the handler returns and immediately abort -- it means we won't process remaining watches but meh. (nih_watch_handle): Get passed the caught_free flag and check it after calling any handlers to make sure we abort properly. (nih_watch_free): Rename to nih_watch_destroy and just handle the internal cleanup. (nih_watch_new): Set the destructor properly. * nih/watch.h: Update prototypes. * nih/tests/test_watch.c (test_free): Rename to test_destroy. (my_delete_handler): Use nih_free not nih_watch_free (my_destructor): Chain up to nih_watch_destroy for NihWatch. * nih/tests/test_watch.c (my_destructor): Neither NihWatch nor NihIo need a destructor to be called. * nih/tests/test_child.c (test_poll): Fix erroneous removal of "1" * TODO: Update. 2007-10-11 Scott James Remnant * nih/option.c, nih/command.c, nih/config.c: Remove references to nih_alloc_set_destructor() from doc strings since this is now considered bad practice. * nih/main.c (nih_main_loop_add_func): Adjust call to set destructor * nih/tests/test_main.c (test_main_loop) (test_main_loop_add_func): Call nih_free instead of nih_list_free * nih/watch.c (nih_watch_add, nih_watch_handle): Call nih_free instead of nih_list_free (nih_watch_add): Set destructor to nih_list_destroy for now. * nih/tests/test_watch.c (my_destructor): Call nih_list_destroy for NihWatch structure. * nih/file.c (nih_dir_walk_visit): Call nih_free instead of nih_list_free (nih_dir_walk, nih_dir_walk_visit): Set destructor on object. * nih/tests/test_io.c (test_add_watch, test_select_fds) (test_handle_fds, test_shutdown, test_watcher): Call nih-free instead of nih_list_free (destructor_called): Call nih_list_destroy when passed an NihIoMessage; a bit icky since this is also called for an NihIo which doesn't have a destructor (yet) * nih/io.c (nih_io_watcher_write, nih_io_read, nih_io_get): Call nih_free instead of nih_list_free. (nih_io_add_watch): Adjust call to set destructor (nih_io_message_new): Set a destructor so the message is removed from a list when freed. * nih/child.c (nih_child_add_watch): Adjust call to set destructor (nih_child_poll): Call nih_free instead of nih_list_free * nih/tests/test_child.c (test_add_watch, test_poll): Call nih_free instead of nih_list_free. (my_destructor): Call nih_list_destroy(). * nih/string.c: Fix documentation as below. * nih/hash.c: Fix doc string, destructors are now considered internal and shouldn't be set by callers. * nih/signal.c (nih_signal_add_handler): Adjust call to set destructor * nih/tests/test_signal.c (test_add_handler): Call nih_free instead of nih_list_free * nih/timer.c: Fix doc strings * nih/timer.c (nih_timer_add_timeout, nih_timer_add_periodic) (nih_timer_add_scheduled): Adjust calls to set destructor. (nih_timer_poll): Call nih_free rather than nih_list_free. * nih/tests/test_timer.c (test_add_timeout, test_add_periodic) (test_add_scheduled, test_next_due): Call nih_free rather than nih_list_free (my_destructor): Call the list destructor. * nih/tree.c (nih_tree_destructor): Rename to nih_tree_destroy() (nih_tree_free): Drop. (nih_tree_new, nih_tree_entry_new): Set destructor. * nih/tree.h: Update prototypes. * nih/tests/test_tree.c (test_destructor): Rename. (test_free): Drop * nih/: Documentation string fix. * nih/tests/test_hash.c (test_string_key): Replace nih_list_free call with nih_free, since we're not overriding the destructor. * nih/list.c (nih_list_free): Drop this function. (nih_list_destructor): Rename to nih_list_destroy() (nih_list_new, nih_list_entry_new): Set destructor function. * nih/list.h: Update prototypes. * nih/tests/test_list.c (test_destructor): Rename. (test_free): Drop. (test_add): Replace nih_list_free calls with nih_free 2007-10-08 Scott James Remnant * configure.ac (AM_GNU_GETTEXT_VERSION): Bump to 0.16.1 since this version of gettext is needed for compatibility with Automake 1.10 * HACKING: Bump version in the docs too. * Makefile.am (ACLOCAL_AMFLAGS): Specify that aclocal install ordinarily system-wide macros into m4 (libtool.m4, specifically). This makes it easier for packagers to modify autoconfery since aclocal is no longer a destructive event. * configure.ac (AM_INIT_AUTOMAKE): Increase Automake requirement to 1.10 to ensure we have aclocal --instal * HACKING: Increase Automake version in the docs. 2007-06-22 Scott James Remnant * nih/tests/test_tree.c (test_next, test_prev, test_next_pre) (test_prev_pre, test_next_post, test_pre_post): Add tests for a single-node tree, because we found a bug where it didn't work. * nih/tree.c (nih_tree_next): Bug fix; check there is a right node before checking whether we've returned from it, otherwise we could confuse it with starting at the top of the tree. (nih_tree_prev): Likewise check there is a left node before checking whether we've returned from it. 2007-06-20 Scott James Remnant * nih/config.c (nih_config_parse_stanza): Free name after use. * nih/config.c (nih_config_parse_stanza): Don't dequote stanza names, since otherwise they can't be made non-special; if we don't recognise the stanza we parsed, raise the error without updating pos, since we want it to point to the start of the token. * nih/tests/test_config.c (test_parse_stanza): Update pos in test. 2007-06-18 Scott James Remnant * nih/list.h (NihListEntry): Define structure combining an NihList with a union of common types. * nih/list.c (nih_list_entry_new): Add a helper function for when we need a simple entry without any extra structure around it. * nih/tests/test_list.c (test_entry_new): Test the new function. * nih/tree.h (NihTreeEntry): Define structure combining an NihTree with a union of common types. * nih/tree.c (nih_tree_entry_new): Add a helper function for when we need a simple node without any extra structure around it. * nih/tests/test_tree.c (test_entry_new): Test the new function. 2007-06-15 Scott James Remnant * nih/tests/test_tree.c (test_next, test_foreach, test_prev) (test_next_pre, test_foreach_pre, test_prev_pre, test_next_post) (test_foreach_post, test_prev_post): Add tests for partial tree traversal, we don't expect to break out of the confines of the root that we've set, even if it has a parent. * nih/tree.c (nih_tree_next, nih_tree_prev, nih_tree_next_pre) (nih_tree_prev_pre, nih_tree_next_post, nih_tree_prev_post): Before moving up to the parent node, check whether the current node is the tree root; if it is, return NULL instead since we've iterated the sub-tree we were looking at. * nih/tests/test_tree.c (test_next, test_foreach, test_prev) (test_next_pre, test_foreach_pre, test_prev_pre, test_next_post) (test_foreach_post, test_prev_post): Use two different arrays to make it really obvious how the tree is constructed and what order we really expect it to be in. This makes it easier to get ready for the next bit ... * nih/tree.c (nih_tree_next, nih_tree_prev): Minor bug fix, set the previous to the tree's parent when visiting for the first time so that partial tree iterations might be able to work. Make algorithm code simpler and more readable. (nih_tree_next_pre, nih_tree_prev_pre): Algorithm for non-recursive pre-order tree iteration, note that unlike the above, these are not symmetrical. (nih_tree_next_post, nih_tree_prev_post): Algorithm for non-recursive post-order tree iteration, note that these aren't symmetrical with each other, but are the symmetrical equivalents of the pre-order functions. * nih/tree.h: Add prototypes for new functions. (NIH_TREE_FOREACH_PRE, NIH_TREE_FOREACH_POST): Add convenience iteration macros for pre-order and post-order iteration. * nih/tests/test_tree.c (test_next, test_foreach, test_prev): Add some documentation for the tree shape, and how we work out the node numbers. In each case, we were accidentally giving the expected first node (which fortunately always worked); to test this harder, give the root node instead! (test_next_pre, test_foreach_pre, text_prev_pre): Test pre-order tree iteration with the same basic code. (test_next_post, test_foreach_post, text_prev_post): Test post-order tree iteration with the same basic code. 2007-06-12 Scott James Remnant * nih/test.h (TEST_HASH_NOT_EMPTY): Add missing ; * nih/main.c (nih_main_unlink_pidfile): Add for completeness. * nih/main.h: Add prototype. * nih/tests/test_main.c: Use the new function here for testing. * nih/main.c (nih_main_pidfile): Rename to nih_main_write_pidfile (nih_main_set_pidfile, nih_main_get_pidfile) (nih_main_read_pidfile): Add companion functions to set and get the current location, and also read from it. * nih/main.h: Add prototypes. * nih/tests/test_main.c (test_set_pidfile, test_read_pidfile) (test_write_pidfile): Test the functions as best we can. * nih/main.c (nih_main_daemonise): Cut the pid file writing out (nih_main_pidfile): and place it into its own function, since we seem to use this elsewhere too. * nih/main.h: add prototype. * nih/main.c (nih_main_daemonise): Don't just write the pid file directly, and hope it works. Write to a temporary file, flush and sync it, then rename to the real filename. This provides a "if the pid file exists, a pid can be read from it" contract - or at least, the nearest we can to that. 2007-06-11 Scott James Remnant * nih/config.c (nih_config_skip_block): Simple function to skip over a block inline without parsing it into a string. * nih/config.h: Add prototype. * nih/tests/test_config.c (test_skip_block): Test the new function. 2007-06-10 Scott James Remnant * nih/test.h (TEST_HASH_EMPTY, TEST_HASH_NOT_EMPTY): Add some tests for hash emptyness. 2007-06-03 Scott James Remnant * nih/file.h (NihFileFilter): add missing data pointer to definition. * nih/file.c (nih_dir_walk_scan): Take the data pointer and pass it to the filter function. (nih_dir_walk, nih_dir_walk_visit): Pass data pointer to scan function. (nih_file_ignore): Accept and ignore a data pointer. * nih/tests/test_file.c (my_filter): Add data pointer. (test_ignore): Pass NULL for data pointer. * nih/watch.c (nih_watch_handle): Pass data to filter function. * nih/tests/test_watch.c (my_filter): Add data pointer. 2007-05-27 Scott James Remnant * nih/config.c (nih_config_parse): Since we've elimated all of the uses of ssize_t in this code, we're safe to parse a file larger than SSIZE_MAX, so drop the check. * nih/errors.h (NIH_CONFIG_TOO_LONG): Drop this error, since there can be no such case anymore; technically we don't handle very large files since we can only map 4GB of memory, but we fail by mapping a smaller part of the file, rather than overrunning any buffers. * nih/config.c (nih_config_parse_block): Don't use -1 in ws to indicate we've not counted it yet, instead use the current value of lines; this elimates the last ssize_t from the code. * nih/config.c (nih_config_block_end): Modify to return TRUE or FALSE, and set the end position through an argument instead. (nih_config_parse_block): Update the way we call nih_config_block_end to receive the end location via the pointer, rather than as the return value. * nih/config.c (nih_config_token): Change return value to an int, and return the token length through an argument pointer if given. This eliminates a need for ssize_t for this function. (nih_config_next_token, nih_config_parse_command): Update way we call nih_config_token to obtain the length through a pointer, and directly check the return value to decide whether to abandon it. * nih/config.h: Update prototype. * nih/tests/test_config.c (test_token): Update the tests to check the pointed value for the length, and the return value for error. 2007-05-18 Scott James Remnant * nih/tests/test_string.c (test_array_append): Make sure that the array is returned unaltered (at least, apparently) if any allocation fails during the append. * nih/string.c (nih_str_array_append): Record the original length, and pass always pass our local length variable to nih_str_array_add. Before returning, overwrite the returned length; if any allocation fails, unwind other allocations and restore the NULL pointer before returning NULL. * nih/string.c (nih_str_array_copy, nih_str_array_append): Add a couple of functions to copy a string array, and to append one onto the end of another. Saves reimplementing this each time. * nih/string.h: Add prototypes. * nih/tests/test_string.c (test_array_copy, test_array_append): Test the new functions. 2007-04-24 Scott James Remnant * nih/string.c (nih_vsprintf): Add va_end to va_copy; C standard says so. 2007-03-13 Scott James Remnant * nih/tests/test_io.c (test_get_family): The elmos of this world like to disable various networking protocols, so expect that and skip test cases. * nih/io.h: Change int_data type to a plain old int; there's no reason for it to be a fixed width type, and we may as well think about supporting ILP64 in case someone does something silly one day. 2007-03-11 Scott James Remnant * m4/compiler.m4: Don't check for __thread unless --enable-threading given to configure, instead define it to empty. * TODO: Update. 2007-03-09 Scott James Remnant * nih/logging.c: Make the current log priority available globally through the nih_log_priority variable. * nih/logging.h: Update. 2007-03-08 Scott James Remnant * nih/macros.h (_n): Add a macro to wrap ngettext() for plural forms. 2007-03-02 Scott James Remnant * nih/tests/test_watch.c: Skip these tests if inotify is not available, since there's not much we can do. 2007-02-16 Scott James Remnant * nih/tree.c (nih_tree_next, nih_tree_prev): Add non-recursive functions to iterate a tree in-order either forwards or backwards. * nih/tree.h (NIH_TREE_FOREACH): Standard macro for wrapping nih_tree_next and turning it into a for loop. * nih/tests/test_tree.c (test_next, test_foreach, test_prev): Test things with a complex tree to see whether they work out ok. * nih/list.h: Fix formatting and ordering. * nih/list.c: Fix function ordering. * nih/tree.c: Add generic code to implement pure binary trees. * nih/tree.h: Structures, typedefs and prototypes. * nih/tests/test_tree.c: Binary tree test suite. * nih/libnih.h: Include tree.h * nih/Makefile.am (libnih_la_SOURCES): Build and link tree.c (nihinclude_HEADERS): Install tree.h (TESTS): Build and run binary tree test suite. (test_tree_SOURCES, test_tree_LDFLAGS, test_tree_LDADD): Details for binary tree test suite binary. 2007-02-15 Scott James Remnant * nih/watch.c (INOTIFY_EVENTS): Use IN_CLOSE_WRITE instead of IN_MODIFY; since that guarantees the file has actually been closed, and is probably on the filesystem now. 2007-02-13 Scott James Remnant * nih/signal.c: Add SIGUNUSED to the list of signals that might not exist. * nih/tests/test_option.c (test_parser): gcc doesn't like using variables inside fixed for loops, so initialise it deliberately. * nih/tests/test_command.c (test_help): Was mistakenly repeatedly opening output. (test_parser): Similar for loop issue. * nih/signal.c: Update signal name list, some signals don't exist on sparc and some turn up unexpectedly. 2007-02-11 Johan Kiviniemi * nih/hash.h (NIH_HASH_FOREACH, NIH_HASH_FOREACH_SAFE): Added missing parenthesis around hash, in case it's a complicated expression with unsurprising precedence results. 2007-02-11 Scott James Remnant * nih/config.c (nih_config_skip_whitespace): It turns out that when parsing, it's often useful to skip any whitespace while retaining the "step over newlines" behaviour. Seperate it out into its own function. (nih_config_next_token): Call the new function. * nih/config.h: Add prototype. * nih/tests/test_config.c (test_skip_whitespace): Check the function * nih/config.c: Remove macro definitions * nih/config.h: and make them public instead * nih/tests/test_config.c: Use macros. * nih/config.c (nih_config_next_token): Strange hybrid function, it behaves like next_arg() but accepts the same arguments as token(); it skips whitespace, but only if the initial whitespace character is in the delim argument. (nih_config_next_arg): This becomes a wrapper around next_token. * nih/config.h: Add prototype. * nih/tests/test_config.c (test_next_token): Check the new function. * nih/config.c (nih_config_next_token): Rename to nih_config_token, since this doesn't behave like the next_arg() function, and we want a similar token function that behaves like that. * nih/config.h: Update. * nih/tests/test_config.c (test_next_token): Rename and update. 2007-02-09 Scott James Remnant * nih/hash.h (NIH_HASH_FOREACH_SAFE): Oops, s/list/hash/ * nih/hash.h (NIH_HASH_FOREACH, NIH_HASH_FOREACH_SAFE): Add macros to iterate over an entire hash table. * nih/tests/test_hash.c (test_foreach, test_foreach_safe): Test the macros. * nih/hash.c (nih_hash_string_key): Add a useful function to return the first member after the list header. * nih/hash.h: Add prototype. * nih/tests/test_hash.c (test_string_key): Add test case. * nih/file.c (nih_file_is_packaging): Check for common packaging filenames -- I swore I wrote this, but I can't find it. (nih_file_ignore): Ignore packaging files. * nih/file.h: Update. * nih/tests/test_file.c (test_is_packaging, test_ignore): Test. 2007-02-07 Scott James Remnant * nih/logging.c (nih_logger_printf): Change printf logger to not prefix anything intended for stdout. * nih/logging.h: Rearrange. * nih/tests/test_logging.c (test_logger_printf): Make sure that we don't prefix the program name for messages that go to stdout. 2007-02-06 Scott James Remnant * nih/signal.c (nih_signal_from_name): Table changed to not contain SIG, so this now strips it off the front if present. * nih/tests/test_signal.c (test_to_name): Strip SIG from the front (test_from_name): Check that we can omit SIG from the front. * nih/signal.c (nih_signal_to_name, nih_signal_from_name): Functions annoyingly missing from the standard library; convert signal names and numbers between each other (e.g. SIGTERM -> 15). * nih/signal.h: Add prototypes. * nih/tests/test_signal.c (test_to_name, test_from_name): Put the new functions through their paces. * nih/string.c (nih_str_array_add, nih_str_array_addn): Correct leak when array allocation fails. * nih/string.c (nih_str_array_add, nih_str_array_addn) (nih_str_array_addp): Allow the array pointed to to be NULL, after all, realloc works anyway. Also allow len to be NULL, in which case, we count the elements automatically. * nih/tests/test_string.c (test_array_addp): Update test cases. * nih/config.c (nih_config_parse_args): Use nih_str_array functions. * nih/file.c (nih_dir_walk_scan): Use nih_str_array functions. * nih/option.c (nih_option_parser): Use nih_str_array functions. (nih_option_add_arg): Drop this function now. * nih/string.c (nih_str_array_addp): Yet another variation on a theme; this one saves duplicating allocs, which is always messy. (nih_str_array_addn): Wrap around the above function. (nih_str_array_add): Make this a wrapper around addp instead. * nih/string.h: Update. * nih/tests/test_string.c (test_array_addp): Check that one works. * nih/string.c (nih_str_split): Use nih_str_array functions. * nih/string.c (nih_str_array_addn): Add a version of nih_str_array_add that calls nih_strndup instead of nih_strdup. (nih_str_array_add): turn into a thin wrapper around the above. * nih/string.h: Update. * nih/tests/test_string.c (test_array_addn): Test new function. * nih/string.c (nih_str_array_add): Flip array and parent arguments to make it more like realloc. * nih/string.h: Update. * nih/tests/test_string.c (test_array_add): Update. * nih/string.c (nih_str_array_new, nih_str_array_add): Functions to handle the common cases of arrays of strings. * nih/string.h: Update. * nih/tests/test_string.c (test_array_new, test_array_add): Test. * nih/watch.c (nih_watch_handle): Never assert on data received from an untrusted source (well, the kernel, anyway). Also make sure nobody sneaks a '/' into the name of an inotify event. 2007-02-05 Scott James Remnant * nih/string.c (nih_vsprintf): Make sure vsnprintf never returns a negative value; C99 says it can't, of course, but Kees was paranoid. 2007-02-03 Scott James Remnant * nih/watch.c (nih_watch_new): Tidy up ENOMEM loop. * nih/tests/test_file.c (test_dir_walk): Fix leak of directory caused by not removing a symlink. * nih/tests/test_watch.c (test_new, test_add): Fix leaks of directories caused by not changing permissions back so we can unlink under them. * nih/watch.h (NihCreateHandler, NihModifyHandler): Add stat argument. * nih/watch.c (nih_watch_handle): stat any object created or modified, and pass the stat buf to the handler function. (nih_watch_add_visitor): Pass stat argument here too. * nih/tests/test_watch.c: Add arguments. * nih/option.c (nih_option_int): Function to parse integer values on the command line. * nih/option.h: Add prototype. * nih/tests/test_option.c (test_int): test case for it. * nih/file.c (nih_file_is_hidden, nih_file_is_backup) (nih_file_is_swap, nih_file_is_rcs): Functions to match common file types by their path. (nih_file_ignore): Function to combine calls to all of the above. * nih/file.h: Add prototypes. * nih/tests/test_file.c: Add test cases for the new functions. * TODO: Update. 2007-02-02 Scott James Remnant * TODO: Update. * nih/watch.c (nih_watch_new): Add a create argument to avoid walking a directory tree twice; store in the structure. (nih_watch_add_visitor): Call the create handler if necessary. * nih/watch.h: Update structure to include member and prototype. * nih/tests/test_watch.c (test_new): Check that, when called with create, the handler is called for each file that exists. (test_reader): Check that a directory is recursed when moved in or created with existing files. * nih/tests/test_watch.c (test_reader): Add test case for watching sub-directories again. * nih/watch.c (nih_watch_new, nih_watch_add): Make safe against ENOMEM; otherwise it's just tricky to decide when it's good and bad to throw things out. * nih/tests/test_watch.c: Update test cases accordingly. * nih/watch.c (nih_watch_add): It's not an error for subdirs to be TRUE when we get passed a filename. * nih/tests/test_watch.c (test_add): Check that it works. * nih/file.c (nih_dir_walk): Initialise ret to zero, otherwise can return an uninitialised value when walking an empty directory. * nih/tests/test_child.c (test_poll): Reap the child we kill, otherwise the next test might fail sometimes. * nih/watch.c (nih_watch_add): Make being unable to recurse into sub-directories to watch them an error. * nih/tests/test_watch.c (test_new, test_add): Update test cases. * nih/file.c (nih_dir_walk): Rework this function to support detection of directory loops, and reporting of errors with a callback handler rather than just aborting the walk. (nih_dir_walk_scan): Build up a sorted list of paths under a directory, filtered with the filter function. Split out because it has different error handling semantics. (nih_dir_walk_visit): Visit a single path and if it's a directory, descend into it. * nih/file.h (NihFileVisitor): Add arguments to pass the top-level directory and the stat buffer of the path (to avoid stating the same things multiple times). (NihFileErrorHandler): Duplicate prototype for the error handler. * nih/errors.h (NIH_DIR_LOOP_DETECTED): Add new error. * nih/tests/test_file.c (test_dir_walk): Update test cases, improving test coverage at the same time. * nih/watch.c (nih_watch_add_visitor): Update to check the stat passed to the visitor, as well as accept the directory name, 2007-02-01 Scott James Remnant * nih/tests/test_io.c: Replace NIH_ZERO in test cases with assert0 * nih/tests/test_main.c (test_main_loop): Eliminate use of NIH_MUST * nih/tests/test_io.c (test_watcher): Remove unnecessary NIH_MUST * nih/test.h (assert0): Add an assert wrapper for the common alternate case. 2007-01-30 Scott James Remnant * nih/io.c (nih_io_buffer_resize): Always keep a buffer filled with zeros when we extend it, so we never pass uninitialised data to syscalls. * m4/misc.m4 (NIH_INIT): Detect valgrind/valgrind.h * nih/tests/test_signal.c: Detect valgrind and don't check the error values from trying to set SIG_DFL or SIG_IGN for SIGKILL; which for no readily apparent reason, works under valgrind. * HACKING: Add newline to end of file. * nih/test.h (TEST_ALLOC_SAFE): Add macro to guard allocations so they aren't counted. * nih/tests/test_file.c (my_visitor, test_dir_walk): Use TEST_ALLOC_SAFE instead of changing the allocator by hand. * nih/tests/test_io.c (test_watcher): Use TEST_ALLOC_SAFE instead of changing the allocator by hand, * nih/macros.h (NIH_MUST_NOT): Rename to NIH_ZERO * nih/io.c (nih_io_message_recv): Use NIH_ZERO, instead of == 0 * nih/main.c (nih_main_loop_init): Use NIH_ZERO, instead of == 0 * nih/tests/test_io.c: Use NIH_ZERO not NIH_MUST...== 0 * nih/tests/test_io.c (test_watcher): Ensure that we don't ignore the return value from nih_io_printf; but also don't fail it. * HACKING: Clarify that returning to indicate insufficient memory warrants warn_unused_result. * nih/io.h: Add warn_unused_result attribute to nih_io_printf. * nih/string.c: Correct doc strings. * nih/string.c (nih_vsprintf): We need to copy the arguments before iterating either time, otherwise we could return NULL after moving the current argument off the end. * TODO: Update. 2007-01-22 Scott James Remnant * nih/io.c (nih_io_reopen): Raises an error (usually ENOMEM), since it can also raise EBADF. * nih/tests/test_io.c (test_reopen): Make sure ENOMEM is raised. * nih/watch.c: New watch API, this is a little higher level than what previously existing in nih/file.c; but is substantially easier to use and should cover all of the corner cases. (INOTIFY_EVENTS): inotify events we always watch for. (nih_watch_new): The master function; this creates a new inotify instance and adds a watch for a path in it. (nih_watch_handle_by_wd): Obtain a watch handle by descriptor (nih_watch_handle_by_path): Obtain a watch handle by path (nih_watch_add): Another useful function, adds a second path to an existing watch; normally used just for sub-directories, but possible for anything. (nih_watch_add_visitor): nih_dir_walk() callback that calls the above (nih_watch_free): Free a watch, and the associated NihIo; closing the inotify descriptor. (nih_watch_reader): Reader function; handles the incoming stream of inotify events by locating the watch handle and dispatching through (nih_watch_handle): this function which handles all the various event ordering corner-cases and dispatches to the watch functions proper. * nih/watch.h: Typedefs, structures and prototypes for the new watch API. * nih/tests/test_watch.c: Test suite for the watch code; covers most of the paths -- though malloc checking here is tricky and could do with improving later. * nih/libnih.h: Include nih/watch.h * nih/Makefile.am (libnih_la_SOURCES): Build and link watch.c (nihinclude_HEADERS): Install watch.h (TESTS): Build and run watch test suite (test_watch_SOURCES, test_watch_LDFLAGS, test_watch_LDADD): Details for watch test suite binary. * nih/file.c: Strip out anything related to inotify, leaving us with just three functions; nih_file_map(), nih_file_unmap() and nih_dir_walk(). Others that will turn up here will be matching and filtering functions. * nih/file.h: Strip out typedefs, structures and prototypes for anything watch-related; add attributes to functions as necessary. * nih/tests/test_file.c: Remove watch-related test cases, and use TEST_ALLOC_FAIL for test_dir_walk(). * nih/tests/test_io.c (test_shutdown): Test NIH_IO_MESSAGE using AF_UNIX socketpairs, not pipes. * HACKING: Document the requirements for function attributes and using TEST_ALLOC_FAIL in test cases. * TODO: Update. * nih/tests/test_signal.c (test_set_handler): Check that SIGCHLD gets the SA_NOCLDSTOP flag, and that SIGKILL returns an error. (test_set_default, test_set_ignore): Check SIGKILL returns error. * nih/tests/test_option.c (test_parser): Check that duplicated options result in the previous string being freed. * nih/main.c (nih_main_daemonise): SIGHUP can always be ignored. * nih/tests/test_io.c (test_reopen): Make sure that we can't reopen a closed file descriptor. (test_set_nonblock, test_set_cloexec): Check with closed descriptors. * nih/config.c: When we call nih_config_skip_comment, we can usually assert that this will never fail; so do so. * nih/tests/test_command.c (test_help): Check a few missing pieces of the command help output to make sure it's right. * nih/file.c (nih_dir_walk): Correct doc string to indicate that this function raises errors. * nih/alloc.h: Fix prototype orders. * nih/child.h: Add attributes to important return values. * nih/config.c: Add attributes to important return values. * nih/config.h: Add attributes to important return values. * nih/error.h: Add attributes to important return values. * nih/io.h: Add attributes to important return values. * nih/main.h: Add attributes to important return values. * nih/signal.h: Add attributes to important return values. * nih/string.h: Add attributes to important return values. * nih/timer.h: Add attributes to important return values. * nih/io.c (nih_io_reopen): Don't ignore failure to ignore SIGPIPE. (nih_io_set_cloexec, nih_io_set_nonblock): The only useful errors returned is EBADF, so just return -1 for that. * nih/main.c (nih_main_daemonise): Don't ignore failure to ignore SIGHUP. * nih/signal.c (nih_signal_set_handler, nih_signal_set_default) (nih_signal_set_ignore): The only useful error sigaction returns is EINVAL, so just return -1. (nih_signal_reset): Ignore EINVAL errors. * nih/tests/test_io.c: Use NIH_MUST around function calls that can fail. * nih/tests/test_main.c: Use NIH_MUST around function calls that can fail. 2007-01-21 Scott James Remnant * nih/test.h (TEST_ALLOC_FAIL): Macro that loops over a block of code as many times as malloc is called within it, causing each malloc in turn to be failed so we can increase code coverage. (nih_test_allocator): Support function for the above; allows dumping of malloc calls. * nih/tests/test_child.c (test_add_watch): Use TEST_ALLOC_FAIL and call nih_child_poll() first to not debug the init function (test_poll): Remove race conditions by making sure the signal has reached the child using waitid(). Test the "child we don't know about has died" branch, along with waitid returning 0 with no pid (needs a child process). * nih/tests/test_command.c (test_parser, test_help): Use TEST_ALLOC_FAIL * nih/tests/test_config.c (test_next_arg, test_parse_args) (test_parse_command, test_parse_block): Use TEST_ALLOC_FAIL * nih/tests/test_error.c (test_raise, test_raise_printf) (test_push_context, test_return_error): Use TEST_ALLOC_FAIL, to make sure allocations are retried. (test_pop_context): Split out from test_push_context. * nih/tests/test_hash.c (test_new): Use TEST_ALLOC_FAIL * nih/tests/test_io.c (test_add_watch, test_buffer_new) (test_buffer_resize, test_buffer_pop, test_buffer_shrink) (test_buffer_push, test_message_new, test_message_add_control) (test_message_recv, test_message_send, test_reopen, test_watcher) (test_read, test_write, test_get, test_printf): Use TEST_ALLOC_FAIL liberally, make sure every code path involving a malloc gets tested. * nih/tests/test_list.c (test_new): Use TEST_ALLOC_FAIL * nih/tests/test_logging.c (test_log_message): Use TEST_ALLOC_FAIL * nih/tests/test_main.c (test_main_loop_add_func): Use TEST_ALLOC_FAIL (test_package_string): Use TEST_ALLOC_FAIL and also check repeated calls return the same string. (test_version): Use TEST_ALLOC_FAIL to check that allocation can never fail. * nih/tests/test_option.c (test_parser, test_version, test_help): Use TEST_ALLOC_FAIL to make sure we behave * nih/tests/test_signal.c (test_add_handler): Use TEST_ALLOC_FAIL and call nih_signal_poll() first to not debug the init function * nih/tests/test_string.c (test_sprintf, test_vsprintf) (test_strdup, test_strndup, test_str_split, test_str_wrap) (test_str_screen_wrap): Use TEST_ALLOC_FAIL (test_str_screen_width): Check that we discard an illegal columns variable. * nih/tests/test_timer.c (test_add_timeout, test_add_periodic) (test_add_scheduled): Use TEST_ALLOC_FAIL and call nih_timer_poll() first to make sure we don't debug the init function * nih/config.c (nih_config_next_arg, nih_config_parse_args) (nih_config_parse_command, nih_config_parse_block): Allow us to fail reading a configuration file because we run out of memory; it's not that important. * nih/io.c (nih_io_get): Catch failure to remove the string, and don't remove the delimiter if that happens. (nih_io_printf): Fix doc, this returns zero, not a length. * nih/io.h: Fix prototype of nih_io_printf * nih/logging.c (nih_log_message): Potentially failing message output is crazy; loop until the alloc succeeds. * nih/option.c (nih_option_handle): Free the options and arguments before exiting; not really necessary, but makes valgrind happier. * nih/string.c (nih_strndup): Failed to correctly detect a failed allocation. (nih_str_split): Correct some mistakes with allocations not being checked. * nih/libnih.supp: Add tmpfile. * TODO: Update. 2007-01-11 Scott James Remnant * nih/file.h (NihDirWatch): New structure that defines a high-level watch on a directory with various handlers to be called. (NihCreateHandler, NihChangeHandler, NihDeleteHandler): Typedefs. * nih/file.c (nih_dir_add_watch): Function to create an NihDirWatch structure and fill it in. (nih_dir_add_file_watch): Add a watch on a single directory, catching errors and logging a warning if we can't watch it. (nih_dir_watcher): Deal with inotify events within a directory tree, taking care of issues such as re-organising of the directory structure without ending up with duplicate watches. (nih_file_reader): Only call the first matching watcher; we hit a limitation in the inotify API caused by our usage of a single descriptor. Will fix that shortly. * nih/tests/test_file.c (test_dir_add_watch): Test that we can add watches and have everything filled in nicely. 2007-01-10 Scott James Remnant * nih/file.c (nih_dir_walk): Function to walk a directory tree calling a function for each object found. * nih/file.h (NihFileFilter, NihFileVisitor): typedefs for function pointers used for nih_dir_walk. * nih/tests/test_file.c (test_walk): Test the walker. * nih/file.c (nih_file_reader): Pass the cookie to the watcher. * nih/file.h (NihFileWatcher): Add cookie argument. * nih/tests/test_file.c (test_add_watch): Check the cookie is passed for a rename. * nih/file.c (nih_file_add_watch): Fix this to not add the inotify watch unless it can allocate memory to handle it. 2007-01-09 Scott James Remnant * nih/config.c (nih_config_get_stanza): Catch entries with a zero length name, and return one instead of NULL if it exists. * nih/tests/test_config.c (test_parse_stanza): Make sure that "" in a stanza table acts as a catch-all. * nih/test.h (TEST_FILENAME): Use dashes not colons, to make things more clear. 2007-01-08 Scott James Remnant * nih/config.c (nih_config_has_token): add a very small test function so parsers can peek to see whether there is a next argument or not. (nih_config_skip_comment, nih_config_parse_args) (nih_config_parse_file): Use the new test function to make it more obvious what we're doing. * nih/config.h: Add prototype. * nih/tests/test_config.c (test_has_token): Add test cases. * nih/config.c: Allow all functions to be called with a zero length file, we're completely guarded against pos going past the length, so this cannot be a bad thing. Plus this allows zero-length tokens to be extracted trivially. (nih_config_next_arg): Raise an error if called in a position where there is no argument. If you want to speculatively check for args, peek first. (nih_config_parse_stanza): No need to check for an empty stanza now, nih_config_next_arg() handles that for us. (nih_config_skip_comment): Function to allow us to skip only a comment, while raising an error if we hit anything else. (nih_config_parse_args, nih_config_parse_command): Skip comment only, to guard against parser errors. * nih/config.h: Update. * nih/tests/test_config.c (test_next_arg): Check the new error is raised, instead of the empty string being returned. (test_parse_stanza): Check the expected token error is raised. (test_skip_comment): Test the new function. * nih/errors.h: Add new errors. * nih/errors.h: Fix capitalisation of error messages. * nih/tests/test_config.c (test_parse_command): Add missing free calls to strings obtained. 2007-01-07 Scott James Remnant * nih/config.c: Convert this file to use size_t where appropriate instead of ssize_t, and raise exceptions for parsing errors rather than logging them. (nih_config_parse): Check a size is not greater then SSIZE_MAX (2GB) to avoid overflows. * nih/config.h: Update prototypes and handler function typedef. * nih/errors.h: Add new error codes and strings. * nih/tests/test_config.c: Adjust test cases. * nih/config.c (nih_config_parse_file): Function to parse a mapped file or string line-by-line starting from the given position. (nih_config_parse): Function to map a file into memory and parse it * nih/config.h: Add prototypes. * nih/tests/test_config.c (test_parse_file): Test the function with a small variety of different valid files. (test_parse): Check we can parse a file, and get an error if it doesn't exist. * nih/config.c (nih_config_parse_stanza): Take a data pointer and pass it to the handler, otherwise we can't fill in structures. * nih/config.h: Update. * nih/tests/test_config.c (test_parse_stanza): Check the data pointer is passed properly. * nih/tests/test_option.c (test_version, test_help): Capture the return value from nih_option_parser, as we've set gcc attributes to not let us do otherwise. * nih/config.h: Add structures, typedefs and macros to allow lists of configuration stanzas to be built up. * nih/config.c (nih_config_parse_args): Split argument parsing into (nih_config_next_arg): This new function that wraps next_token and also skips following whitespace. (nih_config_next_line): Another new function that skips to the end of the line, replacing severael copies of this code. (nih_config_get_stanza): Simple function to find a stanza in a table by its name. (nih_config_parse_stanza): Simple stanza dispatch function; parses an argument at the current position, looks it up in the table, then calls the function. * nih/tests/test_config.c (test_next_arg): Check this function works, we know it does because it was covered by other tests, but it's worth having its own as well. (test_next_line): Check this function works too. (test_parse_stanza): Make sure the dispatcher works properly. * nih/config.c: Write from the code that was used for upstart, making them exported functions to act as a configuration file kit. (nih_config_parse_args): Fix a bug where lineno wasn't incremented for an embedded newline in between arguments. Fix another bug where a line containing only whitespace or whitespace and a comment would hit an assertion - not a problem in practice, but it's a bug. * nih/config.h: Function prototypes. * nih/libnih.h: Include config.h * nih/tests/test_config.c: Write an all new test suite that tests the individual parsing functions for their functionality, rather than trying to squeeze it into something larger. * nih/Makefile.am (libnih_la_SOURCES): Build and link config.c (nihinclude_HEADERS): Install config.h (TESTS): Build and run config test suite (test_config_SOURCES, test_config_LDFLAGS, test_config_LDADD): Config test suite binary details. 2007-01-06 Scott James Remnant * nih/tests/test_io.c (test_watcher): Missing a priority that needed changing to message. * nih/command.h: Warn against unused results. * nih/option.h: Warn against unused results. * nih/logging.h (NihLogLevel): Add a message level between info and warn, as we can't just re-use warn as that goes to stderr! (nih_message): Change to use the new message level. * nih/logging.c (nih_logger_syslog): Output messages at the notice level, rather than the warning level. (nih_log_init): Change the default priority to message. * nih/tests/test_logging.c (test_log_message): Check that messages are logged with the new message priority; reset to the new default. (test_logger_printf): Make sure that ordinary messages go to stdout and warning messages go to stderr. (test_set_logger, test_set_priority): Reset to the new default. * nih/tests/test_option.c (test_quiet, test_verbose, test_debug): Check that messages are also logged, as well as warning; and set the new default priority. * nih/tests/test_error.c (test_raise_again, test_push_context): Set log priority to the new default. * nih/tests/test_io.c (test_watcher): Reset priority to the new default. 2007-01-05 Scott James Remnant * nih/tests/test_io.c (test_shutdown): Uncomment the test for shutdown when all messages are processed by the watcher. * nih/io.c (nih_io_message_recv): Remove note about the remote end being closed; when in message mode, this doesn't usually happen. (nih_io_watcher): Only check for a zero length return if we're in stream mode, otherwise it just means we got a zero length message. (nih_io_watcher_read): Accept zero length messages and return them. * nih/tests/test_io.c (test_watcher): Remove tests that tried to mix a message-mode io and a dgram socket, that way lies disaster. * nih/io.c (nih_io_watcher_read, nih_io_watcher_write): Initialise len to zero, as valgrind can be fussy about this when we call things directly. * nih/io.h (NihIoMessage): Add a user data field to the message structure so we can carry the pid around when queuing notification messages in upstart. 2007-01-02 Scott James Remnant * nih/alloc.h, nih/child.h, nih/command.h, nih/file.h, nih/hash.h: nih/io.h, nih/logging.h, nih/main.h, nih/option.h, nih/signal.h: nih/timer.h: Give names for all arguments in function pointer typedefs so the documentation strings make more sense. * nih/test.h (TEST_EQ_MEM, TEST_NE_MEM): Cast argument for number of bytes to size_t. * configure.ac (AC_COPYRIGHT): Update copyright to 2007. 2006-12-29 Scott James Remnant * nih/errors.h: Drop the NIH_IO_MESSAGE_TRUNCATED error. * nih/io.h (NihIoMessage): Rename msg_buf member to data, and change ctrl_buf member to be an array of cmsg structures called control. * nih/io.c: Update references to NihIoMessage members. (nih_io_message_push_control): Rename to nih_io_message_add_control (nih_io_message_add_control): Rewrite to add the control message header onto the end of an array, rather than a control buffer, (nih_io_message_recv): After receiving the message, extract all control messages and put them into the array. (nih_io_message_send): Take control messages from the array into a single buffer and send them. * nih/tests/test_io.c: Update references to NihIoMessage members. (test_message_new): Check that the control member is initialised to a one-element array containing NULL. (test_message_push_control): Rename to test_message_add_control. (test_message_add_control): Check the array is extended. * nih/io.c (nih_io_message_recv): Loop over a call to recvmsg() with MSG_PEEK in its arguments to avoid ever returning truncated messages. * nih/tests/test_io.c (test_message_recv): Adjust test for truncated messages to make sure they do in fact work. (test_watcher): Remove the oversized message error check. 2006-12-21 Scott James Remnant * nih/tests/test_option.c (test_verbose): Add missing call to free args. * nih/io.c (nih_io_message_send): Change to return the ssize_t received from sendmsg(), rather than an int. (nih_io_watcher_read): Move read functionality out of nih_io_watcher into a separate function that can deal with both stream and message mode. (nih_io_watcher_write): Move write functionality out of nih_io_watcher into a separate function that can deal with both stream and message mode. (nih_io_watcher): Call the separate functions, and handle calling the reader when in message mode. In addition, we now check the error code when writing to a socket as well; there are useful errors there (like ECONNREFUSED). * nih/io.h: Update prototype of nih_io_message_send. * nih/tests/test_io.c (test_message_send): Update return checks. (test_watcher): Test that the error handled can now be called when writing data to a socket, as well as just when reading. Test message mode behaviour. * nih/io.c (nih_io_send_message): Watch socket for writability. (nih_io_write): Extend this function to work in message mode; it allocates a new message, stores the data in that buffer, and adds it to the send queue. (nih_io_printf): Remove restriction that this only be called in stream mode; the fact this calls nih_io_write is sufficient to ensure correct behaviour. * nih/tests/test_io.c (test_send_message): Check that we're testing for writability. (test_write): Test that this works in message mode. (test_printf): Check that this works too, even though this only really calls nih_io_write. * nih/io.c (nih_io_get): Extend so that this can operate in message mode on the oldest message in the queue. * nih/tests/test_io.c (test_get): Check that this works properly in message mode; complete with shutdown check. * nih/io.c (nih_io_message_new): Do not assign a default list destructor, it's not in a hidden list and there are bad consequences of freeing a child with a default destructor if the list its in gets freed first; new rule - default destructors only if the list is hidden and never freed! (nih_io_closed, nih_io_shutdown): Don't call the close handler if the structure is already marked to be closed; there seems little point, and we could accidentally call it multiple times. (nih_io_read_message, nih_io_read, nih_io_get): Check whether we need to shutdown the socket here, in case the watcher isn't polled again. * nih/tests/test_io.c (test_shutdown): Check that shutdown works with message-mode structures (part of this disabled for now). (test_read_message, test_read, test_get): Check that a shutdown socket is closed when these are called. 2006-12-20 Scott James Remnant * nih/io.c (nih_io_read): Extend so that it can be called in message mode, it reads from the first message until it has been exhausted; at which point it frees the message and the next call would read from the next. * nih/tests/test_io.c (test_read): Check that the new functionality works properly. * nih/io.c (nih_io_first_message): Simple static function to obtain the oldest message in the receive queue. (nih_io_read_message, nih_io_send_message): Functions to take the oldest message out of the receive queue and append a message to the send queue. * nih/io.h: Add prototypes. * nih/tests/test_io.c (test_read_message, test_send_message): Check the new functions do what they say on the tin. General clean-up of nih_io, fixing a few API issues and making it more suitable for using in message mode. * nih/io.c (nih_io_buffer_pop, nih_io_buffer_shrink): Remove the silly restrictions that these cannot be called with a length greater than the buffer size, instead just truncate it to the buffer size. (nih_io_buffer_pop): Length is now updated to the actual number of bytes being returned. (nih_io_message_add_control): Rename to nih_io_message_push_control. (nih_io_message_recv): Change the len parameter to a pointer that's updated with the actual number of bytes read. (nih_io_stream_watcher): Rename back to nih_io_watcher. (nih_io_reopen): Use a single watcher function again, initialise close to NULL. Treat failure to set a descriptor non-blocking as a failure to open; otherwise we'll end up screwing up the main loop. (nih_io_watcher): Remove the restriction that this is only called when in the stream mode. Leave data in the receive buffer if there's no reader function, it's now valid to query the buffer size and read by other means. Catch the ENOMEM error and ignore it. Set and keep an eye on the structure close member, if it is TRUE before we return, close the socket. This also means we check for shutdown sockets in the case of error, which we probably should have done. (nih_io_maybe_shutdown): Rename to nih_io_shutdown_check. (nih_io_close): If the close member of the structure is not NULL we're inside a watcher function, so need to set the variable this points to to TRUE instead of closing or freeing the structure. (nih_io_read): Change the len parameter to be updated with the actual number of bytes being returned. * nih/io.h: Renamed function prototype. Updated documentation for function typedefs to clarify that they may all call nih_io_close, but may not call nih_free. * nih/errors.h: Rename NIH_TRUNCATED_MESSAGE to NIH_IO_MESSAGE_TRUNCATED, we should probably namespace these. * nih/tests/test_io.c (test_buffer_pop, test_buffer_shrink): Check that we can pop or shrink the entire buffer if we ask for more. (test_message_add_control): Rename to test_push_control. (test_message_recv): Check that the cases of remote end closed, error received or truncated message are handled properly. (test_message_send): Check that an error is handled. (test_stream_watcher): Rename back to test_watcher. (test_reopen): Check that the socket is not being shutdown or closed. (test_shutdown): Drain the buffer before calling handle on it, as it's not done automatically now. (test_close): Check that a lazy close is performed if io->close is not NULL. * nih/file.c (nih_file_reader): Update call to nih_io_read. * nih/logging.h (nih_assert_notreached): Rename to nih_assert_not_reached, this was annoying me. 2006-12-19 Scott James Remnant * nih/io.c (nih_io_read, nih_io_write, nih_io_get, nih_io_printf): Ensure the NihIo structure is in stream mode; as these only really make sense if there's a limitless buffer. * nih/tests/test_io.c (test_shutdown): Make sure the socket is shut down immediately. * nih/io.c (nih_io_shutdown): Bugfix, should close the socket immediately if there's nothing in the queue, otherwise it may hang around forever if it never polls. * nih/io.c (nih_io_reopen): Receive the type from the arguments, instead of hard-coding to be stream. Set up the structure accordingly. * nih/io.h: Update prototype. * nih/tests/test_io.c (test_reopen): Check message mode is allocated properly. * nih/file.c (nih_file_init): Open in stream mode. * nih/io.c (nih_io_message_new): Catch failure to allocate message or control buffer. (nih_io_message_add_control): No need to try and allocate the control buffer here. (nih_io_message_recv): Only need to resize the buffers here as well. (nih_io_message_send): No need to deal with there being no message or control buffer here either. * nih/tests/test_io.c: Fix test assumptions based on above. * nih/libnih.supp: Add missing nih_io_init suppression. * nih/tests/test_io.c (test_message_add_control): Non need to check allocation of the buffer itself. * nih/io.c (nih_io_message_add_control): Function to add a control message to the control buffer, to save mucking around with difficult bits ourselves. * nih/io.h: Add prototype. * nih/tests/test_io.c (test_message_add_control): Check that it works properly. * nih/io.c (nih_io_buffer_shrink): Make an exported function, resize the buffer once done to save on memory. (nih_io_buffer_pop, nih_io_stream_watcher): No need to explicitly resize here now, as it gets called from shrink. * nih/io.h: Add prototype. * nih/tests/test_io.c (test_buffer_shrink): Test shrink. * nih/io.c (nih_io_message_recv, nih_io_message_send): Functions to send and receive a message over a socket, hiding the difficult bits of dealing with msghdr/iovec. (nih_io_get_family): Function to detect the family of a socket. * nih/io.h: Update. * nih/errors.h: Add truncated message error. * nih/tests/test_io.c (test_message_recv, test_message_send): Check that we can send and receive messages by using socket pairs. (test_get_family): Check that we can get the families of the standard three socket types. 2006-12-18 Scott James Remnant * nih/io.h (NihIoMessage): Structure that represents an individual message in a queue; has a buffer for the message, and for ancillary control data, as well as an address that the message is being sent to or received from. (NihIoType): Enum to select whether an NihIo structure is in stream mode or message mode. (NihIo): Add a type member to select whether this is in stream or message mode, and a union to select whether we're using buffers or message queues. * nih/io.c (nih_io_message_new): Allocate an NihIoMessage and its child buffers. (nih_io_reopen): Initialise the type to NIH_IO_STREAM. (nih_io_watcher): Rename to nih_io_stream_watcher. * nih/tests/test_io.c (test_message_new): Check that the new message structure is initialised properly. (test_reopen): Check that we get a stream structure by default. (test_watcher): Rename to test_stream_watcher. 2006-12-17 Scott James Remnant * nih/logging.h (nih_assert_notreached): Add an assertion for the use in default bits of switches, etc. * nih/test.h (TEST_EQ_U, TEST_NE_U): Versions of the original macros that cast to size_t for display, instead of ssize_t. * nih/tests/test_logging.c, nih/tests/test_string.c: Set local variables to avoid gcc thinking that they may be unused when using TEST_DIVERT_*. 2006-12-14 Scott James Remnant * HACKING: Correct some typos. 2006-12-13 Scott James Remnant * nih/test.h (TEST_FILENAME): Wrap with do { ... } while (0) in case this gets used as a single line statement. 2006-12-13 Johan Kiviniemi * nih/test.h (TEST_FILE_RESET): Wrap with do { ... } while (0) in case this gets used as a single line statement. 2006-12-13 Scott James Remnant * nihify: Link to the nih ChangeLog. 2006-12-12 Scott James Remnant * nih/test.h (TEST_CHILD_WAIT, TEST_CHILD_RELEASE): Sometimes the primitive "when the child is running" locking provided by TEST_CHILD isn't sufficient, and we actually need to perform some actions in the child before we let the parent carry on. These two macros allow that. * nih/libnih.supp: Include a valgrind suppressions file. * nih/Makefile.am (EXTRA_DIST): Distribute the suppressions file. * nih/tests/test_alloc.c (test_realloc): Fix missing free. * configure.ac (AM_GNU_GETTEXT_VERSION): Quote version number. 2006-12-09 Scott James Remnant * nih/test.h (TEST_DIVERT_STDOUT_FD, TEST_DIVERT_STDERR_FD): Flush before dup2ing the original file descriptor back, otherwise we end up with the content still in the buffer later. 2006-12-08 Scott James Remnant * HACKING: Document that test cases are expected. * nih/tests/test_command.c: Port to the new test framework. * nih/tests/test_option.c: Drop unused include. * nih/tests/test_option.c: Port to the new test framework. 2006-12-07 Scott James Remnant * nih/tests/test_io.c: Port to the new test framework. * nih/tests/test_hash.c: Drop use of assert. * nih/tests/test_timer.c (test_poll): Formatting fix. * nih/tests/test_string.c: Port to the new test framework. * nih/test.h (TEST_DIVERT_STDOUT_FD, TEST_DIVERT_STDERR_FD): Macros to divert to a file descriptor instead of a file. (TEST_DIVERT_STDOUT, TEST_DIVERT_STDERR): Redefine as wrappers around the new macros. * nih/tests/test_timer.c: Port to the new test framework. * nih/tests/test_signal.c: Port to the new test framework. * nih/tests/test_main.c: Port to the new test framework. * nih/test.h: Cast strlen return value to int when used to give the length of a string in printf. * nih/tests/test_logging.c: Port to the new test framework. * nih/test.h (TEST_DIVERT_STDOUT, TEST_DIVERT_STDERR): Crazy macros to divert stdout or stderr to a different file, making sure it's flushed before both dups. (TEST_EQ_STRN, TEST_NE_STRN): Functions to check a string up to a particular point. (TEST_FILE_EQ, TEST_FILE_EQ_N, TEST_FILE_NE, TEST_FILE_NE_N): Functions to grab a line from a file and check it against a string. (TEST_FILE_END): Function to determine end of file. (TEST_FILE_RESET): Another function so I don't need to remember the runes to flush, rewind and truncate a file. 2006-12-06 Scott James Remnant * nih/tests/test_file.c: Port to the new test framework. * nih/test.h (TEST_EQ_MEM, TEST_NE_MEM): Tests that wrap memcmp. (TEST_FILENAME): Macro to generate a filename. * nih/tests/test_error.c: Port to the new test framework. * nih/tests/test_alloc.c, nih/tests/test_list.c, nih/tests/test_hash.c: Undo over-zealous removing of includes. * nih/tests/test_child.c: Port to the new test framework. * nih/test.h (TEST_CHILD): Macro to spawn an interlocked child process, so we don't keep having to remember how to. * nih/test.h (TEST_ALLOC_SIZE, TEST_ALLOC_PARENT): Include the expression that generated the pointer, as well as the pointer. (TEST_LIST_EMPTY, TEST_LIST_NOT_EMPTY): Check whether a list is empty or not. * nih/tests/test_list.c (test_empty, test_foreach_safe): Use the new list test macros instead of TEST_TRUE/TEST_FALSE. * nih/tests/test_hash.c (test_new): Likewise. 2006-12-05 Scott James Remnant * nih/tests/test_hash.c: Port to the new test framework. * nih/tests/test_list.c: Port to the new test framework. * nih/tests/test_alloc.c: Port to the new test framework. (test_set_allocator): Test that the allocator is called with zero as the argument. * nih/test.h: Include config.h on behalf of the test suites. * nih/test.h (TEST_EQ_STR, TEST_NE_STR): String comparison tests. * nih/test.h (TEST_FAILED): abort is much better than exit * nih/test.h (INIT_TEST): Drop this, we'll just return directly. (TEST_FAILED): Return directly on failure. (CALL_TEST): Drop this again. * nih/test.h (CALL_TEST): Add "call a function" macro. * nih/test.h: Macros that implement a simple test framework based on the patterns I was using anyway. * nih/Makefile.am (nihinclude_HEADERS): Install nih/test.h * nih/tests/test_command.c (test_parser, test_help): flush stdout or stderr before calling dup2(). * nih/tests/test_option.c (test_parser, test_version, test_help): flush stdout or stderr before calling dup2(). * nih/tests/test_io.c: Formatting fix. * nih/file.c (nih_file_map): Tidy up; in particular don't allow opening in just write mode, seeing as that doesn't work. * nih/tests/test_file.c (test_unmap): Test unmap separately. (test_map): Update for new checks. * nih/file.c (nih_file_add_watch): No need to set ENOMEM if nih_new fails, that will be already set. (nih_file_reader): Clarify why nih_io_read must return a pointer. * nih/tests/test_string.c (test_str_screen_width) (test_str_screen_wrap): flush stdout before calling dup2(). * nih/tests/test_main.c (test_suggest_help, test_version): flush stdout or stderr before calling dup2(). * nih/tests/test_logging.c (test_logger_printf): flush stdout or stderr before calling dup2(), otherwise we don't know which stream the buffered output will be going to. * nih/tests/test_error.c (test_push_context): Check that unhandled errors within a context are notified and freed if the context is popped. * nih/alloc.c (nih_alloc_reparent): Function to reparent a pointer to a new parent or just orphan it. * nih/alloc.h: Update. * nih/tests/test_alloc.c (test_reparent): Make sure it works. * nih/tests/test_alloc.c (test_alloc_using): Check that this works properly if the allocator returns NULL. (test_realloc): A few cases to check here; make sure that it works if the pointer to realloc is NULL, actually test the children reparenting code here and test the reallocator returning NULL. * README: Correct typo. 2006-11-12 Scott James Remnant * nih/Makefile.am (INCLUDES, DEFS): Drop these two variables (AM_CPPFLAGS): in favour of this combined variable. * configure.ac (AM_INIT_AUTOMAKE): Include nostdinc so we don't get Automake's broken default includes. * nih/Makefile.am (INCLUDES): Include $top_builddir and $top_srcdir, everything else wants relative paths from there. (DEFAULT_INCLUDES): Drop override now we don't need it. * m4/compiler.m4 (NIH_C_THREAD): Define a macro in the manner of AC_C_CONST that will #define __thread to empty if it isn't supported by the compiler. * m4/misc.m4 (NIH_INIT): libnih uses __thread. 2006-10-13 Scott James Remnant * nih/command.h: Adjust type of NihCommandAction to include const. * nih/tests/test_command.c (my_action): Update. 2006-10-12 Scott James Remnant * configure.ac: Expand AC_GNU_SOURCE so we get _GNU_SOURCE and so that gettext doesn't complain. (AM_GNU_GETTEXT_VERSION): Increase to 0.15 (AC_PREREQ): Increase to 2.60 * HACKING: Update autoconf and gettext requirements. 2006-10-11 Scott James Remnant * nih/string.c (nih_str_screen_wrap): Don't quite fill the screen, instead leave a character spare as it looks somehow neater that way. * nih/option.c (nih_option_group_help): Likewise. * nih/tests/test_string.c (test_str_screen_wrap): Update tests. * nih/tests/test_option.c (test_help): Fix wrapping test. * TODO: Update. * nih/command.c: Implement a command parser that uses the first non-option argument (or program name) and selects different help and options based on that. * nih/command.h: Structures and prototypes. * nih/libnih.h: Include command.h * nih/tests/test_command.c: Test suite for command parser. * nih/Makefile.am (libnih_la_SOURCES): Build and link command.c (nihinclude_HEADERS): Install command.h (TESTS): Build and run command test cases (test_command_SOURCES, test_command_LDFLAGS, test_command_LDADD): Details for command test suite binary. * nih/tests/test_option.c: Keep a copy of last_option otherwise it's freed while we're not around. * nih/option.c (nih_option_set_footer): Add a footer string. (nih_option_help): Also add the footer string. * nih/option.h: Update. * nih/tests/test_option.c (test_help): Check the footer. * nih/option.c (nih_option_set_usage_stem): Add function to set the "[OPTION]..." bit of the usage line. (nih_option_help): Use the usage stem if set. * nih/option.h: Update. * nih/tests/test_option.c (test_help): Check the usage stem. * nih/option.c (nih_option_join): Add function to combine two lists of options. (nih_option_parser): Join the options and default_options lists, don't play with arrays of lists. (nih_option_get_short, nih_option_get_long): Simply by just iterating the one array. (nih_option_help, nih_option_group_help): Again simply by just iterating the one array. * nih/option.h: Update. * nih/tests/test_option.c (test_parser): Don't check addresses of options as they've moved. * nih/option.c (nih_option_set_usage, nih_option_set_synopsis) (nih_option_set_help): Allow NULL to be set to override existing strings. * nih/option.c (nih_option_help): Make static. * nih/option.h: Update. 2006-10-10 Scott James Remnant * TODO: Update. * nih/option.c (nih_option_group_help): Use a factor of the screen width when formatting help options, but keep at least 20 chars visible at all times. * nih/string.c (nih_str_screen_width): Add function to return just the screen width. (nih_str_screen_wrap): Use that function. * nih/string.h: Update. * nih/tests/test_string.c (test_str_screen_width): Check function. * nih/option.c (nih_option_set_synopsis): Function to set a synopsis string that follows the usage. (nih_option_set_help): Function to set the help string that follows the options. (nih_option_help): Output synopsis and help strings. * nih/option.h: Update. * nih/tests/test_option.c (test_help): Check behaviour * TODO: Update. * nih/main.c (nih_main_version): Use nih_str_screen_wrap to output the GPL preamble bit. * nih/tests/test_main.c (test_version): Unset COLUMNS just in case. * nih/string.c (nih_str_screen_wrap): Add wrapper around nih_str_wrap that obtains the screen width and uses that for len. * nih/string.h: Add prototype. * nih/tests/test_string.c (test_str_screen_wrap): Test new function. * nih/Makefile.am (test_string_LDADD): Link with -lutil so we can use openpty in our "fake terminal" tests. * nih/tests/test_option.c: Fix minor test case memory leak. * nih/tests/test_child.c (test_poll, test_poll): Use better interlocks then usleep. * nih/tests/test_option.c (main): Enable test of --debug, oops. * nih/main.c (nih_main_daemonise): Document why this is better than daemon(), and thus not nih. * nih/tests/test_main.c (test_daemonise): Test the daemonise function works properly. * nih/timer.h: Fix comments. * nih/hash.c (nih_hash_new): This needs a parent pointer too. * nih/hash.h: Update prototype. * nih/tests/test_hash.c: Update test cases. * nih/child.c: Clarify child_watches item types. * nih/file.c: Clarify file_watches item types. * nih/io.c: Clarify io_watches item types. * nih/main.c: Clarify loop_functions item types. * nih/timer.c: Clarify timers item types. * nih/signal.h (NihSignalCb): Rename to NihSignalHandler. (NihSignal): Change callback name to handler and type to NihSignalHandler. * nih/signal.c (nih_signal_add_callback): Rename to nih_signal_add_handler. * nih/tests/test_signal.c: Update. * nih/list.c (nih_list_new): Take a parent pointer like everything else, showing its age slightly. * nih/list.h: Update prototype. * nih/tests/test_list.c: Update test cases. * nih/child.c (nih_child_init): Pass NULL to nih_list_new(). * nih/error.c (nih_error_init): Pass NULL to nih_list_new(). * nih/file.c (nih_file_init): Pass NULL to nih_list_new(). * nih/io.c (nih_io_init): Pass NULL to nih_list_new(). * nih/main.c (nih_main_loop_init): Pass NULL to nih_list_new(). * nih/signal.c (nih_signal_init): Pass NULL to nih_list_new(). * nih/timer.c (nih_timer_init): Pass NULL to nih_list_new(). * nih/tests/test_hash.c: Pass NULL to nih_list_new(). * nih/alloc.c, nih/alloc.h, nih/child.c, nih/child.h, nih/error.c, nih/error.h, nih/file.c, nih/file.h, nih/hash.c, nih/hash.h, nih/io.c, nih/io.h, nih/list.c, nih/list.h, nih/main.c, nih/main.h, nih/option.c, nih/option.h, nih/signal.c, nih/signal.h, nih/string.c, nih/string.h, nih/timer.c, nih/timer.h: Clean up documentation and parent return values. * HACKING: Detail function documentation requirement and format. * nih/tests/test_signal.c (test_set_default, test_set_ignore) (test_reset): amd64 seems to set the SA_NODEFER flag even when you pass zero, so just check we clear important bits. 2006-09-27 Scott James Remnant * m4/misc.m4 (NIH_INIT): Add easier macro for using libnih. * m4/compiler.m4: Remove hack to include misc.m4 * configure.ac: Drop the macro set and replace with NIH_INIT * README: Update. * nihify: Warn if NIH_INIT not present. 2006-09-25 Scott James Remnant * TODO (main): Update. * nih/logging.h (nih_message): Add nih_message as an alias for nih_warn. * nih/tests/test_logging.c (test_log_message): Check new macro. 2006-09-20 Michael Biebl * nih/tests/test_file.c: Include nih/inotify.h when sys/inotify.h is not available. 2006-09-19 Michael Biebl * nih/Makefile.am (nihinclude_HEADERS): Install inotify.h just in case it's required 2006-09-18 Michael Biebl * configure.ac: Check for sys/inotify.h * nih/inotify.h: Taken from udev, this defines the syscalls and flags, etc. for inotify on glibc 2.3 * nih/file.c, nih/file.h: Include nih/inotify.h if we do not have sys/inotify.h 2006-09-13 Scott James Remnant * nih/child.c (nih_child_poll): Zero the siginfo_t struct before every call to waitid(), the kernel doesn't do it for us when running the compat syscall (but does for the native one *sigh). 2006-09-08 Scott James Remnant * TODO: Update. * nih/option.c (nih_option_help): Allow the usage string to be customised. (nih_option_set_usage): Using this function. * nih/option.h: Update. * nih/tests/test_option.c (test_help): Test the usage string. * nih/main.c (nih_main_daemonise): Use program_name for the pid file. * nih/main.h: Update. * nih/main.c (nih_main_daemonise): Add a daemonise function, pretty standard really. * nih/main.h: Update. 2006-09-07 Scott James Remnant * AUTHORS: Mention the ChangeLog file. 2006-09-04 Scott James Remnant * README: Add some documentation for the curious. * nih/file.c (nih_file_add_watch): Set nih_file_remove_watch as the default destructor so that nih_free can be called or work in a tree. (nih_file_remove_watch): Modify to not call nih_free and work if called multiple times. * nih/signal.c (nih_signal_set_default, nih_signal_set_ignore): Set flags to zero when defaulting or ignoring signals. * nih/tests/test_signal.c (test_set_default, test_set_ignore) (test_reset): Modify test cases appropriately. * nih/hash.h: Add missing attribute for nih_hash_new * nih/list.h: Add missing attribute for nih_list_new 2006-09-01 Scott James Remnant * nih/option.c (nih_option_group_help): Cast linelen to not induce a warning. 2006-08-31 Scott James Remnant * nih/main.c (nih_main_loop_interrupt): Always initialise the interrupt pipe. (nih_main_loop_init): Move interrupt pipe initialisation to here so that it's always available. (nih_main_loop): Drop the extra call to nih_signal_poll(). * nih/option.c (nih_option_get_short, nih_option_get_long): Allow catch-all options. * nih/tests/test_option.c (test_parser): Test catch-all options. * TODO: Update. * nih/option.c (nih_option_handle_arg): Free any existing option value. 2006-08-30 Scott James Remnant * nih/option.c (nih_option_debug): Add a hidden --debug option that sets the logging level up really high. (nih_option_handle): Just compare the names rather than offset within a list that can change. * nih/option.h: Update. * nih/tests/test_option.c (test_debug): Check that it works. * nih/option.c (nih_option_group_help): Output "Options" where we only have the one group. * nih/option.c (nih_option_group_help): Don't output options without help strings. * nih/tests/test_option.c (test_help): Update. 2006-08-25 Scott James Remnant * nih/io.c (nih_io_watcher): Clean up the handling of the out of memory condition while extending the buffer so that we just return to be called again rather than end up performing some random action. 2006-08-24 Scott James Remnant * nihify (src_dir): Also copy m4/Makefile.am * nih/file.c (nih_file_remove_watch): Raise the error before performing other actions so errno is not lost. * nih/io.c (nih_io_watcher): Fix a pretty critical bug, we weren't saving the value of errno so it was usually zero by the time we looked at it. * nih/logging.c (nih_logger_syslog): Useful alternative to nih_logger_printf. * nih/logging.h: Update. 2006-08-23 Scott James Remnant * nih/tests/test_string.c: Add missing free calls. * nih/tests/test_io.c (test_watcher): Silence the error message. * nih/tests/test_option.c (test_parser): Add some forgotten calls to nih_free * nih/main.c (nih_main_init_full): Free the package string when overwriting it. * nih/tests/test_logging.c: Keep a copy of the last message otherwise we're reading free'd memory (again). * nih/tests/test_list.c: Memory cleanups. * nih/signal.c (nih_signal_set_default, nih_signal_set_ignore): Don't initialise the signals list, there's no need. * nih/tests/test_hash.c: Various missing calls to nih_free. * nih/file.c (nih_file_remove_watch): Fix another wrong call to nih_free. * nih/tests/test_child.c (test_poll): Free the watcher. * nih/file.c (nih_file_remove_watch): Remove from the containing list before freeing. * nih/tests/test_file.c (my_watcher): Make sure we copy the name as it will be freed by the time we get back to the test. * nih/list.c (nih_list_free): Don't throw away the destructor return value. * nih/tests/test_error.c: Further missing calls to nih_free * nih/tests/test_alloc.c: Correct a few missing nih_free's * nih/file.c (nih_file_map): Correct a thinko, have to mask flags by O_ACCMODE and compare for equality to extract the open access mode. 2006-08-22 Scott James Remnant * nih/file.c (nih_file_map, nih_file_unmap): Add an easier to use wrapper around mmap() when we just want the file in memory. * nih/file.h: Add prototypes. * nih/tests/test_file.c (test_map): Test the functions. 2006-08-21 Scott James Remnant * nih/file.c: Wrap the inotify syscalls with something a little friendlier to deal with. * nih/file.h: Typedefs, structures and prototypes. * nih/libnih.h: Include file.h * nih/io.h: Correct typo in argument name. * nih/Makefile.am (libnih_la_SOURCES): Build and link file.c (nihinclude_HEADERS): Install file.h (TESTS): Build and run file test cases (test_file_SOURCES, test_file_LDFLAGS, test_file_LDADD): Details for file test case binary 2006-08-19 Scott James Remnant * nih/option.c (nih_option_parser): Finish option processing when the first non-option argument is found (command-mode) * nih/option.h: Update. * nih/tests/test_option.c (test_parser): Test command-mode. * nih/option.c: Implement a simple, yet flexible option parser. * nih/option.h: Typedefs, structures and prototypes. * nih/libnih.h: Include option.h * nih/tests/test_option.c: Test it all pretty thoroughly. * nih/Makefile.am (libnih_la_SOURCES): Build and link option.c (nihinclude_HEADERS): Install option.h (TESTS): Run the option test cases (test_option_SOURCES, test_option_LDFLAGS, test_option_LDADD): Details for the option test case binary. * TODO: Update. * nih/string.c (nih_str_wrap): Implement a function to wrap a string into the desired number of characters wide. * nih/string.h: Update. * nih/tests/test_string.c (test_str_wrap): Test the new function to make sure it does the right things. 2006-08-18 Scott James Remnant * TODO: Update. * nih/main.h (nih_main_init_gettext): Macro that expands to the usual gettext initialisation spiel if ENABLE_NLS is set, or nothing if not. (nih_main_init): Expand nih_main_init_gettext as well, we almost always want to do that, after all. * nih/macros.h: Include locale.h if ENABLE_NLS is set, as that contains setlocale, amongst other things. * nih/tests/test_main.c (test_init_gettext): Check the macro does the right things. * nih/io.h (NihIoCb): Rename to NihIoWatcher. (NihIoReadCb): Rename to NihIoReader. (NihIoCloseCb): Rename to NihIoCloseHandler. (NihIoErrorCb): Rename to NihIoErrorHandler. (NihIoWatch): Rename callback member to watcher. (NihIo): Rename read_cb member to reader, close_cb member to close_handler and error_cb member to error_handler. * nih/io.c: Update to use new names. (nih_io_cb): Rename to nih_io_watcher. * nih/tests/test_io.c: Update to use new names. * TODO: Update. 2006-08-16 Scott James Remnant * nih/main.c (nih_main_loop_add_func): Add a loop function (nih_main_loop): Run the loop functions. * nih/main.h (NihMainLoopCb, NihMainLoopFunc): Typedefs and structures for main loop callbacks. * nih/tests/test_main.c (test_main_loop_add_func): Check that the loop function is allocated correctly. (test_main_loop): Make sure it actually gets called. * nih/io.c (nih_io_cb): Add a couple of check assertions. * nih/macros.h (N_): Should be defined to be a no-op. 2006-08-14 Scott James Remnant * nih/alloc.c (nih_realloc): Yet another fix to realloc, we forgot to reinitialise our entry in the parent's children list in the case of no parent. After fixing this and tracing the code, I realised that the previous fix was inelegant and there is a way to deal with children without modifying the pointers until after the reallocation. Documented the reasoning in the function. * nih/io.c (nih_io_reopen): Report on the error rather than just suppressing it. (nih_io_error): Likewise, report on the error. 2006-08-12 Scott James Remnant * nih/main.c (nih_main_loop_close): Drop this function (nih_main_loop): Instead mark them close on exec. * nih/main.h: Update. * nih/main.c (nih_main_loop): Change the main loop to use select instead of poll, as its semantics are a lot easier to deal with. We also use allow select to be interrupted by writing to a pipe from the signal handlers, for when Linux gets around to supporting SA_RESTART properly. (nih_main_loop_interrupt): Write to the pipe so the select call gets interrupted. (nih_main_loop_exit): Interrupt the main loop, in case we're waiting forever. (nih_main_loop_close): Close the interrupt pipe, used in children. * nih/main.h: Update. * nih/io.c (nih_io_add_watch): Change type of events parameter. (nih_io_poll_fds): Remove this function. (nih_io_select_fds): And replace with this that sets the select file descriptor sets instead. (nih_io_handle_fds): Now receives select file descriptor sets, and becomes rather more obvious in the process. Restore the previous behaviour where a callback isn't called unless requests events occur. (nih_io_reopen): Always poll for reading so we pick up errors. (nih_io_cb): Change type of events parameter and events settings. (nih_io_write): Change event settings. * nih/io.h: Update. (NihIoEvents): replace the previous poll events with a new enum. * nih/signal.c (nih_signal_handler): Interrupt the select call in the main loop. * nih/tests/test_io.c: Update with new test cases. * nih/tests/test_child.c: Use select() rather than poll() * nih/tests/test_io.c (test_buffer_push, test_write): Correct uninitialised return value. * nih/main.c (nih_main_loop): Correct a memory leak, we forgot to clean up the poll fds list. * nih/io.c (nih_io_handle_fds): Always call the callback, even if unexpected events happen, otherwise we'll miss ERR, HUP, etc. (nih_io_shutdown): Allow a socket to be closed lazily, so we can send (or receive) a whole bunch of stuff and expect the structure to go away afterwards. (nih_io_cb): If the shutdown flag has been marked and we run out of things in either buffer, act as if one end was closed. (nih_io_reopen): Mark sockets as not shutdown by default. * nih/io.h: Update. * nih/tests/test_io.c (test_shutdown): Test behaviour. (test_handle_fds): Take out some of the tests due to changed behaviour. While "clever" I think overall this is undesirable. * nih/io.c (nih_io_set_cloexec): Function to set the FD_CLOEXEC flag. * nih/io.h: Update. * nih/tests/test_io.c (test_set_cloexec): Test the function. 2006-08-11 Scott James Remnant * nih/alloc.h, nih/child.h, nih/hash.h, nih/logging.h, nih/signal.h, nih/timer.h: Document arguments to function pointers. * nih/io.c: Add a whole bunch of code to provide us with a high- throughput, async file/socket layer; largely copied from the dircproxy code (well, it works!). This allows read and write calls to happen inside the main loop based on whenever poll thinks either is possible, while user space can just write what it likes or get called when there's data in the recv buffer. * nih/io.h: Add the new typedefs, structures and prototypes. * nih/tests/test_io.c: Lots of test cases for this stuff. 2006-08-10 Scott James Remnant * nih/alloc.c (nih_realloc): Fix a fairly critical bug, we weren't dealing with the fact that the children list head can move; do some fancy shifting to make that work. * nih/string.c (nih_str_split): Add a function to split a string based on delimiters into an array. * nih/string.h: Update. * nih/tests/test_string.c (test_str_split): Test the new function. 2006-08-09 Scott James Remnant * nih/tests/test_child.c (test_poll): Add extra sleep calls for safety. * nih/libnih.h: Include errors.h 2006-08-04 Scott James Remnant * nih/errors.h: Include errno.h for helpfulness. 2006-08-03 Scott James Remnant * nih/child.c (nih_child_add_watch): Also takes a parent now. * nih/child.h: Update. * nih/tests/test_child.c: Update. * nih/io.c (nih_io_add_watch): And once more, with feeling; takes a parent for the watch. * nih/io.h: Update. * nih/tests/test_io.c: Update. * nih/signal.c (nih_signal_add_callback): Give this the same treatment, it takes the parent for the signal callback. * nih/signal.h: Update. * nih/tests/test_signal.c: Update. * nih/timer.c (nih_timer_add_timeout, nih_timer_add_periodic) (nih_timer_add_scheduled): Use nih_alloc properly by taking a parent for the timer object and setting a destructor on it so that it's automatically removed when the parent is freed. * nih/timer.h: Update. * nih/tests/test_timer.c: Update function calls. * nih/tests/test_main.c (test_main_loop): Update also. * nih/list.c (nih_list_destructor): Add a destructor function that just cuts the entry out of the list in preperation for being freed. * nih/list.h: Update. * nih/tests/test_list.c (test_destructor): Test the behaviour of the new function. * nih/tests/test_error.c: Include fixes. 2006-08-02 Scott James Remnant * nih/signal.c (nih_signal_set_handler, nih_signal_set_default) (nih_signal_set_ignore): Reset sa_flags so that we don't pass uninitialised data for SIGALRM. (nih_signal_reset): Add function to reset signals back to their default state. * nih/signal.h: Update. * nih/tests/test_signal.c (test_reset): Add test case. * nih/error.c (nih_error_raise_system): Be a lot more careful in this function! Save the value of errno in case we overwrite it and call nih_error_init() * nih/signal.c (nih_signal_set_handler): Add the SA_NOCLDSTOP signal for SIGCHLD. * nih/main.c (nih_main_loop): Drop the code that masked out the child signal, it was inherently racy and there's no particular reason to do it anyway since we use SA_RESTART in signal.c for most things. * nih/signal.c (nih_signal_set_handler, nih_signal_set_default) (nih_signal_set_ignore): don't set SA_RESTART for SIGALRM. * nih/signal.c (nih_signal_set_handler, nih_signal_set_default) (nih_signal_set_ignore): use nih_return_system_error to make the code rather cleaner. * nih/error.h (nih_return_error): Add missing doc for retval (nih_return_system_error): Add additional useful function. * nih/tests/test_error.c (test_return_system_error): Add test case for the new macro. * nih/child.c (nih_child_poll): Convert to use waitid() so that we can obtain the information about the dead child without reaping it until we're done processing; useful because it means /proc/$PID and the child itself is still around during the handlers. * nih/child.h (NihReaper): Gains a new third argument that indicates whether the child exited normally or was killed. * nih/tests/test_child.c (test_poll): Update. * nihify: Add a few useful sanity checks so that it works with relative paths and already-nihified directories. * m4/misc.m4: Remove older force code. * TODO: Updated. * m4/Makefile.am (dist_aclocal_DATA): Distribute misc.m4, long missed. * nihify: Add useful script for symlinking into source trees until we intend to get released. * HACKING: Correct typo (our -> out) 2006-07-28 Scott James Remnant * nih/main.c (nih_main_term_signal): Handy signal callback. * nih/main.h: Update. * nih/tests/test_main.c (my_timeout): Cheat and ensure the latest exit status is used. * nih/main.c (nih_main_loop): Implement a main loop by calling various other functions in the right manner. (nih_main_loop_exit): Function to break the main loop. * nih/main.h: Update. * nih/tests/test_main.c (test_main_loop): Add a trivial test case for the main loop, it's damned difficult to test, but at least this ensures the bases are touched. * nih/signal.c (nih_signal_poll): Add missing call to nih_signal_init() * nih/child.c (nih_child_poll): Add missing call to nih_child_init() * nih/io.c (nih_io_poll_fds, nih_io_handle_fds): Add missing calls to nih_io_init() * nih/io.c: Code for watching file descriptors and sockets for events through poll(), but not actually the poll() call itself. * nih/io.h: Typedefs, structures and prototypes. * nih/libnih.h: Include io.h * nih/tests/test_io.c: Test cases for I/O watches. * nih/Makefile.am (libnih_la_SOURCES): Build and link io.c (nihinclude_HEADERS): Install io.h (TESTS): Build and run I/O test cases (test_io_SOURCES, test_io_LDFLAGS, test_io_LDADD): Details for I/O test case binary. * nih/tests/test_timer.c (test_poll): Free entry after testing. * nih/child.c (nih_child_poll): When the reaper is for a particular process, be sure to remove it from the list. * nih/tests/test_child.c (test_poll): Test for that. * nih/child.c: Simple bit of code to wait for children to terminate and dispatch the reaper functions for them. * nih/child.h: Typedefs, structures and prototypes. * nih/libnih.h: Include child.h * nih/tests/test_child.c: Test cases for child handling code. * nih/Makefile.am (libnih_la_SOURCES): Build and link child.c (nihinclude_HEADERS): Install child.h (TESTS): Build and run child test cases (test_child_SOURCES, test_child_LDFLAGS, test_child_LDADD): Details for child test case binary. * nih/timer.c (nih_timer_add_timeout, nih_timer_add_periodic) (nih_timer_add_scheduled): Change argument order so that the time information is first, to match signal functions. * nih/timer.h: Update. * nih/tests/test_timer.c: Update. * nih/signal.h: Include the system signal.h for ease of use. * nih/signal.c: Code for handling signals inside the main loop, rather than trying to fit delicate code in a signal handler; and for making it generally easier to handle signals. * nih/signal.h: Typedefs and prototypes. * nih/libnih.h: Include signal.h * nih/Makefile.am (libnih_la_SOURCES): Build and link signal.c (nihinclude_HEADERS): Install signal.h (TESTS): Build and run signal test cases (test_signal_SOURCES, test_signal_LDFLAGS, test_signal_LDADD): Details for signal test case binary. 2006-07-27 Scott James Remnant * nih/timer.c: Code for timeouts, periodic and scheduled timers, note that the actual scheduling part of scheduled timers it not implemented yet (we need to think a bit more about it) * nih/timer.h: Structures, macros and prototypes. * nih/libnih.h: Include timer.h * nih/tests/test_timer.c: Test cases for timer code. * nih/Makefile.am (libnih_la_SOURCES): Build and link timer.c (nihinclude_HEADERS): Install timer.h (TESTS): Build and run timer test cases (test_timer_SOURCES, test_timer_LDFLAGS, test_timer_LDADD): Details for timer test case binary. * nih/alloc.c (nih_free): Use new safe list iteration macro. * nih/hash.c (nih_hash_add_unique, nih_hash_replace) (nih_hash_search): Use new list iteration macros. * nih/list.h (NIH_LIST_FOREACH): New macro that expands to the usual list iteration for loop, prevents mistakes. (NIH_LIST_FOREACH_SAFE): Macro that does the same as above, but also includes a "next" variable to allow safe iteration; especially useful to prevent us getting this wrong! * nih/tests/test_list.c (test_foreach, test_foreach_safe): Add test cases for iteration. * nih/error.c (nih_error_init): Make inline and check value first. (nih_error_raise, nih_error_raise_printf, nih_error_raise_again) (nih_error_push_context): Unconditionally call nih_error_init. * nih/alloc.c (nih_alloc_init): Make inline and check value first. (nih_alloc): Unconditionally call nih_alloc_init. * nih/logging.c (nih_log_init): Use the proper functions to initialise details, check values first; also make inline. (nih_log_message): Unconditionally call nih_log_init. * nih/Makefile.am (DEFS): Append to the default DEFS list, rather than overriding, otherwise we lose HAVE_CONFIG_H * nih/macros.h: Check for ENABLE_NLS instead of HAVE_GETTEXT and include libintl.h if defined as well. 2006-07-20 Scott James Remnant * nih/string.c (nih_strv_free): Add a function to free an array of strings. * nih/string.h: Update. * nih/tests/test_string.c (test_strv_free): Test the function. * nih/error.c: Error handling code. * nih/error.h: Structures, macros and prototypes. * nih/errors.h: Error enum and message definitions. * nih/libnih.h: Include error.h and errors.h * nih/tests/test_error.c: Error handling test cases. * nih/Makefile.am (libnih_la_SOURCES): Build and link error.h (nihinclude_HEADERS): Install error.h (TESTS): Build and run error handling test cases. (test_error_SOURCES, test_error_LDFLAGS, test_error_LDADD): Binary for error handling test cases. * nih/macros.h (NIH_MUST, NIH_MUST_NOT): Add handy macros to spin until we get a true or false value from an assignment. Usually used around a call to memory allocation functions that we can't deal with failing. * nih/main.c (nih_main_package_string): Change package_string to be a module-level static so it can be reset by a call to nih_main_init_full. Always return if not NULL. * nih/tests/test_main.c (test_package_string): Call nih_main_init_full instead of futzing with variables so the static string is reset. * nih/alloc.c (nih_alloc_using, nih_alloc, nih_realloc) (nih_alloc_size, nih_alloc_parent): Make various argument pointers const. * nih/alloc.h: Update. * nih/libnih.h, nih/logging.c, nih/main.c: Update to include string.h not strutil.h * nih/strutil.c: Renamed to nih/string.c * nih/strutil.h: Renamed to nih/string.h * nih/tests/test_strutil.c: Renamed to nih/tests/test_string.h * nih/Makefile.am (DEFAULT_INCLUDES): Override to stop automake doing silly things like putting -I. in the pre-processor flags. (libnih_la_SOURCES, nihinclude_HEADERS, TESTS) (test_string_SOURCES, test_string_LDFLAGS, test_string_LDADD): Update. 2006-07-19 Scott James Remnant * nih/alloc.h, nih/logging.h, nih/strutil.h: Reformat attribute declarations to not upset emacs indentation. 2006-07-17 Scott James Remnant * nih/strutil.c (nih_strdup): Implement an nih_alloc-based strdup. (nih_strdup): and strndup. * nih/strutil.h: Update. * nih/tests/test_strutil.c: Test new functions. 2006-07-13 Scott James Remnant * nih/alloc.c (nih_free): Remove the entry from the parent's list. * nih/logging.h (nih_assert): Reexpress to avoid polluting if statements without an else. * nih/alloc.c (nih_realloc): Implement a function that reallocates a block of memory with the original allocator. (nih_alloc_init): Don't double-check the allocator. * nih/alloc.h: Update. * nih/tests/test_alloc.c (test_realloc): Check behaviour of realloc. * nih/alloc.c (NihAllocCtx): Drop the name pointer, we never used that anyway. (nih_alloc_using): Drop name parameter. (nih_alloc_named): Rename to nih_alloc. (nih_alloc_set_name): Drop this function. (nih_alloc_name): And this one. * nih/alloc.h (nih_new): Simplify. (nih_alloc): Drop entirely now it's unneeded. * nih/tests/test_alloc.c: Update. * nih/tests/test_list.c (test_new): Test using nih_alloc_size rather than nih_alloc_name. * nih/logging.h: Put the log priorities back in ascending order, but use the zero to mean "unknown". Fix up the descriptions to be a little more consistent. * nih/logging.c: Rename max_priority back to min_priority so it all makes more sense again. (nih_log_init): Warning is the default minimum priority to show. (nih_log_set_priority): Set minimum priority. (nih_log_message): Discard messages below the minimum priority. (nih_logger_printf): Use stderr when priority is greater than or equal to warning. * nih/tests/test_logging.c: Update to match. * nih/logging.c (nih_log_message): Use nih_vsprintf which makes the function not core dump (always good, that). 2006-07-12 Scott James Remnant * nih/main.c (nih_main_package_string): Use nih_sprintf and make the function rather simpler. * nih/tests/test_alloc.c (main): Formatting fix. * nih/strutil.c (nih_sprintf): Function to wrap sprintf, allocating the necessary space using nih_alloc first. (nih_vsprintf): Function to wrap vsprintf, allocating the necessary space using nih_alloc first. * nih/strutil.h: Prototypes. * nih/libnih.h: Include strutil.h * nih/Makefile.am (libnih_la_SOURCES): Build and link strutil.c (nihinclude_HEADERS): Install strutil.h (TESTS): Build and run strutil test cases (test_strutil_SOURCES, test_strutil_LDFLAGS) (test_strutil_LDADD): Binary for strutil test cases. 2006-07-05 Scott James Remnant * nih/logging.c (nih_log_message): Don't bother catching vsnprintf's return value, C99 doesn't allow it to fail. * nih/main.c (nih_main_package_string): Likewise for here. * nih/logging.c (nih_log_message): Don't use a static variable for no apparent reason, just free afterwards. Catch vsnprintf and malloc failing. * nih/main.c (nih_main_package_string): Catch snprintf and realloc failing here too. 2006-05-30 Scott James Remnant * nih/logging.h (nih_assert): Assertion macro that uses our logging rather than stderr. * nih/alloc.c, nih/hash.c, nih/list.c, nih/logging.c, nih/main.c: Use nih_assert rather than assert. * nih/Makefile.am (test_alloc_LDFLAGS, test_list_LDFLAGS) (test_hash_LDFLAGS, test_main_LDFLAGS, test_logging_LDFLAGS): Link libraries statically. (test_alloc_LDADD, test_list_LDADD, test_hash_LDADD) (test_main_LDADD, test_logging_LDADD): Just link to the library. * nih/macros.h (NIH_STRINGIFY): Correct typo (-s -> _s) (NIH_LIKELY, NIH_UNLIKELY): Add branch prediction macros. 2006-05-29 Scott James Remnant * nih/alloc.c (nih_alloc_init): Restore this function, it's better style to keep variables in shared libraries as zero. (nih_alloc_named): Call nih_alloc_init once more. * nih/logging.h: Reorder such that NONE is the lowest value. * nih/logging.c (min_priority): Rename to max_priority and set value to NIH_LOG_NONE (zero). (nih_log_init): Initialise the default logger and priority. (nih_log_set_priority): Assert priority is greater than NONE. (nih_log_message): Initialise the logging if necessary. (nih_logger_printf): Check priority with <= * TODO: Update. * nih/logging.c: Code for formatting log messages and filtering based on priority. * nih/logging.h: Prototypes and macros. * nih/libnih.h: Include logging.h * nih/tests/test_logging.c: Logging test cases. * nih/Makefile.am (libnih_la_SOURCES): Build and link logging.c (nihinclude_HEADERS): Install logging.h (TESTS): Build and run logging test cases. (test_logging_SOURCES, test_logging_LDADD): Binary for logging test cases. * nih/tests/test_main.c (test_package_string, test_suggest_help) (test_version): Add missing comments before tests. (test_suggest_help, test_version): Close the duplicated stdout/stderr before leaving the test. * nih/alloc.h: Declare nih_alloc_named and nih_alloc_using with the warn_unused_result and malloc attributes. 2006-05-27 Scott James Remnant * m4/compiler.m4 (NIH_COMPILER_WARNINGS): Drop -pedantic as we usually want gcc extensions (all the world IS gcc). 2006-05-26 Scott James Remnant * nih/main.c (nih_main_init_full): Only take the basename of the program name, not the full path. (nih_main_package_string): Use an allocated piece of memory rather than some on the stack, with C99-style snprintf to do the right thing with it. * nih/tests/test_main.c (test_init): Include check for basename. (test_package_string): Drop tests involving basename here. * m4/compiler.m4 (NIH_TRY_C99): Macro that tries compiling some code full of C99 features. (NIH_C_C99): Use the above macro to determine whether the compiler supports C99, or whether it can do it with a compiler flag. * configure.ac: Make sure the compiler does C99. * nih/list.c: Add missing prototype for nih_list_cut. * nih/hash.c: Add missing prototype for fnv_hash. * nih/macros.h (_, N_): Define gettext-wrapper macros if HAVE_GETTEXT, otherwise define them to just expand to their string. * nih/main.h: Drop comments for global variables. * nih/main.c: Provide proper docstrings for them here. * nih/alloc.c (nih_alloc_init): Drop this function, instead just initialise the static variable directly. (nih_alloc_set_allocator): Correct parameter name in docstring, don't call nih_alloc_init (it's already initialised). 2006-05-24 Scott James Remnant * nih/main.c (nih_main_package_string): Clarify documentation. 2006-05-23 Scott James Remnant * nih/main.c: Add code for the various little functions that we usually call from main(). * nih/main.h: Prototypes and macros. * nih/libnih.h: Include main.h * nih/Makefile.am (libnih_la_SOURCES): Build and link main.c (nihinclude_HEADERS): Install main.h (TESTS): Build and run main test-cases (test_main_SOURCES, test_main_LDADD): Code for main tests. * m4/misc.m4 (AC_COPYRIGHT): Wraps the Autoconf AC_COPYRIGHT macro but also defines PACKAGE_COPYRIGHT * m4/compiler.m4: Temporary hack to make sure misc.m4 gets dragged in as aclocal doesn't notice it, will go away once we get something that aclocal will notice. 2006-04-26 Scott James Remnant * nih/hash.c: Add code for FNV hash tables that uses NihList for the actual bins so is largely polymorphic. * nih/hash.h: Prototypes, macros and structures. * nih/macros.h: Include stdint.h as well, we use that a lot. * nih/libnih.h: Include hash.h * nih/tests/test_hash.c: Test cases for new hash table code. * nih/Makefile.am (libnih_la_SOURCES): Build and link hash.c (nihinclude_HEADERS): Install hash.h (TESTS): Build and run hash table test-cases. (test_hash_SOURCES, test_hash_LDADD): Code for hash table tests. * TODO: Update. * nih/tests/test_list.c (test_empty): Fix faulty test case that actually proved one-entry lists were showing up as empty! * nih/list.h (NIH_LIST_EMPTY): Compare the next and previous pointers against the list pointer itself! * nih/list.c (nih_list_cut): Add an inline function that does the job of nih_list_remove without calling nih_list_init afterwards. (nih_list_remove): Call nih_list_cut rather than modifying pointers. (nih_list_free): Use nih_list_cut for efficiency, no point fixing the pointers if we're just going to free it. (nih_list_add, nih_list_add_after): Use nih_list_cut as the pointers get modified afterwards anyway, more efficient this way. 2006-04-25 Scott James Remnant * nih/list.c: Remove unnecessary include of stdlib.h * nih/list.c (nih_list_new): Fix formatting of docstring. * nih/alloc.c (nih_alloc_using, nih_alloc_parent): Fix formatting of docstring. (nih_alloc_named): Fix docstring to mention NULL can be returned. * nih/tests/test_alloc.c, nih/tests/test_list.c: Add missing blank line before includes. * nih/alloc.c (nih_alloc_using): Return NULL if the allocation fails. * nih/list.c (nih_list_new): Also return NULL if the allocation fails. * nih/alloc.c (nih_alloc_set_allocator, nih_alloc_using) (nih_free, nih_alloc_set_name, nih_alloc_set_destructor) (nih_alloc_name, nih_alloc_size, nih_alloc_parent): Use assert to uncover programming errors. * nih/list.c (nih_list_init, nih_list_remove, nih_list_free) (nih_list_add, nih_list_add_after): Use assert to uncover programming errors. (nih_list_new): Comment that nih_new may return NULL and we need to make sure we catch that. 2006-04-24 Scott James Remnant * m4/Makefile.am (dist_aclocal_DATA): Add missing \ * nih/Makefile.am (INCLUDES): Include top_srcdir otherwise we can't be built out of tree. * m4/Makefile.am (dist_aclocal_DATA): Install the m4 files into the aclocal directory, not a package specific one. * m4/compiler.m4, m4/linker.m4: Fix closing comment style. * TODO: Add TODO file. * nih/list.h (NIH_LIST_EMPTY): Document what this actually does. 2006-04-19 Scott James Remnant * nih/list.c (nih_list_entry_new): Removed. This makes the list code more focussed and generic, but also we'll nearly always want the data member to be an nih_alloc child of the list, rather than the other way around! * nih/list.h (NihListEntry, nih_list_add_new) (nih_list_add_new_after): Likewise, remove the structure and helper macros; if we find ourselves wanting this, we can put it in a new file and just make it polymorphic like we plan for hashes. * nih/tests/test_list.c: Replace all uses of NihListEntry with plain NihList, we never checked the data members anyway. (test_entry_new): Remove test case. (test_add): Remove test of nih_list_add_new macro. (test_add_after): Remove test of nih_list_add_new_after macro. (test_empty): Check macro works with any list entry. (test_remove): Test removal of the last list entry, and removal on an already empty list. (test_free): Don't check the pointers of a block we've just freed! 2006-04-18 Scott James Remnant * nih/alloc.c (nih_alloc_init): Call nih_alloc_set_allocator. * nih/alloc.h (NihDestructor): Clarify docstring to not refer to internal structures. * nih/list.h (NIH_LIST_EMPTY): Add convenience macro for this common operation. * nih/tests/test_list.c (test_empty): Test the new macro. 2006-04-16 Scott James Remnant * nih/list.c (nih_list_new, nih_list_entry_new): Call nih_new rather than malloc so the list can be a context for data members. (nih_list_free): Call nih_free rather than free. * nih/tests/test_list.c: Test cases should not be static. (test_new, test_entry_new): Check the new object was allocated using our nih_alloc function. (test_remove): Test a second removal. (destructor_called): Function to test whether destructor was called. (test_free): Test now that we can use an NihDestructor. * nih/Makefile.am (test_list_LDADD): Link alloc.o now that lists depend on the allocator. * nih/list.c, nih/list.h: Fix docstrings to use references where useful. Split functions into blocks separated by a newline. * nih/alloc.h: Update and fix formatting. (NihAllocDestructor): Rename to NihDestructor. * nih/alloc.c (nih_alloc_init): Make safe against repeated calls. (nih_alloc_set_allocator): New function to set the default allocator, overriding any set already. (nih_alloc_set_destructor): Update type of destructor argument.. (NihAllocCtx): Update type of destructor member. * nih/tests/test_alloc.c (my_realloc): Wrapper around realloc so we can check custom allocators are called properly. (test_alloc_using): Test allocation with a custom allocator. (test_free): Check that the block is freed using the allocator, also update destructor checking. (test_set_allocator): Test new allocator is used. * nih/alloc.c (nih_alloc_using): New one-shot function to use a given realloc-style function to make a named block of memory of a given size. (nih_alloc_named): Replace with a thin-wrapper around nih_alloc_using that passes in the default allocator. (NihAllocCtx): Add new allocator member to store the allocator used, so we free with the right one. (nih_alloc_init): Set the default allocator to realloc(). Drop pool initialisation code. (nih_free): Call the context's original allocator with zero size. (used_pool, unused_pool, NIH_ALLOC_SMALLEST): Remove, these really belong in distinct memory handling code. (nih_alloc_set, nih_alloc_new): Drop functions only needed if we're doing our own memory management. (nih_alloc_size, nih_alloc_parent): Add a couple of useful functions. * nih/alloc.h (NihAllocator): Typedef for allocator function prototype. (nih_alloc): Rename to nih_new. (nih_alloc_size): Rename to nih_alloc. * nih/tests/test_alloc.c (test_alloc_named, test_new, test_alloc): Test behaviour of standard functions with and without parents. (destructor_called): Allow it to be called multiple times, change to static to enforce modularity. (child_destructor_called): Another function for testing multiple destructors. (test_free): Test nih_free using alloc destructors. (test_alloc_set_name): Rename to just test_set_name for consistency. * nih/macros.h (NIH_STRINGIFY): Generic hack to turn a numeric macro into a string. * nih/alloc.h (nih_alloc, nih_alloc_size): Use generic NIH_STRINGIFY macro instead of our home-cooked one. 2006-03-31 Scott James Remnant * nih/alloc.c, nih/alloc.h, nih/list.c, nih/list.h, nih/macros.h, nih/libnih.h, nih/tests/test_alloc.c, nih/tests/test_list.c: Update FSF address in GPL header. 2006-03-03 Scott James Remnant * nih/alloc.c, nih/alloc.h, nih/list.c, nih/list.h: Formatting fixes, correct erroneous references to d_* functions and D* structures. * nih/list.h: Correct docstring for nih_list_new and nih_list_entry_new functions so that @data is described for the right one. * nih/Makefile.am: Add blank line between SOURCES and LDFLAGS. 2005-09-29 Scott James Remnant * nih/alloc.c, nih/alloc.h, nih/list.c, nih/list.h: Fix docstring terminators to be **/ not */. * nih/alloc.h: Align function parameters. * nih/tests/test_alloc.c (test_alloc_set_name): Fix to return ret and not zero all the time. 2005-08-29 Scott James Remnant * nih/alloc.c (NIH_ALLOC_SMALLEST): Set to the size of the NihAllocCtx structure shifted left twice; this will divide evenly into a page. * nih/alloc.c (nih_alloc_init): No need to pass NULL to nih_list_new. (nih_alloc_new): No need to initialise data member of NihList structs or cast children member. (nih_alloc_named): Can cast NihList directly to NihAllocCtx now, simplify difference test. (nih_free): Use iter as variable name for clarity. (nih_alloc_return_unused): Cast NihList directly to NihAllocCtx. * nih/tests/test_alloc.c: Output "BAD:" instead of "FAIL:" * nih/list.h (NihList): Remove data pointer, it'll save us 4 bytes where we want to make lists of structures that are always in lists. (NihListEntry): Define new structure for those still wanting data pointers. (nih_list_add_new, nih_list_add_new_after): Use nih_list_entry_new. * nih/list.c (nih_list_new): Remove argument and don't initialise data pointer, this simply allocates and initialises the two-pointer structure. (nih_list_entry_new): New function to allocate and initialise an NihListEntry structure. * nih/tests/test_list.c: Output "BAD:" instead of "FAIL:" (test_new): Test without data pointer. (test_entry_new): Test with data pointer. (test_add, test_add_after, test_remove): Mix and cast NihList and NihListEntry properly. * nih/alloc.c: Implement a heirarchial allocator in a similar style to halloc and talloc, but designed never to return data to the system and re-use it instead. * nih/alloc.h: Prototypes and macros for allocator. * nih/libnih.h: Include allocator header. * nih/tests/test_alloc.c: Test-cases for allocator. * nih/macros.h (MIN, MAX): Define MIN and MAC macros if not already available. * nih/Makefile.am (libnih_la_SOURCES): Compile and link alloc.c (nihinclude_HEADERS): Install alloc.h (TESTS): Build and run the allocator test-cases. (test_alloc_SOURCES, alloc_list_LDADD): Identify the test sources and objects it needs. 2005-08-28 Scott James Remnant * nih/list.c (nih_list_init): Add new function for dealing with statically allocated list entries, and initialising them. (nih_list_new): Use nih_list_init() to initialise the list. (nih_list_new): Use nih_list_init() to re-initialise the list to a single-member. * nih/list.h: Add prototype for nih_list_init. (NihListIter): Remove the iterator structure, it turns out to be harder work to try and use lists in an "all nodes are interesting" manner; so we'll iterate them normally instead. (NIH_LIST_FIRST, NIH_LIST_LAST): Remove iterator test functions. (NIH_LIST_PREV, NIH_LIST_NEXT): Remove iterator change functions. * nih/tests/test_list.c: Use NULL for nih_list_new in all functions. (test_init): New test case for nih_list_init(). (test_iterator): Removed iterator tests. 2005-08-21 Scott James Remnant * nih/list.c: Add code for generic circular doubly-linked lists. * nih/list.h: Prototypes and macros. * nih/macros.h: Some generic macros. * nih/libnih.h: Header to import everything. * nih/tests/test_list.c: Test-cases for linked-list code. * nih/Makefile.am (libnih_la_SOURCES): Link list.c in. (nihincludedir): Define directory to contain header files to be $includedir/nih. (include_HEADERS): Install libnih.h into the main include directory. (nihinclude_HEADERS): Install header files. (TESTS): Build and run the list test-cases. (test_list_SOURCES, test_list_LDADD): Identify the test sources and objects it needs. * nih/libnih.ver: Add simple "everything beginning nih_* is global" version script. * nih/Makefile.am (libnih_la_LDFLAGS): Use the version script if we can pass an argument to do that to the linker. (EXTRA_DIST): Distribute the version script. 2005-07-09 Scott James Remnant * m4/compiler.m4 (NIH_COMPILER_WARNINGS): Macro to add -Wall, -Werror and -pedantic to CFLAGS and CXXFLAGS if using gcc or g++. (NIH_COMPILER_OPTIMISATIONS): Macro to remove any optimisation arguments from CFLAGS and CXXFLAGS and replace them with -O0 to override any default level. (NIH_COMPILER_COVERAGE): Macro to add compiler coverage testing arguments to CFLAGS and CXXFLAGS. * m4/linker.m4 (NIH_LINKER_OPTIMISATIONS): Macro to add -Wl,-O1 to LDFLAGS to increase the optimisation of the linker hash tables. (NIH_LINKER_VERSION_SCRIPT): Macro to test for the right argument to pass a version script to the linker and define HAVE_VERSION_SCRIPT and VERSION_SCRIPT_ARG. * m4/Makefile.am (dist_pkgdata_DATA): Ship macros. * configure.ac: Use new macros. * ChangeLog: Initial project infrastructure created. libnih-1.0.3/config.sub0000755000175000017500000010344511461165277011705 00000000000000#! /bin/sh # Configuration validation subroutine script. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 # Free Software Foundation, Inc. timestamp='2010-01-22' # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software # can handle that machine. It does not imply ALL GNU software can. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA # 02110-1301, USA. # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # Please send patches to . Submit a context # diff and a properly formatted GNU ChangeLog entry. # # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. # If it is invalid, we print an error message on stderr and exit with code 1. # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: # http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases # that are meaningful with *any* GNU software. # Each package is responsible for reporting which valid configurations # it does not support. The user should be able to distinguish # a failure to support a valid configuration from a meaningless # configuration. # The goal of this file is to map all the various variations of a given # machine specification into a single specification in the form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM # or in some cases, the newer four-part form: # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] CPU-MFR-OPSYS $0 [OPTION] ALIAS Canonicalize a configuration name. Operation modes: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.sub ($timestamp) Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try \`$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" exit 1 ;; *local*) # First pass through any local machine types. echo $1 exit ;; * ) break ;; esac done case $# in 0) echo "$me: missing argument$help" >&2 exit 1;; 1) ;; *) echo "$me: too many arguments$help" >&2 exit 1;; esac # Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ kopensolaris*-gnu* | \ storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; *) basic_machine=`echo $1 | sed 's/-[^-]*$//'` if [ $basic_machine != $1 ] then os=`echo $1 | sed 's/.*-/-/'` else os=; fi ;; esac ### Let's recognize common machines as not being operating systems so ### that things like config.sub decstation-3100 work. We also ### recognize some manufacturers as not being operating systems, so we ### can provide default operating systems below. case $os in -sun*os*) # Prevent following clause from handling this invalid input. ;; -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ -apple | -axis | -knuth | -cray | -microblaze) os= basic_machine=$1 ;; -bluegene*) os=-cnk ;; -sim | -cisco | -oki | -wec | -winbond) os= basic_machine=$1 ;; -scout) ;; -wrs) os=-vxworks basic_machine=$1 ;; -chorusos*) os=-chorusos basic_machine=$1 ;; -chorusrdb) os=-chorusrdb basic_machine=$1 ;; -hiux*) os=-hiuxwe2 ;; -sco6) os=-sco5v6 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco5) os=-sco3.2v5 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco4) os=-sco3.2v4 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco3.2.[4-9]*) os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco3.2v[4-9]*) # Don't forget version if it is 3.2v4 or newer. basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco5v6*) # Don't forget version if it is 3.2v4 or newer. basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco*) os=-sco3.2v2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -udk*) basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -isc) os=-isc2.2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -clix*) basic_machine=clipper-intergraph ;; -isc*) basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -lynx*) os=-lynxos ;; -ptx*) basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` ;; -windowsnt*) os=`echo $os | sed -e 's/windowsnt/winnt/'` ;; -psos*) os=-psos ;; -mint | -mint[0-9]*) basic_machine=m68k-atari os=-mint ;; esac # Decode aliases for certain CPU-COMPANY combinations. case $basic_machine in # Recognize the basic CPU types without company name. # Some are omitted here because they have special meanings below. 1750a | 580 \ | a29k \ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ | am33_2.0 \ | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ | bfin \ | c4x | clipper \ | d10v | d30v | dlx | dsp16xx \ | fido | fr30 | frv \ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ | i370 | i860 | i960 | ia64 \ | ip2k | iq2000 \ | lm32 \ | m32c | m32r | m32rle | m68000 | m68k | m88k \ | maxq | mb | microblaze | mcore | mep | metag \ | mips | mipsbe | mipseb | mipsel | mipsle \ | mips16 \ | mips64 | mips64el \ | mips64octeon | mips64octeonel \ | mips64orion | mips64orionel \ | mips64r5900 | mips64r5900el \ | mips64vr | mips64vrel \ | mips64vr4100 | mips64vr4100el \ | mips64vr4300 | mips64vr4300el \ | mips64vr5000 | mips64vr5000el \ | mips64vr5900 | mips64vr5900el \ | mipsisa32 | mipsisa32el \ | mipsisa32r2 | mipsisa32r2el \ | mipsisa64 | mipsisa64el \ | mipsisa64r2 | mipsisa64r2el \ | mipsisa64sb1 | mipsisa64sb1el \ | mipsisa64sr71k | mipsisa64sr71kel \ | mipstx39 | mipstx39el \ | mn10200 | mn10300 \ | moxie \ | mt \ | msp430 \ | nios | nios2 \ | ns16k | ns32k \ | or32 \ | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ | pyramid \ | rx \ | score \ | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ | sh64 | sh64le \ | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ | spu | strongarm \ | tahoe | thumb | tic4x | tic80 | tron \ | ubicom32 \ | v850 | v850e \ | we32k \ | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ | z8k | z80) basic_machine=$basic_machine-unknown ;; m6811 | m68hc11 | m6812 | m68hc12 | picochip) # Motorola 68HC11/12. basic_machine=$basic_machine-unknown os=-none ;; m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) ;; ms1) basic_machine=mt-unknown ;; # We use `pc' rather than `unknown' # because (1) that's what they normally are, and # (2) the word "unknown" tends to confuse beginning users. i*86 | x86_64) basic_machine=$basic_machine-pc ;; # Object if more than one company name word. *-*-*) echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 exit 1 ;; # Recognize the basic CPU types with company name. 580-* \ | a29k-* \ | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ | avr-* | avr32-* \ | bfin-* | bs2000-* \ | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ | clipper-* | craynv-* | cydra-* \ | d10v-* | d30v-* | dlx-* \ | elxsi-* \ | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ | h8300-* | h8500-* \ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ | i*86-* | i860-* | i960-* | ia64-* \ | ip2k-* | iq2000-* \ | lm32-* \ | m32c-* | m32r-* | m32rle-* \ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ | m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ | mips16-* \ | mips64-* | mips64el-* \ | mips64octeon-* | mips64octeonel-* \ | mips64orion-* | mips64orionel-* \ | mips64r5900-* | mips64r5900el-* \ | mips64vr-* | mips64vrel-* \ | mips64vr4100-* | mips64vr4100el-* \ | mips64vr4300-* | mips64vr4300el-* \ | mips64vr5000-* | mips64vr5000el-* \ | mips64vr5900-* | mips64vr5900el-* \ | mipsisa32-* | mipsisa32el-* \ | mipsisa32r2-* | mipsisa32r2el-* \ | mipsisa64-* | mipsisa64el-* \ | mipsisa64r2-* | mipsisa64r2el-* \ | mipsisa64sb1-* | mipsisa64sb1el-* \ | mipsisa64sr71k-* | mipsisa64sr71kel-* \ | mipstx39-* | mipstx39el-* \ | mmix-* \ | mt-* \ | msp430-* \ | nios-* | nios2-* \ | none-* | np1-* | ns16k-* | ns32k-* \ | orion-* \ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ | pyramid-* \ | romp-* | rs6000-* | rx-* \ | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ | sparclite-* \ | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ | tahoe-* | thumb-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tile-* | tilegx-* \ | tron-* \ | ubicom32-* \ | v850-* | v850e-* | vax-* \ | we32k-* \ | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ | xstormy16-* | xtensa*-* \ | ymp-* \ | z8k-* | z80-*) ;; # Recognize the basic CPU types without company name, with glob match. xtensa*) basic_machine=$basic_machine-unknown ;; # Recognize the various machine names and aliases which stand # for a CPU type and a company and sometimes even an OS. 386bsd) basic_machine=i386-unknown os=-bsd ;; 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) basic_machine=m68000-att ;; 3b*) basic_machine=we32k-att ;; a29khif) basic_machine=a29k-amd os=-udi ;; abacus) basic_machine=abacus-unknown ;; adobe68k) basic_machine=m68010-adobe os=-scout ;; alliant | fx80) basic_machine=fx80-alliant ;; altos | altos3068) basic_machine=m68k-altos ;; am29k) basic_machine=a29k-none os=-bsd ;; amd64) basic_machine=x86_64-pc ;; amd64-*) basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` ;; amdahl) basic_machine=580-amdahl os=-sysv ;; amiga | amiga-*) basic_machine=m68k-unknown ;; amigaos | amigados) basic_machine=m68k-unknown os=-amigaos ;; amigaunix | amix) basic_machine=m68k-unknown os=-sysv4 ;; apollo68) basic_machine=m68k-apollo os=-sysv ;; apollo68bsd) basic_machine=m68k-apollo os=-bsd ;; aros) basic_machine=i386-pc os=-aros ;; aux) basic_machine=m68k-apple os=-aux ;; balance) basic_machine=ns32k-sequent os=-dynix ;; blackfin) basic_machine=bfin-unknown os=-linux ;; blackfin-*) basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'` os=-linux ;; bluegene*) basic_machine=powerpc-ibm os=-cnk ;; c90) basic_machine=c90-cray os=-unicos ;; cegcc) basic_machine=arm-unknown os=-cegcc ;; convex-c1) basic_machine=c1-convex os=-bsd ;; convex-c2) basic_machine=c2-convex os=-bsd ;; convex-c32) basic_machine=c32-convex os=-bsd ;; convex-c34) basic_machine=c34-convex os=-bsd ;; convex-c38) basic_machine=c38-convex os=-bsd ;; cray | j90) basic_machine=j90-cray os=-unicos ;; craynv) basic_machine=craynv-cray os=-unicosmp ;; cr16) basic_machine=cr16-unknown os=-elf ;; crds | unos) basic_machine=m68k-crds ;; crisv32 | crisv32-* | etraxfs*) basic_machine=crisv32-axis ;; cris | cris-* | etrax*) basic_machine=cris-axis ;; crx) basic_machine=crx-unknown os=-elf ;; da30 | da30-*) basic_machine=m68k-da30 ;; decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) basic_machine=mips-dec ;; decsystem10* | dec10*) basic_machine=pdp10-dec os=-tops10 ;; decsystem20* | dec20*) basic_machine=pdp10-dec os=-tops20 ;; delta | 3300 | motorola-3300 | motorola-delta \ | 3300-motorola | delta-motorola) basic_machine=m68k-motorola ;; delta88) basic_machine=m88k-motorola os=-sysv3 ;; dicos) basic_machine=i686-pc os=-dicos ;; djgpp) basic_machine=i586-pc os=-msdosdjgpp ;; dpx20 | dpx20-*) basic_machine=rs6000-bull os=-bosx ;; dpx2* | dpx2*-bull) basic_machine=m68k-bull os=-sysv3 ;; ebmon29k) basic_machine=a29k-amd os=-ebmon ;; elxsi) basic_machine=elxsi-elxsi os=-bsd ;; encore | umax | mmax) basic_machine=ns32k-encore ;; es1800 | OSE68k | ose68k | ose | OSE) basic_machine=m68k-ericsson os=-ose ;; fx2800) basic_machine=i860-alliant ;; genix) basic_machine=ns32k-ns ;; gmicro) basic_machine=tron-gmicro os=-sysv ;; go32) basic_machine=i386-pc os=-go32 ;; h3050r* | hiux*) basic_machine=hppa1.1-hitachi os=-hiuxwe2 ;; h8300hms) basic_machine=h8300-hitachi os=-hms ;; h8300xray) basic_machine=h8300-hitachi os=-xray ;; h8500hms) basic_machine=h8500-hitachi os=-hms ;; harris) basic_machine=m88k-harris os=-sysv3 ;; hp300-*) basic_machine=m68k-hp ;; hp300bsd) basic_machine=m68k-hp os=-bsd ;; hp300hpux) basic_machine=m68k-hp os=-hpux ;; hp3k9[0-9][0-9] | hp9[0-9][0-9]) basic_machine=hppa1.0-hp ;; hp9k2[0-9][0-9] | hp9k31[0-9]) basic_machine=m68000-hp ;; hp9k3[2-9][0-9]) basic_machine=m68k-hp ;; hp9k6[0-9][0-9] | hp6[0-9][0-9]) basic_machine=hppa1.0-hp ;; hp9k7[0-79][0-9] | hp7[0-79][0-9]) basic_machine=hppa1.1-hp ;; hp9k78[0-9] | hp78[0-9]) # FIXME: really hppa2.0-hp basic_machine=hppa1.1-hp ;; hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) # FIXME: really hppa2.0-hp basic_machine=hppa1.1-hp ;; hp9k8[0-9][13679] | hp8[0-9][13679]) basic_machine=hppa1.1-hp ;; hp9k8[0-9][0-9] | hp8[0-9][0-9]) basic_machine=hppa1.0-hp ;; hppa-next) os=-nextstep3 ;; hppaosf) basic_machine=hppa1.1-hp os=-osf ;; hppro) basic_machine=hppa1.1-hp os=-proelf ;; i370-ibm* | ibm*) basic_machine=i370-ibm ;; # I'm not sure what "Sysv32" means. Should this be sysv3.2? i*86v32) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv32 ;; i*86v4*) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv4 ;; i*86v) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv ;; i*86sol2) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-solaris2 ;; i386mach) basic_machine=i386-mach os=-mach ;; i386-vsta | vsta) basic_machine=i386-unknown os=-vsta ;; iris | iris4d) basic_machine=mips-sgi case $os in -irix*) ;; *) os=-irix4 ;; esac ;; isi68 | isi) basic_machine=m68k-isi os=-sysv ;; m68knommu) basic_machine=m68k-unknown os=-linux ;; m68knommu-*) basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'` os=-linux ;; m88k-omron*) basic_machine=m88k-omron ;; magnum | m3230) basic_machine=mips-mips os=-sysv ;; merlin) basic_machine=ns32k-utek os=-sysv ;; microblaze) basic_machine=microblaze-xilinx ;; mingw32) basic_machine=i386-pc os=-mingw32 ;; mingw32ce) basic_machine=arm-unknown os=-mingw32ce ;; miniframe) basic_machine=m68000-convergent ;; *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) basic_machine=m68k-atari os=-mint ;; mips3*-*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` ;; mips3*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown ;; monitor) basic_machine=m68k-rom68k os=-coff ;; morphos) basic_machine=powerpc-unknown os=-morphos ;; msdos) basic_machine=i386-pc os=-msdos ;; ms1-*) basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` ;; mvs) basic_machine=i370-ibm os=-mvs ;; ncr3000) basic_machine=i486-ncr os=-sysv4 ;; netbsd386) basic_machine=i386-unknown os=-netbsd ;; netwinder) basic_machine=armv4l-rebel os=-linux ;; news | news700 | news800 | news900) basic_machine=m68k-sony os=-newsos ;; news1000) basic_machine=m68030-sony os=-newsos ;; news-3600 | risc-news) basic_machine=mips-sony os=-newsos ;; necv70) basic_machine=v70-nec os=-sysv ;; next | m*-next ) basic_machine=m68k-next case $os in -nextstep* ) ;; -ns2*) os=-nextstep2 ;; *) os=-nextstep3 ;; esac ;; nh3000) basic_machine=m68k-harris os=-cxux ;; nh[45]000) basic_machine=m88k-harris os=-cxux ;; nindy960) basic_machine=i960-intel os=-nindy ;; mon960) basic_machine=i960-intel os=-mon960 ;; nonstopux) basic_machine=mips-compaq os=-nonstopux ;; np1) basic_machine=np1-gould ;; nsr-tandem) basic_machine=nsr-tandem ;; op50n-* | op60c-*) basic_machine=hppa1.1-oki os=-proelf ;; openrisc | openrisc-*) basic_machine=or32-unknown ;; os400) basic_machine=powerpc-ibm os=-os400 ;; OSE68000 | ose68000) basic_machine=m68000-ericsson os=-ose ;; os68k) basic_machine=m68k-none os=-os68k ;; pa-hitachi) basic_machine=hppa1.1-hitachi os=-hiuxwe2 ;; paragon) basic_machine=i860-intel os=-osf ;; parisc) basic_machine=hppa-unknown os=-linux ;; parisc-*) basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'` os=-linux ;; pbd) basic_machine=sparc-tti ;; pbb) basic_machine=m68k-tti ;; pc532 | pc532-*) basic_machine=ns32k-pc532 ;; pc98) basic_machine=i386-pc ;; pc98-*) basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentium | p5 | k5 | k6 | nexgen | viac3) basic_machine=i586-pc ;; pentiumpro | p6 | 6x86 | athlon | athlon_*) basic_machine=i686-pc ;; pentiumii | pentium2 | pentiumiii | pentium3) basic_machine=i686-pc ;; pentium4) basic_machine=i786-pc ;; pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentiumpro-* | p6-* | 6x86-* | athlon-*) basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentium4-*) basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pn) basic_machine=pn-gould ;; power) basic_machine=power-ibm ;; ppc) basic_machine=powerpc-unknown ;; ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ppcle | powerpclittle | ppc-le | powerpc-little) basic_machine=powerpcle-unknown ;; ppcle-* | powerpclittle-*) basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ppc64) basic_machine=powerpc64-unknown ;; ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ppc64le | powerpc64little | ppc64-le | powerpc64-little) basic_machine=powerpc64le-unknown ;; ppc64le-* | powerpc64little-*) basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ps2) basic_machine=i386-ibm ;; pw32) basic_machine=i586-unknown os=-pw32 ;; rdos) basic_machine=i386-pc os=-rdos ;; rom68k) basic_machine=m68k-rom68k os=-coff ;; rm[46]00) basic_machine=mips-siemens ;; rtpc | rtpc-*) basic_machine=romp-ibm ;; s390 | s390-*) basic_machine=s390-ibm ;; s390x | s390x-*) basic_machine=s390x-ibm ;; sa29200) basic_machine=a29k-amd os=-udi ;; sb1) basic_machine=mipsisa64sb1-unknown ;; sb1el) basic_machine=mipsisa64sb1el-unknown ;; sde) basic_machine=mipsisa32-sde os=-elf ;; sei) basic_machine=mips-sei os=-seiux ;; sequent) basic_machine=i386-sequent ;; sh) basic_machine=sh-hitachi os=-hms ;; sh5el) basic_machine=sh5le-unknown ;; sh64) basic_machine=sh64-unknown ;; sparclite-wrs | simso-wrs) basic_machine=sparclite-wrs os=-vxworks ;; sps7) basic_machine=m68k-bull os=-sysv2 ;; spur) basic_machine=spur-unknown ;; st2000) basic_machine=m68k-tandem ;; stratus) basic_machine=i860-stratus os=-sysv4 ;; sun2) basic_machine=m68000-sun ;; sun2os3) basic_machine=m68000-sun os=-sunos3 ;; sun2os4) basic_machine=m68000-sun os=-sunos4 ;; sun3os3) basic_machine=m68k-sun os=-sunos3 ;; sun3os4) basic_machine=m68k-sun os=-sunos4 ;; sun4os3) basic_machine=sparc-sun os=-sunos3 ;; sun4os4) basic_machine=sparc-sun os=-sunos4 ;; sun4sol2) basic_machine=sparc-sun os=-solaris2 ;; sun3 | sun3-*) basic_machine=m68k-sun ;; sun4) basic_machine=sparc-sun ;; sun386 | sun386i | roadrunner) basic_machine=i386-sun ;; sv1) basic_machine=sv1-cray os=-unicos ;; symmetry) basic_machine=i386-sequent os=-dynix ;; t3e) basic_machine=alphaev5-cray os=-unicos ;; t90) basic_machine=t90-cray os=-unicos ;; tic54x | c54x*) basic_machine=tic54x-unknown os=-coff ;; tic55x | c55x*) basic_machine=tic55x-unknown os=-coff ;; tic6x | c6x*) basic_machine=tic6x-unknown os=-coff ;; # This must be matched before tile*. tilegx*) basic_machine=tilegx-unknown os=-linux-gnu ;; tile*) basic_machine=tile-unknown os=-linux-gnu ;; tx39) basic_machine=mipstx39-unknown ;; tx39el) basic_machine=mipstx39el-unknown ;; toad1) basic_machine=pdp10-xkl os=-tops20 ;; tower | tower-32) basic_machine=m68k-ncr ;; tpf) basic_machine=s390x-ibm os=-tpf ;; udi29k) basic_machine=a29k-amd os=-udi ;; ultra3) basic_machine=a29k-nyu os=-sym1 ;; v810 | necv810) basic_machine=v810-nec os=-none ;; vaxv) basic_machine=vax-dec os=-sysv ;; vms) basic_machine=vax-dec os=-vms ;; vpp*|vx|vx-*) basic_machine=f301-fujitsu ;; vxworks960) basic_machine=i960-wrs os=-vxworks ;; vxworks68) basic_machine=m68k-wrs os=-vxworks ;; vxworks29k) basic_machine=a29k-wrs os=-vxworks ;; w65*) basic_machine=w65-wdc os=-none ;; w89k-*) basic_machine=hppa1.1-winbond os=-proelf ;; xbox) basic_machine=i686-pc os=-mingw32 ;; xps | xps100) basic_machine=xps100-honeywell ;; ymp) basic_machine=ymp-cray os=-unicos ;; z8k-*-coff) basic_machine=z8k-unknown os=-sim ;; z80-*-coff) basic_machine=z80-unknown os=-sim ;; none) basic_machine=none-none os=-none ;; # Here we handle the default manufacturer of certain CPU types. It is in # some cases the only manufacturer, in others, it is the most popular. w89k) basic_machine=hppa1.1-winbond ;; op50n) basic_machine=hppa1.1-oki ;; op60c) basic_machine=hppa1.1-oki ;; romp) basic_machine=romp-ibm ;; mmix) basic_machine=mmix-knuth ;; rs6000) basic_machine=rs6000-ibm ;; vax) basic_machine=vax-dec ;; pdp10) # there are many clones, so DEC is not a safe bet basic_machine=pdp10-unknown ;; pdp11) basic_machine=pdp11-dec ;; we32k) basic_machine=we32k-att ;; sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele) basic_machine=sh-unknown ;; sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) basic_machine=sparc-sun ;; cydra) basic_machine=cydra-cydrome ;; orion) basic_machine=orion-highlevel ;; orion105) basic_machine=clipper-highlevel ;; mac | mpw | mac-mpw) basic_machine=m68k-apple ;; pmac | pmac-mpw) basic_machine=powerpc-apple ;; *-unknown) # Make sure to match an already-canonicalized machine name. ;; *) echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 exit 1 ;; esac # Here we canonicalize certain aliases for manufacturers. case $basic_machine in *-digital*) basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` ;; *-commodore*) basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` ;; *) ;; esac # Decode manufacturer-specific aliases for certain operating systems. if [ x"$os" != x"" ] then case $os in # First match some system type aliases # that might get confused with valid system types. # -solaris* is a basic system type, with this one exception. -auroraux) os=-auroraux ;; -solaris1 | -solaris1.*) os=`echo $os | sed -e 's|solaris1|sunos4|'` ;; -solaris) os=-solaris2 ;; -svr4*) os=-sysv4 ;; -unixware*) os=-sysv4.2uw ;; -gnu/linux*) os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` ;; # First accept the basic system types. # The portable systems comes first. # Each alternative MUST END IN A *, to match a version number. # -sysv* is not here because it comes later, after sysvr4. -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\ | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \ | -sym* | -kopensolaris* \ | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ | -aos* | -aros* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ | -openbsd* | -solidbsd* \ | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -chorusos* | -chorusrdb* | -cegcc* \ | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ | -uxpv* | -beos* | -mpeix* | -udk* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*) # Remember, each alternative MUST END IN *, to match a version number. ;; -qnx*) case $basic_machine in x86-* | i*86-*) ;; *) os=-nto$os ;; esac ;; -nto-qnx*) ;; -nto*) os=`echo $os | sed -e 's|nto|nto-qnx|'` ;; -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) ;; -mac*) os=`echo $os | sed -e 's|mac|macos|'` ;; -linux-dietlibc) os=-linux-dietlibc ;; -linux*) os=`echo $os | sed -e 's|linux|linux-gnu|'` ;; -sunos5*) os=`echo $os | sed -e 's|sunos5|solaris2|'` ;; -sunos6*) os=`echo $os | sed -e 's|sunos6|solaris3|'` ;; -opened*) os=-openedition ;; -os400*) os=-os400 ;; -wince*) os=-wince ;; -osfrose*) os=-osfrose ;; -osf*) os=-osf ;; -utek*) os=-bsd ;; -dynix*) os=-bsd ;; -acis*) os=-aos ;; -atheos*) os=-atheos ;; -syllable*) os=-syllable ;; -386bsd) os=-bsd ;; -ctix* | -uts*) os=-sysv ;; -nova*) os=-rtmk-nova ;; -ns2 ) os=-nextstep2 ;; -nsk*) os=-nsk ;; # Preserve the version number of sinix5. -sinix5.*) os=`echo $os | sed -e 's|sinix|sysv|'` ;; -sinix*) os=-sysv4 ;; -tpf*) os=-tpf ;; -triton*) os=-sysv3 ;; -oss*) os=-sysv3 ;; -svr4) os=-sysv4 ;; -svr3) os=-sysv3 ;; -sysvr4) os=-sysv4 ;; # This must come after -sysvr4. -sysv*) ;; -ose*) os=-ose ;; -es1800*) os=-ose ;; -xenix) os=-xenix ;; -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) os=-mint ;; -aros*) os=-aros ;; -kaos*) os=-kaos ;; -zvmoe) os=-zvmoe ;; -dicos*) os=-dicos ;; -nacl*) ;; -none) ;; *) # Get rid of the `-' at the beginning of $os. os=`echo $os | sed 's/[^-]*-//'` echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 exit 1 ;; esac else # Here we handle the default operating systems that come with various machines. # The value should be what the vendor currently ships out the door with their # machine or put another way, the most popular os provided with the machine. # Note that if you're going to try to match "-MANUFACTURER" here (say, # "-sun"), then you have to tell the case statement up towards the top # that MANUFACTURER isn't an operating system. Otherwise, code above # will signal an error saying that MANUFACTURER isn't an operating # system, and we'll never get to this point. case $basic_machine in score-*) os=-elf ;; spu-*) os=-elf ;; *-acorn) os=-riscix1.2 ;; arm*-rebel) os=-linux ;; arm*-semi) os=-aout ;; c4x-* | tic4x-*) os=-coff ;; # This must come before the *-dec entry. pdp10-*) os=-tops20 ;; pdp11-*) os=-none ;; *-dec | vax-*) os=-ultrix4.2 ;; m68*-apollo) os=-domain ;; i386-sun) os=-sunos4.0.2 ;; m68000-sun) os=-sunos3 # This also exists in the configure program, but was not the # default. # os=-sunos4 ;; m68*-cisco) os=-aout ;; mep-*) os=-elf ;; mips*-cisco) os=-elf ;; mips*-*) os=-elf ;; or32-*) os=-coff ;; *-tti) # must be before sparc entry or we get the wrong os. os=-sysv3 ;; sparc-* | *-sun) os=-sunos4.1.1 ;; *-be) os=-beos ;; *-haiku) os=-haiku ;; *-ibm) os=-aix ;; *-knuth) os=-mmixware ;; *-wec) os=-proelf ;; *-winbond) os=-proelf ;; *-oki) os=-proelf ;; *-hp) os=-hpux ;; *-hitachi) os=-hiux ;; i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) os=-sysv ;; *-cbm) os=-amigaos ;; *-dg) os=-dgux ;; *-dolphin) os=-sysv3 ;; m68k-ccur) os=-rtu ;; m88k-omron*) os=-luna ;; *-next ) os=-nextstep ;; *-sequent) os=-ptx ;; *-crds) os=-unos ;; *-ns) os=-genix ;; i370-*) os=-mvs ;; *-next) os=-nextstep3 ;; *-gould) os=-sysv ;; *-highlevel) os=-bsd ;; *-encore) os=-bsd ;; *-sgi) os=-irix ;; *-siemens) os=-sysv4 ;; *-masscomp) os=-rtu ;; f30[01]-fujitsu | f700-fujitsu) os=-uxpv ;; *-rom68k) os=-coff ;; *-*bug) os=-coff ;; *-apple) os=-macos ;; *-atari*) os=-mint ;; *) os=-none ;; esac fi # Here we handle the case where we know the os, and the CPU type, but not the # manufacturer. We pick the logical manufacturer. vendor=unknown case $basic_machine in *-unknown) case $os in -riscix*) vendor=acorn ;; -sunos*) vendor=sun ;; -cnk*|-aix*) vendor=ibm ;; -beos*) vendor=be ;; -hpux*) vendor=hp ;; -mpeix*) vendor=hp ;; -hiux*) vendor=hitachi ;; -unos*) vendor=crds ;; -dgux*) vendor=dg ;; -luna*) vendor=omron ;; -genix*) vendor=ns ;; -mvs* | -opened*) vendor=ibm ;; -os400*) vendor=ibm ;; -ptx*) vendor=sequent ;; -tpf*) vendor=ibm ;; -vxsim* | -vxworks* | -windiss*) vendor=wrs ;; -aux*) vendor=apple ;; -hms*) vendor=hitachi ;; -mpw* | -macos*) vendor=apple ;; -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) vendor=atari ;; -vos*) vendor=stratus ;; esac basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` ;; esac echo $basic_machine$os exit # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: libnih-1.0.3/config.h.in0000644000175000017500000002760511461165302011735 00000000000000/* config.h.in. Generated from configure.ac by autoheader. */ /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP systems. This function is required for `alloca.c' support on those systems. */ #undef CRAY_STACKSEG_END /* Define to 1 if using `alloca.c'. */ #undef C_ALLOCA /* Define to 1 if translation of program messages to the user's native language is requested. */ #undef ENABLE_NLS /* Define to 1 if you have `alloca', as a function or macro. */ #undef HAVE_ALLOCA /* Define to 1 if you have and it should be used (not on Ultrix). */ #undef HAVE_ALLOCA_H /* Define to 1 if you have the `argz_count' function. */ #undef HAVE_ARGZ_COUNT /* Define to 1 if you have the header file. */ #undef HAVE_ARGZ_H /* Define to 1 if you have the `argz_next' function. */ #undef HAVE_ARGZ_NEXT /* Define to 1 if you have the `argz_stringify' function. */ #undef HAVE_ARGZ_STRINGIFY /* Define to 1 if you have the `asprintf' function. */ #undef HAVE_ASPRINTF /* Define to 1 if the compiler understands __builtin_expect. */ #undef HAVE_BUILTIN_EXPECT /* Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the CoreFoundation framework. */ #undef HAVE_CFLOCALECOPYCURRENT /* Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in the CoreFoundation framework. */ #undef HAVE_CFPREFERENCESCOPYAPPVALUE /* Define if the GNU dcgettext() function is already present or preinstalled. */ #undef HAVE_DCGETTEXT /* Define to 1 if you have the declaration of `feof_unlocked', and to 0 if you don't. */ #undef HAVE_DECL_FEOF_UNLOCKED /* Define to 1 if you have the declaration of `fgets_unlocked', and to 0 if you don't. */ #undef HAVE_DECL_FGETS_UNLOCKED /* Define to 1 if you have the declaration of `getc_unlocked', and to 0 if you don't. */ #undef HAVE_DECL_GETC_UNLOCKED /* Define to 1 if you have the declaration of `_snprintf', and to 0 if you don't. */ #undef HAVE_DECL__SNPRINTF /* Define to 1 if you have the declaration of `_snwprintf', and to 0 if you don't. */ #undef HAVE_DECL__SNWPRINTF /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H /* Define to 1 if you have the `fwprintf' function. */ #undef HAVE_FWPRINTF /* Define to 1 if you have the `getcwd' function. */ #undef HAVE_GETCWD /* Define to 1 if you have the `getegid' function. */ #undef HAVE_GETEGID /* Define to 1 if you have the `geteuid' function. */ #undef HAVE_GETEUID /* Define to 1 if you have the `getgid' function. */ #undef HAVE_GETGID /* Define to 1 if you have the `getpagesize' function. */ #undef HAVE_GETPAGESIZE /* Define if the GNU gettext() function is already present or preinstalled. */ #undef HAVE_GETTEXT /* Define to 1 if you have the `getuid' function. */ #undef HAVE_GETUID /* Define if you have the iconv() function and it works. */ #undef HAVE_ICONV /* Define if you have the 'intmax_t' type in or . */ #undef HAVE_INTMAX_T /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H /* Define if exists, doesn't clash with , and declares uintmax_t. */ #undef HAVE_INTTYPES_H_WITH_UINTMAX /* Define if you have and nl_langinfo(CODESET). */ #undef HAVE_LANGINFO_CODESET /* Define if your file defines LC_MESSAGES. */ #undef HAVE_LC_MESSAGES /* Define to 1 if you have the header file. */ #undef HAVE_LIMITS_H /* Define to 1 if the system has the type `long long int'. */ #undef HAVE_LONG_LONG_INT /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H /* Define to 1 if you have the `mempcpy' function. */ #undef HAVE_MEMPCPY /* Define to 1 if you have a working `mmap' system call. */ #undef HAVE_MMAP /* Define to 1 if you have the `munmap' function. */ #undef HAVE_MUNMAP /* Define if you have and it defines the NL_LOCALE_NAME macro if _GNU_SOURCE is defined. */ #undef HAVE_NL_LOCALE_NAME /* Define if your printf() function supports format strings with positions. */ #undef HAVE_POSIX_PRINTF /* Define if the defines PTHREAD_MUTEX_RECURSIVE. */ #undef HAVE_PTHREAD_MUTEX_RECURSIVE /* Define if the POSIX multithreading library has read/write locks. */ #undef HAVE_PTHREAD_RWLOCK /* Define to 1 if you have the `putenv' function. */ #undef HAVE_PUTENV /* Define to 1 if you have the `setenv' function. */ #undef HAVE_SETENV /* Define to 1 if you have the `setlocale' function. */ #undef HAVE_SETLOCALE /* Define to 1 if you have the `snprintf' function. */ #undef HAVE_SNPRINTF /* Define to 1 if you have the header file. */ #undef HAVE_STDDEF_H /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H /* Define if exists, doesn't clash with , and declares uintmax_t. */ #undef HAVE_STDINT_H_WITH_UINTMAX /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H /* Define to 1 if you have the `stpcpy' function. */ #undef HAVE_STPCPY /* Define to 1 if you have the `strcasecmp' function. */ #undef HAVE_STRCASECMP /* Define to 1 if you have the `strdup' function. */ #undef HAVE_STRDUP /* Define to 1 if you have the header file. */ #undef HAVE_STRINGS_H /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H /* Define to 1 if you have the `strtoul' function. */ #undef HAVE_STRTOUL /* Define to 1 if you have the header file. */ #undef HAVE_SYS_PARAM_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H /* Define to 1 if you have the `tsearch' function. */ #undef HAVE_TSEARCH /* Define if you have the 'uintmax_t' type in or . */ #undef HAVE_UINTMAX_T /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H /* Define to 1 if the system has the type `unsigned long long int'. */ #undef HAVE_UNSIGNED_LONG_LONG_INT /* Define to 1 if you have the header file. */ #undef HAVE_VALGRIND_VALGRIND_H /* Define to 1 or 0, depending whether the compiler supports simple visibility declarations. */ #undef HAVE_VISIBILITY /* Define if you have the 'wchar_t' type. */ #undef HAVE_WCHAR_T /* Define to 1 if you have the `wcslen' function. */ #undef HAVE_WCSLEN /* Define if you have the 'wint_t' type. */ #undef HAVE_WINT_T /* Define to 1 if you have the `__fsetlocking' function. */ #undef HAVE___FSETLOCKING /* Define as const if the declaration of iconv() needs const. */ #undef ICONV_CONST /* Define if integer division by zero raises signal SIGFPE. */ #undef INTDIV0_RAISES_SIGFPE /* Define to the sub-directory in which libtool stores uninstalled libraries. */ #undef LT_OBJDIR /* Define to 1 if your C compiler doesn't accept -c and -o together. */ #undef NO_MINUS_C_MINUS_O /* Name of package */ #undef PACKAGE /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT /* Define to the copyright message of this package. */ #undef PACKAGE_COPYRIGHT /* Define to the full name of this package. */ #undef PACKAGE_NAME /* Define to the full name and version of this package. */ #undef PACKAGE_STRING /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME /* Define to the home page for this package. */ #undef PACKAGE_URL /* Define to the version of this package. */ #undef PACKAGE_VERSION /* Define if exists and defines unusable PRI* macros. */ #undef PRI_MACROS_BROKEN /* Define if the pthread_in_use() detection is hard. */ #undef PTHREAD_IN_USE_DETECTION_HARD /* Define as the maximum value of type 'size_t', if the system doesn't define it. */ #undef SIZE_MAX /* If using the C implementation of alloca, define if you know the direction of stack growth for your system; otherwise it will be automatically deduced at runtime. STACK_DIRECTION > 0 => grows toward higher addresses STACK_DIRECTION < 0 => grows toward lower addresses STACK_DIRECTION = 0 => direction of growth unknown */ #undef STACK_DIRECTION /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS /* Define if the POSIX multithreading library can be used. */ #undef USE_POSIX_THREADS /* Define if references to the POSIX multithreading library should be made weak. */ #undef USE_POSIX_THREADS_WEAK /* Define if the GNU Pth multithreading library can be used. */ #undef USE_PTH_THREADS /* Define if references to the GNU Pth multithreading library should be made weak. */ #undef USE_PTH_THREADS_WEAK /* Define if the old Solaris multithreading library can be used. */ #undef USE_SOLARIS_THREADS /* Define if references to the old Solaris multithreading library should be made weak. */ #undef USE_SOLARIS_THREADS_WEAK /* Enable extensions on AIX 3, Interix. */ #ifndef _ALL_SOURCE # undef _ALL_SOURCE #endif /* Enable GNU extensions on systems that have them. */ #ifndef _GNU_SOURCE # undef _GNU_SOURCE #endif /* Enable threading extensions on Solaris. */ #ifndef _POSIX_PTHREAD_SEMANTICS # undef _POSIX_PTHREAD_SEMANTICS #endif /* Enable extensions on HP NonStop. */ #ifndef _TANDEM_SOURCE # undef _TANDEM_SOURCE #endif /* Enable general extensions on Solaris. */ #ifndef __EXTENSIONS__ # undef __EXTENSIONS__ #endif /* Define if the Win32 multithreading API can be used. */ #undef USE_WIN32_THREADS /* Version number of package */ #undef VERSION /* Define to 1 if on MINIX. */ #undef _MINIX /* Define to 2 if the system does not provide POSIX.1 features except with this defined. */ #undef _POSIX_1_SOURCE /* Define to 1 if you need to in order for `stat' and other things to work. */ #undef _POSIX_SOURCE /* Define to empty if `__thread' is not supported. */ #undef __thread /* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ #ifndef __cplusplus #undef inline #endif /* Define as the type of the result of subtracting two pointers, if the system doesn't define it. */ #undef ptrdiff_t /* Define to `unsigned int' if does not define. */ #undef size_t /* Define to unsigned long or unsigned long long if and don't define. */ #undef uintmax_t #define __libc_lock_t gl_lock_t #define __libc_lock_define gl_lock_define #define __libc_lock_define_initialized gl_lock_define_initialized #define __libc_lock_init gl_lock_init #define __libc_lock_lock gl_lock_lock #define __libc_lock_unlock gl_lock_unlock #define __libc_lock_recursive_t gl_recursive_lock_t #define __libc_lock_define_recursive gl_recursive_lock_define #define __libc_lock_define_initialized_recursive gl_recursive_lock_define_initialized #define __libc_lock_init_recursive gl_recursive_lock_init #define __libc_lock_lock_recursive gl_recursive_lock_lock #define __libc_lock_unlock_recursive gl_recursive_lock_unlock #define glthread_in_use libintl_thread_in_use #define glthread_lock_init libintl_lock_init #define glthread_lock_lock libintl_lock_lock #define glthread_lock_unlock libintl_lock_unlock #define glthread_lock_destroy libintl_lock_destroy #define glthread_rwlock_init libintl_rwlock_init #define glthread_rwlock_rdlock libintl_rwlock_rdlock #define glthread_rwlock_wrlock libintl_rwlock_wrlock #define glthread_rwlock_unlock libintl_rwlock_unlock #define glthread_rwlock_destroy libintl_rwlock_destroy #define glthread_recursive_lock_init libintl_recursive_lock_init #define glthread_recursive_lock_lock libintl_recursive_lock_lock #define glthread_recursive_lock_unlock libintl_recursive_lock_unlock #define glthread_recursive_lock_destroy libintl_recursive_lock_destroy #define glthread_once libintl_once #define glthread_once_call libintl_once_call #define glthread_once_singlethreaded libintl_once_singlethreaded libnih-1.0.3/aclocal.m40000644000175000017500000011516211461165276011560 00000000000000# generated automatically by aclocal 1.11.1 -*- Autoconf -*- # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, # 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.67],, [m4_warning([this file was generated for autoconf 2.67. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically `autoreconf'.])]) # Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_AUTOMAKE_VERSION(VERSION) # ---------------------------- # Automake X.Y traces this macro to ensure aclocal.m4 has been # generated from the m4 files accompanying Automake X.Y. # (This private macro should not be called outside this file.) AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version='1.11' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. m4_if([$1], [1.11.1], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) # _AM_AUTOCONF_VERSION(VERSION) # ----------------------------- # aclocal traces this macro to find the Autoconf version. # This is a private macro too. Using m4_define simplifies # the logic in aclocal, which can simply ignore this definition. m4_define([_AM_AUTOCONF_VERSION], []) # AM_SET_CURRENT_AUTOMAKE_VERSION # ------------------------------- # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], [AM_AUTOMAKE_VERSION([1.11.1])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # AM_AUX_DIR_EXPAND -*- Autoconf -*- # Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets # $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to # `$srcdir', `$srcdir/..', or `$srcdir/../..'. # # Of course, Automake must honor this variable whenever it calls a # tool from the auxiliary directory. The problem is that $srcdir (and # therefore $ac_aux_dir as well) can be either absolute or relative, # depending on how configure is run. This is pretty annoying, since # it makes $ac_aux_dir quite unusable in subdirectories: in the top # source directory, any form will work fine, but in subdirectories a # relative path needs to be adjusted first. # # $ac_aux_dir/missing # fails when called from a subdirectory if $ac_aux_dir is relative # $top_srcdir/$ac_aux_dir/missing # fails if $ac_aux_dir is absolute, # fails when called from a subdirectory in a VPATH build with # a relative $ac_aux_dir # # The reason of the latter failure is that $top_srcdir and $ac_aux_dir # are both prefixed by $srcdir. In an in-source build this is usually # harmless because $srcdir is `.', but things will broke when you # start a VPATH build or use an absolute $srcdir. # # So we could use something similar to $top_srcdir/$ac_aux_dir/missing, # iff we strip the leading $srcdir from $ac_aux_dir. That would be: # am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` # and then we would define $MISSING as # MISSING="\${SHELL} $am_aux_dir/missing" # This will work as long as MISSING is not called from configure, because # unfortunately $(top_srcdir) has no meaning in configure. # However there are other variables, like CC, which are often used in # configure, and could therefore not use this "fixed" $ac_aux_dir. # # Another solution, used here, is to always expand $ac_aux_dir to an # absolute PATH. The drawback is that using absolute paths prevent a # configured tree to be moved without reconfiguration. AC_DEFUN([AM_AUX_DIR_EXPAND], [dnl Rely on autoconf to set up CDPATH properly. AC_PREREQ([2.50])dnl # expand $ac_aux_dir to an absolute path am_aux_dir=`cd $ac_aux_dir && pwd` ]) # AM_CONDITIONAL -*- Autoconf -*- # Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008 # Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # serial 9 # AM_CONDITIONAL(NAME, SHELL-CONDITION) # ------------------------------------- # Define a conditional. AC_DEFUN([AM_CONDITIONAL], [AC_PREREQ(2.52)dnl ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl AC_SUBST([$1_TRUE])dnl AC_SUBST([$1_FALSE])dnl _AM_SUBST_NOTMAKE([$1_TRUE])dnl _AM_SUBST_NOTMAKE([$1_FALSE])dnl m4_define([_AM_COND_VALUE_$1], [$2])dnl if $2; then $1_TRUE= $1_FALSE='#' else $1_TRUE='#' $1_FALSE= fi AC_CONFIG_COMMANDS_PRE( [if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then AC_MSG_ERROR([[conditional "$1" was never defined. Usually this means the macro was only invoked conditionally.]]) fi])]) # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 # Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # serial 10 # There are a few dirty hacks below to avoid letting `AC_PROG_CC' be # written in clear, in which case automake, when reading aclocal.m4, # will think it sees a *use*, and therefore will trigger all it's # C support machinery. Also note that it means that autoscan, seeing # CC etc. in the Makefile, will ask for an AC_PROG_CC use... # _AM_DEPENDENCIES(NAME) # ---------------------- # See how the compiler implements dependency checking. # NAME is "CC", "CXX", "GCJ", or "OBJC". # We try a few techniques and use that to set a single cache variable. # # We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was # modified to invoke _AM_DEPENDENCIES(CC); we would have a circular # dependency, and given that the user is not expected to run this macro, # just rely on AC_PROG_CC. AC_DEFUN([_AM_DEPENDENCIES], [AC_REQUIRE([AM_SET_DEPDIR])dnl AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl AC_REQUIRE([AM_MAKE_INCLUDE])dnl AC_REQUIRE([AM_DEP_TRACK])dnl ifelse([$1], CC, [depcc="$CC" am_compiler_list=], [$1], CXX, [depcc="$CXX" am_compiler_list=], [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'], [$1], UPC, [depcc="$UPC" am_compiler_list=], [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'], [depcc="$$1" am_compiler_list=]) AC_CACHE_CHECK([dependency style of $depcc], [am_cv_$1_dependencies_compiler_type], [if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up # making a dummy file named `D' -- because `-MD' means `put the output # in D'. mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're # using a relative directory. cp "$am_depcomp" conftest.dir cd conftest.dir # We will build objects and dependencies in a subdirectory because # it helps to detect inapplicable dependency modes. For instance # both Tru64's cc and ICC support -MD to output dependencies as a # side effect of compilation, but ICC will put the dependencies in # the current directory while Tru64 will put them in the object # directory. mkdir sub am_cv_$1_dependencies_compiler_type=none if test "$am_compiler_list" = ""; then am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` fi am__universal=false m4_case([$1], [CC], [case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac], [CXX], [case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac]) for depmode in $am_compiler_list; do # Setup a source with many dependencies, because some compilers # like to wrap large dependency lists on column 80 (with \), and # we should not choose a depcomp mode which is confused by this. # # We need to recreate these files for each test, as the compiler may # overwrite some of them when testing with obscure command lines. # This happens at least with the AIX C compiler. : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with # Solaris 8's {/usr,}/bin/sh. touch sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf # We check with `-c' and `-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly # handle `-M -o', and we need to detect this. Also, some Intel # versions had trouble with output in subdirs am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in gcc) # This depmode causes a compiler race in universal mode. test "$am__universal" = false || continue ;; nosideeffect) # after this tag, mechanisms are not by side-effect, so they'll # only be used when explicitly requested if test "x$enable_dependency_tracking" = xyes; then continue else break fi ;; msvisualcpp | msvcmsys) # This compiler won't grok `-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} am__minus_obj= ;; none) break ;; esac if depmode=$depmode \ source=sub/conftest.c object=$am__obj \ depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ >/dev/null 2>conftest.err && grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && grep $am__obj sub/conftest.Po > /dev/null 2>&1 && ${MAKE-make} -s -f confmf > /dev/null 2>&1; then # icc doesn't choke on unknown options, it will just issue warnings # or remarks (even with -Werror). So we grep stderr for any message # that says an option was ignored or not supported. # When given -MP, icc 7.0 and 7.1 complain thusly: # icc: Command line warning: ignoring option '-M'; no argument required # The diagnosis changed in icc 8.0: # icc: Command line remark: option '-MP' not supported if (grep 'ignoring option' conftest.err || grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else am_cv_$1_dependencies_compiler_type=$depmode break fi fi done cd .. rm -rf conftest.dir else am_cv_$1_dependencies_compiler_type=none fi ]) AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) AM_CONDITIONAL([am__fastdep$1], [ test "x$enable_dependency_tracking" != xno \ && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) ]) # AM_SET_DEPDIR # ------------- # Choose a directory name for dependency files. # This macro is AC_REQUIREd in _AM_DEPENDENCIES AC_DEFUN([AM_SET_DEPDIR], [AC_REQUIRE([AM_SET_LEADING_DOT])dnl AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl ]) # AM_DEP_TRACK # ------------ AC_DEFUN([AM_DEP_TRACK], [AC_ARG_ENABLE(dependency-tracking, [ --disable-dependency-tracking speeds up one-time build --enable-dependency-tracking do not reject slow dependency extractors]) if test "x$enable_dependency_tracking" != xno; then am_depcomp="$ac_aux_dir/depcomp" AMDEPBACKSLASH='\' fi AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) AC_SUBST([AMDEPBACKSLASH])dnl _AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl ]) # Generate code to set up dependency tracking. -*- Autoconf -*- # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008 # Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. #serial 5 # _AM_OUTPUT_DEPENDENCY_COMMANDS # ------------------------------ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], [{ # Autoconf 2.62 quotes --file arguments for eval, but not when files # are listed without --file. Let's play safe and only enable the eval # if we detect the quoting. case $CONFIG_FILES in *\'*) eval set x "$CONFIG_FILES" ;; *) set x $CONFIG_FILES ;; esac shift for mf do # Strip MF so we end up with the name of the file. mf=`echo "$mf" | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile or not. # We used to match only the files named `Makefile.in', but # some people rename them; so instead we look at the file content. # Grep'ing the first line is not enough: some people post-process # each Makefile.in and add a new line on top of each file to say so. # Grep'ing the whole file is not good either: AIX grep has a line # limit of 2048, but all sed's we know have understand at least 4000. if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then dirpart=`AS_DIRNAME("$mf")` else continue fi # Extract the definition of DEPDIR, am__include, and am__quote # from the Makefile without running `make'. DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` test -z "$DEPDIR" && continue am__include=`sed -n 's/^am__include = //p' < "$mf"` test -z "am__include" && continue am__quote=`sed -n 's/^am__quote = //p' < "$mf"` # When using ansi2knr, U may be empty or an underscore; expand it U=`sed -n 's/^U = //p' < "$mf"` # Find all dependency output files, they are included files with # $(DEPDIR) in their names. We invoke sed twice because it is the # simplest approach to changing $(DEPDIR) to its actual value in the # expansion. for file in `sed -n " s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do # Make sure the directory exists. test -f "$dirpart/$file" && continue fdir=`AS_DIRNAME(["$file"])` AS_MKDIR_P([$dirpart/$fdir]) # echo "creating $dirpart/$file" echo '# dummy' > "$dirpart/$file" done done } ])# _AM_OUTPUT_DEPENDENCY_COMMANDS # AM_OUTPUT_DEPENDENCY_COMMANDS # ----------------------------- # This macro should only be invoked once -- use via AC_REQUIRE. # # This code is only required when automatic dependency tracking # is enabled. FIXME. This creates each `.P' file that we will # need in order to bootstrap the dependency handling code. AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], [AC_CONFIG_COMMANDS([depfiles], [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) ]) # Do all the work for Automake. -*- Autoconf -*- # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, # 2005, 2006, 2008, 2009 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # serial 16 # This macro actually does too much. Some checks are only needed if # your package does certain things. But this isn't really a big deal. # AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) # AM_INIT_AUTOMAKE([OPTIONS]) # ----------------------------------------------- # The call with PACKAGE and VERSION arguments is the old style # call (pre autoconf-2.50), which is being phased out. PACKAGE # and VERSION should now be passed to AC_INIT and removed from # the call to AM_INIT_AUTOMAKE. # We support both call styles for the transition. After # the next Automake release, Autoconf can make the AC_INIT # arguments mandatory, and then we can depend on a new Autoconf # release and drop the old call support. AC_DEFUN([AM_INIT_AUTOMAKE], [AC_PREREQ([2.62])dnl dnl Autoconf wants to disallow AM_ names. We explicitly allow dnl the ones we care about. m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl AC_REQUIRE([AC_PROG_INSTALL])dnl if test "`cd $srcdir && pwd`" != "`pwd`"; then # Use -I$(srcdir) only when $(srcdir) != ., so that make's output # is not polluted with repeated "-I." AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl # test to see if srcdir already configured if test -f $srcdir/config.status; then AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) fi fi # test whether we have cygpath if test -z "$CYGPATH_W"; then if (cygpath --version) >/dev/null 2>/dev/null; then CYGPATH_W='cygpath -w' else CYGPATH_W=echo fi fi AC_SUBST([CYGPATH_W]) # Define the identity of the package. dnl Distinguish between old-style and new-style calls. m4_ifval([$2], [m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl AC_SUBST([PACKAGE], [$1])dnl AC_SUBST([VERSION], [$2])], [_AM_SET_OPTIONS([$1])dnl dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,, [m4_fatal([AC_INIT should be called with package and version arguments])])dnl AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl _AM_IF_OPTION([no-define],, [AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl # Some tools Automake needs. AC_REQUIRE([AM_SANITY_CHECK])dnl AC_REQUIRE([AC_ARG_PROGRAM])dnl AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version}) AM_MISSING_PROG(AUTOCONF, autoconf) AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}) AM_MISSING_PROG(AUTOHEADER, autoheader) AM_MISSING_PROG(MAKEINFO, makeinfo) AC_REQUIRE([AM_PROG_INSTALL_SH])dnl AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl AC_REQUIRE([AM_PROG_MKDIR_P])dnl # We need awk for the "check" target. The system "awk" is bad on # some platforms. AC_REQUIRE([AC_PROG_AWK])dnl AC_REQUIRE([AC_PROG_MAKE_SET])dnl AC_REQUIRE([AM_SET_LEADING_DOT])dnl _AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], [_AM_PROG_TAR([v7])])]) _AM_IF_OPTION([no-dependencies],, [AC_PROVIDE_IFELSE([AC_PROG_CC], [_AM_DEPENDENCIES(CC)], [define([AC_PROG_CC], defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl AC_PROVIDE_IFELSE([AC_PROG_CXX], [_AM_DEPENDENCIES(CXX)], [define([AC_PROG_CXX], defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl AC_PROVIDE_IFELSE([AC_PROG_OBJC], [_AM_DEPENDENCIES(OBJC)], [define([AC_PROG_OBJC], defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl ]) _AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl dnl The `parallel-tests' driver may need to know about EXEEXT, so add the dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This macro dnl is hooked onto _AC_COMPILER_EXEEXT early, see below. AC_CONFIG_COMMANDS_PRE(dnl [m4_provide_if([_AM_COMPILER_EXEEXT], [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl ]) dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion. Do not dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further dnl mangled by Autoconf and run in a shell conditional statement. m4_define([_AC_COMPILER_EXEEXT], m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])]) # When config.status generates a header, we must update the stamp-h file. # This file resides in the same directory as the config header # that is generated. The stamp files are numbered to have different names. # Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the # loop where config.status creates the headers, so we can generate # our stamp files there. AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], [# Compute $1's index in $config_headers. _am_arg=$1 _am_stamp_count=1 for _am_header in $config_headers :; do case $_am_header in $_am_arg | $_am_arg:* ) break ;; * ) _am_stamp_count=`expr $_am_stamp_count + 1` ;; esac done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) # Copyright (C) 2001, 2003, 2005, 2008 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_PROG_INSTALL_SH # ------------------ # Define $install_sh. AC_DEFUN([AM_PROG_INSTALL_SH], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl if test x"${install_sh}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; *) install_sh="\${SHELL} $am_aux_dir/install-sh" esac fi AC_SUBST(install_sh)]) # Copyright (C) 2003, 2005 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # serial 2 # Check whether the underlying file-system supports filenames # with a leading dot. For instance MS-DOS doesn't. AC_DEFUN([AM_SET_LEADING_DOT], [rm -rf .tst 2>/dev/null mkdir .tst 2>/dev/null if test -d .tst; then am__leading_dot=. else am__leading_dot=_ fi rmdir .tst 2>/dev/null AC_SUBST([am__leading_dot])]) # Add --enable-maintainer-mode option to configure. -*- Autoconf -*- # From Jim Meyering # Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008 # Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # serial 5 # AM_MAINTAINER_MODE([DEFAULT-MODE]) # ---------------------------------- # Control maintainer-specific portions of Makefiles. # Default is to disable them, unless `enable' is passed literally. # For symmetry, `disable' may be passed as well. Anyway, the user # can override the default with the --enable/--disable switch. AC_DEFUN([AM_MAINTAINER_MODE], [m4_case(m4_default([$1], [disable]), [enable], [m4_define([am_maintainer_other], [disable])], [disable], [m4_define([am_maintainer_other], [enable])], [m4_define([am_maintainer_other], [enable]) m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])]) AC_MSG_CHECKING([whether to am_maintainer_other maintainer-specific portions of Makefiles]) dnl maintainer-mode's default is 'disable' unless 'enable' is passed AC_ARG_ENABLE([maintainer-mode], [ --][am_maintainer_other][-maintainer-mode am_maintainer_other make rules and dependencies not useful (and sometimes confusing) to the casual installer], [USE_MAINTAINER_MODE=$enableval], [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes])) AC_MSG_RESULT([$USE_MAINTAINER_MODE]) AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes]) MAINT=$MAINTAINER_MODE_TRUE AC_SUBST([MAINT])dnl ] ) AU_DEFUN([jm_MAINTAINER_MODE], [AM_MAINTAINER_MODE]) # Check to see how 'make' treats includes. -*- Autoconf -*- # Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # serial 4 # AM_MAKE_INCLUDE() # ----------------- # Check to see how make treats includes. AC_DEFUN([AM_MAKE_INCLUDE], [am_make=${MAKE-make} cat > confinc << 'END' am__doit: @echo this is the am__doit target .PHONY: am__doit END # If we don't find an include directive, just comment out the code. AC_MSG_CHECKING([for style of include used by $am_make]) am__include="#" am__quote= _am_result=none # First try GNU make style include. echo "include confinc" > confmf # Ignore all kinds of additional output from `make'. case `$am_make -s -f confmf 2> /dev/null` in #( *the\ am__doit\ target*) am__include=include am__quote= _am_result=GNU ;; esac # Now try BSD make style include. if test "$am__include" = "#"; then echo '.include "confinc"' > confmf case `$am_make -s -f confmf 2> /dev/null` in #( *the\ am__doit\ target*) am__include=.include am__quote="\"" _am_result=BSD ;; esac fi AC_SUBST([am__include]) AC_SUBST([am__quote]) AC_MSG_RESULT([$_am_result]) rm -f confinc confmf ]) # Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2008 # Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # serial 6 # AM_PROG_CC_C_O # -------------- # Like AC_PROG_CC_C_O, but changed for automake. AC_DEFUN([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC_C_O])dnl AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl AC_REQUIRE_AUX_FILE([compile])dnl # FIXME: we rely on the cache variable name because # there is no other way. set dummy $CC am_cc=`echo $[2] | sed ['s/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/']` eval am_t=\$ac_cv_prog_cc_${am_cc}_c_o if test "$am_t" != yes; then # Losing compiler, so override with the script. # FIXME: It is wrong to rewrite CC. # But if we don't then we get into trouble of one sort or another. # A longer-term fix would be to have automake use am__CC in this case, # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" CC="$am_aux_dir/compile $CC" fi dnl Make sure AC_PROG_CC is never called again, or it will override our dnl setting of CC. m4_define([AC_PROG_CC], [m4_fatal([AC_PROG_CC cannot be called after AM_PROG_CC_C_O])]) ]) # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- # Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008 # Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # serial 6 # AM_MISSING_PROG(NAME, PROGRAM) # ------------------------------ AC_DEFUN([AM_MISSING_PROG], [AC_REQUIRE([AM_MISSING_HAS_RUN]) $1=${$1-"${am_missing_run}$2"} AC_SUBST($1)]) # AM_MISSING_HAS_RUN # ------------------ # Define MISSING if not defined so far and test if it supports --run. # If it does, set am_missing_run to use it, otherwise, to nothing. AC_DEFUN([AM_MISSING_HAS_RUN], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl AC_REQUIRE_AUX_FILE([missing])dnl if test x"${MISSING+set}" != xset; then case $am_aux_dir in *\ * | *\ *) MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; *) MISSING="\${SHELL} $am_aux_dir/missing" ;; esac fi # Use eval to expand $SHELL if eval "$MISSING --run true"; then am_missing_run="$MISSING --run " else am_missing_run= AC_MSG_WARN([`missing' script is too old or missing]) fi ]) # Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_PROG_MKDIR_P # --------------- # Check for `mkdir -p'. AC_DEFUN([AM_PROG_MKDIR_P], [AC_PREREQ([2.60])dnl AC_REQUIRE([AC_PROG_MKDIR_P])dnl dnl Automake 1.8 to 1.9.6 used to define mkdir_p. We now use MKDIR_P, dnl while keeping a definition of mkdir_p for backward compatibility. dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile. dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of dnl Makefile.ins that do not define MKDIR_P, so we do our own dnl adjustment using top_builddir (which is defined more often than dnl MKDIR_P). AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl case $mkdir_p in [[\\/$]]* | ?:[[\\/]]*) ;; */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; esac ]) # Helper functions for option handling. -*- Autoconf -*- # Copyright (C) 2001, 2002, 2003, 2005, 2008 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # serial 4 # _AM_MANGLE_OPTION(NAME) # ----------------------- AC_DEFUN([_AM_MANGLE_OPTION], [[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) # _AM_SET_OPTION(NAME) # ------------------------------ # Set option NAME. Presently that only means defining a flag for this option. AC_DEFUN([_AM_SET_OPTION], [m4_define(_AM_MANGLE_OPTION([$1]), 1)]) # _AM_SET_OPTIONS(OPTIONS) # ---------------------------------- # OPTIONS is a space-separated list of Automake options. AC_DEFUN([_AM_SET_OPTIONS], [m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) # _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) # ------------------------------------------- # Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) # Check to make sure that the build environment is sane. -*- Autoconf -*- # Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008 # Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # serial 5 # AM_SANITY_CHECK # --------------- AC_DEFUN([AM_SANITY_CHECK], [AC_MSG_CHECKING([whether build environment is sane]) # Just in case sleep 1 echo timestamp > conftest.file # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' ' case `pwd` in *[[\\\"\#\$\&\'\`$am_lf]]*) AC_MSG_ERROR([unsafe absolute working directory name]);; esac case $srcdir in *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);; esac # Do `set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` if test "$[*]" = "X"; then # -L didn't work. set X `ls -t "$srcdir/configure" conftest.file` fi rm -f conftest.file if test "$[*]" != "X $srcdir/configure conftest.file" \ && test "$[*]" != "X conftest.file $srcdir/configure"; then # If neither matched, then we have a broken ls. This can happen # if, for instance, CONFIG_SHELL is bash and it inherits a # broken ls alias from the environment. This has actually # happened. Such a system could not be considered "sane". AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken alias in your environment]) fi test "$[2]" = conftest.file ) then # Ok. : else AC_MSG_ERROR([newly created file is older than distributed files! Check your system clock]) fi AC_MSG_RESULT(yes)]) # Copyright (C) 2009 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # serial 1 # AM_SILENT_RULES([DEFAULT]) # -------------------------- # Enable less verbose build rules; with the default set to DEFAULT # (`yes' being less verbose, `no' or empty being verbose). AC_DEFUN([AM_SILENT_RULES], [AC_ARG_ENABLE([silent-rules], [ --enable-silent-rules less verbose build output (undo: `make V=1') --disable-silent-rules verbose build output (undo: `make V=0')]) case $enable_silent_rules in yes) AM_DEFAULT_VERBOSITY=0;; no) AM_DEFAULT_VERBOSITY=1;; *) AM_DEFAULT_VERBOSITY=m4_if([$1], [yes], [0], [1]);; esac AC_SUBST([AM_DEFAULT_VERBOSITY])dnl AM_BACKSLASH='\' AC_SUBST([AM_BACKSLASH])dnl _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl ]) # Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_PROG_INSTALL_STRIP # --------------------- # One issue with vendor `install' (even GNU) is that you can't # specify the program used to strip binaries. This is especially # annoying in cross-compiling environments, where the build's strip # is unlikely to handle the host's binaries. # Fortunately install-sh will honor a STRIPPROG variable, so we # always use install-sh in `make install-strip', and initialize # STRIPPROG with the value of the STRIP variable (set by the user). AC_DEFUN([AM_PROG_INSTALL_STRIP], [AC_REQUIRE([AM_PROG_INSTALL_SH])dnl # Installed binaries are usually stripped using `strip' when the user # run `make install-strip'. However `strip' might not be the right # tool to use in cross-compilation environments, therefore Automake # will honor the `STRIP' environment variable to overrule this program. dnl Don't test for $cross_compiling = yes, because it might be `maybe'. if test "$cross_compiling" != no; then AC_CHECK_TOOL([STRIP], [strip], :) fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) # Copyright (C) 2006, 2008 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # serial 2 # _AM_SUBST_NOTMAKE(VARIABLE) # --------------------------- # Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. # This macro is traced by Automake. AC_DEFUN([_AM_SUBST_NOTMAKE]) # AM_SUBST_NOTMAKE(VARIABLE) # --------------------------- # Public sister of _AM_SUBST_NOTMAKE. AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) # Check how to create a tarball. -*- Autoconf -*- # Copyright (C) 2004, 2005 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # serial 2 # _AM_PROG_TAR(FORMAT) # -------------------- # Check how to create a tarball in format FORMAT. # FORMAT should be one of `v7', `ustar', or `pax'. # # Substitute a variable $(am__tar) that is a command # writing to stdout a FORMAT-tarball containing the directory # $tardir. # tardir=directory && $(am__tar) > result.tar # # Substitute a variable $(am__untar) that extract such # a tarball read from stdin. # $(am__untar) < result.tar AC_DEFUN([_AM_PROG_TAR], [# Always define AMTAR for backward compatibility. AM_MISSING_PROG([AMTAR], [tar]) m4_if([$1], [v7], [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'], [m4_case([$1], [ustar],, [pax],, [m4_fatal([Unknown tar format])]) AC_MSG_CHECKING([how to create a $1 tar archive]) # Loop over all known methods to create a tar archive until one works. _am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' _am_tools=${am_cv_prog_tar_$1-$_am_tools} # Do not fold the above two line into one, because Tru64 sh and # Solaris sh will not grok spaces in the rhs of `-'. for _am_tool in $_am_tools do case $_am_tool in gnutar) for _am_tar in tar gnutar gtar; do AM_RUN_LOG([$_am_tar --version]) && break done am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' am__untar="$_am_tar -xf -" ;; plaintar) # Must skip GNU tar: if it does not support --format= it doesn't create # ustar tarball either. (tar --version) >/dev/null 2>&1 && continue am__tar='tar chf - "$$tardir"' am__tar_='tar chf - "$tardir"' am__untar='tar xf -' ;; pax) am__tar='pax -L -x $1 -w "$$tardir"' am__tar_='pax -L -x $1 -w "$tardir"' am__untar='pax -r' ;; cpio) am__tar='find "$$tardir" -print | cpio -o -H $1 -L' am__tar_='find "$tardir" -print | cpio -o -H $1 -L' am__untar='cpio -i -H $1 -d' ;; none) am__tar=false am__tar_=false am__untar=false ;; esac # If the value was cached, stop now. We just wanted to have am__tar # and am__untar set. test -n "${am_cv_prog_tar_$1}" && break # tar/untar a dummy directory, and stop if the command works rm -rf conftest.dir mkdir conftest.dir echo GrepMe > conftest.dir/file AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) rm -rf conftest.dir if test -s conftest.tar; then AM_RUN_LOG([$am__untar /dev/null 2>&1 && break fi done rm -rf conftest.dir AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) AC_MSG_RESULT([$am_cv_prog_tar_$1])]) AC_SUBST([am__tar]) AC_SUBST([am__untar]) ]) # _AM_PROG_TAR m4_include([m4/codeset.m4]) m4_include([m4/gettext.m4]) m4_include([m4/glibc2.m4]) m4_include([m4/glibc21.m4]) m4_include([m4/iconv.m4]) m4_include([m4/intdiv0.m4]) m4_include([m4/intl.m4]) m4_include([m4/intlmacosx.m4]) m4_include([m4/intmax.m4]) m4_include([m4/inttypes-pri.m4]) m4_include([m4/inttypes_h.m4]) m4_include([m4/lcmessage.m4]) m4_include([m4/lib-ld.m4]) m4_include([m4/lib-link.m4]) m4_include([m4/lib-prefix.m4]) m4_include([m4/libnih.m4]) m4_include([m4/libtool.m4]) m4_include([m4/lock.m4]) m4_include([m4/longlong.m4]) m4_include([m4/ltoptions.m4]) m4_include([m4/ltsugar.m4]) m4_include([m4/ltversion.m4]) m4_include([m4/lt~obsolete.m4]) m4_include([m4/nls.m4]) m4_include([m4/pkg.m4]) m4_include([m4/po.m4]) m4_include([m4/printf-posix.m4]) m4_include([m4/progtest.m4]) m4_include([m4/size_max.m4]) m4_include([m4/stdint_h.m4]) m4_include([m4/uintmax_t.m4]) m4_include([m4/visibility.m4]) m4_include([m4/wchar_t.m4]) m4_include([m4/wint_t.m4]) m4_include([m4/xsize.m4]) libnih-1.0.3/configure.ac0000644000175000017500000000407411445765555012215 00000000000000# Process this file with autoconf to produce a configure script. AC_PREREQ(2.62) AC_INIT([libnih], [1.0.3], [http://bugs.launchpad.net/libnih/]) NIH_COPYRIGHT([[Copyright © 2010 Scott James Remnant .]]) AC_CONFIG_SRCDIR([nih/libnih.h]) AC_CONFIG_MACRO_DIR([m4]) AC_GNU_SOURCE AM_INIT_AUTOMAKE([1.11 gnu nostdinc check-news color-tests silent-rules]) AM_SILENT_RULES([yes]) AM_MAINTAINER_MODE([enable]) LT_PREREQ(2.2.4) LT_INIT AM_GNU_GETTEXT_VERSION([0.17]) AM_GNU_GETTEXT() # Checks for programs. AC_PROG_CC PKG_PROG_PKG_CONFIG([0.22]) # Checks for libraries. PKG_CHECK_MODULES([DBUS], [dbus-1 >= 1.2.16]) AC_CHECK_LIB([expat], [XML_ParserCreate], [AC_CHECK_LIB([expat], [XML_StopParser], [AC_SUBST([EXPAT_LIBS], [-lexpat])], [AC_MSG_ERROR([expat >= 2.0.0 required])])], [AC_MSG_ERROR([expat library not found])]) # Checks for header files. AC_CHECK_HEADERS([valgrind/valgrind.h]) # Checks for typedefs, structures, and compiler characteristics. AC_PROG_CC_C99 AM_PROG_CC_C_O NIH_C_THREAD # Checks for library functions. # Other checks NIH_COMPILER_WARNINGS NIH_COMPILER_OPTIMISATIONS NIH_COMPILER_COVERAGE NIH_LINKER_OPTIMISATIONS NIH_LINKER_VERSION_SCRIPT # Allow a pre-build nih-dbus-tool to be used when cross-compiling. # Programs can just use AC_CHECK_PROGS for this AC_ARG_VAR([NIH_DBUS_TOOL], [Path to external nih-dbus-tool when cross-compiling]) AS_IF([test "$cross_compiling" = "yes"], [AC_CHECK_PROGS([NIH_DBUS_TOOL], [nih-dbus-tool]) AS_IF([test -z "$NIH_DBUS_TOOL"], [AC_MSG_WARN([nih-dbus-tool not found, but you are cross-compiling. Using built copy, which is probably not what you want. Set NIH_DBUS_TOOL maybe?]) AC_SUBST([NIH_DBUS_TOOL], ["\${top_builddir}/nih-dbus-tool/nih-dbus-tool"])])], [AC_SUBST([NIH_DBUS_TOOL], ["\${top_builddir}/nih-dbus-tool/nih-dbus-tool"])]) AC_CONFIG_FILES([ Makefile m4/Makefile intl/Makefile nih/Makefile nih/libnih.pc nih-dbus/Makefile nih-dbus/libnih-dbus.pc nih-dbus-tool/Makefile po/Makefile.in ]) AC_CONFIG_HEADERS([config.h]) AC_OUTPUT libnih-1.0.3/README0000644000175000017500000000362511445765555010610 00000000000000libnih is a light-weight "standard library" of C functions to ease the development of other libraries and applications. Its goals are: * despite its name, to _not_ reimplement anything found in the standard C library or any library normally found in /lib; * use standard C types and conventions where appropriate; * have a simple and consistent programming interface; * be useful to library developers without needing to be exposed in the library's API; * not hide implementation details or structure contents, we're all adults after all. Dependencies ------------ The D-Bus messaging system is required to build the libnih-dbus library and nih-dbus-tool utility. In order to query the availability of the external library, the pkg-config tool is used; and in order to parse D-Bus introspection data, the expat XML parsing library will be used. The recommended versions are: * pkg-config 0.22 * D-Bus 1.2.16 * expat 2.0.0 These should all be available from the current release of any modern Linux distribution. For detailed compilation and installation instructions see the INSTALL file. If you've checked libnih out from revision control, or want to hack on libnih, see the HACKING file. Cross-compiling --------------- libnih uses the nih-dbus-tool utility it builds during its own build process to generate further sources to be built. When cross-compiling this will fail because the built nih-dbus-tool will most likely not be able to run on the build architecture. This can be solved by building and installing nih-dbus-tool for the build architecture first, then when performing the cross-compile, the installed copy will be used instead. If installed into a common system directory, this is automatic; if not, you can pass the path of the nih-dbus-tool binary to the configure script, e.g.: ./configure --build=i486-linux-gnu --host=gnueabi-linux-arm \ NIH_DBUS_TOOL=/cross/bin/nih-dbus-tool libnih-1.0.3/m4/0000755000175000017500000000000011504742362010305 500000000000000libnih-1.0.3/m4/nls.m40000644000175000017500000000226611461165270011270 00000000000000# nls.m4 serial 3 (gettext-0.15) dnl Copyright (C) 1995-2003, 2005-2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl dnl This file can can be used in projects which are not available under dnl the GNU General Public License or the GNU Library General Public dnl License but which still want to provide support for the GNU gettext dnl functionality. dnl Please note that the actual code of the GNU gettext library is covered dnl by the GNU Library General Public License, and the rest of the GNU dnl gettext package package is covered by the GNU General Public License. dnl They are *not* in the public domain. dnl Authors: dnl Ulrich Drepper , 1995-2000. dnl Bruno Haible , 2000-2003. AC_PREREQ(2.50) AC_DEFUN([AM_NLS], [ AC_MSG_CHECKING([whether NLS is requested]) dnl Default is enabled NLS AC_ARG_ENABLE(nls, [ --disable-nls do not use Native Language Support], USE_NLS=$enableval, USE_NLS=yes) AC_MSG_RESULT($USE_NLS) AC_SUBST(USE_NLS) ]) libnih-1.0.3/m4/intmax.m40000644000175000017500000000201111461165270011760 00000000000000# intmax.m4 serial 3 (gettext-0.16) dnl Copyright (C) 2002-2005 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. dnl Test whether the system has the 'intmax_t' type, but don't attempt to dnl find a replacement if it is lacking. AC_DEFUN([gt_TYPE_INTMAX_T], [ AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) AC_REQUIRE([gl_AC_HEADER_STDINT_H]) AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t, [AC_TRY_COMPILE([ #include #include #if HAVE_STDINT_H_WITH_UINTMAX #include #endif #if HAVE_INTTYPES_H_WITH_UINTMAX #include #endif ], [intmax_t x = -1; return !x;], gt_cv_c_intmax_t=yes, gt_cv_c_intmax_t=no)]) if test $gt_cv_c_intmax_t = yes; then AC_DEFINE(HAVE_INTMAX_T, 1, [Define if you have the 'intmax_t' type in or .]) fi ]) libnih-1.0.3/m4/gettext.m40000644000175000017500000003457011461165270012163 00000000000000# gettext.m4 serial 60 (gettext-0.17) dnl Copyright (C) 1995-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl dnl This file can can be used in projects which are not available under dnl the GNU General Public License or the GNU Library General Public dnl License but which still want to provide support for the GNU gettext dnl functionality. dnl Please note that the actual code of the GNU gettext library is covered dnl by the GNU Library General Public License, and the rest of the GNU dnl gettext package package is covered by the GNU General Public License. dnl They are *not* in the public domain. dnl Authors: dnl Ulrich Drepper , 1995-2000. dnl Bruno Haible , 2000-2006. dnl Macro to add for using GNU gettext. dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]). dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The dnl default (if it is not specified or empty) is 'no-libtool'. dnl INTLSYMBOL should be 'external' for packages with no intl directory, dnl and 'no-libtool' or 'use-libtool' for packages with an intl directory. dnl If INTLSYMBOL is 'use-libtool', then a libtool library dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static, dnl depending on --{enable,disable}-{shared,static} and on the presence of dnl AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library dnl $(top_builddir)/intl/libintl.a will be created. dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext dnl implementations (in libc or libintl) without the ngettext() function dnl will be ignored. If NEEDSYMBOL is specified and is dnl 'need-formatstring-macros', then GNU gettext implementations that don't dnl support the ISO C 99 formatstring macros will be ignored. dnl INTLDIR is used to find the intl libraries. If empty, dnl the value `$(top_builddir)/intl/' is used. dnl dnl The result of the configuration is one of three cases: dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled dnl and used. dnl Catalog format: GNU --> install in $(datadir) dnl Catalog extension: .mo after installation, .gmo in source tree dnl 2) GNU gettext has been found in the system's C library. dnl Catalog format: GNU --> install in $(datadir) dnl Catalog extension: .mo after installation, .gmo in source tree dnl 3) No internationalization, always use English msgid. dnl Catalog format: none dnl Catalog extension: none dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur. dnl The use of .gmo is historical (it was needed to avoid overwriting the dnl GNU format catalogs when building on a platform with an X/Open gettext), dnl but we keep it in order not to force irrelevant filename changes on the dnl maintainers. dnl AC_DEFUN([AM_GNU_GETTEXT], [ dnl Argument checking. ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], , [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT ])])])])]) ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], , [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT ])])])]) define([gt_included_intl], ifelse([$1], [external], ifdef([AM_GNU_GETTEXT_][INTL_SUBDIR], [yes], [no]), [yes])) define([gt_libtool_suffix_prefix], ifelse([$1], [use-libtool], [l], [])) gt_NEEDS_INIT AM_GNU_GETTEXT_NEED([$2]) AC_REQUIRE([AM_PO_SUBDIRS])dnl ifelse(gt_included_intl, yes, [ AC_REQUIRE([AM_INTL_SUBDIR])dnl ]) dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) AC_REQUIRE([AC_LIB_RPATH]) dnl Sometimes libintl requires libiconv, so first search for libiconv. dnl Ideally we would do this search only after the dnl if test "$USE_NLS" = "yes"; then dnl if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT dnl the configure script would need to contain the same shell code dnl again, outside any 'if'. There are two solutions: dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'. dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE. dnl Since AC_PROVIDE_IFELSE is only in autoconf >= 2.52 and not dnl documented, we avoid it. ifelse(gt_included_intl, yes, , [ AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY]) ]) dnl Sometimes, on MacOS X, libintl requires linking with CoreFoundation. gt_INTL_MACOSX dnl Set USE_NLS. AC_REQUIRE([AM_NLS]) ifelse(gt_included_intl, yes, [ BUILD_INCLUDED_LIBINTL=no USE_INCLUDED_LIBINTL=no ]) LIBINTL= LTLIBINTL= POSUB= dnl Add a version number to the cache macros. case " $gt_needs " in *" need-formatstring-macros "*) gt_api_version=3 ;; *" need-ngettext "*) gt_api_version=2 ;; *) gt_api_version=1 ;; esac gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc" gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl" dnl If we use NLS figure out what method if test "$USE_NLS" = "yes"; then gt_use_preinstalled_gnugettext=no ifelse(gt_included_intl, yes, [ AC_MSG_CHECKING([whether included gettext is requested]) AC_ARG_WITH(included-gettext, [ --with-included-gettext use the GNU gettext library included here], nls_cv_force_use_gnu_gettext=$withval, nls_cv_force_use_gnu_gettext=no) AC_MSG_RESULT($nls_cv_force_use_gnu_gettext) nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext" if test "$nls_cv_force_use_gnu_gettext" != "yes"; then ]) dnl User does not insist on using GNU NLS library. Figure out what dnl to use. If GNU gettext is available we use this. Else we have dnl to fall back to GNU NLS library. if test $gt_api_version -ge 3; then gt_revision_test_code=' #ifndef __GNU_GETTEXT_SUPPORTED_REVISION #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) #endif changequote(,)dnl typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; changequote([,])dnl ' else gt_revision_test_code= fi if test $gt_api_version -ge 2; then gt_expression_test_code=' + * ngettext ("", "", 0)' else gt_expression_test_code= fi AC_CACHE_CHECK([for GNU gettext in libc], [$gt_func_gnugettext_libc], [AC_TRY_LINK([#include $gt_revision_test_code extern int _nl_msg_cat_cntr; extern int *_nl_domain_bindings;], [bindtextdomain ("", ""); return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_bindings], [eval "$gt_func_gnugettext_libc=yes"], [eval "$gt_func_gnugettext_libc=no"])]) if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then dnl Sometimes libintl requires libiconv, so first search for libiconv. ifelse(gt_included_intl, yes, , [ AM_ICONV_LINK ]) dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv]) dnl because that would add "-liconv" to LIBINTL and LTLIBINTL dnl even if libiconv doesn't exist. AC_LIB_LINKFLAGS_BODY([intl]) AC_CACHE_CHECK([for GNU gettext in libintl], [$gt_func_gnugettext_libintl], [gt_save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $INCINTL" gt_save_LIBS="$LIBS" LIBS="$LIBS $LIBINTL" dnl Now see whether libintl exists and does not depend on libiconv. AC_TRY_LINK([#include $gt_revision_test_code extern int _nl_msg_cat_cntr; extern #ifdef __cplusplus "C" #endif const char *_nl_expand_alias (const char *);], [bindtextdomain ("", ""); return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")], [eval "$gt_func_gnugettext_libintl=yes"], [eval "$gt_func_gnugettext_libintl=no"]) dnl Now see whether libintl exists and depends on libiconv. if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then LIBS="$LIBS $LIBICONV" AC_TRY_LINK([#include $gt_revision_test_code extern int _nl_msg_cat_cntr; extern #ifdef __cplusplus "C" #endif const char *_nl_expand_alias (const char *);], [bindtextdomain ("", ""); return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")], [LIBINTL="$LIBINTL $LIBICONV" LTLIBINTL="$LTLIBINTL $LTLIBICONV" eval "$gt_func_gnugettext_libintl=yes" ]) fi CPPFLAGS="$gt_save_CPPFLAGS" LIBS="$gt_save_LIBS"]) fi dnl If an already present or preinstalled GNU gettext() is found, dnl use it. But if this macro is used in GNU gettext, and GNU dnl gettext is already preinstalled in libintl, we update this dnl libintl. (Cf. the install rule in intl/Makefile.in.) if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \ || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \ && test "$PACKAGE" != gettext-runtime \ && test "$PACKAGE" != gettext-tools; }; then gt_use_preinstalled_gnugettext=yes else dnl Reset the values set by searching for libintl. LIBINTL= LTLIBINTL= INCINTL= fi ifelse(gt_included_intl, yes, [ if test "$gt_use_preinstalled_gnugettext" != "yes"; then dnl GNU gettext is not found in the C library. dnl Fall back on included GNU gettext library. nls_cv_use_gnu_gettext=yes fi fi if test "$nls_cv_use_gnu_gettext" = "yes"; then dnl Mark actions used to generate GNU NLS library. BUILD_INCLUDED_LIBINTL=yes USE_INCLUDED_LIBINTL=yes LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV $LIBTHREAD" LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV $LTLIBTHREAD" LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'` fi CATOBJEXT= if test "$gt_use_preinstalled_gnugettext" = "yes" \ || test "$nls_cv_use_gnu_gettext" = "yes"; then dnl Mark actions to use GNU gettext tools. CATOBJEXT=.gmo fi ]) if test -n "$INTL_MACOSX_LIBS"; then if test "$gt_use_preinstalled_gnugettext" = "yes" \ || test "$nls_cv_use_gnu_gettext" = "yes"; then dnl Some extra flags are needed during linking. LIBINTL="$LIBINTL $INTL_MACOSX_LIBS" LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS" fi fi if test "$gt_use_preinstalled_gnugettext" = "yes" \ || test "$nls_cv_use_gnu_gettext" = "yes"; then AC_DEFINE(ENABLE_NLS, 1, [Define to 1 if translation of program messages to the user's native language is requested.]) else USE_NLS=no fi fi AC_MSG_CHECKING([whether to use NLS]) AC_MSG_RESULT([$USE_NLS]) if test "$USE_NLS" = "yes"; then AC_MSG_CHECKING([where the gettext function comes from]) if test "$gt_use_preinstalled_gnugettext" = "yes"; then if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then gt_source="external libintl" else gt_source="libc" fi else gt_source="included intl directory" fi AC_MSG_RESULT([$gt_source]) fi if test "$USE_NLS" = "yes"; then if test "$gt_use_preinstalled_gnugettext" = "yes"; then if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then AC_MSG_CHECKING([how to link with libintl]) AC_MSG_RESULT([$LIBINTL]) AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL]) fi dnl For backward compatibility. Some packages may be using this. AC_DEFINE(HAVE_GETTEXT, 1, [Define if the GNU gettext() function is already present or preinstalled.]) AC_DEFINE(HAVE_DCGETTEXT, 1, [Define if the GNU dcgettext() function is already present or preinstalled.]) fi dnl We need to process the po/ directory. POSUB=po fi ifelse(gt_included_intl, yes, [ dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL dnl to 'yes' because some of the testsuite requires it. if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then BUILD_INCLUDED_LIBINTL=yes fi dnl Make all variables we use known to autoconf. AC_SUBST(BUILD_INCLUDED_LIBINTL) AC_SUBST(USE_INCLUDED_LIBINTL) AC_SUBST(CATOBJEXT) dnl For backward compatibility. Some configure.ins may be using this. nls_cv_header_intl= nls_cv_header_libgt= dnl For backward compatibility. Some Makefiles may be using this. DATADIRNAME=share AC_SUBST(DATADIRNAME) dnl For backward compatibility. Some Makefiles may be using this. INSTOBJEXT=.mo AC_SUBST(INSTOBJEXT) dnl For backward compatibility. Some Makefiles may be using this. GENCAT=gencat AC_SUBST(GENCAT) dnl For backward compatibility. Some Makefiles may be using this. INTLOBJS= if test "$USE_INCLUDED_LIBINTL" = yes; then INTLOBJS="\$(GETTOBJS)" fi AC_SUBST(INTLOBJS) dnl Enable libtool support if the surrounding package wishes it. INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX) ]) dnl For backward compatibility. Some Makefiles may be using this. INTLLIBS="$LIBINTL" AC_SUBST(INTLLIBS) dnl Make all documented variables known to autoconf. AC_SUBST(LIBINTL) AC_SUBST(LTLIBINTL) AC_SUBST(POSUB) ]) dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized. m4_define([gt_NEEDS_INIT], [ m4_divert_text([DEFAULTS], [gt_needs=]) m4_define([gt_NEEDS_INIT], []) ]) dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL]) AC_DEFUN([AM_GNU_GETTEXT_NEED], [ m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"]) ]) dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version]) AC_DEFUN([AM_GNU_GETTEXT_VERSION], []) libnih-1.0.3/m4/glibc21.m40000644000175000017500000000144511461165270011715 00000000000000# glibc21.m4 serial 3 dnl Copyright (C) 2000-2002, 2004 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. # Test for the GNU C Library, version 2.1 or newer. # From Bruno Haible. AC_DEFUN([gl_GLIBC21], [ AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer, ac_cv_gnu_library_2_1, [AC_EGREP_CPP([Lucky GNU user], [ #include #ifdef __GNU_LIBRARY__ #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2) Lucky GNU user #endif #endif ], ac_cv_gnu_library_2_1=yes, ac_cv_gnu_library_2_1=no) ] ) AC_SUBST(GLIBC21) GLIBC21="$ac_cv_gnu_library_2_1" ] ) libnih-1.0.3/m4/inttypes_h.m40000644000175000017500000000164411461165270012661 00000000000000# inttypes_h.m4 serial 7 dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Paul Eggert. # Define HAVE_INTTYPES_H_WITH_UINTMAX if exists, # doesn't clash with , and declares uintmax_t. AC_DEFUN([gl_AC_HEADER_INTTYPES_H], [ AC_CACHE_CHECK([for inttypes.h], gl_cv_header_inttypes_h, [AC_TRY_COMPILE( [#include #include ], [uintmax_t i = (uintmax_t) -1; return !i;], gl_cv_header_inttypes_h=yes, gl_cv_header_inttypes_h=no)]) if test $gl_cv_header_inttypes_h = yes; then AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H_WITH_UINTMAX, 1, [Define if exists, doesn't clash with , and declares uintmax_t. ]) fi ]) libnih-1.0.3/m4/lib-prefix.m40000644000175000017500000001503611461165270012534 00000000000000# lib-prefix.m4 serial 5 (gettext-0.15) dnl Copyright (C) 2001-2005 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't dnl require excessive bracketing. ifdef([AC_HELP_STRING], [AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])], [AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])]) dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed dnl to access previously installed libraries. The basic assumption is that dnl a user will want packages to use other packages he previously installed dnl with the same --prefix option. dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate dnl libraries, but is otherwise very convenient. AC_DEFUN([AC_LIB_PREFIX], [ AC_BEFORE([$0], [AC_LIB_LINKFLAGS]) AC_REQUIRE([AC_PROG_CC]) AC_REQUIRE([AC_CANONICAL_HOST]) AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) dnl By default, look in $includedir and $libdir. use_additional=yes AC_LIB_WITH_FINAL_PREFIX([ eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" ]) AC_LIB_ARG_WITH([lib-prefix], [ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib --without-lib-prefix don't search for libraries in includedir and libdir], [ if test "X$withval" = "Xno"; then use_additional=no else if test "X$withval" = "X"; then AC_LIB_WITH_FINAL_PREFIX([ eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" ]) else additional_includedir="$withval/include" additional_libdir="$withval/$acl_libdirstem" fi fi ]) if test $use_additional = yes; then dnl Potentially add $additional_includedir to $CPPFLAGS. dnl But don't add it dnl 1. if it's the standard /usr/include, dnl 2. if it's already present in $CPPFLAGS, dnl 3. if it's /usr/local/include and we are using GCC on Linux, dnl 4. if it doesn't exist as a directory. if test "X$additional_includedir" != "X/usr/include"; then haveit= for x in $CPPFLAGS; do AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) if test "X$x" = "X-I$additional_includedir"; then haveit=yes break fi done if test -z "$haveit"; then if test "X$additional_includedir" = "X/usr/local/include"; then if test -n "$GCC"; then case $host_os in linux* | gnu* | k*bsd*-gnu) haveit=yes;; esac fi fi if test -z "$haveit"; then if test -d "$additional_includedir"; then dnl Really add $additional_includedir to $CPPFLAGS. CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir" fi fi fi fi dnl Potentially add $additional_libdir to $LDFLAGS. dnl But don't add it dnl 1. if it's the standard /usr/lib, dnl 2. if it's already present in $LDFLAGS, dnl 3. if it's /usr/local/lib and we are using GCC on Linux, dnl 4. if it doesn't exist as a directory. if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then haveit= for x in $LDFLAGS; do AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) if test "X$x" = "X-L$additional_libdir"; then haveit=yes break fi done if test -z "$haveit"; then if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then if test -n "$GCC"; then case $host_os in linux*) haveit=yes;; esac fi fi if test -z "$haveit"; then if test -d "$additional_libdir"; then dnl Really add $additional_libdir to $LDFLAGS. LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir" fi fi fi fi fi ]) dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix, dnl acl_final_exec_prefix, containing the values to which $prefix and dnl $exec_prefix will expand at the end of the configure script. AC_DEFUN([AC_LIB_PREPARE_PREFIX], [ dnl Unfortunately, prefix and exec_prefix get only finally determined dnl at the end of configure. if test "X$prefix" = "XNONE"; then acl_final_prefix="$ac_default_prefix" else acl_final_prefix="$prefix" fi if test "X$exec_prefix" = "XNONE"; then acl_final_exec_prefix='${prefix}' else acl_final_exec_prefix="$exec_prefix" fi acl_save_prefix="$prefix" prefix="$acl_final_prefix" eval acl_final_exec_prefix=\"$acl_final_exec_prefix\" prefix="$acl_save_prefix" ]) dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the dnl variables prefix and exec_prefix bound to the values they will have dnl at the end of the configure script. AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX], [ acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" $1 exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" ]) dnl AC_LIB_PREPARE_MULTILIB creates a variable acl_libdirstem, containing dnl the basename of the libdir, either "lib" or "lib64". AC_DEFUN([AC_LIB_PREPARE_MULTILIB], [ dnl There is no formal standard regarding lib and lib64. The current dnl practice is that on a system supporting 32-bit and 64-bit instruction dnl sets or ABIs, 64-bit libraries go under $prefix/lib64 and 32-bit dnl libraries go under $prefix/lib. We determine the compiler's default dnl mode by looking at the compiler's library search path. If at least dnl of its elements ends in /lib64 or points to a directory whose absolute dnl pathname ends in /lib64, we assume a 64-bit ABI. Otherwise we use the dnl default, namely "lib". acl_libdirstem=lib searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'` if test -n "$searchpath"; then acl_save_IFS="${IFS= }"; IFS=":" for searchdir in $searchpath; do if test -d "$searchdir"; then case "$searchdir" in */lib64/ | */lib64 ) acl_libdirstem=lib64 ;; *) searchdir=`cd "$searchdir" && pwd` case "$searchdir" in */lib64 ) acl_libdirstem=lib64 ;; esac ;; esac fi done IFS="$acl_save_IFS" fi ]) libnih-1.0.3/m4/lib-link.m40000644000175000017500000007205511461165270012200 00000000000000# lib-link.m4 serial 13 (gettext-0.17) dnl Copyright (C) 2001-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. AC_PREREQ(2.54) dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and dnl the libraries corresponding to explicit and implicit dependencies. dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and dnl augments the CPPFLAGS variable. dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem. AC_DEFUN([AC_LIB_LINKFLAGS], [ AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) AC_REQUIRE([AC_LIB_RPATH]) define([Name],[translit([$1],[./-], [___])]) define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [ AC_LIB_LINKFLAGS_BODY([$1], [$2]) ac_cv_lib[]Name[]_libs="$LIB[]NAME" ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME" ac_cv_lib[]Name[]_cppflags="$INC[]NAME" ac_cv_lib[]Name[]_prefix="$LIB[]NAME[]_PREFIX" ]) LIB[]NAME="$ac_cv_lib[]Name[]_libs" LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs" INC[]NAME="$ac_cv_lib[]Name[]_cppflags" LIB[]NAME[]_PREFIX="$ac_cv_lib[]Name[]_prefix" AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) AC_SUBST([LIB]NAME) AC_SUBST([LTLIB]NAME) AC_SUBST([LIB]NAME[_PREFIX]) dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the dnl results of this search when this library appears as a dependency. HAVE_LIB[]NAME=yes undefine([Name]) undefine([NAME]) ]) dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode) dnl searches for libname and the libraries corresponding to explicit and dnl implicit dependencies, together with the specified include files and dnl the ability to compile and link the specified testcode. If found, it dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty. dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem. AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], [ AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) AC_REQUIRE([AC_LIB_RPATH]) define([Name],[translit([$1],[./-], [___])]) define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME dnl accordingly. AC_LIB_LINKFLAGS_BODY([$1], [$2]) dnl Add $INC[]NAME to CPPFLAGS before performing the following checks, dnl because if the user has installed lib[]Name and not disabled its use dnl via --without-lib[]Name-prefix, he wants to use it. ac_save_CPPFLAGS="$CPPFLAGS" AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [ ac_save_LIBS="$LIBS" LIBS="$LIBS $LIB[]NAME" AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no]) LIBS="$ac_save_LIBS" ]) if test "$ac_cv_lib[]Name" = yes; then HAVE_LIB[]NAME=yes AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.]) AC_MSG_CHECKING([how to link with lib[]$1]) AC_MSG_RESULT([$LIB[]NAME]) else HAVE_LIB[]NAME=no dnl If $LIB[]NAME didn't lead to a usable library, we don't need dnl $INC[]NAME either. CPPFLAGS="$ac_save_CPPFLAGS" LIB[]NAME= LTLIB[]NAME= LIB[]NAME[]_PREFIX= fi AC_SUBST([HAVE_LIB]NAME) AC_SUBST([LIB]NAME) AC_SUBST([LTLIB]NAME) AC_SUBST([LIB]NAME[_PREFIX]) undefine([Name]) undefine([NAME]) ]) dnl Determine the platform dependent parameters needed to use rpath: dnl acl_libext, dnl acl_shlibext, dnl acl_hardcode_libdir_flag_spec, dnl acl_hardcode_libdir_separator, dnl acl_hardcode_direct, dnl acl_hardcode_minus_L. AC_DEFUN([AC_LIB_RPATH], [ dnl Tell automake >= 1.10 to complain if config.rpath is missing. m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])]) AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir AC_CACHE_CHECK([for shared library run path origin], acl_cv_rpath, [ CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \ ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh . ./conftest.sh rm -f ./conftest.sh acl_cv_rpath=done ]) wl="$acl_cv_wl" acl_libext="$acl_cv_libext" acl_shlibext="$acl_cv_shlibext" acl_libname_spec="$acl_cv_libname_spec" acl_library_names_spec="$acl_cv_library_names_spec" acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" acl_hardcode_direct="$acl_cv_hardcode_direct" acl_hardcode_minus_L="$acl_cv_hardcode_minus_L" dnl Determine whether the user wants rpath handling at all. AC_ARG_ENABLE(rpath, [ --disable-rpath do not hardcode runtime library paths], :, enable_rpath=yes) ]) dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and dnl the libraries corresponding to explicit and implicit dependencies. dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables. dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem. AC_DEFUN([AC_LIB_LINKFLAGS_BODY], [ AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) dnl Autoconf >= 2.61 supports dots in --with options. define([N_A_M_E],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[translit([$1],[.],[_])],[$1])]) dnl By default, look in $includedir and $libdir. use_additional=yes AC_LIB_WITH_FINAL_PREFIX([ eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" ]) AC_LIB_ARG_WITH([lib]N_A_M_E[-prefix], [ --with-lib]N_A_M_E[-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib --without-lib]N_A_M_E[-prefix don't search for lib$1 in includedir and libdir], [ if test "X$withval" = "Xno"; then use_additional=no else if test "X$withval" = "X"; then AC_LIB_WITH_FINAL_PREFIX([ eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" ]) else additional_includedir="$withval/include" additional_libdir="$withval/$acl_libdirstem" fi fi ]) dnl Search the library and its dependencies in $additional_libdir and dnl $LDFLAGS. Using breadth-first-seach. LIB[]NAME= LTLIB[]NAME= INC[]NAME= LIB[]NAME[]_PREFIX= rpathdirs= ltrpathdirs= names_already_handled= names_next_round='$1 $2' while test -n "$names_next_round"; do names_this_round="$names_next_round" names_next_round= for name in $names_this_round; do already_handled= for n in $names_already_handled; do if test "$n" = "$name"; then already_handled=yes break fi done if test -z "$already_handled"; then names_already_handled="$names_already_handled $name" dnl See if it was already located by an earlier AC_LIB_LINKFLAGS dnl or AC_LIB_HAVE_LINKFLAGS call. uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'` eval value=\"\$HAVE_LIB$uppername\" if test -n "$value"; then if test "$value" = yes; then eval value=\"\$LIB$uppername\" test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value" eval value=\"\$LTLIB$uppername\" test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value" else dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined dnl that this library doesn't exist. So just drop it. : fi else dnl Search the library lib$name in $additional_libdir and $LDFLAGS dnl and the already constructed $LIBNAME/$LTLIBNAME. found_dir= found_la= found_so= found_a= eval libname=\"$acl_libname_spec\" # typically: libname=lib$name if test -n "$acl_shlibext"; then shrext=".$acl_shlibext" # typically: shrext=.so else shrext= fi if test $use_additional = yes; then dir="$additional_libdir" dnl The same code as in the loop below: dnl First look for a shared library. if test -n "$acl_shlibext"; then if test -f "$dir/$libname$shrext"; then found_dir="$dir" found_so="$dir/$libname$shrext" else if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then ver=`(cd "$dir" && \ for f in "$libname$shrext".*; do echo "$f"; done \ | sed -e "s,^$libname$shrext\\\\.,," \ | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | sed 1q ) 2>/dev/null` if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then found_dir="$dir" found_so="$dir/$libname$shrext.$ver" fi else eval library_names=\"$acl_library_names_spec\" for f in $library_names; do if test -f "$dir/$f"; then found_dir="$dir" found_so="$dir/$f" break fi done fi fi fi dnl Then look for a static library. if test "X$found_dir" = "X"; then if test -f "$dir/$libname.$acl_libext"; then found_dir="$dir" found_a="$dir/$libname.$acl_libext" fi fi if test "X$found_dir" != "X"; then if test -f "$dir/$libname.la"; then found_la="$dir/$libname.la" fi fi fi if test "X$found_dir" = "X"; then for x in $LDFLAGS $LTLIB[]NAME; do AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) case "$x" in -L*) dir=`echo "X$x" | sed -e 's/^X-L//'` dnl First look for a shared library. if test -n "$acl_shlibext"; then if test -f "$dir/$libname$shrext"; then found_dir="$dir" found_so="$dir/$libname$shrext" else if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then ver=`(cd "$dir" && \ for f in "$libname$shrext".*; do echo "$f"; done \ | sed -e "s,^$libname$shrext\\\\.,," \ | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | sed 1q ) 2>/dev/null` if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then found_dir="$dir" found_so="$dir/$libname$shrext.$ver" fi else eval library_names=\"$acl_library_names_spec\" for f in $library_names; do if test -f "$dir/$f"; then found_dir="$dir" found_so="$dir/$f" break fi done fi fi fi dnl Then look for a static library. if test "X$found_dir" = "X"; then if test -f "$dir/$libname.$acl_libext"; then found_dir="$dir" found_a="$dir/$libname.$acl_libext" fi fi if test "X$found_dir" != "X"; then if test -f "$dir/$libname.la"; then found_la="$dir/$libname.la" fi fi ;; esac if test "X$found_dir" != "X"; then break fi done fi if test "X$found_dir" != "X"; then dnl Found the library. LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name" if test "X$found_so" != "X"; then dnl Linking with a shared library. We attempt to hardcode its dnl directory into the executable's runpath, unless it's the dnl standard /usr/lib. if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/$acl_libdirstem"; then dnl No hardcoding is needed. LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" else dnl Use an explicit option to hardcode DIR into the resulting dnl binary. dnl Potentially add DIR to ltrpathdirs. dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. haveit= for x in $ltrpathdirs; do if test "X$x" = "X$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then ltrpathdirs="$ltrpathdirs $found_dir" fi dnl The hardcoding into $LIBNAME is system dependent. if test "$acl_hardcode_direct" = yes; then dnl Using DIR/libNAME.so during linking hardcodes DIR into the dnl resulting binary. LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" else if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then dnl Use an explicit option to hardcode DIR into the resulting dnl binary. LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" dnl Potentially add DIR to rpathdirs. dnl The rpathdirs will be appended to $LIBNAME at the end. haveit= for x in $rpathdirs; do if test "X$x" = "X$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then rpathdirs="$rpathdirs $found_dir" fi else dnl Rely on "-L$found_dir". dnl But don't add it if it's already contained in the LDFLAGS dnl or the already constructed $LIBNAME haveit= for x in $LDFLAGS $LIB[]NAME; do AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) if test "X$x" = "X-L$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir" fi if test "$acl_hardcode_minus_L" != no; then dnl FIXME: Not sure whether we should use dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" dnl here. LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" else dnl We cannot use $acl_hardcode_runpath_var and LD_RUN_PATH dnl here, because this doesn't fit in flags passed to the dnl compiler. So give up. No hardcoding. This affects only dnl very old systems. dnl FIXME: Not sure whether we should use dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" dnl here. LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" fi fi fi fi else if test "X$found_a" != "X"; then dnl Linking with a static library. LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a" else dnl We shouldn't come here, but anyway it's good to have a dnl fallback. LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name" fi fi dnl Assume the include files are nearby. additional_includedir= case "$found_dir" in */$acl_libdirstem | */$acl_libdirstem/) basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'` LIB[]NAME[]_PREFIX="$basedir" additional_includedir="$basedir/include" ;; esac if test "X$additional_includedir" != "X"; then dnl Potentially add $additional_includedir to $INCNAME. dnl But don't add it dnl 1. if it's the standard /usr/include, dnl 2. if it's /usr/local/include and we are using GCC on Linux, dnl 3. if it's already present in $CPPFLAGS or the already dnl constructed $INCNAME, dnl 4. if it doesn't exist as a directory. if test "X$additional_includedir" != "X/usr/include"; then haveit= if test "X$additional_includedir" = "X/usr/local/include"; then if test -n "$GCC"; then case $host_os in linux* | gnu* | k*bsd*-gnu) haveit=yes;; esac fi fi if test -z "$haveit"; then for x in $CPPFLAGS $INC[]NAME; do AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) if test "X$x" = "X-I$additional_includedir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_includedir"; then dnl Really add $additional_includedir to $INCNAME. INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir" fi fi fi fi fi dnl Look for dependencies. if test -n "$found_la"; then dnl Read the .la file. It defines the variables dnl dlname, library_names, old_library, dependency_libs, current, dnl age, revision, installed, dlopen, dlpreopen, libdir. save_libdir="$libdir" case "$found_la" in */* | *\\*) . "$found_la" ;; *) . "./$found_la" ;; esac libdir="$save_libdir" dnl We use only dependency_libs. for dep in $dependency_libs; do case "$dep" in -L*) additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'` dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME. dnl But don't add it dnl 1. if it's the standard /usr/lib, dnl 2. if it's /usr/local/lib and we are using GCC on Linux, dnl 3. if it's already present in $LDFLAGS or the already dnl constructed $LIBNAME, dnl 4. if it doesn't exist as a directory. if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then haveit= if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then if test -n "$GCC"; then case $host_os in linux* | gnu* | k*bsd*-gnu) haveit=yes;; esac fi fi if test -z "$haveit"; then haveit= for x in $LDFLAGS $LIB[]NAME; do AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) if test "X$x" = "X-L$additional_libdir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_libdir"; then dnl Really add $additional_libdir to $LIBNAME. LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir" fi fi haveit= for x in $LDFLAGS $LTLIB[]NAME; do AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) if test "X$x" = "X-L$additional_libdir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_libdir"; then dnl Really add $additional_libdir to $LTLIBNAME. LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir" fi fi fi fi ;; -R*) dir=`echo "X$dep" | sed -e 's/^X-R//'` if test "$enable_rpath" != no; then dnl Potentially add DIR to rpathdirs. dnl The rpathdirs will be appended to $LIBNAME at the end. haveit= for x in $rpathdirs; do if test "X$x" = "X$dir"; then haveit=yes break fi done if test -z "$haveit"; then rpathdirs="$rpathdirs $dir" fi dnl Potentially add DIR to ltrpathdirs. dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. haveit= for x in $ltrpathdirs; do if test "X$x" = "X$dir"; then haveit=yes break fi done if test -z "$haveit"; then ltrpathdirs="$ltrpathdirs $dir" fi fi ;; -l*) dnl Handle this in the next round. names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'` ;; *.la) dnl Handle this in the next round. Throw away the .la's dnl directory; it is already contained in a preceding -L dnl option. names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'` ;; *) dnl Most likely an immediate library name. LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep" LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep" ;; esac done fi else dnl Didn't find the library; assume it is in the system directories dnl known to the linker and runtime loader. (All the system dnl directories known to the linker should also be known to the dnl runtime loader, otherwise the system is severely misconfigured.) LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name" fi fi fi done done if test "X$rpathdirs" != "X"; then if test -n "$acl_hardcode_libdir_separator"; then dnl Weird platform: only the last -rpath option counts, the user must dnl pass all path elements in one option. We can arrange that for a dnl single library, but not when more than one $LIBNAMEs are used. alldirs= for found_dir in $rpathdirs; do alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir" done dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl. acl_save_libdir="$libdir" libdir="$alldirs" eval flag=\"$acl_hardcode_libdir_flag_spec\" libdir="$acl_save_libdir" LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" else dnl The -rpath options are cumulative. for found_dir in $rpathdirs; do acl_save_libdir="$libdir" libdir="$found_dir" eval flag=\"$acl_hardcode_libdir_flag_spec\" libdir="$acl_save_libdir" LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" done fi fi if test "X$ltrpathdirs" != "X"; then dnl When using libtool, the option that works for both libraries and dnl executables is -R. The -R options are cumulative. for found_dir in $ltrpathdirs; do LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir" done fi ]) dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR, dnl unless already present in VAR. dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes dnl contains two or three consecutive elements that belong together. AC_DEFUN([AC_LIB_APPENDTOVAR], [ for element in [$2]; do haveit= for x in $[$1]; do AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) if test "X$x" = "X$element"; then haveit=yes break fi done if test -z "$haveit"; then [$1]="${[$1]}${[$1]:+ }$element" fi done ]) dnl For those cases where a variable contains several -L and -l options dnl referring to unknown libraries and directories, this macro determines the dnl necessary additional linker options for the runtime path. dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL]) dnl sets LDADDVAR to linker options needed together with LIBSVALUE. dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed, dnl otherwise linking without libtool is assumed. AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS], [ AC_REQUIRE([AC_LIB_RPATH]) AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) $1= if test "$enable_rpath" != no; then if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then dnl Use an explicit option to hardcode directories into the resulting dnl binary. rpathdirs= next= for opt in $2; do if test -n "$next"; then dir="$next" dnl No need to hardcode the standard /usr/lib. if test "X$dir" != "X/usr/$acl_libdirstem"; then rpathdirs="$rpathdirs $dir" fi next= else case $opt in -L) next=yes ;; -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'` dnl No need to hardcode the standard /usr/lib. if test "X$dir" != "X/usr/$acl_libdirstem"; then rpathdirs="$rpathdirs $dir" fi next= ;; *) next= ;; esac fi done if test "X$rpathdirs" != "X"; then if test -n ""$3""; then dnl libtool is used for linking. Use -R options. for dir in $rpathdirs; do $1="${$1}${$1:+ }-R$dir" done else dnl The linker is used for linking directly. if test -n "$acl_hardcode_libdir_separator"; then dnl Weird platform: only the last -rpath option counts, the user dnl must pass all path elements in one option. alldirs= for dir in $rpathdirs; do alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$dir" done acl_save_libdir="$libdir" libdir="$alldirs" eval flag=\"$acl_hardcode_libdir_flag_spec\" libdir="$acl_save_libdir" $1="$flag" else dnl The -rpath options are cumulative. for dir in $rpathdirs; do acl_save_libdir="$libdir" libdir="$dir" eval flag=\"$acl_hardcode_libdir_flag_spec\" libdir="$acl_save_libdir" $1="${$1}${$1:+ }$flag" done fi fi fi fi fi AC_SUBST([$1]) ]) libnih-1.0.3/m4/size_max.m40000644000175000017500000000513311461165270012307 00000000000000# size_max.m4 serial 6 dnl Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. AC_DEFUN([gl_SIZE_MAX], [ AC_CHECK_HEADERS(stdint.h) dnl First test whether the system already has SIZE_MAX. AC_MSG_CHECKING([for SIZE_MAX]) AC_CACHE_VAL([gl_cv_size_max], [ gl_cv_size_max= AC_EGREP_CPP([Found it], [ #include #if HAVE_STDINT_H #include #endif #ifdef SIZE_MAX Found it #endif ], gl_cv_size_max=yes) if test -z "$gl_cv_size_max"; then dnl Define it ourselves. Here we assume that the type 'size_t' is not wider dnl than the type 'unsigned long'. Try hard to find a definition that can dnl be used in a preprocessor #if, i.e. doesn't contain a cast. AC_COMPUTE_INT([size_t_bits_minus_1], [sizeof (size_t) * CHAR_BIT - 1], [#include #include ], size_t_bits_minus_1=) AC_COMPUTE_INT([fits_in_uint], [sizeof (size_t) <= sizeof (unsigned int)], [#include ], fits_in_uint=) if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then if test $fits_in_uint = 1; then dnl Even though SIZE_MAX fits in an unsigned int, it must be of type dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'. AC_TRY_COMPILE([#include extern size_t foo; extern unsigned long foo; ], [], fits_in_uint=0) fi dnl We cannot use 'expr' to simplify this expression, because 'expr' dnl works only with 'long' integers in the host environment, while we dnl might be cross-compiling from a 32-bit platform to a 64-bit platform. if test $fits_in_uint = 1; then gl_cv_size_max="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)" else gl_cv_size_max="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)" fi else dnl Shouldn't happen, but who knows... gl_cv_size_max='((size_t)~(size_t)0)' fi fi ]) AC_MSG_RESULT([$gl_cv_size_max]) if test "$gl_cv_size_max" != yes; then AC_DEFINE_UNQUOTED([SIZE_MAX], [$gl_cv_size_max], [Define as the maximum value of type 'size_t', if the system doesn't define it.]) fi ]) dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. dnl Remove this when we can assume autoconf >= 2.61. m4_ifdef([AC_COMPUTE_INT], [], [ AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) ]) libnih-1.0.3/m4/Makefile.am0000644000175000017500000000017411445765555012300 00000000000000## Process this file with automake to produce Makefile.in aclocaldir = $(datadir)/aclocal dist_aclocal_DATA = \ libnih.m4 libnih-1.0.3/m4/intlmacosx.m40000644000175000017500000000456511461165270012661 00000000000000# intlmacosx.m4 serial 1 (gettext-0.17) dnl Copyright (C) 2004-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl dnl This file can can be used in projects which are not available under dnl the GNU General Public License or the GNU Library General Public dnl License but which still want to provide support for the GNU gettext dnl functionality. dnl Please note that the actual code of the GNU gettext library is covered dnl by the GNU Library General Public License, and the rest of the GNU dnl gettext package package is covered by the GNU General Public License. dnl They are *not* in the public domain. dnl Checks for special options needed on MacOS X. dnl Defines INTL_MACOSX_LIBS. AC_DEFUN([gt_INTL_MACOSX], [ dnl Check for API introduced in MacOS X 10.2. AC_CACHE_CHECK([for CFPreferencesCopyAppValue], gt_cv_func_CFPreferencesCopyAppValue, [gt_save_LIBS="$LIBS" LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" AC_TRY_LINK([#include ], [CFPreferencesCopyAppValue(NULL, NULL)], [gt_cv_func_CFPreferencesCopyAppValue=yes], [gt_cv_func_CFPreferencesCopyAppValue=no]) LIBS="$gt_save_LIBS"]) if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], 1, [Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in the CoreFoundation framework.]) fi dnl Check for API introduced in MacOS X 10.3. AC_CACHE_CHECK([for CFLocaleCopyCurrent], gt_cv_func_CFLocaleCopyCurrent, [gt_save_LIBS="$LIBS" LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" AC_TRY_LINK([#include ], [CFLocaleCopyCurrent();], [gt_cv_func_CFLocaleCopyCurrent=yes], [gt_cv_func_CFLocaleCopyCurrent=no]) LIBS="$gt_save_LIBS"]) if test $gt_cv_func_CFLocaleCopyCurrent = yes; then AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], 1, [Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the CoreFoundation framework.]) fi INTL_MACOSX_LIBS= if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation" fi AC_SUBST([INTL_MACOSX_LIBS]) ]) libnih-1.0.3/m4/printf-posix.m40000644000175000017500000000271111461165270013131 00000000000000# printf-posix.m4 serial 3 (gettext-0.17) dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. dnl Test whether the printf() function supports POSIX/XSI format strings with dnl positions. AC_DEFUN([gt_PRINTF_POSIX], [ AC_REQUIRE([AC_PROG_CC]) AC_CACHE_CHECK([whether printf() supports POSIX/XSI format strings], gt_cv_func_printf_posix, [ AC_TRY_RUN([ #include #include /* The string "%2$d %1$d", with dollar characters protected from the shell's dollar expansion (possibly an autoconf bug). */ static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' }; static char buf[100]; int main () { sprintf (buf, format, 33, 55); return (strcmp (buf, "55 33") != 0); }], gt_cv_func_printf_posix=yes, gt_cv_func_printf_posix=no, [ AC_EGREP_CPP(notposix, [ #if defined __NetBSD__ || defined __BEOS__ || defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__ notposix #endif ], gt_cv_func_printf_posix="guessing no", gt_cv_func_printf_posix="guessing yes") ]) ]) case $gt_cv_func_printf_posix in *yes) AC_DEFINE(HAVE_POSIX_PRINTF, 1, [Define if your printf() function supports format strings with positions.]) ;; esac ]) libnih-1.0.3/m4/longlong.m40000644000175000017500000001005411461165270012305 00000000000000# longlong.m4 serial 13 dnl Copyright (C) 1999-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Paul Eggert. # Define HAVE_LONG_LONG_INT if 'long long int' works. # This fixes a bug in Autoconf 2.61, but can be removed once we # assume 2.62 everywhere. # Note: If the type 'long long int' exists but is only 32 bits large # (as on some very old compilers), HAVE_LONG_LONG_INT will not be # defined. In this case you can treat 'long long int' like 'long int'. AC_DEFUN([AC_TYPE_LONG_LONG_INT], [ AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int], [AC_LINK_IFELSE( [_AC_TYPE_LONG_LONG_SNIPPET], [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004. dnl If cross compiling, assume the bug isn't important, since dnl nobody cross compiles for this platform as far as we know. AC_RUN_IFELSE( [AC_LANG_PROGRAM( [[@%:@include @%:@ifndef LLONG_MAX @%:@ define HALF \ (1LL << (sizeof (long long int) * CHAR_BIT - 2)) @%:@ define LLONG_MAX (HALF - 1 + HALF) @%:@endif]], [[long long int n = 1; int i; for (i = 0; ; i++) { long long int m = n << i; if (m >> i != n) return 1; if (LLONG_MAX / 2 < m) break; } return 0;]])], [ac_cv_type_long_long_int=yes], [ac_cv_type_long_long_int=no], [ac_cv_type_long_long_int=yes])], [ac_cv_type_long_long_int=no])]) if test $ac_cv_type_long_long_int = yes; then AC_DEFINE([HAVE_LONG_LONG_INT], 1, [Define to 1 if the system has the type `long long int'.]) fi ]) # Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works. # This fixes a bug in Autoconf 2.61, but can be removed once we # assume 2.62 everywhere. # Note: If the type 'unsigned long long int' exists but is only 32 bits # large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT # will not be defined. In this case you can treat 'unsigned long long int' # like 'unsigned long int'. AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT], [ AC_CACHE_CHECK([for unsigned long long int], [ac_cv_type_unsigned_long_long_int], [AC_LINK_IFELSE( [_AC_TYPE_LONG_LONG_SNIPPET], [ac_cv_type_unsigned_long_long_int=yes], [ac_cv_type_unsigned_long_long_int=no])]) if test $ac_cv_type_unsigned_long_long_int = yes; then AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], 1, [Define to 1 if the system has the type `unsigned long long int'.]) fi ]) # Expands to a C program that can be used to test for simultaneous support # of 'long long' and 'unsigned long long'. We don't want to say that # 'long long' is available if 'unsigned long long' is not, or vice versa, # because too many programs rely on the symmetry between signed and unsigned # integer types (excluding 'bool'). AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET], [ AC_LANG_PROGRAM( [[/* Test preprocessor. */ #if ! (-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) error in preprocessor; #endif #if ! (18446744073709551615ULL <= -1ull) error in preprocessor; #endif /* Test literals. */ long long int ll = 9223372036854775807ll; long long int nll = -9223372036854775807LL; unsigned long long int ull = 18446744073709551615ULL; /* Test constant expressions. */ typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) ? 1 : -1)]; typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1 ? 1 : -1)]; int i = 63;]], [[/* Test availability of runtime routines for shift and division. */ long long int llmax = 9223372036854775807ll; unsigned long long int ullmax = 18446744073709551615ull; return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) | (llmax / ll) | (llmax % ll) | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i) | (ullmax / ull) | (ullmax % ull));]]) ]) libnih-1.0.3/m4/lock.m40000644000175000017500000003022311461165270011416 00000000000000# lock.m4 serial 7 (gettext-0.17) dnl Copyright (C) 2005-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. dnl Tests for a multithreading library to be used. dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS, dnl USE_PTH_THREADS, USE_WIN32_THREADS dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with dnl libtool). dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for dnl programs that really need multithread functionality. The difference dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak dnl symbols, typically LIBTHREAD="" whereas LIBMULTITHREAD="-lpthread". dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for dnl multithread-safe programs. AC_DEFUN([gl_LOCK_EARLY], [ AC_REQUIRE([gl_LOCK_EARLY_BODY]) ]) dnl The guts of gl_LOCK_EARLY. Needs to be expanded only once. AC_DEFUN([gl_LOCK_EARLY_BODY], [ dnl Ordering constraints: This macro modifies CPPFLAGS in a way that dnl influences the result of the autoconf tests that test for *_unlocked dnl declarations, on AIX 5 at least. Therefore it must come early. AC_BEFORE([$0], [gl_FUNC_GLIBC_UNLOCKED_IO])dnl AC_BEFORE([$0], [gl_ARGP])dnl AC_REQUIRE([AC_CANONICAL_HOST]) dnl _GNU_SOURCE is needed for pthread_rwlock_t on glibc systems. dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes dnl AC_GNU_SOURCE. m4_ifdef([AC_USE_SYSTEM_EXTENSIONS], [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])], [AC_REQUIRE([AC_GNU_SOURCE])]) dnl Check for multithreading. AC_ARG_ENABLE(threads, AC_HELP_STRING([--enable-threads={posix|solaris|pth|win32}], [specify multithreading API]) AC_HELP_STRING([--disable-threads], [build without multithread safety]), [gl_use_threads=$enableval], [case "$host_os" in dnl Disable multithreading by default on OSF/1, because it interferes dnl with fork()/exec(): When msgexec is linked with -lpthread, its child dnl process gets an endless segmentation fault inside execvp(). osf*) gl_use_threads=no ;; *) gl_use_threads=yes ;; esac ]) if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then # For using : case "$host_os" in osf*) # On OSF/1, the compiler needs the flag -D_REENTRANT so that it # groks . cc also understands the flag -pthread, but # we don't use it because 1. gcc-2.95 doesn't understand -pthread, # 2. putting a flag into CPPFLAGS that has an effect on the linker # causes the AC_TRY_LINK test below to succeed unexpectedly, # leading to wrong values of LIBTHREAD and LTLIBTHREAD. CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;; esac # Some systems optimize for single-threaded programs by default, and # need special flags to disable these optimizations. For example, the # definition of 'errno' in . case "$host_os" in aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;; solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;; esac fi ]) dnl The guts of gl_LOCK. Needs to be expanded only once. AC_DEFUN([gl_LOCK_BODY], [ AC_REQUIRE([gl_LOCK_EARLY_BODY]) gl_threads_api=none LIBTHREAD= LTLIBTHREAD= LIBMULTITHREAD= LTLIBMULTITHREAD= if test "$gl_use_threads" != no; then dnl Check whether the compiler and linker support weak declarations. AC_MSG_CHECKING([whether imported symbols can be declared weak]) gl_have_weak=no AC_TRY_LINK([extern void xyzzy (); #pragma weak xyzzy], [xyzzy();], [gl_have_weak=yes]) AC_MSG_RESULT([$gl_have_weak]) if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that # it groks . It's added above, in gl_LOCK_EARLY_BODY. AC_CHECK_HEADER(pthread.h, gl_have_pthread_h=yes, gl_have_pthread_h=no) if test "$gl_have_pthread_h" = yes; then # Other possible tests: # -lpthreads (FSU threads, PCthreads) # -lgthreads gl_have_pthread= # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist # in libc. IRIX 6.5 has the first one in both libc and libpthread, but # the second one only in libpthread, and lock.c needs it. AC_TRY_LINK([#include ], [pthread_mutex_lock((pthread_mutex_t*)0); pthread_mutexattr_init((pthread_mutexattr_t*)0);], [gl_have_pthread=yes]) # Test for libpthread by looking for pthread_kill. (Not pthread_self, # since it is defined as a macro on OSF/1.) if test -n "$gl_have_pthread"; then # The program links fine without libpthread. But it may actually # need to link with libpthread in order to create multiple threads. AC_CHECK_LIB(pthread, pthread_kill, [LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread # On Solaris and HP-UX, most pthread functions exist also in libc. # Therefore pthread_in_use() needs to actually try to create a # thread: pthread_create from libc will fail, whereas # pthread_create will actually create a thread. case "$host_os" in solaris* | hpux*) AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], 1, [Define if the pthread_in_use() detection is hard.]) esac ]) else # Some library is needed. Try libpthread and libc_r. AC_CHECK_LIB(pthread, pthread_kill, [gl_have_pthread=yes LIBTHREAD=-lpthread LTLIBTHREAD=-lpthread LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread]) if test -z "$gl_have_pthread"; then # For FreeBSD 4. AC_CHECK_LIB(c_r, pthread_kill, [gl_have_pthread=yes LIBTHREAD=-lc_r LTLIBTHREAD=-lc_r LIBMULTITHREAD=-lc_r LTLIBMULTITHREAD=-lc_r]) fi fi if test -n "$gl_have_pthread"; then gl_threads_api=posix AC_DEFINE([USE_POSIX_THREADS], 1, [Define if the POSIX multithreading library can be used.]) if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then if test $gl_have_weak = yes; then AC_DEFINE([USE_POSIX_THREADS_WEAK], 1, [Define if references to the POSIX multithreading library should be made weak.]) LIBTHREAD= LTLIBTHREAD= fi fi # OSF/1 4.0 and MacOS X 10.1 lack the pthread_rwlock_t type and the # pthread_rwlock_* functions. AC_CHECK_TYPE([pthread_rwlock_t], [AC_DEFINE([HAVE_PTHREAD_RWLOCK], 1, [Define if the POSIX multithreading library has read/write locks.])], [], [#include ]) # glibc defines PTHREAD_MUTEX_RECURSIVE as enum, not as a macro. AC_TRY_COMPILE([#include ], [#if __FreeBSD__ == 4 error "No, in FreeBSD 4.0 recursive mutexes actually don't work." #else int x = (int)PTHREAD_MUTEX_RECURSIVE; return !x; #endif], [AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE], 1, [Define if the defines PTHREAD_MUTEX_RECURSIVE.])]) fi fi fi if test -z "$gl_have_pthread"; then if test "$gl_use_threads" = yes || test "$gl_use_threads" = solaris; then gl_have_solaristhread= gl_save_LIBS="$LIBS" LIBS="$LIBS -lthread" AC_TRY_LINK([#include #include ], [thr_self();], [gl_have_solaristhread=yes]) LIBS="$gl_save_LIBS" if test -n "$gl_have_solaristhread"; then gl_threads_api=solaris LIBTHREAD=-lthread LTLIBTHREAD=-lthread LIBMULTITHREAD="$LIBTHREAD" LTLIBMULTITHREAD="$LTLIBTHREAD" AC_DEFINE([USE_SOLARIS_THREADS], 1, [Define if the old Solaris multithreading library can be used.]) if test $gl_have_weak = yes; then AC_DEFINE([USE_SOLARIS_THREADS_WEAK], 1, [Define if references to the old Solaris multithreading library should be made weak.]) LIBTHREAD= LTLIBTHREAD= fi fi fi fi if test "$gl_use_threads" = pth; then gl_save_CPPFLAGS="$CPPFLAGS" AC_LIB_LINKFLAGS(pth) gl_have_pth= gl_save_LIBS="$LIBS" LIBS="$LIBS -lpth" AC_TRY_LINK([#include ], [pth_self();], gl_have_pth=yes) LIBS="$gl_save_LIBS" if test -n "$gl_have_pth"; then gl_threads_api=pth LIBTHREAD="$LIBPTH" LTLIBTHREAD="$LTLIBPTH" LIBMULTITHREAD="$LIBTHREAD" LTLIBMULTITHREAD="$LTLIBTHREAD" AC_DEFINE([USE_PTH_THREADS], 1, [Define if the GNU Pth multithreading library can be used.]) if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then if test $gl_have_weak = yes; then AC_DEFINE([USE_PTH_THREADS_WEAK], 1, [Define if references to the GNU Pth multithreading library should be made weak.]) LIBTHREAD= LTLIBTHREAD= fi fi else CPPFLAGS="$gl_save_CPPFLAGS" fi fi if test -z "$gl_have_pthread"; then if test "$gl_use_threads" = yes || test "$gl_use_threads" = win32; then if { case "$host_os" in mingw*) true;; *) false;; esac }; then gl_threads_api=win32 AC_DEFINE([USE_WIN32_THREADS], 1, [Define if the Win32 multithreading API can be used.]) fi fi fi fi AC_MSG_CHECKING([for multithread API to use]) AC_MSG_RESULT([$gl_threads_api]) AC_SUBST(LIBTHREAD) AC_SUBST(LTLIBTHREAD) AC_SUBST(LIBMULTITHREAD) AC_SUBST(LTLIBMULTITHREAD) ]) AC_DEFUN([gl_LOCK], [ AC_REQUIRE([gl_LOCK_EARLY]) AC_REQUIRE([gl_LOCK_BODY]) gl_PREREQ_LOCK ]) # Prerequisites of lib/lock.c. AC_DEFUN([gl_PREREQ_LOCK], [ AC_REQUIRE([AC_C_INLINE]) ]) dnl Survey of platforms: dnl dnl Platform Available Compiler Supports test-lock dnl flavours option weak result dnl --------------- --------- --------- -------- --------- dnl Linux 2.4/glibc posix -lpthread Y OK dnl dnl GNU Hurd/glibc posix dnl dnl FreeBSD 5.3 posix -lc_r Y dnl posix -lkse ? Y dnl posix -lpthread ? Y dnl posix -lthr Y dnl dnl FreeBSD 5.2 posix -lc_r Y dnl posix -lkse Y dnl posix -lthr Y dnl dnl FreeBSD 4.0,4.10 posix -lc_r Y OK dnl dnl NetBSD 1.6 -- dnl dnl OpenBSD 3.4 posix -lpthread Y OK dnl dnl MacOS X 10.[123] posix -lpthread Y OK dnl dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK dnl dnl HP-UX 11 posix -lpthread N (cc) OK dnl Y (gcc) dnl dnl IRIX 6.5 posix -lpthread Y 0.5 dnl dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK dnl dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK dnl -lpthread (gcc) Y dnl dnl Cygwin posix -lpthread Y OK dnl dnl Any of the above pth -lpth 0.0 dnl dnl Mingw win32 N OK dnl dnl BeOS 5 -- dnl dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is dnl turned off: dnl OK if all three tests terminate OK, dnl 0.5 if the first test terminates OK but the second one loops endlessly, dnl 0.0 if the first test already loops endlessly. libnih-1.0.3/m4/uintmax_t.m40000644000175000017500000000211211461165270012472 00000000000000# uintmax_t.m4 serial 10 dnl Copyright (C) 1997-2004, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Paul Eggert. AC_PREREQ(2.13) # Define uintmax_t to 'unsigned long' or 'unsigned long long' # if it is not already defined in or . AC_DEFUN([gl_AC_TYPE_UINTMAX_T], [ AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) AC_REQUIRE([gl_AC_HEADER_STDINT_H]) if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) test $ac_cv_type_unsigned_long_long_int = yes \ && ac_type='unsigned long long' \ || ac_type='unsigned long' AC_DEFINE_UNQUOTED(uintmax_t, $ac_type, [Define to unsigned long or unsigned long long if and don't define.]) else AC_DEFINE(HAVE_UINTMAX_T, 1, [Define if you have the 'uintmax_t' type in or .]) fi ]) libnih-1.0.3/m4/lt~obsolete.m40000644000175000017500000001311311461165274013043 00000000000000# lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- # # Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc. # Written by Scott James Remnant, 2004. # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # serial 4 lt~obsolete.m4 # These exist entirely to fool aclocal when bootstrapping libtool. # # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN) # which have later been changed to m4_define as they aren't part of the # exported API, or moved to Autoconf or Automake where they belong. # # The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us # using a macro with the same name in our local m4/libtool.m4 it'll # pull the old libtool.m4 in (it doesn't see our shiny new m4_define # and doesn't know about Autoconf macros at all.) # # So we provide this file, which has a silly filename so it's always # included after everything else. This provides aclocal with the # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything # because those macros already exist, or will be overwritten later. # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. # # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. # Yes, that means every name once taken will need to remain here until # we give up compatibility with versions before 1.7, at which point # we need to keep only those names which we still refer to. # This is to help aclocal find these macros, as it can't see m4_define. AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) m4_ifndef([AC_LIBTOOL_RC], [AC_DEFUN([AC_LIBTOOL_RC])]) m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) libnih-1.0.3/m4/stdint_h.m40000644000175000017500000000161411461165270012304 00000000000000# stdint_h.m4 serial 6 dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Paul Eggert. # Define HAVE_STDINT_H_WITH_UINTMAX if exists, # doesn't clash with , and declares uintmax_t. AC_DEFUN([gl_AC_HEADER_STDINT_H], [ AC_CACHE_CHECK([for stdint.h], gl_cv_header_stdint_h, [AC_TRY_COMPILE( [#include #include ], [uintmax_t i = (uintmax_t) -1; return !i;], gl_cv_header_stdint_h=yes, gl_cv_header_stdint_h=no)]) if test $gl_cv_header_stdint_h = yes; then AC_DEFINE_UNQUOTED(HAVE_STDINT_H_WITH_UINTMAX, 1, [Define if exists, doesn't clash with , and declares uintmax_t. ]) fi ]) libnih-1.0.3/m4/Makefile.in0000644000175000017500000003407011503251217012267 00000000000000# Makefile.in generated by automake 1.11.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, # 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, # Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ subdir = m4 DIST_COMMON = $(dist_aclocal_DATA) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/codeset.m4 \ $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/glibc2.m4 \ $(top_srcdir)/m4/glibc21.m4 $(top_srcdir)/m4/iconv.m4 \ $(top_srcdir)/m4/intdiv0.m4 $(top_srcdir)/m4/intl.m4 \ $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/intmax.m4 \ $(top_srcdir)/m4/inttypes-pri.m4 \ $(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/lcmessage.m4 \ $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libnih.m4 \ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/lock.m4 \ $(top_srcdir)/m4/longlong.m4 $(top_srcdir)/m4/ltoptions.m4 \ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \ $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/m4/po.m4 \ $(top_srcdir)/m4/printf-posix.m4 $(top_srcdir)/m4/progtest.m4 \ $(top_srcdir)/m4/size_max.m4 $(top_srcdir)/m4/stdint_h.m4 \ $(top_srcdir)/m4/uintmax_t.m4 $(top_srcdir)/m4/visibility.m4 \ $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/m4/wint_t.m4 \ $(top_srcdir)/m4/xsize.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = AM_V_GEN = $(am__v_GEN_$(V)) am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) am__v_GEN_0 = @echo " GEN " $@; AM_V_at = $(am__v_at_$(V)) am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) am__v_at_0 = @ SOURCES = DIST_SOURCES = am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__installdirs = "$(DESTDIR)$(aclocaldir)" DATA = $(dist_aclocal_DATA) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ ALLOCA = @ALLOCA@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@ CATOBJEXT = @CATOBJEXT@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CFLAG_VISIBILITY = @CFLAG_VISIBILITY@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DATADIRNAME = @DATADIRNAME@ DBUS_CFLAGS = @DBUS_CFLAGS@ DBUS_LIBS = @DBUS_LIBS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ EXPAT_LIBS = @EXPAT_LIBS@ FGREP = @FGREP@ GENCAT = @GENCAT@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ GLIBC2 = @GLIBC2@ GLIBC21 = @GLIBC21@ GMSGFMT = @GMSGFMT@ GMSGFMT_015 = @GMSGFMT_015@ GREP = @GREP@ HAVE_ASPRINTF = @HAVE_ASPRINTF@ HAVE_POSIX_PRINTF = @HAVE_POSIX_PRINTF@ HAVE_SNPRINTF = @HAVE_SNPRINTF@ HAVE_VISIBILITY = @HAVE_VISIBILITY@ HAVE_WPRINTF = @HAVE_WPRINTF@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INSTOBJEXT = @INSTOBJEXT@ INTLBISON = @INTLBISON@ INTLLIBS = @INTLLIBS@ INTLOBJS = @INTLOBJS@ INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@ INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBMULTITHREAD = @LIBMULTITHREAD@ LIBOBJS = @LIBOBJS@ LIBPTH = @LIBPTH@ LIBPTH_PREFIX = @LIBPTH_PREFIX@ LIBS = @LIBS@ LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBC = @LTLIBC@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ LTLIBMULTITHREAD = @LTLIBMULTITHREAD@ LTLIBOBJS = @LTLIBOBJS@ LTLIBPTH = @LTLIBPTH@ LTLIBTHREAD = @LTLIBTHREAD@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ NIH_DBUS_TOOL = @NIH_DBUS_TOOL@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_COPYRIGHT = @PACKAGE_COPYRIGHT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ POSUB = @POSUB@ PRI_MACROS_BROKEN = @PRI_MACROS_BROKEN@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@ USE_NLS = @USE_NLS@ VERSION = @VERSION@ VERSION_SCRIPT_ARG = @VERSION_SCRIPT_ARG@ WINDRES = @WINDRES@ WOE32 = @WOE32@ WOE32DLL = @WOE32DLL@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ aclocaldir = $(datadir)/aclocal dist_aclocal_DATA = \ libnih.m4 all: all-am .SUFFIXES: $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu m4/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu m4/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-dist_aclocalDATA: $(dist_aclocal_DATA) @$(NORMAL_INSTALL) test -z "$(aclocaldir)" || $(MKDIR_P) "$(DESTDIR)$(aclocaldir)" @list='$(dist_aclocal_DATA)'; test -n "$(aclocaldir)" || list=; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(aclocaldir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(aclocaldir)" || exit $$?; \ done uninstall-dist_aclocalDATA: @$(NORMAL_UNINSTALL) @list='$(dist_aclocal_DATA)'; test -n "$(aclocaldir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ test -n "$$files" || exit 0; \ echo " ( cd '$(DESTDIR)$(aclocaldir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(aclocaldir)" && rm -f $$files tags: TAGS TAGS: ctags: CTAGS CTAGS: distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: Makefile $(DATA) installdirs: for dir in "$(DESTDIR)$(aclocaldir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ `test -z '$(STRIP)' || \ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install mostlyclean-generic: clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-am clean-am: clean-generic clean-libtool mostlyclean-am distclean: distclean-am -rm -f Makefile distclean-am: clean-am distclean-generic dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-dist_aclocalDATA install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-generic mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-dist_aclocalDATA .MAKE: install-am install-strip .PHONY: all all-am check check-am clean clean-generic clean-libtool \ distclean distclean-generic distclean-libtool distdir dvi \ dvi-am html html-am info info-am install install-am \ install-data install-data-am install-dist_aclocalDATA \ install-dvi install-dvi-am install-exec install-exec-am \ install-html install-html-am install-info install-info-am \ install-man install-pdf install-pdf-am install-ps \ install-ps-am install-strip installcheck installcheck-am \ installdirs maintainer-clean maintainer-clean-generic \ mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \ ps ps-am uninstall uninstall-am uninstall-dist_aclocalDATA # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: libnih-1.0.3/m4/pkg.m40000644000175000017500000001250111461165274011252 00000000000000# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- # serial 1 (pkg-config-0.24) # # Copyright © 2004 Scott James Remnant . # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # PKG_PROG_PKG_CONFIG([MIN-VERSION]) # ---------------------------------- AC_DEFUN([PKG_PROG_PKG_CONFIG], [m4_pattern_forbid([^_?PKG_[A-Z_]+$]) m4_pattern_allow([^PKG_CONFIG(_PATH)?$]) AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility]) AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path]) AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path]) if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) fi if test -n "$PKG_CONFIG"; then _pkg_min_version=m4_default([$1], [0.9.0]) AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) PKG_CONFIG="" fi fi[]dnl ])# PKG_PROG_PKG_CONFIG # PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) # # Check to see whether a particular set of modules exists. Similar # to PKG_CHECK_MODULES(), but does not set variables or print errors. # # Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) # only at the first occurence in configure.ac, so if the first place # it's called might be skipped (such as if it is within an "if", you # have to call PKG_CHECK_EXISTS manually # -------------------------------------------------------------- AC_DEFUN([PKG_CHECK_EXISTS], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl if test -n "$PKG_CONFIG" && \ AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then m4_default([$2], [:]) m4_ifvaln([$3], [else $3])dnl fi]) # _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) # --------------------------------------------- m4_define([_PKG_CONFIG], [if test -n "$$1"; then pkg_cv_[]$1="$$1" elif test -n "$PKG_CONFIG"; then PKG_CHECK_EXISTS([$3], [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`], [pkg_failed=yes]) else pkg_failed=untried fi[]dnl ])# _PKG_CONFIG # _PKG_SHORT_ERRORS_SUPPORTED # ----------------------------- AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], [AC_REQUIRE([PKG_PROG_PKG_CONFIG]) if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then _pkg_short_errors_supported=yes else _pkg_short_errors_supported=no fi[]dnl ])# _PKG_SHORT_ERRORS_SUPPORTED # PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], # [ACTION-IF-NOT-FOUND]) # # # Note that if there is a possibility the first call to # PKG_CHECK_MODULES might not happen, you should be sure to include an # explicit call to PKG_PROG_PKG_CONFIG in your configure.ac # # # -------------------------------------------------------------- AC_DEFUN([PKG_CHECK_MODULES], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl pkg_failed=no AC_MSG_CHECKING([for $1]) _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) _PKG_CONFIG([$1][_LIBS], [libs], [$2]) m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS and $1[]_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.]) if test $pkg_failed = yes; then AC_MSG_RESULT([no]) _PKG_SHORT_ERRORS_SUPPORTED if test $_pkg_short_errors_supported = yes; then $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1` else $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1` fi # Put the nasty error message in config.log where it belongs echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD m4_default([$4], [AC_MSG_ERROR( [Package requirements ($2) were not met: $$1_PKG_ERRORS Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. _PKG_TEXT])dnl ]) elif test $pkg_failed = untried; then AC_MSG_RESULT([no]) m4_default([$4], [AC_MSG_FAILURE( [The pkg-config script could not be found or is too old. Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config. _PKG_TEXT To get pkg-config, see .])dnl ]) else $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS $1[]_LIBS=$pkg_cv_[]$1[]_LIBS AC_MSG_RESULT([yes]) $3 fi[]dnl ])# PKG_CHECK_MODULES libnih-1.0.3/m4/wchar_t.m40000644000175000017500000000132611461165270012117 00000000000000# wchar_t.m4 serial 1 (gettext-0.12) dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. dnl Test whether has the 'wchar_t' type. dnl Prerequisite: AC_PROG_CC AC_DEFUN([gt_TYPE_WCHAR_T], [ AC_CACHE_CHECK([for wchar_t], gt_cv_c_wchar_t, [AC_TRY_COMPILE([#include wchar_t foo = (wchar_t)'\0';], , gt_cv_c_wchar_t=yes, gt_cv_c_wchar_t=no)]) if test $gt_cv_c_wchar_t = yes; then AC_DEFINE(HAVE_WCHAR_T, 1, [Define if you have the 'wchar_t' type.]) fi ]) libnih-1.0.3/m4/ltversion.m40000644000175000017500000000127711461165274012526 00000000000000# ltversion.m4 -- version numbers -*- Autoconf -*- # # Copyright (C) 2004 Free Software Foundation, Inc. # Written by Scott James Remnant, 2004 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # Generated from ltversion.in. # serial 3017 ltversion.m4 # This file is part of GNU Libtool m4_define([LT_PACKAGE_VERSION], [2.2.6b]) m4_define([LT_PACKAGE_REVISION], [1.3017]) AC_DEFUN([LTVERSION_VERSION], [macro_version='2.2.6b' macro_revision='1.3017' _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) _LT_DECL(, macro_revision, 0) ]) libnih-1.0.3/m4/ltoptions.m40000644000175000017500000002724211461165274012534 00000000000000# Helper functions for option handling. -*- Autoconf -*- # # Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. # Written by Gary V. Vaughan, 2004 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # serial 6 ltoptions.m4 # This is to help aclocal find these macros, as it can't see m4_define. AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) # _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME) # ------------------------------------------ m4_define([_LT_MANGLE_OPTION], [[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])]) # _LT_SET_OPTION(MACRO-NAME, OPTION-NAME) # --------------------------------------- # Set option OPTION-NAME for macro MACRO-NAME, and if there is a # matching handler defined, dispatch to it. Other OPTION-NAMEs are # saved as a flag. m4_define([_LT_SET_OPTION], [m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]), _LT_MANGLE_DEFUN([$1], [$2]), [m4_warning([Unknown $1 option `$2'])])[]dnl ]) # _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET]) # ------------------------------------------------------------ # Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. m4_define([_LT_IF_OPTION], [m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])]) # _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET) # ------------------------------------------------------- # Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME # are set. m4_define([_LT_UNLESS_OPTIONS], [m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option), [m4_define([$0_found])])])[]dnl m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3 ])[]dnl ]) # _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST) # ---------------------------------------- # OPTION-LIST is a space-separated list of Libtool options associated # with MACRO-NAME. If any OPTION has a matching handler declared with # LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about # the unknown option and exit. m4_defun([_LT_SET_OPTIONS], [# Set options m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), [_LT_SET_OPTION([$1], _LT_Option)]) m4_if([$1],[LT_INIT],[ dnl dnl Simply set some default values (i.e off) if boolean options were not dnl specified: _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no ]) _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no ]) dnl dnl If no reference was made to various pairs of opposing options, then dnl we run the default mode handler for the pair. For example, if neither dnl `shared' nor `disable-shared' was passed, we enable building of shared dnl archives by default: _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED]) _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC]) _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC]) _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install], [_LT_ENABLE_FAST_INSTALL]) ]) ])# _LT_SET_OPTIONS ## --------------------------------- ## ## Macros to handle LT_INIT options. ## ## --------------------------------- ## # _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME) # ----------------------------------------- m4_define([_LT_MANGLE_DEFUN], [[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])]) # LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE) # ----------------------------------------------- m4_define([LT_OPTION_DEFINE], [m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl ])# LT_OPTION_DEFINE # dlopen # ------ LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes ]) AU_DEFUN([AC_LIBTOOL_DLOPEN], [_LT_SET_OPTION([LT_INIT], [dlopen]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the `dlopen' option into LT_INIT's first parameter.]) ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], []) # win32-dll # --------- # Declare package support for building win32 dll's. LT_OPTION_DEFINE([LT_INIT], [win32-dll], [enable_win32_dll=yes case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-cegcc*) AC_CHECK_TOOL(AS, as, false) AC_CHECK_TOOL(DLLTOOL, dlltool, false) AC_CHECK_TOOL(OBJDUMP, objdump, false) ;; esac test -z "$AS" && AS=as _LT_DECL([], [AS], [0], [Assembler program])dnl test -z "$DLLTOOL" && DLLTOOL=dlltool _LT_DECL([], [DLLTOOL], [0], [DLL creation program])dnl test -z "$OBJDUMP" && OBJDUMP=objdump _LT_DECL([], [OBJDUMP], [0], [Object dumper program])dnl ])# win32-dll AU_DEFUN([AC_LIBTOOL_WIN32_DLL], [AC_REQUIRE([AC_CANONICAL_HOST])dnl _LT_SET_OPTION([LT_INIT], [win32-dll]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the `win32-dll' option into LT_INIT's first parameter.]) ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], []) # _LT_ENABLE_SHARED([DEFAULT]) # ---------------------------- # implement the --enable-shared flag, and supports the `shared' and # `disable-shared' LT_INIT options. # DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. m4_define([_LT_ENABLE_SHARED], [m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl AC_ARG_ENABLE([shared], [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@], [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])], [p=${PACKAGE-default} case $enableval in yes) enable_shared=yes ;; no) enable_shared=no ;; *) enable_shared=no # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for pkg in $enableval; do IFS="$lt_save_ifs" if test "X$pkg" = "X$p"; then enable_shared=yes fi done IFS="$lt_save_ifs" ;; esac], [enable_shared=]_LT_ENABLE_SHARED_DEFAULT) _LT_DECL([build_libtool_libs], [enable_shared], [0], [Whether or not to build shared libraries]) ])# _LT_ENABLE_SHARED LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])]) LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])]) # Old names: AC_DEFUN([AC_ENABLE_SHARED], [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared]) ]) AC_DEFUN([AC_DISABLE_SHARED], [_LT_SET_OPTION([LT_INIT], [disable-shared]) ]) AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AM_ENABLE_SHARED], []) dnl AC_DEFUN([AM_DISABLE_SHARED], []) # _LT_ENABLE_STATIC([DEFAULT]) # ---------------------------- # implement the --enable-static flag, and support the `static' and # `disable-static' LT_INIT options. # DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. m4_define([_LT_ENABLE_STATIC], [m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl AC_ARG_ENABLE([static], [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@], [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])], [p=${PACKAGE-default} case $enableval in yes) enable_static=yes ;; no) enable_static=no ;; *) enable_static=no # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for pkg in $enableval; do IFS="$lt_save_ifs" if test "X$pkg" = "X$p"; then enable_static=yes fi done IFS="$lt_save_ifs" ;; esac], [enable_static=]_LT_ENABLE_STATIC_DEFAULT) _LT_DECL([build_old_libs], [enable_static], [0], [Whether or not to build static libraries]) ])# _LT_ENABLE_STATIC LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])]) LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])]) # Old names: AC_DEFUN([AC_ENABLE_STATIC], [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static]) ]) AC_DEFUN([AC_DISABLE_STATIC], [_LT_SET_OPTION([LT_INIT], [disable-static]) ]) AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AM_ENABLE_STATIC], []) dnl AC_DEFUN([AM_DISABLE_STATIC], []) # _LT_ENABLE_FAST_INSTALL([DEFAULT]) # ---------------------------------- # implement the --enable-fast-install flag, and support the `fast-install' # and `disable-fast-install' LT_INIT options. # DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. m4_define([_LT_ENABLE_FAST_INSTALL], [m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl AC_ARG_ENABLE([fast-install], [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], [p=${PACKAGE-default} case $enableval in yes) enable_fast_install=yes ;; no) enable_fast_install=no ;; *) enable_fast_install=no # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for pkg in $enableval; do IFS="$lt_save_ifs" if test "X$pkg" = "X$p"; then enable_fast_install=yes fi done IFS="$lt_save_ifs" ;; esac], [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT) _LT_DECL([fast_install], [enable_fast_install], [0], [Whether or not to optimize for fast installation])dnl ])# _LT_ENABLE_FAST_INSTALL LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])]) LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])]) # Old names: AU_DEFUN([AC_ENABLE_FAST_INSTALL], [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the `fast-install' option into LT_INIT's first parameter.]) ]) AU_DEFUN([AC_DISABLE_FAST_INSTALL], [_LT_SET_OPTION([LT_INIT], [disable-fast-install]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the `disable-fast-install' option into LT_INIT's first parameter.]) ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], []) dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], []) # _LT_WITH_PIC([MODE]) # -------------------- # implement the --with-pic flag, and support the `pic-only' and `no-pic' # LT_INIT options. # MODE is either `yes' or `no'. If omitted, it defaults to `both'. m4_define([_LT_WITH_PIC], [AC_ARG_WITH([pic], [AS_HELP_STRING([--with-pic], [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], [pic_mode="$withval"], [pic_mode=default]) test -z "$pic_mode" && pic_mode=m4_default([$1], [default]) _LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl ])# _LT_WITH_PIC LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])]) LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])]) # Old name: AU_DEFUN([AC_LIBTOOL_PICMODE], [_LT_SET_OPTION([LT_INIT], [pic-only]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the `pic-only' option into LT_INIT's first parameter.]) ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_PICMODE], []) ## ----------------- ## ## LTDL_INIT Options ## ## ----------------- ## m4_define([_LTDL_MODE], []) LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive], [m4_define([_LTDL_MODE], [nonrecursive])]) LT_OPTION_DEFINE([LTDL_INIT], [recursive], [m4_define([_LTDL_MODE], [recursive])]) LT_OPTION_DEFINE([LTDL_INIT], [subproject], [m4_define([_LTDL_MODE], [subproject])]) m4_define([_LTDL_TYPE], []) LT_OPTION_DEFINE([LTDL_INIT], [installable], [m4_define([_LTDL_TYPE], [installable])]) LT_OPTION_DEFINE([LTDL_INIT], [convenience], [m4_define([_LTDL_TYPE], [convenience])]) libnih-1.0.3/m4/visibility.m40000644000175000017500000000413011461165270012653 00000000000000# visibility.m4 serial 1 (gettext-0.15) dnl Copyright (C) 2005 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. dnl Tests whether the compiler supports the command-line option dnl -fvisibility=hidden and the function and variable attributes dnl __attribute__((__visibility__("hidden"))) and dnl __attribute__((__visibility__("default"))). dnl Does *not* test for __visibility__("protected") - which has tricky dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on dnl MacOS X. dnl Does *not* test for __visibility__("internal") - which has processor dnl dependent semantics. dnl Does *not* test for #pragma GCC visibility push(hidden) - which is dnl "really only recommended for legacy code". dnl Set the variable CFLAG_VISIBILITY. dnl Defines and sets the variable HAVE_VISIBILITY. AC_DEFUN([gl_VISIBILITY], [ AC_REQUIRE([AC_PROG_CC]) CFLAG_VISIBILITY= HAVE_VISIBILITY=0 if test -n "$GCC"; then AC_MSG_CHECKING([for simple visibility declarations]) AC_CACHE_VAL(gl_cv_cc_visibility, [ gl_save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -fvisibility=hidden" AC_TRY_COMPILE( [extern __attribute__((__visibility__("hidden"))) int hiddenvar; extern __attribute__((__visibility__("default"))) int exportedvar; extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void); extern __attribute__((__visibility__("default"))) int exportedfunc (void);], [], gl_cv_cc_visibility=yes, gl_cv_cc_visibility=no) CFLAGS="$gl_save_CFLAGS"]) AC_MSG_RESULT([$gl_cv_cc_visibility]) if test $gl_cv_cc_visibility = yes; then CFLAG_VISIBILITY="-fvisibility=hidden" HAVE_VISIBILITY=1 fi fi AC_SUBST([CFLAG_VISIBILITY]) AC_SUBST([HAVE_VISIBILITY]) AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY], [Define to 1 or 0, depending whether the compiler supports simple visibility declarations.]) ]) libnih-1.0.3/m4/intdiv0.m40000644000175000017500000000443111461165270012045 00000000000000# intdiv0.m4 serial 2 (gettext-0.17) dnl Copyright (C) 2002, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. AC_DEFUN([gt_INTDIV0], [ AC_REQUIRE([AC_PROG_CC])dnl AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_CACHE_CHECK([whether integer division by zero raises SIGFPE], gt_cv_int_divbyzero_sigfpe, [ gt_cv_int_divbyzero_sigfpe= changequote(,)dnl case "$host_os" in macos* | darwin[6-9]* | darwin[1-9][0-9]*) # On MacOS X 10.2 or newer, just assume the same as when cross- # compiling. If we were to perform the real test, 1 Crash Report # dialog window would pop up. case "$host_cpu" in i[34567]86 | x86_64) gt_cv_int_divbyzero_sigfpe="guessing yes" ;; esac ;; esac changequote([,])dnl if test -z "$gt_cv_int_divbyzero_sigfpe"; then AC_TRY_RUN([ #include #include static void sigfpe_handler (int sig) { /* Exit with code 0 if SIGFPE, with code 1 if any other signal. */ exit (sig != SIGFPE); } int x = 1; int y = 0; int z; int nan; int main () { signal (SIGFPE, sigfpe_handler); /* IRIX and AIX (when "xlc -qcheck" is used) yield signal SIGTRAP. */ #if (defined (__sgi) || defined (_AIX)) && defined (SIGTRAP) signal (SIGTRAP, sigfpe_handler); #endif /* Linux/SPARC yields signal SIGILL. */ #if defined (__sparc__) && defined (__linux__) signal (SIGILL, sigfpe_handler); #endif z = x / y; nan = y / y; exit (1); } ], gt_cv_int_divbyzero_sigfpe=yes, gt_cv_int_divbyzero_sigfpe=no, [ # Guess based on the CPU. changequote(,)dnl case "$host_cpu" in alpha* | i[34567]86 | x86_64 | m68k | s390*) gt_cv_int_divbyzero_sigfpe="guessing yes";; *) gt_cv_int_divbyzero_sigfpe="guessing no";; esac changequote([,])dnl ]) fi ]) case "$gt_cv_int_divbyzero_sigfpe" in *yes) value=1;; *) value=0;; esac AC_DEFINE_UNQUOTED(INTDIV0_RAISES_SIGFPE, $value, [Define if integer division by zero raises signal SIGFPE.]) ]) libnih-1.0.3/m4/iconv.m40000644000175000017500000001375311461165270011615 00000000000000# iconv.m4 serial AM6 (gettext-0.17) dnl Copyright (C) 2000-2002, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. AC_DEFUN([AM_ICONV_LINKFLAGS_BODY], [ dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) AC_REQUIRE([AC_LIB_RPATH]) dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV dnl accordingly. AC_LIB_LINKFLAGS_BODY([iconv]) ]) AC_DEFUN([AM_ICONV_LINK], [ dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and dnl those with the standalone portable GNU libiconv installed). AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV dnl accordingly. AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY]) dnl Add $INCICONV to CPPFLAGS before performing the following checks, dnl because if the user has installed libiconv and not disabled its use dnl via --without-libiconv-prefix, he wants to use it. The first dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed. am_save_CPPFLAGS="$CPPFLAGS" AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV]) AC_CACHE_CHECK([for iconv], am_cv_func_iconv, [ am_cv_func_iconv="no, consider installing GNU libiconv" am_cv_lib_iconv=no AC_TRY_LINK([#include #include ], [iconv_t cd = iconv_open("",""); iconv(cd,NULL,NULL,NULL,NULL); iconv_close(cd);], am_cv_func_iconv=yes) if test "$am_cv_func_iconv" != yes; then am_save_LIBS="$LIBS" LIBS="$LIBS $LIBICONV" AC_TRY_LINK([#include #include ], [iconv_t cd = iconv_open("",""); iconv(cd,NULL,NULL,NULL,NULL); iconv_close(cd);], am_cv_lib_iconv=yes am_cv_func_iconv=yes) LIBS="$am_save_LIBS" fi ]) if test "$am_cv_func_iconv" = yes; then AC_CACHE_CHECK([for working iconv], am_cv_func_iconv_works, [ dnl This tests against bugs in AIX 5.1 and HP-UX 11.11. am_save_LIBS="$LIBS" if test $am_cv_lib_iconv = yes; then LIBS="$LIBS $LIBICONV" fi AC_TRY_RUN([ #include #include int main () { /* Test against AIX 5.1 bug: Failures are not distinguishable from successful returns. */ { iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8"); if (cd_utf8_to_88591 != (iconv_t)(-1)) { static const char input[] = "\342\202\254"; /* EURO SIGN */ char buf[10]; const char *inptr = input; size_t inbytesleft = strlen (input); char *outptr = buf; size_t outbytesleft = sizeof (buf); size_t res = iconv (cd_utf8_to_88591, (char **) &inptr, &inbytesleft, &outptr, &outbytesleft); if (res == 0) return 1; } } #if 0 /* This bug could be worked around by the caller. */ /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */ { iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591"); if (cd_88591_to_utf8 != (iconv_t)(-1)) { static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; char buf[50]; const char *inptr = input; size_t inbytesleft = strlen (input); char *outptr = buf; size_t outbytesleft = sizeof (buf); size_t res = iconv (cd_88591_to_utf8, (char **) &inptr, &inbytesleft, &outptr, &outbytesleft); if ((int)res > 0) return 1; } } #endif /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is provided. */ if (/* Try standardized names. */ iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1) /* Try IRIX, OSF/1 names. */ && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1) /* Try AIX names. */ && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1) /* Try HP-UX names. */ && iconv_open ("utf8", "eucJP") == (iconv_t)(-1)) return 1; return 0; }], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no], [case "$host_os" in aix* | hpux*) am_cv_func_iconv_works="guessing no" ;; *) am_cv_func_iconv_works="guessing yes" ;; esac]) LIBS="$am_save_LIBS" ]) case "$am_cv_func_iconv_works" in *no) am_func_iconv=no am_cv_lib_iconv=no ;; *) am_func_iconv=yes ;; esac else am_func_iconv=no am_cv_lib_iconv=no fi if test "$am_func_iconv" = yes; then AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function and it works.]) fi if test "$am_cv_lib_iconv" = yes; then AC_MSG_CHECKING([how to link with libiconv]) AC_MSG_RESULT([$LIBICONV]) else dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV dnl either. CPPFLAGS="$am_save_CPPFLAGS" LIBICONV= LTLIBICONV= fi AC_SUBST(LIBICONV) AC_SUBST(LTLIBICONV) ]) AC_DEFUN([AM_ICONV], [ AM_ICONV_LINK if test "$am_cv_func_iconv" = yes; then AC_MSG_CHECKING([for iconv declaration]) AC_CACHE_VAL(am_cv_proto_iconv, [ AC_TRY_COMPILE([ #include #include extern #ifdef __cplusplus "C" #endif #if defined(__STDC__) || defined(__cplusplus) size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); #else size_t iconv(); #endif ], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const") am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"]) am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'` AC_MSG_RESULT([$]{ac_t:- }[$]am_cv_proto_iconv) AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1, [Define as const if the declaration of iconv() needs const.]) fi ]) libnih-1.0.3/m4/xsize.m40000644000175000017500000000064511461165270011635 00000000000000# xsize.m4 serial 3 dnl Copyright (C) 2003-2004 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_XSIZE], [ dnl Prerequisites of lib/xsize.h. AC_REQUIRE([gl_SIZE_MAX]) AC_REQUIRE([AC_C_INLINE]) AC_CHECK_HEADERS(stdint.h) ]) libnih-1.0.3/m4/glibc2.m40000644000175000017500000000135411461165270011633 00000000000000# glibc2.m4 serial 1 dnl Copyright (C) 2000-2002, 2004 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. # Test for the GNU C Library, version 2.0 or newer. # From Bruno Haible. AC_DEFUN([gt_GLIBC2], [ AC_CACHE_CHECK(whether we are using the GNU C Library 2 or newer, ac_cv_gnu_library_2, [AC_EGREP_CPP([Lucky GNU user], [ #include #ifdef __GNU_LIBRARY__ #if (__GLIBC__ >= 2) Lucky GNU user #endif #endif ], ac_cv_gnu_library_2=yes, ac_cv_gnu_library_2=no) ] ) AC_SUBST(GLIBC2) GLIBC2="$ac_cv_gnu_library_2" ] ) libnih-1.0.3/m4/intl.m40000644000175000017500000002525011461165270011440 00000000000000# intl.m4 serial 8 (gettext-0.17) dnl Copyright (C) 1995-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl dnl This file can can be used in projects which are not available under dnl the GNU General Public License or the GNU Library General Public dnl License but which still want to provide support for the GNU gettext dnl functionality. dnl Please note that the actual code of the GNU gettext library is covered dnl by the GNU Library General Public License, and the rest of the GNU dnl gettext package package is covered by the GNU General Public License. dnl They are *not* in the public domain. dnl Authors: dnl Ulrich Drepper , 1995-2000. dnl Bruno Haible , 2000-2006. AC_PREREQ(2.52) dnl Checks for all prerequisites of the intl subdirectory, dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS, dnl USE_INCLUDED_LIBINTL, BUILD_INCLUDED_LIBINTL. AC_DEFUN([AM_INTL_SUBDIR], [ AC_REQUIRE([AC_PROG_INSTALL])dnl AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake AC_REQUIRE([AC_PROG_CC])dnl AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([gt_GLIBC2])dnl AC_REQUIRE([AC_PROG_RANLIB])dnl AC_REQUIRE([gl_VISIBILITY])dnl AC_REQUIRE([gt_INTL_SUBDIR_CORE])dnl AC_REQUIRE([AC_TYPE_LONG_LONG_INT])dnl AC_REQUIRE([gt_TYPE_WCHAR_T])dnl AC_REQUIRE([gt_TYPE_WINT_T])dnl AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) AC_REQUIRE([gt_TYPE_INTMAX_T]) AC_REQUIRE([gt_PRINTF_POSIX]) AC_REQUIRE([gl_GLIBC21])dnl AC_REQUIRE([gl_XSIZE])dnl AC_REQUIRE([gt_INTL_MACOSX])dnl AC_CHECK_TYPE([ptrdiff_t], , [AC_DEFINE([ptrdiff_t], [long], [Define as the type of the result of subtracting two pointers, if the system doesn't define it.]) ]) AC_CHECK_HEADERS([stddef.h stdlib.h string.h]) AC_CHECK_FUNCS([asprintf fwprintf putenv setenv setlocale snprintf wcslen]) dnl Use the _snprintf function only if it is declared (because on NetBSD it dnl is defined as a weak alias of snprintf; we prefer to use the latter). gt_CHECK_DECL(_snprintf, [#include ]) gt_CHECK_DECL(_snwprintf, [#include ]) dnl Use the *_unlocked functions only if they are declared. dnl (because some of them were defined without being declared in Solaris dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built dnl on Solaris 2.5.1 to run on Solaris 2.6). dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. gt_CHECK_DECL(getc_unlocked, [#include ]) case $gt_cv_func_printf_posix in *yes) HAVE_POSIX_PRINTF=1 ;; *) HAVE_POSIX_PRINTF=0 ;; esac AC_SUBST([HAVE_POSIX_PRINTF]) if test "$ac_cv_func_asprintf" = yes; then HAVE_ASPRINTF=1 else HAVE_ASPRINTF=0 fi AC_SUBST([HAVE_ASPRINTF]) if test "$ac_cv_func_snprintf" = yes; then HAVE_SNPRINTF=1 else HAVE_SNPRINTF=0 fi AC_SUBST([HAVE_SNPRINTF]) if test "$ac_cv_func_wprintf" = yes; then HAVE_WPRINTF=1 else HAVE_WPRINTF=0 fi AC_SUBST([HAVE_WPRINTF]) AM_LANGINFO_CODESET gt_LC_MESSAGES dnl Compilation on mingw and Cygwin needs special Makefile rules, because dnl 1. when we install a shared library, we must arrange to export dnl auxiliary pointer variables for every exported variable, dnl 2. when we install a shared library and a static library simultaneously, dnl the include file specifies __declspec(dllimport) and therefore we dnl must arrange to define the auxiliary pointer variables for the dnl exported variables _also_ in the static library. if test "$enable_shared" = yes; then case "$host_os" in mingw* | cygwin*) is_woe32dll=yes ;; *) is_woe32dll=no ;; esac else is_woe32dll=no fi WOE32DLL=$is_woe32dll AC_SUBST([WOE32DLL]) dnl On mingw and Cygwin, we can activate special Makefile rules which add dnl version information to the shared libraries and executables. case "$host_os" in mingw* | cygwin*) is_woe32=yes ;; *) is_woe32=no ;; esac WOE32=$is_woe32 AC_SUBST([WOE32]) if test $WOE32 = yes; then dnl Check for a program that compiles Windows resource files. AC_CHECK_TOOL([WINDRES], [windres]) fi dnl Determine whether when creating a library, "-lc" should be passed to dnl libtool or not. On many platforms, it is required for the libtool option dnl -no-undefined to work. On HP-UX, however, the -lc - stored by libtool dnl in the *.la files - makes it impossible to create multithreaded programs, dnl because libtool also reorders the -lc to come before the -pthread, and dnl this disables pthread_create() . case "$host_os" in hpux*) LTLIBC="" ;; *) LTLIBC="-lc" ;; esac AC_SUBST([LTLIBC]) dnl Rename some macros and functions used for locking. AH_BOTTOM([ #define __libc_lock_t gl_lock_t #define __libc_lock_define gl_lock_define #define __libc_lock_define_initialized gl_lock_define_initialized #define __libc_lock_init gl_lock_init #define __libc_lock_lock gl_lock_lock #define __libc_lock_unlock gl_lock_unlock #define __libc_lock_recursive_t gl_recursive_lock_t #define __libc_lock_define_recursive gl_recursive_lock_define #define __libc_lock_define_initialized_recursive gl_recursive_lock_define_initialized #define __libc_lock_init_recursive gl_recursive_lock_init #define __libc_lock_lock_recursive gl_recursive_lock_lock #define __libc_lock_unlock_recursive gl_recursive_lock_unlock #define glthread_in_use libintl_thread_in_use #define glthread_lock_init libintl_lock_init #define glthread_lock_lock libintl_lock_lock #define glthread_lock_unlock libintl_lock_unlock #define glthread_lock_destroy libintl_lock_destroy #define glthread_rwlock_init libintl_rwlock_init #define glthread_rwlock_rdlock libintl_rwlock_rdlock #define glthread_rwlock_wrlock libintl_rwlock_wrlock #define glthread_rwlock_unlock libintl_rwlock_unlock #define glthread_rwlock_destroy libintl_rwlock_destroy #define glthread_recursive_lock_init libintl_recursive_lock_init #define glthread_recursive_lock_lock libintl_recursive_lock_lock #define glthread_recursive_lock_unlock libintl_recursive_lock_unlock #define glthread_recursive_lock_destroy libintl_recursive_lock_destroy #define glthread_once libintl_once #define glthread_once_call libintl_once_call #define glthread_once_singlethreaded libintl_once_singlethreaded ]) ]) dnl Checks for the core files of the intl subdirectory: dnl dcigettext.c dnl eval-plural.h dnl explodename.c dnl finddomain.c dnl gettextP.h dnl gmo.h dnl hash-string.h hash-string.c dnl l10nflist.c dnl libgnuintl.h.in (except the *printf stuff) dnl loadinfo.h dnl loadmsgcat.c dnl localealias.c dnl log.c dnl plural-exp.h plural-exp.c dnl plural.y dnl Used by libglocale. AC_DEFUN([gt_INTL_SUBDIR_CORE], [ AC_REQUIRE([AC_C_INLINE])dnl AC_REQUIRE([AC_TYPE_SIZE_T])dnl AC_REQUIRE([gl_AC_HEADER_STDINT_H]) AC_REQUIRE([AC_FUNC_ALLOCA])dnl AC_REQUIRE([AC_FUNC_MMAP])dnl AC_REQUIRE([gt_INTDIV0])dnl AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])dnl AC_REQUIRE([gt_INTTYPES_PRI])dnl AC_REQUIRE([gl_LOCK])dnl AC_TRY_LINK( [int foo (int a) { a = __builtin_expect (a, 10); return a == 10 ? 0 : 1; }], [], [AC_DEFINE([HAVE_BUILTIN_EXPECT], 1, [Define to 1 if the compiler understands __builtin_expect.])]) AC_CHECK_HEADERS([argz.h inttypes.h limits.h unistd.h sys/param.h]) AC_CHECK_FUNCS([getcwd getegid geteuid getgid getuid mempcpy munmap \ stpcpy strcasecmp strdup strtoul tsearch argz_count argz_stringify \ argz_next __fsetlocking]) dnl Use the *_unlocked functions only if they are declared. dnl (because some of them were defined without being declared in Solaris dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built dnl on Solaris 2.5.1 to run on Solaris 2.6). dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. gt_CHECK_DECL(feof_unlocked, [#include ]) gt_CHECK_DECL(fgets_unlocked, [#include ]) AM_ICONV dnl glibc >= 2.4 has a NL_LOCALE_NAME macro when _GNU_SOURCE is defined, dnl and a _NL_LOCALE_NAME macro always. AC_CACHE_CHECK([for NL_LOCALE_NAME macro], gt_cv_nl_locale_name, [AC_TRY_LINK([#include #include ], [char* cs = nl_langinfo(_NL_LOCALE_NAME(LC_MESSAGES)); return !cs; ], gt_cv_nl_locale_name=yes, gt_cv_nl_locale_name=no) ]) if test $gt_cv_nl_locale_name = yes; then AC_DEFINE(HAVE_NL_LOCALE_NAME, 1, [Define if you have and it defines the NL_LOCALE_NAME macro if _GNU_SOURCE is defined.]) fi dnl intl/plural.c is generated from intl/plural.y. It requires bison, dnl because plural.y uses bison specific features. It requires at least dnl bison-1.26 because earlier versions generate a plural.c that doesn't dnl compile. dnl bison is only needed for the maintainer (who touches plural.y). But in dnl order to avoid separate Makefiles or --enable-maintainer-mode, we put dnl the rule in general Makefile. Now, some people carelessly touch the dnl files or have a broken "make" program, hence the plural.c rule will dnl sometimes fire. To avoid an error, defines BISON to ":" if it is not dnl present or too old. AC_CHECK_PROGS([INTLBISON], [bison]) if test -z "$INTLBISON"; then ac_verc_fail=yes else dnl Found it, now check the version. AC_MSG_CHECKING([version of bison]) changequote(<<,>>)dnl ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'` case $ac_prog_version in '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*) changequote([,])dnl ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; esac AC_MSG_RESULT([$ac_prog_version]) fi if test $ac_verc_fail = yes; then INTLBISON=: fi ]) dnl gt_CHECK_DECL(FUNC, INCLUDES) dnl Check whether a function is declared. AC_DEFUN([gt_CHECK_DECL], [ AC_CACHE_CHECK([whether $1 is declared], ac_cv_have_decl_$1, [AC_TRY_COMPILE([$2], [ #ifndef $1 char *p = (char *) $1; #endif ], ac_cv_have_decl_$1=yes, ac_cv_have_decl_$1=no)]) if test $ac_cv_have_decl_$1 = yes; then gt_value=1 else gt_value=0 fi AC_DEFINE_UNQUOTED([HAVE_DECL_]translit($1, [a-z], [A-Z]), [$gt_value], [Define to 1 if you have the declaration of `$1', and to 0 if you don't.]) ]) libnih-1.0.3/m4/libtool.m40000644000175000017500000077464711461165274012167 00000000000000# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, # 2006, 2007, 2008 Free Software Foundation, Inc. # Written by Gordon Matzigkeit, 1996 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. m4_define([_LT_COPYING], [dnl # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, # 2006, 2007, 2008 Free Software Foundation, Inc. # Written by Gordon Matzigkeit, 1996 # # This file is part of GNU Libtool. # # GNU Libtool is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # # As a special exception to the GNU General Public License, # if you distribute this file as part of a program or library that # is built using GNU Libtool, you may include this file under the # same distribution terms that you use for the rest of that program. # # GNU Libtool is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GNU Libtool; see the file COPYING. If not, a copy # can be downloaded from http://www.gnu.org/licenses/gpl.html, or # obtained by writing to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ]) # serial 56 LT_INIT # LT_PREREQ(VERSION) # ------------------ # Complain and exit if this libtool version is less that VERSION. m4_defun([LT_PREREQ], [m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1, [m4_default([$3], [m4_fatal([Libtool version $1 or higher is required], 63)])], [$2])]) # _LT_CHECK_BUILDDIR # ------------------ # Complain if the absolute build directory name contains unusual characters m4_defun([_LT_CHECK_BUILDDIR], [case `pwd` in *\ * | *\ *) AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;; esac ]) # LT_INIT([OPTIONS]) # ------------------ AC_DEFUN([LT_INIT], [AC_PREREQ([2.58])dnl We use AC_INCLUDES_DEFAULT AC_BEFORE([$0], [LT_LANG])dnl AC_BEFORE([$0], [LT_OUTPUT])dnl AC_BEFORE([$0], [LTDL_INIT])dnl m4_require([_LT_CHECK_BUILDDIR])dnl dnl Autoconf doesn't catch unexpanded LT_ macros by default: m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4 dnl unless we require an AC_DEFUNed macro: AC_REQUIRE([LTOPTIONS_VERSION])dnl AC_REQUIRE([LTSUGAR_VERSION])dnl AC_REQUIRE([LTVERSION_VERSION])dnl AC_REQUIRE([LTOBSOLETE_VERSION])dnl m4_require([_LT_PROG_LTMAIN])dnl dnl Parse OPTIONS _LT_SET_OPTIONS([$0], [$1]) # This can be used to rebuild libtool when needed LIBTOOL_DEPS="$ltmain" # Always use our own libtool. LIBTOOL='$(SHELL) $(top_builddir)/libtool' AC_SUBST(LIBTOOL)dnl _LT_SETUP # Only expand once: m4_define([LT_INIT]) ])# LT_INIT # Old names: AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT]) AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_PROG_LIBTOOL], []) dnl AC_DEFUN([AM_PROG_LIBTOOL], []) # _LT_CC_BASENAME(CC) # ------------------- # Calculate cc_basename. Skip known compiler wrappers and cross-prefix. m4_defun([_LT_CC_BASENAME], [for cc_temp in $1""; do case $cc_temp in compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;; distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;; \-*) ;; *) break;; esac done cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` ]) # _LT_FILEUTILS_DEFAULTS # ---------------------- # It is okay to use these file commands and assume they have been set # sensibly after `m4_require([_LT_FILEUTILS_DEFAULTS])'. m4_defun([_LT_FILEUTILS_DEFAULTS], [: ${CP="cp -f"} : ${MV="mv -f"} : ${RM="rm -f"} ])# _LT_FILEUTILS_DEFAULTS # _LT_SETUP # --------- m4_defun([_LT_SETUP], [AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([AC_CANONICAL_BUILD])dnl _LT_DECL([], [host_alias], [0], [The host system])dnl _LT_DECL([], [host], [0])dnl _LT_DECL([], [host_os], [0])dnl dnl _LT_DECL([], [build_alias], [0], [The build system])dnl _LT_DECL([], [build], [0])dnl _LT_DECL([], [build_os], [0])dnl dnl AC_REQUIRE([AC_PROG_CC])dnl AC_REQUIRE([LT_PATH_LD])dnl AC_REQUIRE([LT_PATH_NM])dnl dnl AC_REQUIRE([AC_PROG_LN_S])dnl test -z "$LN_S" && LN_S="ln -s" _LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl dnl AC_REQUIRE([LT_CMD_MAX_LEN])dnl _LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl _LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_CHECK_SHELL_FEATURES])dnl m4_require([_LT_CMD_RELOAD])dnl m4_require([_LT_CHECK_MAGIC_METHOD])dnl m4_require([_LT_CMD_OLD_ARCHIVE])dnl m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl _LT_CONFIG_LIBTOOL_INIT([ # See if we are running on zsh, and set the options which allow our # commands through without removal of \ escapes INIT. if test -n "\${ZSH_VERSION+set}" ; then setopt NO_GLOB_SUBST fi ]) if test -n "${ZSH_VERSION+set}" ; then setopt NO_GLOB_SUBST fi _LT_CHECK_OBJDIR m4_require([_LT_TAG_COMPILER])dnl _LT_PROG_ECHO_BACKSLASH case $host_os in aix3*) # AIX sometimes has problems with the GCC collect2 program. For some # reason, if we set the COLLECT_NAMES environment variable, the problems # vanish in a puff of smoke. if test "X${COLLECT_NAMES+set}" != Xset; then COLLECT_NAMES= export COLLECT_NAMES fi ;; esac # Sed substitution that helps us do robust quoting. It backslashifies # metacharacters that are still active within double-quoted strings. sed_quote_subst='s/\([["`$\\]]\)/\\\1/g' # Same as above, but do not quote variable references. double_quote_subst='s/\([["`\\]]\)/\\\1/g' # Sed substitution to delay expansion of an escaped shell variable in a # double_quote_subst'ed string. delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' # Sed substitution to delay expansion of an escaped single quote. delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' # Sed substitution to avoid accidental globbing in evaled expressions no_glob_subst='s/\*/\\\*/g' # Global variables: ofile=libtool can_build_shared=yes # All known linkers require a `.a' archive for static linking (except MSVC, # which needs '.lib'). libext=a with_gnu_ld="$lt_cv_prog_gnu_ld" old_CC="$CC" old_CFLAGS="$CFLAGS" # Set sane defaults for various variables test -z "$CC" && CC=cc test -z "$LTCC" && LTCC=$CC test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS test -z "$LD" && LD=ld test -z "$ac_objext" && ac_objext=o _LT_CC_BASENAME([$compiler]) # Only perform the check for file, if the check method requires it test -z "$MAGIC_CMD" && MAGIC_CMD=file case $deplibs_check_method in file_magic*) if test "$file_magic_cmd" = '$MAGIC_CMD'; then _LT_PATH_MAGIC fi ;; esac # Use C for the default configuration in the libtool script LT_SUPPORTED_TAG([CC]) _LT_LANG_C_CONFIG _LT_LANG_DEFAULT_CONFIG _LT_CONFIG_COMMANDS ])# _LT_SETUP # _LT_PROG_LTMAIN # --------------- # Note that this code is called both from `configure', and `config.status' # now that we use AC_CONFIG_COMMANDS to generate libtool. Notably, # `config.status' has no value for ac_aux_dir unless we are using Automake, # so we pass a copy along to make sure it has a sensible value anyway. m4_defun([_LT_PROG_LTMAIN], [m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl _LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir']) ltmain="$ac_aux_dir/ltmain.sh" ])# _LT_PROG_LTMAIN ## ------------------------------------- ## ## Accumulate code for creating libtool. ## ## ------------------------------------- ## # So that we can recreate a full libtool script including additional # tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS # in macros and then make a single call at the end using the `libtool' # label. # _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS]) # ---------------------------------------- # Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later. m4_define([_LT_CONFIG_LIBTOOL_INIT], [m4_ifval([$1], [m4_append([_LT_OUTPUT_LIBTOOL_INIT], [$1 ])])]) # Initialize. m4_define([_LT_OUTPUT_LIBTOOL_INIT]) # _LT_CONFIG_LIBTOOL([COMMANDS]) # ------------------------------ # Register COMMANDS to be passed to AC_CONFIG_COMMANDS later. m4_define([_LT_CONFIG_LIBTOOL], [m4_ifval([$1], [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS], [$1 ])])]) # Initialize. m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS]) # _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS]) # ----------------------------------------------------- m4_defun([_LT_CONFIG_SAVE_COMMANDS], [_LT_CONFIG_LIBTOOL([$1]) _LT_CONFIG_LIBTOOL_INIT([$2]) ]) # _LT_FORMAT_COMMENT([COMMENT]) # ----------------------------- # Add leading comment marks to the start of each line, and a trailing # full-stop to the whole comment if one is not present already. m4_define([_LT_FORMAT_COMMENT], [m4_ifval([$1], [ m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])], [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.]) )]) ## ------------------------ ## ## FIXME: Eliminate VARNAME ## ## ------------------------ ## # _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?]) # ------------------------------------------------------------------- # CONFIGNAME is the name given to the value in the libtool script. # VARNAME is the (base) name used in the configure script. # VALUE may be 0, 1 or 2 for a computed quote escaped value based on # VARNAME. Any other value will be used directly. m4_define([_LT_DECL], [lt_if_append_uniq([lt_decl_varnames], [$2], [, ], [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name], [m4_ifval([$1], [$1], [$2])]) lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3]) m4_ifval([$4], [lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])]) lt_dict_add_subkey([lt_decl_dict], [$2], [tagged?], [m4_ifval([$5], [yes], [no])])]) ]) # _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION]) # -------------------------------------------------------- m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])]) # lt_decl_tag_varnames([SEPARATOR], [VARNAME1...]) # ------------------------------------------------ m4_define([lt_decl_tag_varnames], [_lt_decl_filter([tagged?], [yes], $@)]) # _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..]) # --------------------------------------------------------- m4_define([_lt_decl_filter], [m4_case([$#], [0], [m4_fatal([$0: too few arguments: $#])], [1], [m4_fatal([$0: too few arguments: $#: $1])], [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)], [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)], [lt_dict_filter([lt_decl_dict], $@)])[]dnl ]) # lt_decl_quote_varnames([SEPARATOR], [VARNAME1...]) # -------------------------------------------------- m4_define([lt_decl_quote_varnames], [_lt_decl_filter([value], [1], $@)]) # lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...]) # --------------------------------------------------- m4_define([lt_decl_dquote_varnames], [_lt_decl_filter([value], [2], $@)]) # lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...]) # --------------------------------------------------- m4_define([lt_decl_varnames_tagged], [m4_assert([$# <= 2])dnl _$0(m4_quote(m4_default([$1], [[, ]])), m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]), m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))]) m4_define([_lt_decl_varnames_tagged], [m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])]) # lt_decl_all_varnames([SEPARATOR], [VARNAME1...]) # ------------------------------------------------ m4_define([lt_decl_all_varnames], [_$0(m4_quote(m4_default([$1], [[, ]])), m4_if([$2], [], m4_quote(lt_decl_varnames), m4_quote(m4_shift($@))))[]dnl ]) m4_define([_lt_decl_all_varnames], [lt_join($@, lt_decl_varnames_tagged([$1], lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl ]) # _LT_CONFIG_STATUS_DECLARE([VARNAME]) # ------------------------------------ # Quote a variable value, and forward it to `config.status' so that its # declaration there will have the same value as in `configure'. VARNAME # must have a single quote delimited value for this to work. m4_define([_LT_CONFIG_STATUS_DECLARE], [$1='`$ECHO "X$][$1" | $Xsed -e "$delay_single_quote_subst"`']) # _LT_CONFIG_STATUS_DECLARATIONS # ------------------------------ # We delimit libtool config variables with single quotes, so when # we write them to config.status, we have to be sure to quote all # embedded single quotes properly. In configure, this macro expands # each variable declared with _LT_DECL (and _LT_TAGDECL) into: # # ='`$ECHO "X$" | $Xsed -e "$delay_single_quote_subst"`' m4_defun([_LT_CONFIG_STATUS_DECLARATIONS], [m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames), [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])]) # _LT_LIBTOOL_TAGS # ---------------- # Output comment and list of tags supported by the script m4_defun([_LT_LIBTOOL_TAGS], [_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl available_tags="_LT_TAGS"dnl ]) # _LT_LIBTOOL_DECLARE(VARNAME, [TAG]) # ----------------------------------- # Extract the dictionary values for VARNAME (optionally with TAG) and # expand to a commented shell variable setting: # # # Some comment about what VAR is for. # visible_name=$lt_internal_name m4_define([_LT_LIBTOOL_DECLARE], [_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [description])))[]dnl m4_pushdef([_libtool_name], m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])), [0], [_libtool_name=[$]$1], [1], [_libtool_name=$lt_[]$1], [2], [_libtool_name=$lt_[]$1], [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl ]) # _LT_LIBTOOL_CONFIG_VARS # ----------------------- # Produce commented declarations of non-tagged libtool config variables # suitable for insertion in the LIBTOOL CONFIG section of the `libtool' # script. Tagged libtool config variables (even for the LIBTOOL CONFIG # section) are produced by _LT_LIBTOOL_TAG_VARS. m4_defun([_LT_LIBTOOL_CONFIG_VARS], [m4_foreach([_lt_var], m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)), [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])]) # _LT_LIBTOOL_TAG_VARS(TAG) # ------------------------- m4_define([_LT_LIBTOOL_TAG_VARS], [m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames), [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])]) # _LT_TAGVAR(VARNAME, [TAGNAME]) # ------------------------------ m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])]) # _LT_CONFIG_COMMANDS # ------------------- # Send accumulated output to $CONFIG_STATUS. Thanks to the lists of # variables for single and double quote escaping we saved from calls # to _LT_DECL, we can put quote escaped variables declarations # into `config.status', and then the shell code to quote escape them in # for loops in `config.status'. Finally, any additional code accumulated # from calls to _LT_CONFIG_LIBTOOL_INIT is expanded. m4_defun([_LT_CONFIG_COMMANDS], [AC_PROVIDE_IFELSE([LT_OUTPUT], dnl If the libtool generation code has been placed in $CONFIG_LT, dnl instead of duplicating it all over again into config.status, dnl then we will have config.status run $CONFIG_LT later, so it dnl needs to know what name is stored there: [AC_CONFIG_COMMANDS([libtool], [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])], dnl If the libtool generation code is destined for config.status, dnl expand the accumulated commands and init code now: [AC_CONFIG_COMMANDS([libtool], [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])]) ])#_LT_CONFIG_COMMANDS # Initialize. m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT], [ # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH sed_quote_subst='$sed_quote_subst' double_quote_subst='$double_quote_subst' delay_variable_subst='$delay_variable_subst' _LT_CONFIG_STATUS_DECLARATIONS LTCC='$LTCC' LTCFLAGS='$LTCFLAGS' compiler='$compiler_DEFAULT' # Quote evaled strings. for var in lt_decl_all_varnames([[ \ ]], lt_decl_quote_varnames); do case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in *[[\\\\\\\`\\"\\\$]]*) eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" ;; *) eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" ;; esac done # Double-quote double-evaled strings. for var in lt_decl_all_varnames([[ \ ]], lt_decl_dquote_varnames); do case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in *[[\\\\\\\`\\"\\\$]]*) eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" ;; *) eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" ;; esac done # Fix-up fallback echo if it was mangled by the above quoting rules. case \$lt_ECHO in *'\\\[$]0 --fallback-echo"')dnl " lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\[$]0 --fallback-echo"\[$]/\[$]0 --fallback-echo"/'\` ;; esac _LT_OUTPUT_LIBTOOL_INIT ]) # LT_OUTPUT # --------- # This macro allows early generation of the libtool script (before # AC_OUTPUT is called), incase it is used in configure for compilation # tests. AC_DEFUN([LT_OUTPUT], [: ${CONFIG_LT=./config.lt} AC_MSG_NOTICE([creating $CONFIG_LT]) cat >"$CONFIG_LT" <<_LTEOF #! $SHELL # Generated by $as_me. # Run this file to recreate a libtool stub with the current configuration. lt_cl_silent=false SHELL=\${CONFIG_SHELL-$SHELL} _LTEOF cat >>"$CONFIG_LT" <<\_LTEOF AS_SHELL_SANITIZE _AS_PREPARE exec AS_MESSAGE_FD>&1 exec AS_MESSAGE_LOG_FD>>config.log { echo AS_BOX([Running $as_me.]) } >&AS_MESSAGE_LOG_FD lt_cl_help="\ \`$as_me' creates a local libtool stub from the current configuration, for use in further configure time tests before the real libtool is generated. Usage: $[0] [[OPTIONS]] -h, --help print this help, then exit -V, --version print version number, then exit -q, --quiet do not print progress messages -d, --debug don't remove temporary files Report bugs to ." lt_cl_version="\ m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION]) configured by $[0], generated by m4_PACKAGE_STRING. Copyright (C) 2008 Free Software Foundation, Inc. This config.lt script is free software; the Free Software Foundation gives unlimited permision to copy, distribute and modify it." while test $[#] != 0 do case $[1] in --version | --v* | -V ) echo "$lt_cl_version"; exit 0 ;; --help | --h* | -h ) echo "$lt_cl_help"; exit 0 ;; --debug | --d* | -d ) debug=: ;; --quiet | --q* | --silent | --s* | -q ) lt_cl_silent=: ;; -*) AC_MSG_ERROR([unrecognized option: $[1] Try \`$[0] --help' for more information.]) ;; *) AC_MSG_ERROR([unrecognized argument: $[1] Try \`$[0] --help' for more information.]) ;; esac shift done if $lt_cl_silent; then exec AS_MESSAGE_FD>/dev/null fi _LTEOF cat >>"$CONFIG_LT" <<_LTEOF _LT_OUTPUT_LIBTOOL_COMMANDS_INIT _LTEOF cat >>"$CONFIG_LT" <<\_LTEOF AC_MSG_NOTICE([creating $ofile]) _LT_OUTPUT_LIBTOOL_COMMANDS AS_EXIT(0) _LTEOF chmod +x "$CONFIG_LT" # configure is writing to config.log, but config.lt does its own redirection, # appending to config.log, which fails on DOS, as config.log is still kept # open by configure. Here we exec the FD to /dev/null, effectively closing # config.log, so it can be properly (re)opened and appended to by config.lt. if test "$no_create" != yes; then lt_cl_success=: test "$silent" = yes && lt_config_lt_args="$lt_config_lt_args --quiet" exec AS_MESSAGE_LOG_FD>/dev/null $SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false exec AS_MESSAGE_LOG_FD>>config.log $lt_cl_success || AS_EXIT(1) fi ])# LT_OUTPUT # _LT_CONFIG(TAG) # --------------- # If TAG is the built-in tag, create an initial libtool script with a # default configuration from the untagged config vars. Otherwise add code # to config.status for appending the configuration named by TAG from the # matching tagged config vars. m4_defun([_LT_CONFIG], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl _LT_CONFIG_SAVE_COMMANDS([ m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl m4_if(_LT_TAG, [C], [ # See if we are running on zsh, and set the options which allow our # commands through without removal of \ escapes. if test -n "${ZSH_VERSION+set}" ; then setopt NO_GLOB_SUBST fi cfgfile="${ofile}T" trap "$RM \"$cfgfile\"; exit 1" 1 2 15 $RM "$cfgfile" cat <<_LT_EOF >> "$cfgfile" #! $SHELL # `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services. # Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION # Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # _LT_COPYING _LT_LIBTOOL_TAGS # ### BEGIN LIBTOOL CONFIG _LT_LIBTOOL_CONFIG_VARS _LT_LIBTOOL_TAG_VARS # ### END LIBTOOL CONFIG _LT_EOF case $host_os in aix3*) cat <<\_LT_EOF >> "$cfgfile" # AIX sometimes has problems with the GCC collect2 program. For some # reason, if we set the COLLECT_NAMES environment variable, the problems # vanish in a puff of smoke. if test "X${COLLECT_NAMES+set}" != Xset; then COLLECT_NAMES= export COLLECT_NAMES fi _LT_EOF ;; esac _LT_PROG_LTMAIN # We use sed instead of cat because bash on DJGPP gets confused if # if finds mixed CR/LF and LF-only lines. Since sed operates in # text mode, it properly converts lines to CR/LF. This bash problem # is reportedly fixed, but why not run on old versions too? sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \ || (rm -f "$cfgfile"; exit 1) _LT_PROG_XSI_SHELLFNS sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \ || (rm -f "$cfgfile"; exit 1) mv -f "$cfgfile" "$ofile" || (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") chmod +x "$ofile" ], [cat <<_LT_EOF >> "$ofile" dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded dnl in a comment (ie after a #). # ### BEGIN LIBTOOL TAG CONFIG: $1 _LT_LIBTOOL_TAG_VARS(_LT_TAG) # ### END LIBTOOL TAG CONFIG: $1 _LT_EOF ])dnl /m4_if ], [m4_if([$1], [], [ PACKAGE='$PACKAGE' VERSION='$VERSION' TIMESTAMP='$TIMESTAMP' RM='$RM' ofile='$ofile'], []) ])dnl /_LT_CONFIG_SAVE_COMMANDS ])# _LT_CONFIG # LT_SUPPORTED_TAG(TAG) # --------------------- # Trace this macro to discover what tags are supported by the libtool # --tag option, using: # autoconf --trace 'LT_SUPPORTED_TAG:$1' AC_DEFUN([LT_SUPPORTED_TAG], []) # C support is built-in for now m4_define([_LT_LANG_C_enabled], []) m4_define([_LT_TAGS], []) # LT_LANG(LANG) # ------------- # Enable libtool support for the given language if not already enabled. AC_DEFUN([LT_LANG], [AC_BEFORE([$0], [LT_OUTPUT])dnl m4_case([$1], [C], [_LT_LANG(C)], [C++], [_LT_LANG(CXX)], [Java], [_LT_LANG(GCJ)], [Fortran 77], [_LT_LANG(F77)], [Fortran], [_LT_LANG(FC)], [Windows Resource], [_LT_LANG(RC)], [m4_ifdef([_LT_LANG_]$1[_CONFIG], [_LT_LANG($1)], [m4_fatal([$0: unsupported language: "$1"])])])dnl ])# LT_LANG # _LT_LANG(LANGNAME) # ------------------ m4_defun([_LT_LANG], [m4_ifdef([_LT_LANG_]$1[_enabled], [], [LT_SUPPORTED_TAG([$1])dnl m4_append([_LT_TAGS], [$1 ])dnl m4_define([_LT_LANG_]$1[_enabled], [])dnl _LT_LANG_$1_CONFIG($1)])dnl ])# _LT_LANG # _LT_LANG_DEFAULT_CONFIG # ----------------------- m4_defun([_LT_LANG_DEFAULT_CONFIG], [AC_PROVIDE_IFELSE([AC_PROG_CXX], [LT_LANG(CXX)], [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])]) AC_PROVIDE_IFELSE([AC_PROG_F77], [LT_LANG(F77)], [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])]) AC_PROVIDE_IFELSE([AC_PROG_FC], [LT_LANG(FC)], [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])]) dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal dnl pulling things in needlessly. AC_PROVIDE_IFELSE([AC_PROG_GCJ], [LT_LANG(GCJ)], [AC_PROVIDE_IFELSE([A][M_PROG_GCJ], [LT_LANG(GCJ)], [AC_PROVIDE_IFELSE([LT_PROG_GCJ], [LT_LANG(GCJ)], [m4_ifdef([AC_PROG_GCJ], [m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])]) m4_ifdef([A][M_PROG_GCJ], [m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])]) m4_ifdef([LT_PROG_GCJ], [m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])]) AC_PROVIDE_IFELSE([LT_PROG_RC], [LT_LANG(RC)], [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])]) ])# _LT_LANG_DEFAULT_CONFIG # Obsolete macros: AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)]) AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)]) AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)]) AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_CXX], []) dnl AC_DEFUN([AC_LIBTOOL_F77], []) dnl AC_DEFUN([AC_LIBTOOL_FC], []) dnl AC_DEFUN([AC_LIBTOOL_GCJ], []) # _LT_TAG_COMPILER # ---------------- m4_defun([_LT_TAG_COMPILER], [AC_REQUIRE([AC_PROG_CC])dnl _LT_DECL([LTCC], [CC], [1], [A C compiler])dnl _LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl _LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl _LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl # If no C compiler was specified, use CC. LTCC=${LTCC-"$CC"} # If no C compiler flags were specified, use CFLAGS. LTCFLAGS=${LTCFLAGS-"$CFLAGS"} # Allow CC to be a program name with arguments. compiler=$CC ])# _LT_TAG_COMPILER # _LT_COMPILER_BOILERPLATE # ------------------------ # Check for compiler boilerplate output or warnings with # the simple compiler test code. m4_defun([_LT_COMPILER_BOILERPLATE], [m4_require([_LT_DECL_SED])dnl ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" >conftest.$ac_ext eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err _lt_compiler_boilerplate=`cat conftest.err` $RM conftest* ])# _LT_COMPILER_BOILERPLATE # _LT_LINKER_BOILERPLATE # ---------------------- # Check for linker boilerplate output or warnings with # the simple link test code. m4_defun([_LT_LINKER_BOILERPLATE], [m4_require([_LT_DECL_SED])dnl ac_outfile=conftest.$ac_objext echo "$lt_simple_link_test_code" >conftest.$ac_ext eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err _lt_linker_boilerplate=`cat conftest.err` $RM -r conftest* ])# _LT_LINKER_BOILERPLATE # _LT_REQUIRED_DARWIN_CHECKS # ------------------------- m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ case $host_os in rhapsody* | darwin*) AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:]) AC_CHECK_TOOL([NMEDIT], [nmedit], [:]) AC_CHECK_TOOL([LIPO], [lipo], [:]) AC_CHECK_TOOL([OTOOL], [otool], [:]) AC_CHECK_TOOL([OTOOL64], [otool64], [:]) _LT_DECL([], [DSYMUTIL], [1], [Tool to manipulate archived DWARF debug symbol files on Mac OS X]) _LT_DECL([], [NMEDIT], [1], [Tool to change global to local symbols on Mac OS X]) _LT_DECL([], [LIPO], [1], [Tool to manipulate fat objects and archives on Mac OS X]) _LT_DECL([], [OTOOL], [1], [ldd/readelf like tool for Mach-O binaries on Mac OS X]) _LT_DECL([], [OTOOL64], [1], [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4]) AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod], [lt_cv_apple_cc_single_mod=no if test -z "${LT_MULTI_MODULE}"; then # By default we will add the -single_module flag. You can override # by either setting the environment variable LT_MULTI_MODULE # non-empty at configure time, or by adding -multi_module to the # link flags. rm -rf libconftest.dylib* echo "int foo(void){return 1;}" > conftest.c echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ -dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ -dynamiclib -Wl,-single_module conftest.c 2>conftest.err _lt_result=$? if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then lt_cv_apple_cc_single_mod=yes else cat conftest.err >&AS_MESSAGE_LOG_FD fi rm -rf libconftest.dylib* rm -f conftest.* fi]) AC_CACHE_CHECK([for -exported_symbols_list linker flag], [lt_cv_ld_exported_symbols_list], [lt_cv_ld_exported_symbols_list=no save_LDFLAGS=$LDFLAGS echo "_main" > conftest.sym LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], [lt_cv_ld_exported_symbols_list=yes], [lt_cv_ld_exported_symbols_list=no]) LDFLAGS="$save_LDFLAGS" ]) case $host_os in rhapsody* | darwin1.[[012]]) _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; darwin1.*) _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; darwin*) # darwin 5.x on # if running on 10.5 or later, the deployment target defaults # to the OS version, if on x86, and 10.4, the deployment # target defaults to 10.4. Don't you love it? case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in 10.0,*86*-darwin8*|10.0,*-darwin[[91]]*) _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; 10.[[012]]*) _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; 10.*) _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; esac ;; esac if test "$lt_cv_apple_cc_single_mod" = "yes"; then _lt_dar_single_mod='$single_module' fi if test "$lt_cv_ld_exported_symbols_list" = "yes"; then _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym' else _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}' fi if test "$DSYMUTIL" != ":"; then _lt_dsymutil='~$DSYMUTIL $lib || :' else _lt_dsymutil= fi ;; esac ]) # _LT_DARWIN_LINKER_FEATURES # -------------------------- # Checks for linker and compiler features on darwin m4_defun([_LT_DARWIN_LINKER_FEATURES], [ m4_require([_LT_REQUIRED_DARWIN_CHECKS]) _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_automatic, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported _LT_TAGVAR(whole_archive_flag_spec, $1)='' _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined" case $cc_basename in ifort*) _lt_dar_can_shared=yes ;; *) _lt_dar_can_shared=$GCC ;; esac if test "$_lt_dar_can_shared" = "yes"; then output_verbose_link_cmd=echo _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" m4_if([$1], [CXX], [ if test "$lt_cv_apple_cc_single_mod" != "yes"; then _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" fi ],[]) else _LT_TAGVAR(ld_shlibs, $1)=no fi ]) # _LT_SYS_MODULE_PATH_AIX # ----------------------- # Links a minimal program and checks the executable # for the system default hardcoded library path. In most cases, # this is /usr/lib:/lib, but when the MPI compilers are used # the location of the communication and MPI libs are included too. # If we don't find anything, use the default library path according # to the aix ld manual. m4_defun([_LT_SYS_MODULE_PATH_AIX], [m4_require([_LT_DECL_SED])dnl AC_LINK_IFELSE(AC_LANG_PROGRAM,[ lt_aix_libpath_sed=' /Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/ p } }' aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` # Check for a 64-bit object if we didn't find anything. if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi],[]) if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi ])# _LT_SYS_MODULE_PATH_AIX # _LT_SHELL_INIT(ARG) # ------------------- m4_define([_LT_SHELL_INIT], [ifdef([AC_DIVERSION_NOTICE], [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)], [AC_DIVERT_PUSH(NOTICE)]) $1 AC_DIVERT_POP ])# _LT_SHELL_INIT # _LT_PROG_ECHO_BACKSLASH # ----------------------- # Add some code to the start of the generated configure script which # will find an echo command which doesn't interpret backslashes. m4_defun([_LT_PROG_ECHO_BACKSLASH], [_LT_SHELL_INIT([ # Check that we are running under the correct shell. SHELL=${CONFIG_SHELL-/bin/sh} case X$lt_ECHO in X*--fallback-echo) # Remove one level of quotation (which was required for Make). ECHO=`echo "$lt_ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','` ;; esac ECHO=${lt_ECHO-echo} if test "X[$]1" = X--no-reexec; then # Discard the --no-reexec flag, and continue. shift elif test "X[$]1" = X--fallback-echo; then # Avoid inline document here, it may be left over : elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then # Yippee, $ECHO works! : else # Restart under the correct shell. exec $SHELL "[$]0" --no-reexec ${1+"[$]@"} fi if test "X[$]1" = X--fallback-echo; then # used as fallback echo shift cat <<_LT_EOF [$]* _LT_EOF exit 0 fi # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH if test -z "$lt_ECHO"; then if test "X${echo_test_string+set}" != Xset; then # find a string as large as possible, as long as the shell can cope with it for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ... if { echo_test_string=`eval $cmd`; } 2>/dev/null && { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null then break fi done fi if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && test "X$echo_testing_string" = "X$echo_test_string"; then : else # The Solaris, AIX, and Digital Unix default echo programs unquote # backslashes. This makes it impossible to quote backslashes using # echo "$something" | sed 's/\\/\\\\/g' # # So, first we look for a working echo in the user's PATH. lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR for dir in $PATH /usr/ucb; do IFS="$lt_save_ifs" if (test -f $dir/echo || test -f $dir/echo$ac_exeext) && test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' && echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` && test "X$echo_testing_string" = "X$echo_test_string"; then ECHO="$dir/echo" break fi done IFS="$lt_save_ifs" if test "X$ECHO" = Xecho; then # We didn't find a better echo, so look for alternatives. if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' && echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` && test "X$echo_testing_string" = "X$echo_test_string"; then # This shell has a builtin print -r that does the trick. ECHO='print -r' elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } && test "X$CONFIG_SHELL" != X/bin/ksh; then # If we have ksh, try running configure again with it. ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh} export ORIGINAL_CONFIG_SHELL CONFIG_SHELL=/bin/ksh export CONFIG_SHELL exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"} else # Try using printf. ECHO='printf %s\n' if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && test "X$echo_testing_string" = "X$echo_test_string"; then # Cool, printf works : elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && test "X$echo_testing_string" = 'X\t' && echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && test "X$echo_testing_string" = "X$echo_test_string"; then CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL export CONFIG_SHELL SHELL="$CONFIG_SHELL" export SHELL ECHO="$CONFIG_SHELL [$]0 --fallback-echo" elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && test "X$echo_testing_string" = 'X\t' && echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && test "X$echo_testing_string" = "X$echo_test_string"; then ECHO="$CONFIG_SHELL [$]0 --fallback-echo" else # maybe with a smaller string... prev=: for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null then break fi prev="$cmd" done if test "$prev" != 'sed 50q "[$]0"'; then echo_test_string=`eval $prev` export echo_test_string exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"} else # Oops. We lost completely, so just stick with echo. ECHO=echo fi fi fi fi fi fi # Copy echo and quote the copy suitably for passing to libtool from # the Makefile, instead of quoting the original, which is used later. lt_ECHO=$ECHO if test "X$lt_ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then lt_ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo" fi AC_SUBST(lt_ECHO) ]) _LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts]) _LT_DECL([], [ECHO], [1], [An echo program that does not interpret backslashes]) ])# _LT_PROG_ECHO_BACKSLASH # _LT_ENABLE_LOCK # --------------- m4_defun([_LT_ENABLE_LOCK], [AC_ARG_ENABLE([libtool-lock], [AS_HELP_STRING([--disable-libtool-lock], [avoid locking (might break parallel builds)])]) test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes # Some flags need to be propagated to the compiler or linker for good # libtool support. case $host in ia64-*-hpux*) # Find out which ABI we are using. echo 'int i;' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then case `/usr/bin/file conftest.$ac_objext` in *ELF-32*) HPUX_IA64_MODE="32" ;; *ELF-64*) HPUX_IA64_MODE="64" ;; esac fi rm -rf conftest* ;; *-*-irix6*) # Find out which ABI we are using. echo '[#]line __oline__ "configure"' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then if test "$lt_cv_prog_gnu_ld" = yes; then case `/usr/bin/file conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -melf32bsmip" ;; *N32*) LD="${LD-ld} -melf32bmipn32" ;; *64-bit*) LD="${LD-ld} -melf64bmip" ;; esac else case `/usr/bin/file conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -32" ;; *N32*) LD="${LD-ld} -n32" ;; *64-bit*) LD="${LD-ld} -64" ;; esac fi fi rm -rf conftest* ;; x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) # Find out which ABI we are using. echo 'int i;' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then case `/usr/bin/file conftest.o` in *32-bit*) case $host in x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_i386_fbsd" ;; x86_64-*linux*) LD="${LD-ld} -m elf_i386" ;; ppc64-*linux*|powerpc64-*linux*) LD="${LD-ld} -m elf32ppclinux" ;; s390x-*linux*) LD="${LD-ld} -m elf_s390" ;; sparc64-*linux*) LD="${LD-ld} -m elf32_sparc" ;; esac ;; *64-bit*) case $host in x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_x86_64_fbsd" ;; x86_64-*linux*) LD="${LD-ld} -m elf_x86_64" ;; ppc*-*linux*|powerpc*-*linux*) LD="${LD-ld} -m elf64ppc" ;; s390*-*linux*|s390*-*tpf*) LD="${LD-ld} -m elf64_s390" ;; sparc*-*linux*) LD="${LD-ld} -m elf64_sparc" ;; esac ;; esac fi rm -rf conftest* ;; *-*-sco3.2v5*) # On SCO OpenServer 5, we need -belf to get full-featured binaries. SAVE_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -belf" AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf, [AC_LANG_PUSH(C) AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no]) AC_LANG_POP]) if test x"$lt_cv_cc_needs_belf" != x"yes"; then # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf CFLAGS="$SAVE_CFLAGS" fi ;; sparc*-*solaris*) # Find out which ABI we are using. echo 'int i;' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then case `/usr/bin/file conftest.o` in *64-bit*) case $lt_cv_prog_gnu_ld in yes*) LD="${LD-ld} -m elf64_sparc" ;; *) if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then LD="${LD-ld} -64" fi ;; esac ;; esac fi rm -rf conftest* ;; esac need_locks="$enable_libtool_lock" ])# _LT_ENABLE_LOCK # _LT_CMD_OLD_ARCHIVE # ------------------- m4_defun([_LT_CMD_OLD_ARCHIVE], [AC_CHECK_TOOL(AR, ar, false) test -z "$AR" && AR=ar test -z "$AR_FLAGS" && AR_FLAGS=cru _LT_DECL([], [AR], [1], [The archiver]) _LT_DECL([], [AR_FLAGS], [1]) AC_CHECK_TOOL(STRIP, strip, :) test -z "$STRIP" && STRIP=: _LT_DECL([], [STRIP], [1], [A symbol stripping program]) AC_CHECK_TOOL(RANLIB, ranlib, :) test -z "$RANLIB" && RANLIB=: _LT_DECL([], [RANLIB], [1], [Commands used to install an old-style archive]) # Determine commands to create old-style static archives. old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' old_postinstall_cmds='chmod 644 $oldlib' old_postuninstall_cmds= if test -n "$RANLIB"; then case $host_os in openbsd*) old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib" ;; *) old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib" ;; esac old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib" fi _LT_DECL([], [old_postinstall_cmds], [2]) _LT_DECL([], [old_postuninstall_cmds], [2]) _LT_TAGDECL([], [old_archive_cmds], [2], [Commands used to build an old-style archive]) ])# _LT_CMD_OLD_ARCHIVE # _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, # [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE]) # ---------------------------------------------------------------- # Check whether the given compiler option works AC_DEFUN([_LT_COMPILER_OPTION], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_SED])dnl AC_CACHE_CHECK([$1], [$2], [$2=no m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4]) echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="$3" # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. # The option is referenced via a variable to avoid confusing sed. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&AS_MESSAGE_LOG_FD echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then $2=yes fi fi $RM conftest* ]) if test x"[$]$2" = xyes; then m4_if([$5], , :, [$5]) else m4_if([$6], , :, [$6]) fi ])# _LT_COMPILER_OPTION # Old name: AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], []) # _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, # [ACTION-SUCCESS], [ACTION-FAILURE]) # ---------------------------------------------------- # Check whether the given linker option works AC_DEFUN([_LT_LINKER_OPTION], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_SED])dnl AC_CACHE_CHECK([$1], [$2], [$2=no save_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS $3" echo "$lt_simple_link_test_code" > conftest.$ac_ext if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then # The linker can only warn and ignore the option if not recognized # So say no if there are warnings if test -s conftest.err; then # Append any errors to the config.log. cat conftest.err 1>&AS_MESSAGE_LOG_FD $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 if diff conftest.exp conftest.er2 >/dev/null; then $2=yes fi else $2=yes fi fi $RM -r conftest* LDFLAGS="$save_LDFLAGS" ]) if test x"[$]$2" = xyes; then m4_if([$4], , :, [$4]) else m4_if([$5], , :, [$5]) fi ])# _LT_LINKER_OPTION # Old name: AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], []) # LT_CMD_MAX_LEN #--------------- AC_DEFUN([LT_CMD_MAX_LEN], [AC_REQUIRE([AC_CANONICAL_HOST])dnl # find the maximum length of command line arguments AC_MSG_CHECKING([the maximum length of command line arguments]) AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl i=0 teststring="ABCD" case $build_os in msdosdjgpp*) # On DJGPP, this test can blow up pretty badly due to problems in libc # (any single argument exceeding 2000 bytes causes a buffer overrun # during glob expansion). Even if it were fixed, the result of this # check would be larger than it should be. lt_cv_sys_max_cmd_len=12288; # 12K is about right ;; gnu*) # Under GNU Hurd, this test is not required because there is # no limit to the length of command line arguments. # Libtool will interpret -1 as no limit whatsoever lt_cv_sys_max_cmd_len=-1; ;; cygwin* | mingw* | cegcc*) # On Win9x/ME, this test blows up -- it succeeds, but takes # about 5 minutes as the teststring grows exponentially. # Worse, since 9x/ME are not pre-emptively multitasking, # you end up with a "frozen" computer, even though with patience # the test eventually succeeds (with a max line length of 256k). # Instead, let's just punt: use the minimum linelength reported by # all of the supported platforms: 8192 (on NT/2K/XP). lt_cv_sys_max_cmd_len=8192; ;; amigaos*) # On AmigaOS with pdksh, this test takes hours, literally. # So we just punt and use a minimum line length of 8192. lt_cv_sys_max_cmd_len=8192; ;; netbsd* | freebsd* | openbsd* | darwin* | dragonfly*) # This has been around since 386BSD, at least. Likely further. if test -x /sbin/sysctl; then lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` elif test -x /usr/sbin/sysctl; then lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` else lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs fi # And add a safety zone lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` ;; interix*) # We know the value 262144 and hardcode it with a safety zone (like BSD) lt_cv_sys_max_cmd_len=196608 ;; osf*) # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not # nice to cause kernel panics so lets avoid the loop below. # First set a reasonable default. lt_cv_sys_max_cmd_len=16384 # if test -x /sbin/sysconfig; then case `/sbin/sysconfig -q proc exec_disable_arg_limit` in *1*) lt_cv_sys_max_cmd_len=-1 ;; esac fi ;; sco3.2v5*) lt_cv_sys_max_cmd_len=102400 ;; sysv5* | sco5v6* | sysv4.2uw2*) kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` if test -n "$kargmax"; then lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ ]]//'` else lt_cv_sys_max_cmd_len=32768 fi ;; *) lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` if test -n "$lt_cv_sys_max_cmd_len"; then lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` else # Make teststring a little bigger before we do anything with it. # a 1K string should be a reasonable start. for i in 1 2 3 4 5 6 7 8 ; do teststring=$teststring$teststring done SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} # If test is not a shell built-in, we'll probably end up computing a # maximum length that is only half of the actual maximum length, but # we can't tell. while { test "X"`$SHELL [$]0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \ = "XX$teststring$teststring"; } >/dev/null 2>&1 && test $i != 17 # 1/2 MB should be enough do i=`expr $i + 1` teststring=$teststring$teststring done # Only check the string length outside the loop. lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` teststring= # Add a significant safety factor because C++ compilers can tack on # massive amounts of additional arguments before passing them to the # linker. It appears as though 1/2 is a usable value. lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` fi ;; esac ]) if test -n $lt_cv_sys_max_cmd_len ; then AC_MSG_RESULT($lt_cv_sys_max_cmd_len) else AC_MSG_RESULT(none) fi max_cmd_len=$lt_cv_sys_max_cmd_len _LT_DECL([], [max_cmd_len], [0], [What is the maximum length of a command?]) ])# LT_CMD_MAX_LEN # Old name: AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], []) # _LT_HEADER_DLFCN # ---------------- m4_defun([_LT_HEADER_DLFCN], [AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl ])# _LT_HEADER_DLFCN # _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE, # ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING) # ---------------------------------------------------------------- m4_defun([_LT_TRY_DLOPEN_SELF], [m4_require([_LT_HEADER_DLFCN])dnl if test "$cross_compiling" = yes; then : [$4] else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF [#line __oline__ "configure" #include "confdefs.h" #if HAVE_DLFCN_H #include #endif #include #ifdef RTLD_GLOBAL # define LT_DLGLOBAL RTLD_GLOBAL #else # ifdef DL_GLOBAL # define LT_DLGLOBAL DL_GLOBAL # else # define LT_DLGLOBAL 0 # endif #endif /* We may have to define LT_DLLAZY_OR_NOW in the command line if we find out it does not work in some platform. */ #ifndef LT_DLLAZY_OR_NOW # ifdef RTLD_LAZY # define LT_DLLAZY_OR_NOW RTLD_LAZY # else # ifdef DL_LAZY # define LT_DLLAZY_OR_NOW DL_LAZY # else # ifdef RTLD_NOW # define LT_DLLAZY_OR_NOW RTLD_NOW # else # ifdef DL_NOW # define LT_DLLAZY_OR_NOW DL_NOW # else # define LT_DLLAZY_OR_NOW 0 # endif # endif # endif # endif #endif void fnord() { int i=42;} int main () { void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); int status = $lt_dlunknown; if (self) { if (dlsym (self,"fnord")) status = $lt_dlno_uscore; else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; /* dlclose (self); */ } else puts (dlerror ()); return status; }] _LT_EOF if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null lt_status=$? case x$lt_status in x$lt_dlno_uscore) $1 ;; x$lt_dlneed_uscore) $2 ;; x$lt_dlunknown|x*) $3 ;; esac else : # compilation failed $3 fi fi rm -fr conftest* ])# _LT_TRY_DLOPEN_SELF # LT_SYS_DLOPEN_SELF # ------------------ AC_DEFUN([LT_SYS_DLOPEN_SELF], [m4_require([_LT_HEADER_DLFCN])dnl if test "x$enable_dlopen" != xyes; then enable_dlopen=unknown enable_dlopen_self=unknown enable_dlopen_self_static=unknown else lt_cv_dlopen=no lt_cv_dlopen_libs= case $host_os in beos*) lt_cv_dlopen="load_add_on" lt_cv_dlopen_libs= lt_cv_dlopen_self=yes ;; mingw* | pw32* | cegcc*) lt_cv_dlopen="LoadLibrary" lt_cv_dlopen_libs= ;; cygwin*) lt_cv_dlopen="dlopen" lt_cv_dlopen_libs= ;; darwin*) # if libdl is installed we need to link against it AC_CHECK_LIB([dl], [dlopen], [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[ lt_cv_dlopen="dyld" lt_cv_dlopen_libs= lt_cv_dlopen_self=yes ]) ;; *) AC_CHECK_FUNC([shl_load], [lt_cv_dlopen="shl_load"], [AC_CHECK_LIB([dld], [shl_load], [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"], [AC_CHECK_FUNC([dlopen], [lt_cv_dlopen="dlopen"], [AC_CHECK_LIB([dl], [dlopen], [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"], [AC_CHECK_LIB([svld], [dlopen], [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"], [AC_CHECK_LIB([dld], [dld_link], [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"]) ]) ]) ]) ]) ]) ;; esac if test "x$lt_cv_dlopen" != xno; then enable_dlopen=yes else enable_dlopen=no fi case $lt_cv_dlopen in dlopen) save_CPPFLAGS="$CPPFLAGS" test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" save_LDFLAGS="$LDFLAGS" wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" save_LIBS="$LIBS" LIBS="$lt_cv_dlopen_libs $LIBS" AC_CACHE_CHECK([whether a program can dlopen itself], lt_cv_dlopen_self, [dnl _LT_TRY_DLOPEN_SELF( lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes, lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross) ]) if test "x$lt_cv_dlopen_self" = xyes; then wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" AC_CACHE_CHECK([whether a statically linked program can dlopen itself], lt_cv_dlopen_self_static, [dnl _LT_TRY_DLOPEN_SELF( lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross) ]) fi CPPFLAGS="$save_CPPFLAGS" LDFLAGS="$save_LDFLAGS" LIBS="$save_LIBS" ;; esac case $lt_cv_dlopen_self in yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; *) enable_dlopen_self=unknown ;; esac case $lt_cv_dlopen_self_static in yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; *) enable_dlopen_self_static=unknown ;; esac fi _LT_DECL([dlopen_support], [enable_dlopen], [0], [Whether dlopen is supported]) _LT_DECL([dlopen_self], [enable_dlopen_self], [0], [Whether dlopen of programs is supported]) _LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0], [Whether dlopen of statically linked programs is supported]) ])# LT_SYS_DLOPEN_SELF # Old name: AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], []) # _LT_COMPILER_C_O([TAGNAME]) # --------------------------- # Check to see if options -c and -o are simultaneously supported by compiler. # This macro does not hard code the compiler like AC_PROG_CC_C_O. m4_defun([_LT_COMPILER_C_O], [m4_require([_LT_DECL_SED])dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_TAG_COMPILER])dnl AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext], [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)], [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no $RM -r conftest 2>/dev/null mkdir conftest cd conftest mkdir out echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="-o out/conftest2.$ac_objext" # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&AS_MESSAGE_LOG_FD echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes fi fi chmod u+w . 2>&AS_MESSAGE_LOG_FD $RM conftest* # SGI C++ compiler will create directory out/ii_files/ for # template instantiation test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files $RM out/* && rmdir out cd .. $RM -r conftest $RM conftest* ]) _LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1], [Does compiler simultaneously support -c and -o options?]) ])# _LT_COMPILER_C_O # _LT_COMPILER_FILE_LOCKS([TAGNAME]) # ---------------------------------- # Check to see if we can do hard links to lock some files if needed m4_defun([_LT_COMPILER_FILE_LOCKS], [m4_require([_LT_ENABLE_LOCK])dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl _LT_COMPILER_C_O([$1]) hard_links="nottested" if test "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then # do not overwrite the value of need_locks provided by the user AC_MSG_CHECKING([if we can lock with hard links]) hard_links=yes $RM conftest* ln conftest.a conftest.b 2>/dev/null && hard_links=no touch conftest.a ln conftest.a conftest.b 2>&5 || hard_links=no ln conftest.a conftest.b 2>/dev/null && hard_links=no AC_MSG_RESULT([$hard_links]) if test "$hard_links" = no; then AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe]) need_locks=warn fi else need_locks=no fi _LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?]) ])# _LT_COMPILER_FILE_LOCKS # _LT_CHECK_OBJDIR # ---------------- m4_defun([_LT_CHECK_OBJDIR], [AC_CACHE_CHECK([for objdir], [lt_cv_objdir], [rm -f .libs 2>/dev/null mkdir .libs 2>/dev/null if test -d .libs; then lt_cv_objdir=.libs else # MS-DOS does not allow filenames that begin with a dot. lt_cv_objdir=_libs fi rmdir .libs 2>/dev/null]) objdir=$lt_cv_objdir _LT_DECL([], [objdir], [0], [The name of the directory that contains temporary libtool files])dnl m4_pattern_allow([LT_OBJDIR])dnl AC_DEFINE_UNQUOTED(LT_OBJDIR, "$lt_cv_objdir/", [Define to the sub-directory in which libtool stores uninstalled libraries.]) ])# _LT_CHECK_OBJDIR # _LT_LINKER_HARDCODE_LIBPATH([TAGNAME]) # -------------------------------------- # Check hardcoding attributes. m4_defun([_LT_LINKER_HARDCODE_LIBPATH], [AC_MSG_CHECKING([how to hardcode library paths into programs]) _LT_TAGVAR(hardcode_action, $1)= if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" || test -n "$_LT_TAGVAR(runpath_var, $1)" || test "X$_LT_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then # We can hardcode non-existent directories. if test "$_LT_TAGVAR(hardcode_direct, $1)" != no && # If the only mechanism to avoid hardcoding is shlibpath_var, we # have to relink, otherwise we might link with an installed library # when we should be linking with a yet-to-be-installed one ## test "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" != no && test "$_LT_TAGVAR(hardcode_minus_L, $1)" != no; then # Linking always hardcodes the temporary library directory. _LT_TAGVAR(hardcode_action, $1)=relink else # We can link without hardcoding, and we can hardcode nonexisting dirs. _LT_TAGVAR(hardcode_action, $1)=immediate fi else # We cannot hardcode anything, or else we can only hardcode existing # directories. _LT_TAGVAR(hardcode_action, $1)=unsupported fi AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)]) if test "$_LT_TAGVAR(hardcode_action, $1)" = relink || test "$_LT_TAGVAR(inherit_rpath, $1)" = yes; then # Fast installation is not supported enable_fast_install=no elif test "$shlibpath_overrides_runpath" = yes || test "$enable_shared" = no; then # Fast installation is not necessary enable_fast_install=needless fi _LT_TAGDECL([], [hardcode_action], [0], [How to hardcode a shared library path into an executable]) ])# _LT_LINKER_HARDCODE_LIBPATH # _LT_CMD_STRIPLIB # ---------------- m4_defun([_LT_CMD_STRIPLIB], [m4_require([_LT_DECL_EGREP]) striplib= old_striplib= AC_MSG_CHECKING([whether stripping libraries is possible]) if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" test -z "$striplib" && striplib="$STRIP --strip-unneeded" AC_MSG_RESULT([yes]) else # FIXME - insert some real tests, host_os isn't really good enough case $host_os in darwin*) if test -n "$STRIP" ; then striplib="$STRIP -x" old_striplib="$STRIP -S" AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) fi ;; *) AC_MSG_RESULT([no]) ;; esac fi _LT_DECL([], [old_striplib], [1], [Commands to strip libraries]) _LT_DECL([], [striplib], [1]) ])# _LT_CMD_STRIPLIB # _LT_SYS_DYNAMIC_LINKER([TAG]) # ----------------------------- # PORTME Fill in your ld.so characteristics m4_defun([_LT_SYS_DYNAMIC_LINKER], [AC_REQUIRE([AC_CANONICAL_HOST])dnl m4_require([_LT_DECL_EGREP])dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_OBJDUMP])dnl m4_require([_LT_DECL_SED])dnl AC_MSG_CHECKING([dynamic linker characteristics]) m4_if([$1], [], [ if test "$GCC" = yes; then case $host_os in darwin*) lt_awk_arg="/^libraries:/,/LR/" ;; *) lt_awk_arg="/^libraries:/" ;; esac lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"` if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then # if the path contains ";" then we assume it to be the separator # otherwise default to the standard path separator (i.e. ":") - it is # assumed that no part of a normal pathname contains ";" but that should # okay in the real world where ";" in dirpaths is itself problematic. lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'` else lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` fi # Ok, now we have the path, separated by spaces, we can step through it # and add multilib dir if necessary. lt_tmp_lt_search_path_spec= lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` for lt_sys_path in $lt_search_path_spec; do if test -d "$lt_sys_path/$lt_multi_os_dir"; then lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir" else test -d "$lt_sys_path" && \ lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" fi done lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk ' BEGIN {RS=" "; FS="/|\n";} { lt_foo=""; lt_count=0; for (lt_i = NF; lt_i > 0; lt_i--) { if ($lt_i != "" && $lt_i != ".") { if ($lt_i == "..") { lt_count++; } else { if (lt_count == 0) { lt_foo="/" $lt_i lt_foo; } else { lt_count--; } } } } if (lt_foo != "") { lt_freq[[lt_foo]]++; } if (lt_freq[[lt_foo]] == 1) { print lt_foo; } }'` sys_lib_search_path_spec=`$ECHO $lt_search_path_spec` else sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" fi]) library_names_spec= libname_spec='lib$name' soname_spec= shrext_cmds=".so" postinstall_cmds= postuninstall_cmds= finish_cmds= finish_eval= shlibpath_var= shlibpath_overrides_runpath=unknown version_type=none dynamic_linker="$host_os ld.so" sys_lib_dlsearch_path_spec="/lib /usr/lib" need_lib_prefix=unknown hardcode_into_libs=no # when you set need_version to no, make sure it does not cause -set_version # flags to be left without arguments need_version=unknown case $host_os in aix3*) version_type=linux library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' shlibpath_var=LIBPATH # AIX 3 has no versioning support, so we append a major version to the name. soname_spec='${libname}${release}${shared_ext}$major' ;; aix[[4-9]]*) version_type=linux need_lib_prefix=no need_version=no hardcode_into_libs=yes if test "$host_cpu" = ia64; then # AIX 5 supports IA64 library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH else # With GCC up to 2.95.x, collect2 would create an import file # for dependence libraries. The import file would start with # the line `#! .'. This would cause the generated library to # depend on `.', always an invalid library. This was fixed in # development snapshots of GCC prior to 3.0. case $host_os in aix4 | aix4.[[01]] | aix4.[[01]].*) if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' echo ' yes ' echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then : else can_build_shared=no fi ;; esac # AIX (on Power*) has no versioning support, so currently we can not hardcode correct # soname into executable. Probably we can add versioning support to # collect2, so additional links can be useful in future. if test "$aix_use_runtimelinking" = yes; then # If using run time linking (on AIX 4.2 or later) use lib.so # instead of lib.a to let people know that these are not # typical AIX shared libraries. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' else # We preserve .a as extension for shared libraries through AIX4.2 # and later when we are not doing run time linking. library_names_spec='${libname}${release}.a $libname.a' soname_spec='${libname}${release}${shared_ext}$major' fi shlibpath_var=LIBPATH fi ;; amigaos*) case $host_cpu in powerpc) # Since July 2007 AmigaOS4 officially supports .so libraries. # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' ;; m68k) library_names_spec='$libname.ixlibrary $libname.a' # Create ${libname}_ixlibrary.a entries in /sys/libs. finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' ;; esac ;; beos*) library_names_spec='${libname}${shared_ext}' dynamic_linker="$host_os ld.so" shlibpath_var=LIBRARY_PATH ;; bsdi[[45]]*) version_type=linux need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' shlibpath_var=LD_LIBRARY_PATH sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" # the default ld.so.conf also contains /usr/contrib/lib and # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow # libtool to hard-code these into programs ;; cygwin* | mingw* | pw32* | cegcc*) version_type=windows shrext_cmds=".dll" need_version=no need_lib_prefix=no case $GCC,$host_os in yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*) library_names_spec='$libname.dll.a' # DLL is installed to $(libdir)/../bin by postinstall_cmds postinstall_cmds='base_file=`basename \${file}`~ dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~ dldir=$destdir/`dirname \$dlpath`~ test -d \$dldir || mkdir -p \$dldir~ $install_prog $dir/$dlname \$dldir/$dlname~ chmod a+x \$dldir/$dlname~ if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; fi' postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ dlpath=$dir/\$dldll~ $RM \$dlpath' shlibpath_overrides_runpath=yes case $host_os in cygwin*) # Cygwin DLLs use 'cyg' prefix rather than 'lib' soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib" ;; mingw* | cegcc*) # MinGW DLLs use traditional 'lib' prefix soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then # It is most probably a Windows format PATH printed by # mingw gcc, but we are running on Cygwin. Gcc prints its search # path with ; separators, and with drive letters. We can handle the # drive letters (cygwin fileutils understands them), so leave them, # especially as we might pass files found there to a mingw objdump, # which wouldn't understand a cygwinified path. Ahh. sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` else sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` fi ;; pw32*) # pw32 DLLs use 'pw' prefix rather than 'lib' library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' ;; esac ;; *) library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib' ;; esac dynamic_linker='Win32 ld.exe' # FIXME: first we should search . and the directory the executable is in shlibpath_var=PATH ;; darwin* | rhapsody*) dynamic_linker="$host_os dyld" version_type=darwin need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext' soname_spec='${libname}${release}${major}$shared_ext' shlibpath_overrides_runpath=yes shlibpath_var=DYLD_LIBRARY_PATH shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' m4_if([$1], [],[ sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"]) sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' ;; dgux*) version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH ;; freebsd1*) dynamic_linker=no ;; freebsd* | dragonfly*) # DragonFly does not have aout. When/if they implement a new # versioning mechanism, adjust this. if test -x /usr/bin/objformat; then objformat=`/usr/bin/objformat` else case $host_os in freebsd[[123]]*) objformat=aout ;; *) objformat=elf ;; esac fi version_type=freebsd-$objformat case $version_type in freebsd-elf*) library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' need_version=no need_lib_prefix=no ;; freebsd-*) library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' need_version=yes ;; esac shlibpath_var=LD_LIBRARY_PATH case $host_os in freebsd2*) shlibpath_overrides_runpath=yes ;; freebsd3.[[01]]* | freebsdelf3.[[01]]*) shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \ freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1) shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; *) # from 4.6 on, and DragonFly shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; esac ;; gnu*) version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH hardcode_into_libs=yes ;; hpux9* | hpux10* | hpux11*) # Give a soname corresponding to the major version so that dld.sl refuses to # link against other versions. version_type=sunos need_lib_prefix=no need_version=no case $host_cpu in ia64*) shrext_cmds='.so' hardcode_into_libs=yes dynamic_linker="$host_os dld.so" shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' if test "X$HPUX_IA64_MODE" = X32; then sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" else sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" fi sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec ;; hppa*64*) shrext_cmds='.sl' hardcode_into_libs=yes dynamic_linker="$host_os dld.sl" shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec ;; *) shrext_cmds='.sl' dynamic_linker="$host_os dld.sl" shlibpath_var=SHLIB_PATH shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' ;; esac # HP-UX runs *really* slowly unless shared libraries are mode 555. postinstall_cmds='chmod 555 $lib' ;; interix[[3-9]]*) version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; irix5* | irix6* | nonstopux*) case $host_os in nonstopux*) version_type=nonstopux ;; *) if test "$lt_cv_prog_gnu_ld" = yes; then version_type=linux else version_type=irix fi ;; esac need_lib_prefix=no need_version=no soname_spec='${libname}${release}${shared_ext}$major' library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' case $host_os in irix5* | nonstopux*) libsuff= shlibsuff= ;; *) case $LD in # libtool.m4 will add one of these switches to LD *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") libsuff= shlibsuff= libmagic=32-bit;; *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") libsuff=32 shlibsuff=N32 libmagic=N32;; *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") libsuff=64 shlibsuff=64 libmagic=64-bit;; *) libsuff= shlibsuff= libmagic=never-match;; esac ;; esac shlibpath_var=LD_LIBRARY${shlibsuff}_PATH shlibpath_overrides_runpath=no sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" hardcode_into_libs=yes ;; # No shared lib support for Linux oldld, aout, or coff. linux*oldld* | linux*aout* | linux*coff*) dynamic_linker=no ;; # This must be Linux ELF. linux* | k*bsd*-gnu | kopensolaris*-gnu) version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no # Some binutils ld are patched to set DT_RUNPATH save_LDFLAGS=$LDFLAGS save_libdir=$libdir eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \ LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\"" AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null], [shlibpath_overrides_runpath=yes])]) LDFLAGS=$save_LDFLAGS libdir=$save_libdir # This implies no fast_install, which is unacceptable. # Some rework will be needed to allow for fast_install # before this can be enabled. hardcode_into_libs=yes # Append ld.so.conf contents to the search path if test -f /etc/ld.so.conf; then lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '` sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" fi # We used to test for /lib/ld.so.1 and disable shared libraries on # powerpc, because MkLinux only supported shared libraries with the # GNU dynamic linker. Since this was broken with cross compilers, # most powerpc-linux boxes support dynamic linking these days and # people can always --disable-shared, the test was removed, and we # assume the GNU/Linux dynamic linker is in use. dynamic_linker='GNU/Linux ld.so' ;; netbsdelf*-gnu) version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes dynamic_linker='NetBSD ld.elf_so' ;; netbsd*) version_type=sunos need_lib_prefix=no need_version=no if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' dynamic_linker='NetBSD (a.out) ld.so' else library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' dynamic_linker='NetBSD ld.elf_so' fi shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; newsos6) version_type=linux library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes ;; *nto* | *qnx*) version_type=qnx need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes dynamic_linker='ldqnx.so' ;; openbsd*) version_type=sunos sys_lib_dlsearch_path_spec="/usr/lib" need_lib_prefix=no # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. case $host_os in openbsd3.3 | openbsd3.3.*) need_version=yes ;; *) need_version=no ;; esac library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' shlibpath_var=LD_LIBRARY_PATH if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then case $host_os in openbsd2.[[89]] | openbsd2.[[89]].*) shlibpath_overrides_runpath=no ;; *) shlibpath_overrides_runpath=yes ;; esac else shlibpath_overrides_runpath=yes fi ;; os2*) libname_spec='$name' shrext_cmds=".dll" need_lib_prefix=no library_names_spec='$libname${shared_ext} $libname.a' dynamic_linker='OS/2 ld.exe' shlibpath_var=LIBPATH ;; osf3* | osf4* | osf5*) version_type=osf need_lib_prefix=no need_version=no soname_spec='${libname}${release}${shared_ext}$major' library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" ;; rdos*) dynamic_linker=no ;; solaris*) version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes # ldd complains unless libraries are executable postinstall_cmds='chmod +x $lib' ;; sunos4*) version_type=sunos library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes if test "$with_gnu_ld" = yes; then need_lib_prefix=no fi need_version=yes ;; sysv4 | sysv4.3*) version_type=linux library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH case $host_vendor in sni) shlibpath_overrides_runpath=no need_lib_prefix=no runpath_var=LD_RUN_PATH ;; siemens) need_lib_prefix=no ;; motorola) need_lib_prefix=no need_version=no shlibpath_overrides_runpath=no sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' ;; esac ;; sysv4*MP*) if test -d /usr/nec ;then version_type=linux library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' soname_spec='$libname${shared_ext}.$major' shlibpath_var=LD_LIBRARY_PATH fi ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) version_type=freebsd-elf need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes if test "$with_gnu_ld" = yes; then sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' else sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' case $host_os in sco3.2v5*) sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" ;; esac fi sys_lib_dlsearch_path_spec='/usr/lib' ;; tpf*) # TPF is a cross-target only. Preferred cross-host = GNU/Linux. version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; uts4*) version_type=linux library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH ;; *) dynamic_linker=no ;; esac AC_MSG_RESULT([$dynamic_linker]) test "$dynamic_linker" = no && can_build_shared=no variables_saved_for_relink="PATH $shlibpath_var $runpath_var" if test "$GCC" = yes; then variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" fi if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec" fi if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec" fi _LT_DECL([], [variables_saved_for_relink], [1], [Variables whose values should be saved in libtool wrapper scripts and restored at link time]) _LT_DECL([], [need_lib_prefix], [0], [Do we need the "lib" prefix for modules?]) _LT_DECL([], [need_version], [0], [Do we need a version for libraries?]) _LT_DECL([], [version_type], [0], [Library versioning type]) _LT_DECL([], [runpath_var], [0], [Shared library runtime path variable]) _LT_DECL([], [shlibpath_var], [0],[Shared library path variable]) _LT_DECL([], [shlibpath_overrides_runpath], [0], [Is shlibpath searched before the hard-coded library search path?]) _LT_DECL([], [libname_spec], [1], [Format of library name prefix]) _LT_DECL([], [library_names_spec], [1], [[List of archive names. First name is the real one, the rest are links. The last name is the one that the linker finds with -lNAME]]) _LT_DECL([], [soname_spec], [1], [[The coded name of the library, if different from the real name]]) _LT_DECL([], [postinstall_cmds], [2], [Command to use after installation of a shared archive]) _LT_DECL([], [postuninstall_cmds], [2], [Command to use after uninstallation of a shared archive]) _LT_DECL([], [finish_cmds], [2], [Commands used to finish a libtool library installation in a directory]) _LT_DECL([], [finish_eval], [1], [[As "finish_cmds", except a single script fragment to be evaled but not shown]]) _LT_DECL([], [hardcode_into_libs], [0], [Whether we should hardcode library paths into libraries]) _LT_DECL([], [sys_lib_search_path_spec], [2], [Compile-time system search path for libraries]) _LT_DECL([], [sys_lib_dlsearch_path_spec], [2], [Run-time system search path for libraries]) ])# _LT_SYS_DYNAMIC_LINKER # _LT_PATH_TOOL_PREFIX(TOOL) # -------------------------- # find a file program which can recognize shared library AC_DEFUN([_LT_PATH_TOOL_PREFIX], [m4_require([_LT_DECL_EGREP])dnl AC_MSG_CHECKING([for $1]) AC_CACHE_VAL(lt_cv_path_MAGIC_CMD, [case $MAGIC_CMD in [[\\/*] | ?:[\\/]*]) lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. ;; *) lt_save_MAGIC_CMD="$MAGIC_CMD" lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR dnl $ac_dummy forces splitting on constant user-supplied paths. dnl POSIX.2 word splitting is done only on the output of word expansions, dnl not every word. This closes a longstanding sh security hole. ac_dummy="m4_if([$2], , $PATH, [$2])" for ac_dir in $ac_dummy; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$1; then lt_cv_path_MAGIC_CMD="$ac_dir/$1" if test -n "$file_magic_test_file"; then case $deplibs_check_method in "file_magic "*) file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` MAGIC_CMD="$lt_cv_path_MAGIC_CMD" if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | $EGREP "$file_magic_regex" > /dev/null; then : else cat <<_LT_EOF 1>&2 *** Warning: the command libtool uses to detect shared libraries, *** $file_magic_cmd, produces output that libtool cannot recognize. *** The result is that libtool may fail to recognize shared libraries *** as such. This will affect the creation of libtool libraries that *** depend on shared libraries, but programs linked with such libtool *** libraries will work regardless of this problem. Nevertheless, you *** may want to report the problem to your system manager and/or to *** bug-libtool@gnu.org _LT_EOF fi ;; esac fi break fi done IFS="$lt_save_ifs" MAGIC_CMD="$lt_save_MAGIC_CMD" ;; esac]) MAGIC_CMD="$lt_cv_path_MAGIC_CMD" if test -n "$MAGIC_CMD"; then AC_MSG_RESULT($MAGIC_CMD) else AC_MSG_RESULT(no) fi _LT_DECL([], [MAGIC_CMD], [0], [Used to examine libraries when file_magic_cmd begins with "file"])dnl ])# _LT_PATH_TOOL_PREFIX # Old name: AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], []) # _LT_PATH_MAGIC # -------------- # find a file program which can recognize a shared library m4_defun([_LT_PATH_MAGIC], [_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH) if test -z "$lt_cv_path_MAGIC_CMD"; then if test -n "$ac_tool_prefix"; then _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH) else MAGIC_CMD=: fi fi ])# _LT_PATH_MAGIC # LT_PATH_LD # ---------- # find the pathname to the GNU or non-GNU linker AC_DEFUN([LT_PATH_LD], [AC_REQUIRE([AC_PROG_CC])dnl AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([AC_CANONICAL_BUILD])dnl m4_require([_LT_DECL_SED])dnl m4_require([_LT_DECL_EGREP])dnl AC_ARG_WITH([gnu-ld], [AS_HELP_STRING([--with-gnu-ld], [assume the C compiler uses GNU ld @<:@default=no@:>@])], [test "$withval" = no || with_gnu_ld=yes], [with_gnu_ld=no])dnl ac_prog=ld if test "$GCC" = yes; then # Check if gcc -print-prog-name=ld gives a path. AC_MSG_CHECKING([for ld used by $CC]) case $host in *-*-mingw*) # gcc leaves a trailing carriage return which upsets mingw ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; *) ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; esac case $ac_prog in # Accept absolute paths. [[\\/]]* | ?:[[\\/]]*) re_direlt='/[[^/]][[^/]]*/\.\./' # Canonicalize the pathname of ld ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` done test -z "$LD" && LD="$ac_prog" ;; "") # If it fails, then pretend we aren't using GCC. ac_prog=ld ;; *) # If it is relative, then search for the first ld in PATH. with_gnu_ld=unknown ;; esac elif test "$with_gnu_ld" = yes; then AC_MSG_CHECKING([for GNU ld]) else AC_MSG_CHECKING([for non-GNU ld]) fi AC_CACHE_VAL(lt_cv_path_LD, [if test -z "$LD"; then lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then lt_cv_path_LD="$ac_dir/$ac_prog" # Check to see if the program is GNU ld. I'd rather use --version, # but apparently some variants of GNU ld only accept -v. # Break only if it was the GNU/non-GNU ld that we prefer. case `"$lt_cv_path_LD" -v 2>&1 &1 /dev/null 2>&1; then lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' lt_cv_file_magic_cmd='func_win32_libid' else lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?' lt_cv_file_magic_cmd='$OBJDUMP -f' fi ;; cegcc) # use the weaker test based on 'objdump'. See mingw*. lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' lt_cv_file_magic_cmd='$OBJDUMP -f' ;; darwin* | rhapsody*) lt_cv_deplibs_check_method=pass_all ;; freebsd* | dragonfly*) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then case $host_cpu in i*86 ) # Not sure whether the presence of OpenBSD here was a mistake. # Let's accept both of them until this is cleared up. lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library' lt_cv_file_magic_cmd=/usr/bin/file lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` ;; esac else lt_cv_deplibs_check_method=pass_all fi ;; gnu*) lt_cv_deplibs_check_method=pass_all ;; hpux10.20* | hpux11*) lt_cv_file_magic_cmd=/usr/bin/file case $host_cpu in ia64*) lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64' lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so ;; hppa*64*) [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]'] lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl ;; *) lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library' lt_cv_file_magic_test_file=/usr/lib/libc.sl ;; esac ;; interix[[3-9]]*) # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$' ;; irix5* | irix6* | nonstopux*) case $LD in *-32|*"-32 ") libmagic=32-bit;; *-n32|*"-n32 ") libmagic=N32;; *-64|*"-64 ") libmagic=64-bit;; *) libmagic=never-match;; esac lt_cv_deplibs_check_method=pass_all ;; # This must be Linux ELF. linux* | k*bsd*-gnu | kopensolaris*-gnu) lt_cv_deplibs_check_method=pass_all ;; netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' else lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$' fi ;; newos6*) lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)' lt_cv_file_magic_cmd=/usr/bin/file lt_cv_file_magic_test_file=/usr/lib/libnls.so ;; *nto* | *qnx*) lt_cv_deplibs_check_method=pass_all ;; openbsd*) if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$' else lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' fi ;; osf3* | osf4* | osf5*) lt_cv_deplibs_check_method=pass_all ;; rdos*) lt_cv_deplibs_check_method=pass_all ;; solaris*) lt_cv_deplibs_check_method=pass_all ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) lt_cv_deplibs_check_method=pass_all ;; sysv4 | sysv4.3*) case $host_vendor in motorola) lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]' lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` ;; ncr) lt_cv_deplibs_check_method=pass_all ;; sequent) lt_cv_file_magic_cmd='/bin/file' lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )' ;; sni) lt_cv_file_magic_cmd='/bin/file' lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib" lt_cv_file_magic_test_file=/lib/libc.so ;; siemens) lt_cv_deplibs_check_method=pass_all ;; pc) lt_cv_deplibs_check_method=pass_all ;; esac ;; tpf*) lt_cv_deplibs_check_method=pass_all ;; esac ]) file_magic_cmd=$lt_cv_file_magic_cmd deplibs_check_method=$lt_cv_deplibs_check_method test -z "$deplibs_check_method" && deplibs_check_method=unknown _LT_DECL([], [deplibs_check_method], [1], [Method to check whether dependent libraries are shared objects]) _LT_DECL([], [file_magic_cmd], [1], [Command to use when deplibs_check_method == "file_magic"]) ])# _LT_CHECK_MAGIC_METHOD # LT_PATH_NM # ---------- # find the pathname to a BSD- or MS-compatible name lister AC_DEFUN([LT_PATH_NM], [AC_REQUIRE([AC_PROG_CC])dnl AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM, [if test -n "$NM"; then # Let the user override the test. lt_cv_path_NM="$NM" else lt_nm_to_check="${ac_tool_prefix}nm" if test -n "$ac_tool_prefix" && test "$build" = "$host"; then lt_nm_to_check="$lt_nm_to_check nm" fi for lt_tmp_nm in $lt_nm_to_check; do lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. tmp_nm="$ac_dir/$lt_tmp_nm" if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then # Check to see if the nm accepts a BSD-compat flag. # Adding the `sed 1q' prevents false positives on HP-UX, which says: # nm: unknown option "B" ignored # Tru64's nm complains that /dev/null is an invalid object file case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in */dev/null* | *'Invalid file or object type'*) lt_cv_path_NM="$tmp_nm -B" break ;; *) case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in */dev/null*) lt_cv_path_NM="$tmp_nm -p" break ;; *) lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but continue # so that we can try to find one that supports BSD flags ;; esac ;; esac fi done IFS="$lt_save_ifs" done : ${lt_cv_path_NM=no} fi]) if test "$lt_cv_path_NM" != "no"; then NM="$lt_cv_path_NM" else # Didn't find any BSD compatible name lister, look for dumpbin. AC_CHECK_TOOLS(DUMPBIN, ["dumpbin -symbols" "link -dump -symbols"], :) AC_SUBST([DUMPBIN]) if test "$DUMPBIN" != ":"; then NM="$DUMPBIN" fi fi test -z "$NM" && NM=nm AC_SUBST([NM]) _LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface], [lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext (eval echo "\"\$as_me:__oline__: $ac_compile\"" >&AS_MESSAGE_LOG_FD) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&AS_MESSAGE_LOG_FD (eval echo "\"\$as_me:__oline__: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&AS_MESSAGE_LOG_FD (eval echo "\"\$as_me:__oline__: output\"" >&AS_MESSAGE_LOG_FD) cat conftest.out >&AS_MESSAGE_LOG_FD if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" fi rm -f conftest*]) ])# LT_PATH_NM # Old names: AU_ALIAS([AM_PROG_NM], [LT_PATH_NM]) AU_ALIAS([AC_PROG_NM], [LT_PATH_NM]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AM_PROG_NM], []) dnl AC_DEFUN([AC_PROG_NM], []) # LT_LIB_M # -------- # check for math library AC_DEFUN([LT_LIB_M], [AC_REQUIRE([AC_CANONICAL_HOST])dnl LIBM= case $host in *-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*) # These system don't have libm, or don't need it ;; *-ncr-sysv4.3*) AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw") AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm") ;; *) AC_CHECK_LIB(m, cos, LIBM="-lm") ;; esac AC_SUBST([LIBM]) ])# LT_LIB_M # Old name: AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_CHECK_LIBM], []) # _LT_COMPILER_NO_RTTI([TAGNAME]) # ------------------------------- m4_defun([_LT_COMPILER_NO_RTTI], [m4_require([_LT_TAG_COMPILER])dnl _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= if test "$GCC" = yes; then _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions], lt_cv_prog_compiler_rtti_exceptions, [-fno-rtti -fno-exceptions], [], [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"]) fi _LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1], [Compiler flag to turn off builtin functions]) ])# _LT_COMPILER_NO_RTTI # _LT_CMD_GLOBAL_SYMBOLS # ---------------------- m4_defun([_LT_CMD_GLOBAL_SYMBOLS], [AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([AC_PROG_CC])dnl AC_REQUIRE([LT_PATH_NM])dnl AC_REQUIRE([LT_PATH_LD])dnl m4_require([_LT_DECL_SED])dnl m4_require([_LT_DECL_EGREP])dnl m4_require([_LT_TAG_COMPILER])dnl # Check for command to grab the raw symbol name followed by C symbol from nm. AC_MSG_CHECKING([command to parse $NM output from $compiler object]) AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe], [ # These are sane defaults that work on at least a few old systems. # [They come from Ultrix. What could be older than Ultrix?!! ;)] # Character class describing NM global symbol codes. symcode='[[BCDEGRST]]' # Regexp to match symbols that can be accessed directly from C. sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)' # Define system-specific variables. case $host_os in aix*) symcode='[[BCDT]]' ;; cygwin* | mingw* | pw32* | cegcc*) symcode='[[ABCDGISTW]]' ;; hpux*) if test "$host_cpu" = ia64; then symcode='[[ABCDEGRST]]' fi ;; irix* | nonstopux*) symcode='[[BCDEGRST]]' ;; osf*) symcode='[[BCDEGQRST]]' ;; solaris*) symcode='[[BDRT]]' ;; sco3.2v5*) symcode='[[DT]]' ;; sysv4.2uw2*) symcode='[[DT]]' ;; sysv5* | sco5v6* | unixware* | OpenUNIX*) symcode='[[ABDT]]' ;; sysv4) symcode='[[DFNSTU]]' ;; esac # If we're using GNU nm, then use its standard symbol codes. case `$NM -V 2>&1` in *GNU* | *'with BFD'*) symcode='[[ABCDGIRSTW]]' ;; esac # Transform an extracted symbol line into a proper C declaration. # Some systems (esp. on ia64) link data and code symbols differently, # so use this general approach. lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" # Transform an extracted symbol line into symbol name and symbol address lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (void *) \&\2},/p'" lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \(lib[[^ ]]*\)$/ {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"lib\2\", (void *) \&\2},/p'" # Handle CRLF in mingw tool chain opt_cr= case $build_os in mingw*) opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp ;; esac # Try without a prefix underscore, then with it. for ac_symprfx in "" "_"; do # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. symxfrm="\\1 $ac_symprfx\\2 \\2" # Write the raw and C identifiers. if test "$lt_cv_nm_interface" = "MS dumpbin"; then # Fake it for dumpbin and say T for any non-static function # and D for any global variable. # Also find C++ and __fastcall symbols from MSVC++, # which start with @ or ?. lt_cv_sys_global_symbol_pipe="$AWK ['"\ " {last_section=section; section=\$ 3};"\ " /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ " \$ 0!~/External *\|/{next};"\ " / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ " {if(hide[section]) next};"\ " {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\ " {split(\$ 0, a, /\||\r/); split(a[2], s)};"\ " s[1]~/^[@?]/{print s[1], s[1]; next};"\ " s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\ " ' prfx=^$ac_symprfx]" else lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" fi # Check to see that the pipe works correctly. pipe_works=no rm -f conftest* cat > conftest.$ac_ext <<_LT_EOF #ifdef __cplusplus extern "C" { #endif char nm_test_var; void nm_test_func(void); void nm_test_func(void){} #ifdef __cplusplus } #endif int main(){nm_test_var='a';nm_test_func();return(0);} _LT_EOF if AC_TRY_EVAL(ac_compile); then # Now try to grab the symbols. nlist=conftest.nm if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) && test -s "$nlist"; then # Try sorting and uniquifying the output. if sort "$nlist" | uniq > "$nlist"T; then mv -f "$nlist"T "$nlist" else rm -f "$nlist"T fi # Make sure that we snagged all the symbols we need. if $GREP ' nm_test_var$' "$nlist" >/dev/null; then if $GREP ' nm_test_func$' "$nlist" >/dev/null; then cat <<_LT_EOF > conftest.$ac_ext #ifdef __cplusplus extern "C" { #endif _LT_EOF # Now generate the symbol file. eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' cat <<_LT_EOF >> conftest.$ac_ext /* The mapping between symbol names and symbols. */ const struct { const char *name; void *address; } lt__PROGRAM__LTX_preloaded_symbols[[]] = { { "@PROGRAM@", (void *) 0 }, _LT_EOF $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/ {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext cat <<\_LT_EOF >> conftest.$ac_ext {0, (void *) 0} }; /* This works around a problem in FreeBSD linker */ #ifdef FREEBSD_WORKAROUND static const void *lt_preloaded_setup() { return lt__PROGRAM__LTX_preloaded_symbols; } #endif #ifdef __cplusplus } #endif _LT_EOF # Now try linking the two files. mv conftest.$ac_objext conftstm.$ac_objext lt_save_LIBS="$LIBS" lt_save_CFLAGS="$CFLAGS" LIBS="conftstm.$ac_objext" CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)" if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then pipe_works=yes fi LIBS="$lt_save_LIBS" CFLAGS="$lt_save_CFLAGS" else echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD fi else echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD fi else echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD fi else echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD cat conftest.$ac_ext >&5 fi rm -rf conftest* conftst* # Do not use the global_symbol_pipe unless it works. if test "$pipe_works" = yes; then break else lt_cv_sys_global_symbol_pipe= fi done ]) if test -z "$lt_cv_sys_global_symbol_pipe"; then lt_cv_sys_global_symbol_to_cdecl= fi if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then AC_MSG_RESULT(failed) else AC_MSG_RESULT(ok) fi _LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1], [Take the output of nm and produce a listing of raw symbols and C names]) _LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1], [Transform the output of nm in a proper C declaration]) _LT_DECL([global_symbol_to_c_name_address], [lt_cv_sys_global_symbol_to_c_name_address], [1], [Transform the output of nm in a C name address pair]) _LT_DECL([global_symbol_to_c_name_address_lib_prefix], [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1], [Transform the output of nm in a C name address pair when lib prefix is needed]) ]) # _LT_CMD_GLOBAL_SYMBOLS # _LT_COMPILER_PIC([TAGNAME]) # --------------------------- m4_defun([_LT_COMPILER_PIC], [m4_require([_LT_TAG_COMPILER])dnl _LT_TAGVAR(lt_prog_compiler_wl, $1)= _LT_TAGVAR(lt_prog_compiler_pic, $1)= _LT_TAGVAR(lt_prog_compiler_static, $1)= AC_MSG_CHECKING([for $compiler option to produce PIC]) m4_if([$1], [CXX], [ # C++ specific cases for pic, static, wl, etc. if test "$GXX" = yes; then _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' case $host_os in aix*) # All AIX code is PIC. if test "$host_cpu" = ia64; then # AIX 5 now supports IA64 processor _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; m68k) # FIXME: we need at least 68020 code to build shared libraries, but # adding the `-m68020' flag to GCC prevents building anything better, # like `-m68040'. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' ;; esac ;; beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) # PIC is the default for these OSes. ;; mingw* | cygwin* | os2* | pw32* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style # (--disable-auto-import) libraries m4_if([$1], [GCJ], [], [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) ;; darwin* | rhapsody*) # PIC is the default on this platform # Common symbols not allowed in MH_DYLIB files _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' ;; *djgpp*) # DJGPP does not support shared libraries at all _LT_TAGVAR(lt_prog_compiler_pic, $1)= ;; interix[[3-9]]*) # Interix 3.x gcc -fpic/-fPIC options generate broken code. # Instead, we relocate shared libraries at runtime. ;; sysv4*MP*) if test -d /usr/nec; then _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic fi ;; hpux*) # PIC is the default for 64-bit PA HP-UX, but not for 32-bit # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag # sets the default TLS model and affects inlining. case $host_cpu in hppa*64*) ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; esac ;; *qnx* | *nto*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; esac else case $host_os in aix[[4-9]]*) # All AIX code is PIC. if test "$host_cpu" = ia64; then # AIX 5 now supports IA64 processor _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' else _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' fi ;; chorus*) case $cc_basename in cxch68*) # Green Hills C++ Compiler # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" ;; esac ;; dgux*) case $cc_basename in ec++*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' ;; ghcx*) # Green Hills C++ Compiler _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' ;; *) ;; esac ;; freebsd* | dragonfly*) # FreeBSD uses GNU C++ ;; hpux9* | hpux10* | hpux11*) case $cc_basename in CC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' if test "$host_cpu" != ia64; then _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' fi ;; aCC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' case $host_cpu in hppa*64*|ia64*) # +Z the default ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' ;; esac ;; *) ;; esac ;; interix*) # This is c89, which is MS Visual C++ (no shared libs) # Anyone wants to do a port? ;; irix5* | irix6* | nonstopux*) case $cc_basename in CC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' # CC pic flag -KPIC is the default. ;; *) ;; esac ;; linux* | k*bsd*-gnu | kopensolaris*-gnu) case $cc_basename in KCC*) # KAI C++ Compiler _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; ecpc* ) # old Intel C++ for x86_64 which still supported -KPIC. _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; icpc* ) # Intel C++, used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; pgCC* | pgcpp*) # Portland Group C++ compiler _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; cxx*) # Compaq C++ # Make sure the PIC flag is empty. It appears that all Alpha # Linux and Compaq Tru64 Unix objects are PIC. _LT_TAGVAR(lt_prog_compiler_pic, $1)= _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; xlc* | xlC*) # IBM XL 8.0 on PPC _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' ;; *) case `$CC -V 2>&1 | sed 5q` in *Sun\ C*) # Sun C++ 5.9 _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' ;; esac ;; esac ;; lynxos*) ;; m88k*) ;; mvs*) case $cc_basename in cxx*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall' ;; *) ;; esac ;; netbsd* | netbsdelf*-gnu) ;; *qnx* | *nto*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' ;; osf3* | osf4* | osf5*) case $cc_basename in KCC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' ;; RCC*) # Rational C++ 2.4.1 _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' ;; cxx*) # Digital/Compaq C++ _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # Make sure the PIC flag is empty. It appears that all Alpha # Linux and Compaq Tru64 Unix objects are PIC. _LT_TAGVAR(lt_prog_compiler_pic, $1)= _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; *) ;; esac ;; psos*) ;; solaris*) case $cc_basename in CC*) # Sun C++ 4.2, 5.x and Centerline C++ _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' ;; gcx*) # Green Hills C++ Compiler _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' ;; *) ;; esac ;; sunos4*) case $cc_basename in CC*) # Sun C++ 4.x _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; lcc*) # Lucid _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' ;; *) ;; esac ;; sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) case $cc_basename in CC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; esac ;; tandem*) case $cc_basename in NCC*) # NonStop-UX NCC 3.20 _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' ;; *) ;; esac ;; vxworks*) ;; *) _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no ;; esac fi ], [ if test "$GCC" = yes; then _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' case $host_os in aix*) # All AIX code is PIC. if test "$host_cpu" = ia64; then # AIX 5 now supports IA64 processor _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; m68k) # FIXME: we need at least 68020 code to build shared libraries, but # adding the `-m68020' flag to GCC prevents building anything better, # like `-m68040'. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' ;; esac ;; beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) # PIC is the default for these OSes. ;; mingw* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style # (--disable-auto-import) libraries m4_if([$1], [GCJ], [], [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) ;; darwin* | rhapsody*) # PIC is the default on this platform # Common symbols not allowed in MH_DYLIB files _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' ;; hpux*) # PIC is the default for 64-bit PA HP-UX, but not for 32-bit # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag # sets the default TLS model and affects inlining. case $host_cpu in hppa*64*) # +Z the default ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; esac ;; interix[[3-9]]*) # Interix 3.x gcc -fpic/-fPIC options generate broken code. # Instead, we relocate shared libraries at runtime. ;; msdosdjgpp*) # Just because we use GCC doesn't mean we suddenly get shared libraries # on systems that don't support them. _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no enable_shared=no ;; *nto* | *qnx*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' ;; sysv4*MP*) if test -d /usr/nec; then _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic fi ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; esac else # PORTME Check for flag to pass linker flags through the system compiler. case $host_os in aix*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' if test "$host_cpu" = ia64; then # AIX 5 now supports IA64 processor _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' else _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' fi ;; mingw* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). m4_if([$1], [GCJ], [], [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) ;; hpux9* | hpux10* | hpux11*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but # not for PA HP-UX. case $host_cpu in hppa*64*|ia64*) # +Z the default ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' ;; esac # Is there a better lt_prog_compiler_static that works with the bundled CC? _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' ;; irix5* | irix6* | nonstopux*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # PIC (with -KPIC) is the default. _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; linux* | k*bsd*-gnu | kopensolaris*-gnu) case $cc_basename in # old Intel for x86_64 which still supported -KPIC. ecc*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; # icc used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. icc* | ifort*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; # Lahey Fortran 8.1. lf95*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared' _LT_TAGVAR(lt_prog_compiler_static, $1)='--static' ;; pgcc* | pgf77* | pgf90* | pgf95*) # Portland Group compilers (*not* the Pentium gcc compiler, # which looks to be a dead project) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; ccc*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # All Alpha code is PIC. _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; xl*) # IBM XL C 8.0/Fortran 10.1 on PPC _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' ;; *) case `$CC -V 2>&1 | sed 5q` in *Sun\ C*) # Sun C 5.9 _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' ;; *Sun\ F*) # Sun Fortran 8.3 passes all unrecognized flags to the linker _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='' ;; esac ;; esac ;; newsos6) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; *nto* | *qnx*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' ;; osf3* | osf4* | osf5*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # All OSF/1 code is PIC. _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; rdos*) _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; solaris*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' case $cc_basename in f77* | f90* | f95*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';; *) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';; esac ;; sunos4*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; sysv4 | sysv4.2uw2* | sysv4.3*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; sysv4*MP*) if test -d /usr/nec ;then _LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' fi ;; sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; unicos*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no ;; uts4*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; *) _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no ;; esac fi ]) case $host_os in # For platforms which do not support PIC, -DPIC is meaningless: *djgpp*) _LT_TAGVAR(lt_prog_compiler_pic, $1)= ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])" ;; esac AC_MSG_RESULT([$_LT_TAGVAR(lt_prog_compiler_pic, $1)]) _LT_TAGDECL([wl], [lt_prog_compiler_wl], [1], [How to pass a linker flag through the compiler]) # # Check to make sure the PIC flag actually works. # if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works], [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)], [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [], [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in "" | " "*) ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;; esac], [_LT_TAGVAR(lt_prog_compiler_pic, $1)= _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no]) fi _LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1], [Additional compiler flags for building library objects]) # # Check to make sure the static flag actually works. # wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\" _LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works], _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1), $lt_tmp_static_flag, [], [_LT_TAGVAR(lt_prog_compiler_static, $1)=]) _LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1], [Compiler flag to prevent dynamic linking]) ])# _LT_COMPILER_PIC # _LT_LINKER_SHLIBS([TAGNAME]) # ---------------------------- # See if the linker supports building shared libraries. m4_defun([_LT_LINKER_SHLIBS], [AC_REQUIRE([LT_PATH_LD])dnl AC_REQUIRE([LT_PATH_NM])dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_EGREP])dnl m4_require([_LT_DECL_SED])dnl m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl m4_require([_LT_TAG_COMPILER])dnl AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) m4_if([$1], [CXX], [ _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' case $host_os in aix[[4-9]]*) # If we're using GNU nm, then we don't want the "-C" option. # -C means demangle to AIX nm, but means don't demangle with GNU nm if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' else _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' fi ;; pw32*) _LT_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds" ;; cygwin* | mingw* | cegcc*) _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' ;; linux* | k*bsd*-gnu) _LT_TAGVAR(link_all_deplibs, $1)=no ;; *) _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' ;; esac _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] ], [ runpath_var= _LT_TAGVAR(allow_undefined_flag, $1)= _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(archive_cmds, $1)= _LT_TAGVAR(archive_expsym_cmds, $1)= _LT_TAGVAR(compiler_needs_object, $1)=no _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' _LT_TAGVAR(hardcode_automatic, $1)=no _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= _LT_TAGVAR(hardcode_libdir_separator, $1)= _LT_TAGVAR(hardcode_minus_L, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported _LT_TAGVAR(inherit_rpath, $1)=no _LT_TAGVAR(link_all_deplibs, $1)=unknown _LT_TAGVAR(module_cmds, $1)= _LT_TAGVAR(module_expsym_cmds, $1)= _LT_TAGVAR(old_archive_from_new_cmds, $1)= _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)= _LT_TAGVAR(thread_safe_flag_spec, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= # include_expsyms should be a list of space-separated symbols to be *always* # included in the symbol list _LT_TAGVAR(include_expsyms, $1)= # exclude_expsyms can be an extended regexp of symbols to exclude # it will be wrapped by ` (' and `)$', so one must not match beginning or # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', # as well as any symbol that contains `d'. _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out # platforms (ab)use it in PIC code, but their linkers get confused if # the symbol is explicitly referenced. Since portable code cannot # rely on this symbol name, it's probably fine to never include it in # preloaded symbol tables. # Exclude shared library initialization/finalization symbols. dnl Note also adjust exclude_expsyms for C++ above. extract_expsyms_cmds= case $host_os in cygwin* | mingw* | pw32* | cegcc*) # FIXME: the MSVC++ port hasn't been tested in a loooong time # When not using gcc, we currently assume that we are using # Microsoft Visual C++. if test "$GCC" != yes; then with_gnu_ld=no fi ;; interix*) # we just hope/assume this is gcc and not c89 (= MSVC++) with_gnu_ld=yes ;; openbsd*) with_gnu_ld=no ;; linux* | k*bsd*-gnu) _LT_TAGVAR(link_all_deplibs, $1)=no ;; esac _LT_TAGVAR(ld_shlibs, $1)=yes if test "$with_gnu_ld" = yes; then # If archive_cmds runs LD, not CC, wlarc should be empty wlarc='${wl}' # Set some defaults for GNU ld with shared library support. These # are reset later if shared libraries are not supported. Putting them # here allows them to be overridden if necessary. runpath_var=LD_RUN_PATH _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' # ancient GNU ld didn't support --whole-archive et. al. if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' else _LT_TAGVAR(whole_archive_flag_spec, $1)= fi supports_anon_versioning=no case `$LD -v 2>&1` in *GNU\ gold*) supports_anon_versioning=yes ;; *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11 *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... *\ 2.11.*) ;; # other 2.11 versions *) supports_anon_versioning=yes ;; esac # See if GNU ld supports shared libraries. case $host_os in aix[[3-9]]*) # On AIX/PPC, the GNU linker is very broken if test "$host_cpu" != ia64; then _LT_TAGVAR(ld_shlibs, $1)=no cat <<_LT_EOF 1>&2 *** Warning: the GNU linker, at least up to release 2.9.1, is reported *** to be unable to reliably create shared libraries on AIX. *** Therefore, libtool is disabling shared libraries support. If you *** really care for shared libraries, you may want to modify your PATH *** so that a non-GNU linker is found, and then restart. _LT_EOF fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='' ;; m68k) _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_minus_L, $1)=yes ;; esac ;; beos*) if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(allow_undefined_flag, $1)=unsupported # Joseph Beckenbach says some releases of gcc # support --undefined. This deserves some investigation. FIXME _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; cygwin* | mingw* | pw32* | cegcc*) # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, # as there is no search path for DLLs. _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols' if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' # If the export-symbols file already is a .def file (1st line # is EXPORTS), use it as is; otherwise, prepend... _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then cp $export_symbols $output_objdir/$soname.def; else echo EXPORTS > $output_objdir/$soname.def; cat $export_symbols >> $output_objdir/$soname.def; fi~ $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; interix[[3-9]]*) _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. # Instead, shared libraries are loaded at an image base (0x10000000 by # default) and relocated if they conflict, which is a slow very memory # consuming and fragmenting process. To avoid this, we pick a random, # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link # time. Moving up from 0x10000000 also allows more sbrk(2) space. _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' ;; gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) tmp_diet=no if test "$host_os" = linux-dietlibc; then case $cc_basename in diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) esac fi if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ && test "$tmp_diet" = no then tmp_addflag= tmp_sharedflag='-shared' case $cc_basename,$host_cpu in pgcc*) # Portland Group C compiler _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' tmp_addflag=' $pic_flag' ;; pgf77* | pgf90* | pgf95*) # Portland Group f77 and f90 compilers _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' tmp_addflag=' $pic_flag -Mnomain' ;; ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 tmp_addflag=' -i_dynamic' ;; efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 tmp_addflag=' -i_dynamic -nofor_main' ;; ifc* | ifort*) # Intel Fortran compiler tmp_addflag=' -nofor_main' ;; lf95*) # Lahey Fortran 8.1 _LT_TAGVAR(whole_archive_flag_spec, $1)= tmp_sharedflag='--shared' ;; xl[[cC]]*) # IBM XL C 8.0 on PPC (deal with xlf below) tmp_sharedflag='-qmkshrobj' tmp_addflag= ;; esac case `$CC -V 2>&1 | sed 5q` in *Sun\ C*) # Sun C 5.9 _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' _LT_TAGVAR(compiler_needs_object, $1)=yes tmp_sharedflag='-G' ;; *Sun\ F*) # Sun Fortran 8.3 tmp_sharedflag='-G' ;; esac _LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' if test "x$supports_anon_versioning" = xyes; then _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' fi case $cc_basename in xlf*) # IBM XL Fortran 10.1 on PPC cannot create shared libs itself _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir' _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib' if test "x$supports_anon_versioning" = xyes; then _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' fi ;; esac else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= else _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' fi ;; solaris*) if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then _LT_TAGVAR(ld_shlibs, $1)=no cat <<_LT_EOF 1>&2 *** Warning: The releases 2.8.* of the GNU linker cannot reliably *** create shared libraries on Solaris systems. Therefore, libtool *** is disabling shared libraries support. We urge you to upgrade GNU *** binutils to release 2.9.1 or newer. Another option is to modify *** your PATH or compiler configuration so that the native linker is *** used, and then restart. _LT_EOF elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) case `$LD -v 2>&1` in *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*) _LT_TAGVAR(ld_shlibs, $1)=no cat <<_LT_EOF 1>&2 *** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not *** reliably create shared libraries on SCO systems. Therefore, libtool *** is disabling shared libraries support. We urge you to upgrade GNU *** binutils to release 2.16.91.0.3 or newer. Another option is to modify *** your PATH or compiler configuration so that the native linker is *** used, and then restart. _LT_EOF ;; *) # For security reasons, it is highly recommended that you always # use absolute paths for naming shared libraries, and exclude the # DT_RUNPATH tag from executables and libraries. But doing so # requires that you compile everything twice, which is a pain. if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; sunos4*) _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' wlarc= _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *) if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac if test "$_LT_TAGVAR(ld_shlibs, $1)" = no; then runpath_var= _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= fi else # PORTME fill in a description of your system's linker (not GNU ld) case $host_os in aix3*) _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=yes _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' # Note: this linker hardcodes the directories in LIBPATH if there # are no directories specified by -L. _LT_TAGVAR(hardcode_minus_L, $1)=yes if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then # Neither direct hardcoding nor static linking is supported with a # broken collect2. _LT_TAGVAR(hardcode_direct, $1)=unsupported fi ;; aix[[4-9]]*) if test "$host_cpu" = ia64; then # On IA64, the linker does run time linking by default, so we don't # have to do anything special. aix_use_runtimelinking=no exp_sym_flag='-Bexport' no_entry_flag="" else # If we're using GNU nm, then we don't want the "-C" option. # -C means demangle to AIX nm, but means don't demangle with GNU nm if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' else _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' fi aix_use_runtimelinking=no # Test if we are trying to use run time linking or normal # AIX style linking. If -brtl is somewhere in LDFLAGS, we # need to do runtime linking. case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) for ld_flag in $LDFLAGS; do if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then aix_use_runtimelinking=yes break fi done ;; esac exp_sym_flag='-bexport' no_entry_flag='-bnoentry' fi # When large executables or shared objects are built, AIX ld can # have problems creating the table of contents. If linking a library # or program results in "error TOC overflow" add -mminimal-toc to # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. _LT_TAGVAR(archive_cmds, $1)='' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(hardcode_libdir_separator, $1)=':' _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(file_list_spec, $1)='${wl}-f,' if test "$GCC" = yes; then case $host_os in aix4.[[012]]|aix4.[[012]].*) # We only want to do this on AIX 4.2 and lower, the check # below for broken collect2 doesn't work under 4.3+ collect2name=`${CC} -print-prog-name=collect2` if test -f "$collect2name" && strings "$collect2name" | $GREP resolve_lib_name >/dev/null then # We have reworked collect2 : else # We have old collect2 _LT_TAGVAR(hardcode_direct, $1)=unsupported # It fails to find uninstalled libraries when the uninstalled # path is not listed in the libpath. Setting hardcode_minus_L # to unsupported forces relinking _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)= fi ;; esac shared_flag='-shared' if test "$aix_use_runtimelinking" = yes; then shared_flag="$shared_flag "'${wl}-G' fi _LT_TAGVAR(link_all_deplibs, $1)=no else # not using gcc if test "$host_cpu" = ia64; then # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release # chokes on -Wl,-G. The following line is correct: shared_flag='-G' else if test "$aix_use_runtimelinking" = yes; then shared_flag='${wl}-G' else shared_flag='${wl}-bM:SRE' fi fi fi _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall' # It seems that -bexpall does not export symbols beginning with # underscore (_), so it is better to generate a list of symbols to export. _LT_TAGVAR(always_export_symbols, $1)=yes if test "$aix_use_runtimelinking" = yes; then # Warning - without using the other runtime loading flags (-brtl), # -berok will link without error, but may produce a broken library. _LT_TAGVAR(allow_undefined_flag, $1)='-berok' # Determine the default libpath from the value encoded in an # empty executable. _LT_SYS_MODULE_PATH_AIX _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" else if test "$host_cpu" = ia64; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" else # Determine the default libpath from the value encoded in an # empty executable. _LT_SYS_MODULE_PATH_AIX _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" # Warning - without using the other run time loading flags, # -berok will link without error, but may produce a broken library. _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' # Exported symbols can be pulled into shared objects from archives _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' _LT_TAGVAR(archive_cmds_need_lc, $1)=yes # This is similar to how AIX traditionally builds its shared libraries. _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' fi fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='' ;; m68k) _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_minus_L, $1)=yes ;; esac ;; bsdi[[45]]*) _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic ;; cygwin* | mingw* | pw32* | cegcc*) # When not using gcc, we currently assume that we are using # Microsoft Visual C++. # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported # Tell ltmain to make .lib files, not .a files. libext=lib # Tell ltmain to make .dll files, not .so files. shrext_cmds=".dll" # FIXME: Setting linknames here is a bad hack. _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames=' # The linker will automatically build a .lib file if we build a DLL. _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' # FIXME: Should let the user specify the lib program. _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs' _LT_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes ;; darwin* | rhapsody*) _LT_DARWIN_LINKER_FEATURES($1) ;; dgux*) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; freebsd1*) _LT_TAGVAR(ld_shlibs, $1)=no ;; # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor # support. Future versions do this automatically, but an explicit c++rt0.o # does not break anything, and helps significantly (at the cost of a little # extra space). freebsd2.2*) _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; # Unfortunately, older versions of FreeBSD 2 do not have this feature. freebsd2*) _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; # FreeBSD 3 and greater uses gcc -shared to do shared libraries. freebsd* | dragonfly*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; hpux9*) if test "$GCC" = yes; then _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' else _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(hardcode_direct, $1)=yes # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' ;; hpux10*) if test "$GCC" = yes -a "$with_gnu_ld" = no; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' else _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' fi if test "$with_gnu_ld" = no; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. _LT_TAGVAR(hardcode_minus_L, $1)=yes fi ;; hpux11*) if test "$GCC" = yes -a "$with_gnu_ld" = no; then case $host_cpu in hppa*64*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' ;; ia64*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' ;; esac else case $host_cpu in hppa*64*) _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' ;; ia64*) _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' ;; esac fi if test "$with_gnu_ld" = no; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: case $host_cpu in hppa*64*|ia64*) _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *) _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. _LT_TAGVAR(hardcode_minus_L, $1)=yes ;; esac fi ;; irix5* | irix6* | nonstopux*) if test "$GCC" = yes; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' # Try to use the -exported_symbol ld option, if it does not # work, assume that -exports_file does not work either and # implicitly export all symbols. save_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null" AC_LINK_IFELSE(int foo(void) {}, _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib' ) LDFLAGS="$save_LDFLAGS" else _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib' fi _LT_TAGVAR(archive_cmds_need_lc, $1)='no' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(inherit_rpath, $1)=yes _LT_TAGVAR(link_all_deplibs, $1)=yes ;; netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else _LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; newsos6) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *nto* | *qnx*) ;; openbsd*) if test -f /usr/libexec/ld.so; then _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=yes if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' else case $host_os in openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*) _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' ;; esac fi else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; os2*) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' ;; osf3*) if test "$GCC" = yes; then _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' else _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' fi _LT_TAGVAR(archive_cmds_need_lc, $1)='no' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: ;; osf4* | osf5*) # as osf3* with the addition of -msym flag if test "$GCC" = yes; then _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' else _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp' # Both c and cxx compiler support -rpath directly _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' fi _LT_TAGVAR(archive_cmds_need_lc, $1)='no' _LT_TAGVAR(hardcode_libdir_separator, $1)=: ;; solaris*) _LT_TAGVAR(no_undefined_flag, $1)=' -z defs' if test "$GCC" = yes; then wlarc='${wl}' _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' else case `$CC -V 2>&1` in *"Compilers 5.0"*) wlarc='' _LT_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' ;; *) wlarc='${wl}' _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' ;; esac fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no case $host_os in solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; *) # The compiler driver will combine and reorder linker options, # but understands `-z linker_flag'. GCC discards it without `$wl', # but is careful enough not to reorder. # Supported since Solaris 2.6 (maybe 2.5.1?) if test "$GCC" = yes; then _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' else _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' fi ;; esac _LT_TAGVAR(link_all_deplibs, $1)=yes ;; sunos4*) if test "x$host_vendor" = xsequent; then # Use $CC to link under sequent, because it throws in some extra .o # files that make .init and .fini sections work. _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' else _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; sysv4) case $host_vendor in sni) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true??? ;; siemens) ## LD is ld it makes a PLAMLIB ## CC just makes a GrossModule. _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs' _LT_TAGVAR(hardcode_direct, $1)=no ;; motorola) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie ;; esac runpath_var='LD_RUN_PATH' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; sysv4.3*) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport' ;; sysv4*MP*) if test -d /usr/nec; then _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no runpath_var=LD_RUN_PATH hardcode_runpath_var=yes _LT_TAGVAR(ld_shlibs, $1)=yes fi ;; sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no runpath_var='LD_RUN_PATH' if test "$GCC" = yes; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' else _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' fi ;; sysv5* | sco3.2v5* | sco5v6*) # Note: We can NOT use -z defs as we might desire, because we do not # link with -lc, and that would cause any symbols used from libc to # always be unresolved, which means just about no library would # ever link correctly. If we're not using GNU ld we use -z text # though, which does catch some bad symbols but isn't as heavy-handed # as -z defs. _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=':' _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' runpath_var='LD_RUN_PATH' if test "$GCC" = yes; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' else _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' fi ;; uts4*) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *) _LT_TAGVAR(ld_shlibs, $1)=no ;; esac if test x$host_vendor = xsni; then case $host in sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Blargedynsym' ;; esac fi fi ]) AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no _LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld _LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl _LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl _LT_DECL([], [extract_expsyms_cmds], [2], [The commands to extract the exported symbol list from a shared archive]) # # Do we need to explicitly link libc? # case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in x|xyes) # Assume -lc should be added _LT_TAGVAR(archive_cmds_need_lc, $1)=yes if test "$enable_shared" = yes && test "$GCC" = yes; then case $_LT_TAGVAR(archive_cmds, $1) in *'~'*) # FIXME: we may have to deal with multi-command sequences. ;; '$CC '*) # Test whether the compiler implicitly links with -lc since on some # systems, -lgcc has to come before -lc. If gcc already passes -lc # to ld, don't add -lc before -lgcc. AC_MSG_CHECKING([whether -lc should be explicitly linked in]) $RM conftest* echo "$lt_simple_compile_test_code" > conftest.$ac_ext if AC_TRY_EVAL(ac_compile) 2>conftest.err; then soname=conftest lib=conftest libobjs=conftest.$ac_objext deplibs= wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1) compiler_flags=-v linker_flags=-v verstring= output_objdir=. libname=conftest lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1) _LT_TAGVAR(allow_undefined_flag, $1)= if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) then _LT_TAGVAR(archive_cmds_need_lc, $1)=no else _LT_TAGVAR(archive_cmds_need_lc, $1)=yes fi _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag else cat conftest.err 1>&5 fi $RM conftest* AC_MSG_RESULT([$_LT_TAGVAR(archive_cmds_need_lc, $1)]) ;; esac fi ;; esac _LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0], [Whether or not to add -lc for building shared libraries]) _LT_TAGDECL([allow_libtool_libs_with_static_runtimes], [enable_shared_with_static_runtimes], [0], [Whether or not to disallow shared libs when runtime libs are static]) _LT_TAGDECL([], [export_dynamic_flag_spec], [1], [Compiler flag to allow reflexive dlopens]) _LT_TAGDECL([], [whole_archive_flag_spec], [1], [Compiler flag to generate shared objects directly from archives]) _LT_TAGDECL([], [compiler_needs_object], [1], [Whether the compiler copes with passing no objects directly]) _LT_TAGDECL([], [old_archive_from_new_cmds], [2], [Create an old-style archive from a shared archive]) _LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2], [Create a temporary old-style archive to link instead of a shared archive]) _LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive]) _LT_TAGDECL([], [archive_expsym_cmds], [2]) _LT_TAGDECL([], [module_cmds], [2], [Commands used to build a loadable module if different from building a shared archive.]) _LT_TAGDECL([], [module_expsym_cmds], [2]) _LT_TAGDECL([], [with_gnu_ld], [1], [Whether we are building with GNU ld or not]) _LT_TAGDECL([], [allow_undefined_flag], [1], [Flag that allows shared libraries with undefined symbols to be built]) _LT_TAGDECL([], [no_undefined_flag], [1], [Flag that enforces no undefined symbols]) _LT_TAGDECL([], [hardcode_libdir_flag_spec], [1], [Flag to hardcode $libdir into a binary during linking. This must work even if $libdir does not exist]) _LT_TAGDECL([], [hardcode_libdir_flag_spec_ld], [1], [[If ld is used when linking, flag to hardcode $libdir into a binary during linking. This must work even if $libdir does not exist]]) _LT_TAGDECL([], [hardcode_libdir_separator], [1], [Whether we need a single "-rpath" flag with a separated argument]) _LT_TAGDECL([], [hardcode_direct], [0], [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the resulting binary]) _LT_TAGDECL([], [hardcode_direct_absolute], [0], [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the resulting binary and the resulting library dependency is "absolute", i.e impossible to change by setting ${shlibpath_var} if the library is relocated]) _LT_TAGDECL([], [hardcode_minus_L], [0], [Set to "yes" if using the -LDIR flag during linking hardcodes DIR into the resulting binary]) _LT_TAGDECL([], [hardcode_shlibpath_var], [0], [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into the resulting binary]) _LT_TAGDECL([], [hardcode_automatic], [0], [Set to "yes" if building a shared library automatically hardcodes DIR into the library and all subsequent libraries and executables linked against it]) _LT_TAGDECL([], [inherit_rpath], [0], [Set to yes if linker adds runtime paths of dependent libraries to runtime path list]) _LT_TAGDECL([], [link_all_deplibs], [0], [Whether libtool must link a program against all its dependency libraries]) _LT_TAGDECL([], [fix_srcfile_path], [1], [Fix the shell variable $srcfile for the compiler]) _LT_TAGDECL([], [always_export_symbols], [0], [Set to "yes" if exported symbols are required]) _LT_TAGDECL([], [export_symbols_cmds], [2], [The commands to list exported symbols]) _LT_TAGDECL([], [exclude_expsyms], [1], [Symbols that should not be listed in the preloaded symbols]) _LT_TAGDECL([], [include_expsyms], [1], [Symbols that must always be exported]) _LT_TAGDECL([], [prelink_cmds], [2], [Commands necessary for linking programs (against libraries) with templates]) _LT_TAGDECL([], [file_list_spec], [1], [Specify filename containing input files]) dnl FIXME: Not yet implemented dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1], dnl [Compiler flag to generate thread safe objects]) ])# _LT_LINKER_SHLIBS # _LT_LANG_C_CONFIG([TAG]) # ------------------------ # Ensure that the configuration variables for a C compiler are suitably # defined. These variables are subsequently used by _LT_CONFIG to write # the compiler configuration to `libtool'. m4_defun([_LT_LANG_C_CONFIG], [m4_require([_LT_DECL_EGREP])dnl lt_save_CC="$CC" AC_LANG_PUSH(C) # Source file extension for C test sources. ac_ext=c # Object file extension for compiled C test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # Code to be used in simple compile tests lt_simple_compile_test_code="int some_variable = 0;" # Code to be used in simple link tests lt_simple_link_test_code='int main(){return(0);}' _LT_TAG_COMPILER # Save the default compiler, since it gets overwritten when the other # tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. compiler_DEFAULT=$CC # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... if test -n "$compiler"; then _LT_COMPILER_NO_RTTI($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_SYS_DYNAMIC_LINKER($1) _LT_LINKER_HARDCODE_LIBPATH($1) LT_SYS_DLOPEN_SELF _LT_CMD_STRIPLIB # Report which library types will actually be built AC_MSG_CHECKING([if libtool supports shared libraries]) AC_MSG_RESULT([$can_build_shared]) AC_MSG_CHECKING([whether to build shared libraries]) test "$can_build_shared" = "no" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and # are all built from PIC. case $host_os in aix3*) test "$enable_shared" = yes && enable_static=no if test -n "$RANLIB"; then archive_cmds="$archive_cmds~\$RANLIB \$lib" postinstall_cmds='$RANLIB $lib' fi ;; aix[[4-9]]*) if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then test "$enable_shared" = yes && enable_static=no fi ;; esac AC_MSG_RESULT([$enable_shared]) AC_MSG_CHECKING([whether to build static libraries]) # Make sure either enable_shared or enable_static is yes. test "$enable_shared" = yes || enable_static=yes AC_MSG_RESULT([$enable_static]) _LT_CONFIG($1) fi AC_LANG_POP CC="$lt_save_CC" ])# _LT_LANG_C_CONFIG # _LT_PROG_CXX # ------------ # Since AC_PROG_CXX is broken, in that it returns g++ if there is no c++ # compiler, we have our own version here. m4_defun([_LT_PROG_CXX], [ pushdef([AC_MSG_ERROR], [_lt_caught_CXX_error=yes]) AC_PROG_CXX if test -n "$CXX" && ( test "X$CXX" != "Xno" && ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) || (test "X$CXX" != "Xg++"))) ; then AC_PROG_CXXCPP else _lt_caught_CXX_error=yes fi popdef([AC_MSG_ERROR]) ])# _LT_PROG_CXX dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([_LT_PROG_CXX], []) # _LT_LANG_CXX_CONFIG([TAG]) # -------------------------- # Ensure that the configuration variables for a C++ compiler are suitably # defined. These variables are subsequently used by _LT_CONFIG to write # the compiler configuration to `libtool'. m4_defun([_LT_LANG_CXX_CONFIG], [AC_REQUIRE([_LT_PROG_CXX])dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_EGREP])dnl AC_LANG_PUSH(C++) _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(allow_undefined_flag, $1)= _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(archive_expsym_cmds, $1)= _LT_TAGVAR(compiler_needs_object, $1)=no _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= _LT_TAGVAR(hardcode_libdir_separator, $1)= _LT_TAGVAR(hardcode_minus_L, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported _LT_TAGVAR(hardcode_automatic, $1)=no _LT_TAGVAR(inherit_rpath, $1)=no _LT_TAGVAR(module_cmds, $1)= _LT_TAGVAR(module_expsym_cmds, $1)= _LT_TAGVAR(link_all_deplibs, $1)=unknown _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds _LT_TAGVAR(no_undefined_flag, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no # Source file extension for C++ test sources. ac_ext=cpp # Object file extension for compiled C++ test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # No sense in running all these tests if we already determined that # the CXX compiler isn't working. Some variables (like enable_shared) # are currently assumed to apply to all compilers on this platform, # and will be corrupted by setting them based on a non-working compiler. if test "$_lt_caught_CXX_error" != yes; then # Code to be used in simple compile tests lt_simple_compile_test_code="int some_variable = 0;" # Code to be used in simple link tests lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }' # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC=$CC lt_save_LD=$LD lt_save_GCC=$GCC GCC=$GXX lt_save_with_gnu_ld=$with_gnu_ld lt_save_path_LD=$lt_cv_path_LD if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx else $as_unset lt_cv_prog_gnu_ld fi if test -n "${lt_cv_path_LDCXX+set}"; then lt_cv_path_LD=$lt_cv_path_LDCXX else $as_unset lt_cv_path_LD fi test -z "${LDCXX+set}" || LD=$LDCXX CC=${CXX-"c++"} compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_CC_BASENAME([$compiler]) if test -n "$compiler"; then # We don't want -fno-exception when compiling C++ code, so set the # no_builtin_flag separately if test "$GXX" = yes; then _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' else _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= fi if test "$GXX" = yes; then # Set up default GNU C++ configuration LT_PATH_LD # Check if GNU C++ uses GNU ld as the underlying linker, since the # archiving commands below assume that GNU ld is being used. if test "$with_gnu_ld" = yes; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' # If archive_cmds runs LD, not CC, wlarc should be empty # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to # investigate it a little bit more. (MM) wlarc='${wl}' # ancient GNU ld didn't support --whole-archive et. al. if eval "`$CC -print-prog-name=ld` --help 2>&1" | $GREP 'no-whole-archive' > /dev/null; then _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' else _LT_TAGVAR(whole_archive_flag_spec, $1)= fi else with_gnu_ld=no wlarc= # A generic and very simple default shared library creation # command for GNU C++ for the case where it uses the native # linker, instead of GNU ld. If possible, this setting should # overridden to take advantage of the native linker features on # the platform it is being used on. _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' else GXX=no with_gnu_ld=no wlarc= fi # PORTME: fill in a description of your system's C++ link characteristics AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) _LT_TAGVAR(ld_shlibs, $1)=yes case $host_os in aix3*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; aix[[4-9]]*) if test "$host_cpu" = ia64; then # On IA64, the linker does run time linking by default, so we don't # have to do anything special. aix_use_runtimelinking=no exp_sym_flag='-Bexport' no_entry_flag="" else aix_use_runtimelinking=no # Test if we are trying to use run time linking or normal # AIX style linking. If -brtl is somewhere in LDFLAGS, we # need to do runtime linking. case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) for ld_flag in $LDFLAGS; do case $ld_flag in *-brtl*) aix_use_runtimelinking=yes break ;; esac done ;; esac exp_sym_flag='-bexport' no_entry_flag='-bnoentry' fi # When large executables or shared objects are built, AIX ld can # have problems creating the table of contents. If linking a library # or program results in "error TOC overflow" add -mminimal-toc to # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. _LT_TAGVAR(archive_cmds, $1)='' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(hardcode_libdir_separator, $1)=':' _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(file_list_spec, $1)='${wl}-f,' if test "$GXX" = yes; then case $host_os in aix4.[[012]]|aix4.[[012]].*) # We only want to do this on AIX 4.2 and lower, the check # below for broken collect2 doesn't work under 4.3+ collect2name=`${CC} -print-prog-name=collect2` if test -f "$collect2name" && strings "$collect2name" | $GREP resolve_lib_name >/dev/null then # We have reworked collect2 : else # We have old collect2 _LT_TAGVAR(hardcode_direct, $1)=unsupported # It fails to find uninstalled libraries when the uninstalled # path is not listed in the libpath. Setting hardcode_minus_L # to unsupported forces relinking _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)= fi esac shared_flag='-shared' if test "$aix_use_runtimelinking" = yes; then shared_flag="$shared_flag "'${wl}-G' fi else # not using gcc if test "$host_cpu" = ia64; then # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release # chokes on -Wl,-G. The following line is correct: shared_flag='-G' else if test "$aix_use_runtimelinking" = yes; then shared_flag='${wl}-G' else shared_flag='${wl}-bM:SRE' fi fi fi _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall' # It seems that -bexpall does not export symbols beginning with # underscore (_), so it is better to generate a list of symbols to # export. _LT_TAGVAR(always_export_symbols, $1)=yes if test "$aix_use_runtimelinking" = yes; then # Warning - without using the other runtime loading flags (-brtl), # -berok will link without error, but may produce a broken library. _LT_TAGVAR(allow_undefined_flag, $1)='-berok' # Determine the default libpath from the value encoded in an empty # executable. _LT_SYS_MODULE_PATH_AIX _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" else if test "$host_cpu" = ia64; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" else # Determine the default libpath from the value encoded in an # empty executable. _LT_SYS_MODULE_PATH_AIX _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" # Warning - without using the other run time loading flags, # -berok will link without error, but may produce a broken library. _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' # Exported symbols can be pulled into shared objects from archives _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' _LT_TAGVAR(archive_cmds_need_lc, $1)=yes # This is similar to how AIX traditionally builds its shared # libraries. _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' fi fi ;; beos*) if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(allow_undefined_flag, $1)=unsupported # Joseph Beckenbach says some releases of gcc # support --undefined. This deserves some investigation. FIXME _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; chorus*) case $cc_basename in *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; cygwin* | mingw* | pw32* | cegcc*) # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, # as there is no search path for DLLs. _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' # If the export-symbols file already is a .def file (1st line # is EXPORTS), use it as is; otherwise, prepend... _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then cp $export_symbols $output_objdir/$soname.def; else echo EXPORTS > $output_objdir/$soname.def; cat $export_symbols >> $output_objdir/$soname.def; fi~ $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; darwin* | rhapsody*) _LT_DARWIN_LINKER_FEATURES($1) ;; dgux*) case $cc_basename in ec++*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; ghcx*) # Green Hills C++ Compiler # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; freebsd[[12]]*) # C++ shared libraries reported to be fairly broken before # switch to ELF _LT_TAGVAR(ld_shlibs, $1)=no ;; freebsd-elf*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; freebsd* | dragonfly*) # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF # conventions _LT_TAGVAR(ld_shlibs, $1)=yes ;; gnu*) ;; hpux9*) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, # but as the default # location of the library. case $cc_basename in CC*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; aCC*) _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' ;; *) if test "$GXX" = yes; then _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' else # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; hpux10*|hpux11*) if test $with_gnu_ld = no; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: case $host_cpu in hppa*64*|ia64*) ;; *) _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' ;; esac fi case $host_cpu in hppa*64*|ia64*) _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *) _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, # but as the default # location of the library. ;; esac case $cc_basename in CC*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; aCC*) case $host_cpu in hppa*64*) _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; ia64*) _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; esac # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' ;; *) if test "$GXX" = yes; then if test $with_gnu_ld = no; then case $host_cpu in hppa*64*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; ia64*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; esac fi else # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; interix[[3-9]]*) _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. # Instead, shared libraries are loaded at an image base (0x10000000 by # default) and relocated if they conflict, which is a slow very memory # consuming and fragmenting process. To avoid this, we pick a random, # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link # time. Moving up from 0x10000000 also allows more sbrk(2) space. _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' ;; irix5* | irix6*) case $cc_basename in CC*) # SGI C++ _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' # Archives containing C++ object files must be created using # "CC -ar", where "CC" is the IRIX C++ compiler. This is # necessary to make sure instantiated templates are included # in the archive. _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs' ;; *) if test "$GXX" = yes; then if test "$with_gnu_ld" = no; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' else _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` -o $lib' fi fi _LT_TAGVAR(link_all_deplibs, $1)=yes ;; esac _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(inherit_rpath, $1)=yes ;; linux* | k*bsd*-gnu | kopensolaris*-gnu) case $cc_basename in KCC*) # Kuck and Associates, Inc. (KAI) C++ Compiler # KCC will only create a shared library if the output file # ends with ".so" (or ".sl" for HP-UX), so rename the library # to its proper name (with version) after linking. _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib' # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' # Archives containing C++ object files must be created using # "CC -Bstatic", where "CC" is the KAI C++ compiler. _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;; icpc* | ecpc* ) # Intel C++ with_gnu_ld=yes # version 8.0 and above of icpc choke on multiply defined symbols # if we add $predep_objects and $postdep_objects, however 7.1 and # earlier do not add the objects themselves. case `$CC -V 2>&1` in *"Version 7."*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' ;; *) # Version 8.0 or newer tmp_idyn= case $host_cpu in ia64*) tmp_idyn=' -i_dynamic';; esac _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' ;; esac _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive' ;; pgCC* | pgcpp*) # Portland Group C++ compiler case `$CC -V` in *pgCC\ [[1-5]]* | *pgcpp\ [[1-5]]*) _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~ rm -rf $tpldir~ $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~ compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"' _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~ rm -rf $tpldir~ $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~ $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~ $RANLIB $oldlib' _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~ rm -rf $tpldir~ $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~ rm -rf $tpldir~ $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' ;; *) # Version 6 will use weak symbols _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' ;; esac _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' ;; cxx*) # Compaq C++ _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib ${wl}-retain-symbols-file $wl$export_symbols' runpath_var=LD_RUN_PATH _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' ;; xl*) # IBM XL 8.0 on PPC, with GNU ld _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' if test "x$supports_anon_versioning" = xyes; then _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' fi ;; *) case `$CC -V 2>&1 | sed 5q` in *Sun\ C*) # Sun C++ 5.9 _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' _LT_TAGVAR(compiler_needs_object, $1)=yes # Not sure whether something based on # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 # would be better. output_verbose_link_cmd='echo' # Archives containing C++ object files must be created using # "CC -xar", where "CC" is the Sun C++ compiler. This is # necessary to make sure instantiated templates are included # in the archive. _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' ;; esac ;; esac ;; lynxos*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; m88k*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; mvs*) case $cc_basename in cxx*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' wlarc= _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no fi # Workaround some broken pre-1.5 toolchains output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' ;; *nto* | *qnx*) _LT_TAGVAR(ld_shlibs, $1)=yes ;; openbsd2*) # C++ shared libraries are fairly broken _LT_TAGVAR(ld_shlibs, $1)=no ;; openbsd*) if test -f /usr/libexec/ld.so; then _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' fi output_verbose_link_cmd=echo else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; osf3* | osf4* | osf5*) case $cc_basename in KCC*) # Kuck and Associates, Inc. (KAI) C++ Compiler # KCC will only create a shared library if the output file # ends with ".so" (or ".sl" for HP-UX), so rename the library # to its proper name (with version) after linking. _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: # Archives containing C++ object files must be created using # the KAI C++ compiler. case $host in osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;; *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;; esac ;; RCC*) # Rational C++ 2.4.1 # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; cxx*) case $host in osf3*) _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && $ECHO "X${wl}-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' ;; *) _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ echo "-hidden">> $lib.exp~ $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname ${wl}-input ${wl}$lib.exp `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~ $RM $lib.exp' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' ;; esac _LT_TAGVAR(hardcode_libdir_separator, $1)=: # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed' ;; *) if test "$GXX" = yes && test "$with_gnu_ld" = no; then _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' case $host in osf3*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' ;; esac _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' else # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; psos*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; sunos4*) case $cc_basename in CC*) # Sun C++ 4.x # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; lcc*) # Lucid # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; solaris*) case $cc_basename in CC*) # Sun C++ 4.2, 5.x and Centerline C++ _LT_TAGVAR(archive_cmds_need_lc,$1)=yes _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no case $host_os in solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; *) # The compiler driver will combine and reorder linker options, # but understands `-z linker_flag'. # Supported since Solaris 2.6 (maybe 2.5.1?) _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' ;; esac _LT_TAGVAR(link_all_deplibs, $1)=yes output_verbose_link_cmd='echo' # Archives containing C++ object files must be created using # "CC -xar", where "CC" is the Sun C++ compiler. This is # necessary to make sure instantiated templates are included # in the archive. _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' ;; gcx*) # Green Hills C++ Compiler _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' # The C++ compiler must be used to create the archive. _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs' ;; *) # GNU C++ compiler with Solaris linker if test "$GXX" = yes && test "$with_gnu_ld" = no; then _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs' if $CC --version | $GREP -v '^2\.7' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' else # g++ 2.7 appears to require `-G' NOT `-shared' on this # platform. _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"' fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir' case $host_os in solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; *) _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' ;; esac fi ;; esac ;; sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no runpath_var='LD_RUN_PATH' case $cc_basename in CC*) _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' ;; esac ;; sysv5* | sco3.2v5* | sco5v6*) # Note: We can NOT use -z defs as we might desire, because we do not # link with -lc, and that would cause any symbols used from libc to # always be unresolved, which means just about no library would # ever link correctly. If we're not using GNU ld we use -z text # though, which does catch some bad symbols but isn't as heavy-handed # as -z defs. _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=':' _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' runpath_var='LD_RUN_PATH' case $cc_basename in CC*) _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' ;; esac ;; tandem*) case $cc_basename in NCC*) # NonStop-UX NCC 3.20 # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; vxworks*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no _LT_TAGVAR(GCC, $1)="$GXX" _LT_TAGVAR(LD, $1)="$LD" ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... _LT_SYS_HIDDEN_LIBDEPS($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_SYS_DYNAMIC_LINKER($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi # test -n "$compiler" CC=$lt_save_CC LDCXX=$LD LD=$lt_save_LD GCC=$lt_save_GCC with_gnu_ld=$lt_save_with_gnu_ld lt_cv_path_LDCXX=$lt_cv_path_LD lt_cv_path_LD=$lt_save_path_LD lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld fi # test "$_lt_caught_CXX_error" != yes AC_LANG_POP ])# _LT_LANG_CXX_CONFIG # _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) # --------------------------------- # Figure out "hidden" library dependencies from verbose # compiler output when linking a shared library. # Parse the compiler output and extract the necessary # objects, libraries and library flags. m4_defun([_LT_SYS_HIDDEN_LIBDEPS], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl # Dependencies to place before and after the object being linked: _LT_TAGVAR(predep_objects, $1)= _LT_TAGVAR(postdep_objects, $1)= _LT_TAGVAR(predeps, $1)= _LT_TAGVAR(postdeps, $1)= _LT_TAGVAR(compiler_lib_search_path, $1)= dnl we can't use the lt_simple_compile_test_code here, dnl because it contains code intended for an executable, dnl not a library. It's possible we should let each dnl tag define a new lt_????_link_test_code variable, dnl but it's only used here... m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF int a; void foo (void) { a = 0; } _LT_EOF ], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF class Foo { public: Foo (void) { a = 0; } private: int a; }; _LT_EOF ], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF subroutine foo implicit none integer*4 a a=0 return end _LT_EOF ], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF subroutine foo implicit none integer a a=0 return end _LT_EOF ], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF public class foo { private int a; public void bar (void) { a = 0; } }; _LT_EOF ]) dnl Parse the compiler output and extract the necessary dnl objects, libraries and library flags. if AC_TRY_EVAL(ac_compile); then # Parse the compiler output and extract the necessary # objects, libraries and library flags. # Sentinel used to keep track of whether or not we are before # the conftest object file. pre_test_object_deps_done=no for p in `eval "$output_verbose_link_cmd"`; do case $p in -L* | -R* | -l*) # Some compilers place space between "-{L,R}" and the path. # Remove the space. if test $p = "-L" || test $p = "-R"; then prev=$p continue else prev= fi if test "$pre_test_object_deps_done" = no; then case $p in -L* | -R*) # Internal compiler library paths should come after those # provided the user. The postdeps already come after the # user supplied libs so there is no need to process them. if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then _LT_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}" else _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}" fi ;; # The "-l" case would never come before the object being # linked, so don't bother handling this case. esac else if test -z "$_LT_TAGVAR(postdeps, $1)"; then _LT_TAGVAR(postdeps, $1)="${prev}${p}" else _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} ${prev}${p}" fi fi ;; *.$objext) # This assumes that the test object file only shows up # once in the compiler output. if test "$p" = "conftest.$objext"; then pre_test_object_deps_done=yes continue fi if test "$pre_test_object_deps_done" = no; then if test -z "$_LT_TAGVAR(predep_objects, $1)"; then _LT_TAGVAR(predep_objects, $1)="$p" else _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p" fi else if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then _LT_TAGVAR(postdep_objects, $1)="$p" else _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p" fi fi ;; *) ;; # Ignore the rest. esac done # Clean up. rm -f a.out a.exe else echo "libtool.m4: error: problem compiling $1 test program" fi $RM -f confest.$objext # PORTME: override above test on systems where it is broken m4_if([$1], [CXX], [case $host_os in interix[[3-9]]*) # Interix 3.5 installs completely hosed .la files for C++, so rather than # hack all around it, let's just trust "g++" to DTRT. _LT_TAGVAR(predep_objects,$1)= _LT_TAGVAR(postdep_objects,$1)= _LT_TAGVAR(postdeps,$1)= ;; linux*) case `$CC -V 2>&1 | sed 5q` in *Sun\ C*) # Sun C++ 5.9 # The more standards-conforming stlport4 library is # incompatible with the Cstd library. Avoid specifying # it if it's in CXXFLAGS. Ignore libCrun as # -library=stlport4 depends on it. case " $CXX $CXXFLAGS " in *" -library=stlport4 "*) solaris_use_stlport4=yes ;; esac if test "$solaris_use_stlport4" != yes; then _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun' fi ;; esac ;; solaris*) case $cc_basename in CC*) # The more standards-conforming stlport4 library is # incompatible with the Cstd library. Avoid specifying # it if it's in CXXFLAGS. Ignore libCrun as # -library=stlport4 depends on it. case " $CXX $CXXFLAGS " in *" -library=stlport4 "*) solaris_use_stlport4=yes ;; esac # Adding this requires a known-good setup of shared libraries for # Sun compiler versions before 5.6, else PIC objects from an old # archive will be linked into the output, leading to subtle bugs. if test "$solaris_use_stlport4" != yes; then _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun' fi ;; esac ;; esac ]) case " $_LT_TAGVAR(postdeps, $1) " in *" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; esac _LT_TAGVAR(compiler_lib_search_dirs, $1)= if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | ${SED} -e 's! -L! !g' -e 's!^ !!'` fi _LT_TAGDECL([], [compiler_lib_search_dirs], [1], [The directories searched by this compiler when creating a shared library]) _LT_TAGDECL([], [predep_objects], [1], [Dependencies to place before and after the objects being linked to create a shared library]) _LT_TAGDECL([], [postdep_objects], [1]) _LT_TAGDECL([], [predeps], [1]) _LT_TAGDECL([], [postdeps], [1]) _LT_TAGDECL([], [compiler_lib_search_path], [1], [The library search path used internally by the compiler when linking a shared library]) ])# _LT_SYS_HIDDEN_LIBDEPS # _LT_PROG_F77 # ------------ # Since AC_PROG_F77 is broken, in that it returns the empty string # if there is no fortran compiler, we have our own version here. m4_defun([_LT_PROG_F77], [ pushdef([AC_MSG_ERROR], [_lt_disable_F77=yes]) AC_PROG_F77 if test -z "$F77" || test "X$F77" = "Xno"; then _lt_disable_F77=yes fi popdef([AC_MSG_ERROR]) ])# _LT_PROG_F77 dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([_LT_PROG_F77], []) # _LT_LANG_F77_CONFIG([TAG]) # -------------------------- # Ensure that the configuration variables for a Fortran 77 compiler are # suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to `libtool'. m4_defun([_LT_LANG_F77_CONFIG], [AC_REQUIRE([_LT_PROG_F77])dnl AC_LANG_PUSH(Fortran 77) _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(allow_undefined_flag, $1)= _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(archive_expsym_cmds, $1)= _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= _LT_TAGVAR(hardcode_libdir_separator, $1)= _LT_TAGVAR(hardcode_minus_L, $1)=no _LT_TAGVAR(hardcode_automatic, $1)=no _LT_TAGVAR(inherit_rpath, $1)=no _LT_TAGVAR(module_cmds, $1)= _LT_TAGVAR(module_expsym_cmds, $1)= _LT_TAGVAR(link_all_deplibs, $1)=unknown _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds _LT_TAGVAR(no_undefined_flag, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no # Source file extension for f77 test sources. ac_ext=f # Object file extension for compiled f77 test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # No sense in running all these tests if we already determined that # the F77 compiler isn't working. Some variables (like enable_shared) # are currently assumed to apply to all compilers on this platform, # and will be corrupted by setting them based on a non-working compiler. if test "$_lt_disable_F77" != yes; then # Code to be used in simple compile tests lt_simple_compile_test_code="\ subroutine t return end " # Code to be used in simple link tests lt_simple_link_test_code="\ program t end " # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC="$CC" lt_save_GCC=$GCC CC=${F77-"f77"} compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_CC_BASENAME([$compiler]) GCC=$G77 if test -n "$compiler"; then AC_MSG_CHECKING([if libtool supports shared libraries]) AC_MSG_RESULT([$can_build_shared]) AC_MSG_CHECKING([whether to build shared libraries]) test "$can_build_shared" = "no" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and # are all built from PIC. case $host_os in aix3*) test "$enable_shared" = yes && enable_static=no if test -n "$RANLIB"; then archive_cmds="$archive_cmds~\$RANLIB \$lib" postinstall_cmds='$RANLIB $lib' fi ;; aix[[4-9]]*) if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then test "$enable_shared" = yes && enable_static=no fi ;; esac AC_MSG_RESULT([$enable_shared]) AC_MSG_CHECKING([whether to build static libraries]) # Make sure either enable_shared or enable_static is yes. test "$enable_shared" = yes || enable_static=yes AC_MSG_RESULT([$enable_static]) _LT_TAGVAR(GCC, $1)="$G77" _LT_TAGVAR(LD, $1)="$LD" ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_SYS_DYNAMIC_LINKER($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi # test -n "$compiler" GCC=$lt_save_GCC CC="$lt_save_CC" fi # test "$_lt_disable_F77" != yes AC_LANG_POP ])# _LT_LANG_F77_CONFIG # _LT_PROG_FC # ----------- # Since AC_PROG_FC is broken, in that it returns the empty string # if there is no fortran compiler, we have our own version here. m4_defun([_LT_PROG_FC], [ pushdef([AC_MSG_ERROR], [_lt_disable_FC=yes]) AC_PROG_FC if test -z "$FC" || test "X$FC" = "Xno"; then _lt_disable_FC=yes fi popdef([AC_MSG_ERROR]) ])# _LT_PROG_FC dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([_LT_PROG_FC], []) # _LT_LANG_FC_CONFIG([TAG]) # ------------------------- # Ensure that the configuration variables for a Fortran compiler are # suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to `libtool'. m4_defun([_LT_LANG_FC_CONFIG], [AC_REQUIRE([_LT_PROG_FC])dnl AC_LANG_PUSH(Fortran) _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(allow_undefined_flag, $1)= _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(archive_expsym_cmds, $1)= _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= _LT_TAGVAR(hardcode_libdir_separator, $1)= _LT_TAGVAR(hardcode_minus_L, $1)=no _LT_TAGVAR(hardcode_automatic, $1)=no _LT_TAGVAR(inherit_rpath, $1)=no _LT_TAGVAR(module_cmds, $1)= _LT_TAGVAR(module_expsym_cmds, $1)= _LT_TAGVAR(link_all_deplibs, $1)=unknown _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds _LT_TAGVAR(no_undefined_flag, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no # Source file extension for fc test sources. ac_ext=${ac_fc_srcext-f} # Object file extension for compiled fc test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # No sense in running all these tests if we already determined that # the FC compiler isn't working. Some variables (like enable_shared) # are currently assumed to apply to all compilers on this platform, # and will be corrupted by setting them based on a non-working compiler. if test "$_lt_disable_FC" != yes; then # Code to be used in simple compile tests lt_simple_compile_test_code="\ subroutine t return end " # Code to be used in simple link tests lt_simple_link_test_code="\ program t end " # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC="$CC" lt_save_GCC=$GCC CC=${FC-"f95"} compiler=$CC GCC=$ac_cv_fc_compiler_gnu _LT_TAGVAR(compiler, $1)=$CC _LT_CC_BASENAME([$compiler]) if test -n "$compiler"; then AC_MSG_CHECKING([if libtool supports shared libraries]) AC_MSG_RESULT([$can_build_shared]) AC_MSG_CHECKING([whether to build shared libraries]) test "$can_build_shared" = "no" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and # are all built from PIC. case $host_os in aix3*) test "$enable_shared" = yes && enable_static=no if test -n "$RANLIB"; then archive_cmds="$archive_cmds~\$RANLIB \$lib" postinstall_cmds='$RANLIB $lib' fi ;; aix[[4-9]]*) if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then test "$enable_shared" = yes && enable_static=no fi ;; esac AC_MSG_RESULT([$enable_shared]) AC_MSG_CHECKING([whether to build static libraries]) # Make sure either enable_shared or enable_static is yes. test "$enable_shared" = yes || enable_static=yes AC_MSG_RESULT([$enable_static]) _LT_TAGVAR(GCC, $1)="$ac_cv_fc_compiler_gnu" _LT_TAGVAR(LD, $1)="$LD" ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... _LT_SYS_HIDDEN_LIBDEPS($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_SYS_DYNAMIC_LINKER($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi # test -n "$compiler" GCC=$lt_save_GCC CC="$lt_save_CC" fi # test "$_lt_disable_FC" != yes AC_LANG_POP ])# _LT_LANG_FC_CONFIG # _LT_LANG_GCJ_CONFIG([TAG]) # -------------------------- # Ensure that the configuration variables for the GNU Java Compiler compiler # are suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to `libtool'. m4_defun([_LT_LANG_GCJ_CONFIG], [AC_REQUIRE([LT_PROG_GCJ])dnl AC_LANG_SAVE # Source file extension for Java test sources. ac_ext=java # Object file extension for compiled Java test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # Code to be used in simple compile tests lt_simple_compile_test_code="class foo {}" # Code to be used in simple link tests lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }' # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC="$CC" lt_save_GCC=$GCC GCC=yes CC=${GCJ-"gcj"} compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_TAGVAR(LD, $1)="$LD" _LT_CC_BASENAME([$compiler]) # GCJ did not exist at the time GCC didn't implicitly link libc in. _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... if test -n "$compiler"; then _LT_COMPILER_NO_RTTI($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi AC_LANG_RESTORE GCC=$lt_save_GCC CC="$lt_save_CC" ])# _LT_LANG_GCJ_CONFIG # _LT_LANG_RC_CONFIG([TAG]) # ------------------------- # Ensure that the configuration variables for the Windows resource compiler # are suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to `libtool'. m4_defun([_LT_LANG_RC_CONFIG], [AC_REQUIRE([LT_PROG_RC])dnl AC_LANG_SAVE # Source file extension for RC test sources. ac_ext=rc # Object file extension for compiled RC test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # Code to be used in simple compile tests lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }' # Code to be used in simple link tests lt_simple_link_test_code="$lt_simple_compile_test_code" # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC="$CC" lt_save_GCC=$GCC GCC= CC=${RC-"windres"} compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_CC_BASENAME([$compiler]) _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes if test -n "$compiler"; then : _LT_CONFIG($1) fi GCC=$lt_save_GCC AC_LANG_RESTORE CC="$lt_save_CC" ])# _LT_LANG_RC_CONFIG # LT_PROG_GCJ # ----------- AC_DEFUN([LT_PROG_GCJ], [m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ], [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ], [AC_CHECK_TOOL(GCJ, gcj,) test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2" AC_SUBST(GCJFLAGS)])])[]dnl ]) # Old name: AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([LT_AC_PROG_GCJ], []) # LT_PROG_RC # ---------- AC_DEFUN([LT_PROG_RC], [AC_CHECK_TOOL(RC, windres,) ]) # Old name: AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([LT_AC_PROG_RC], []) # _LT_DECL_EGREP # -------------- # If we don't have a new enough Autoconf to choose the best grep # available, choose the one first in the user's PATH. m4_defun([_LT_DECL_EGREP], [AC_REQUIRE([AC_PROG_EGREP])dnl AC_REQUIRE([AC_PROG_FGREP])dnl test -z "$GREP" && GREP=grep _LT_DECL([], [GREP], [1], [A grep program that handles long lines]) _LT_DECL([], [EGREP], [1], [An ERE matcher]) _LT_DECL([], [FGREP], [1], [A literal string matcher]) dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too AC_SUBST([GREP]) ]) # _LT_DECL_OBJDUMP # -------------- # If we don't have a new enough Autoconf to choose the best objdump # available, choose the one first in the user's PATH. m4_defun([_LT_DECL_OBJDUMP], [AC_CHECK_TOOL(OBJDUMP, objdump, false) test -z "$OBJDUMP" && OBJDUMP=objdump _LT_DECL([], [OBJDUMP], [1], [An object symbol dumper]) AC_SUBST([OBJDUMP]) ]) # _LT_DECL_SED # ------------ # Check for a fully-functional sed program, that truncates # as few characters as possible. Prefer GNU sed if found. m4_defun([_LT_DECL_SED], [AC_PROG_SED test -z "$SED" && SED=sed Xsed="$SED -e 1s/^X//" _LT_DECL([], [SED], [1], [A sed program that does not truncate output]) _LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"], [Sed that helps us avoid accidentally triggering echo(1) options like -n]) ])# _LT_DECL_SED m4_ifndef([AC_PROG_SED], [ ############################################################ # NOTE: This macro has been submitted for inclusion into # # GNU Autoconf as AC_PROG_SED. When it is available in # # a released version of Autoconf we should remove this # # macro and use it instead. # ############################################################ m4_defun([AC_PROG_SED], [AC_MSG_CHECKING([for a sed that does not truncate output]) AC_CACHE_VAL(lt_cv_path_SED, [# Loop through the user's path and test for sed and gsed. # Then use that list of sed's as ones to test for truncation. as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for lt_ac_prog in sed gsed; do for ac_exec_ext in '' $ac_executable_extensions; do if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext" fi done done done IFS=$as_save_IFS lt_ac_max=0 lt_ac_count=0 # Add /usr/xpg4/bin/sed as it is typically found on Solaris # along with /bin/sed that truncates output. for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do test ! -f $lt_ac_sed && continue cat /dev/null > conftest.in lt_ac_count=0 echo $ECHO_N "0123456789$ECHO_C" >conftest.in # Check for GNU sed and select it if it is found. if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then lt_cv_path_SED=$lt_ac_sed break fi while true; do cat conftest.in conftest.in >conftest.tmp mv conftest.tmp conftest.in cp conftest.in conftest.nl echo >>conftest.nl $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break cmp -s conftest.out conftest.nl || break # 10000 chars as input seems more than enough test $lt_ac_count -gt 10 && break lt_ac_count=`expr $lt_ac_count + 1` if test $lt_ac_count -gt $lt_ac_max; then lt_ac_max=$lt_ac_count lt_cv_path_SED=$lt_ac_sed fi done done ]) SED=$lt_cv_path_SED AC_SUBST([SED]) AC_MSG_RESULT([$SED]) ])#AC_PROG_SED ])#m4_ifndef # Old name: AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([LT_AC_PROG_SED], []) # _LT_CHECK_SHELL_FEATURES # ------------------------ # Find out whether the shell is Bourne or XSI compatible, # or has some other useful features. m4_defun([_LT_CHECK_SHELL_FEATURES], [AC_MSG_CHECKING([whether the shell understands some XSI constructs]) # Try some XSI features xsi_shell=no ( _lt_dummy="a/b/c" test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \ = c,a/b,, \ && eval 'test $(( 1 + 1 )) -eq 2 \ && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \ && xsi_shell=yes AC_MSG_RESULT([$xsi_shell]) _LT_CONFIG_LIBTOOL_INIT([xsi_shell='$xsi_shell']) AC_MSG_CHECKING([whether the shell understands "+="]) lt_shell_append=no ( foo=bar; set foo baz; eval "$[1]+=\$[2]" && test "$foo" = barbaz ) \ >/dev/null 2>&1 \ && lt_shell_append=yes AC_MSG_RESULT([$lt_shell_append]) _LT_CONFIG_LIBTOOL_INIT([lt_shell_append='$lt_shell_append']) if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then lt_unset=unset else lt_unset=false fi _LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl # test EBCDIC or ASCII case `echo X|tr X '\101'` in A) # ASCII based system # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr lt_SP2NL='tr \040 \012' lt_NL2SP='tr \015\012 \040\040' ;; *) # EBCDIC based system lt_SP2NL='tr \100 \n' lt_NL2SP='tr \r\n \100\100' ;; esac _LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl _LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl ])# _LT_CHECK_SHELL_FEATURES # _LT_PROG_XSI_SHELLFNS # --------------------- # Bourne and XSI compatible variants of some useful shell functions. m4_defun([_LT_PROG_XSI_SHELLFNS], [case $xsi_shell in yes) cat << \_LT_EOF >> "$cfgfile" # func_dirname file append nondir_replacement # Compute the dirname of FILE. If nonempty, add APPEND to the result, # otherwise set result to NONDIR_REPLACEMENT. func_dirname () { case ${1} in */*) func_dirname_result="${1%/*}${2}" ;; * ) func_dirname_result="${3}" ;; esac } # func_basename file func_basename () { func_basename_result="${1##*/}" } # func_dirname_and_basename file append nondir_replacement # perform func_basename and func_dirname in a single function # call: # dirname: Compute the dirname of FILE. If nonempty, # add APPEND to the result, otherwise set result # to NONDIR_REPLACEMENT. # value returned in "$func_dirname_result" # basename: Compute filename of FILE. # value retuned in "$func_basename_result" # Implementation must be kept synchronized with func_dirname # and func_basename. For efficiency, we do not delegate to # those functions but instead duplicate the functionality here. func_dirname_and_basename () { case ${1} in */*) func_dirname_result="${1%/*}${2}" ;; * ) func_dirname_result="${3}" ;; esac func_basename_result="${1##*/}" } # func_stripname prefix suffix name # strip PREFIX and SUFFIX off of NAME. # PREFIX and SUFFIX must not contain globbing or regex special # characters, hashes, percent signs, but SUFFIX may contain a leading # dot (in which case that matches only a dot). func_stripname () { # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are # positional parameters, so assign one to ordinary parameter first. func_stripname_result=${3} func_stripname_result=${func_stripname_result#"${1}"} func_stripname_result=${func_stripname_result%"${2}"} } # func_opt_split func_opt_split () { func_opt_split_opt=${1%%=*} func_opt_split_arg=${1#*=} } # func_lo2o object func_lo2o () { case ${1} in *.lo) func_lo2o_result=${1%.lo}.${objext} ;; *) func_lo2o_result=${1} ;; esac } # func_xform libobj-or-source func_xform () { func_xform_result=${1%.*}.lo } # func_arith arithmetic-term... func_arith () { func_arith_result=$(( $[*] )) } # func_len string # STRING may not start with a hyphen. func_len () { func_len_result=${#1} } _LT_EOF ;; *) # Bourne compatible functions. cat << \_LT_EOF >> "$cfgfile" # func_dirname file append nondir_replacement # Compute the dirname of FILE. If nonempty, add APPEND to the result, # otherwise set result to NONDIR_REPLACEMENT. func_dirname () { # Extract subdirectory from the argument. func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"` if test "X$func_dirname_result" = "X${1}"; then func_dirname_result="${3}" else func_dirname_result="$func_dirname_result${2}" fi } # func_basename file func_basename () { func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"` } dnl func_dirname_and_basename dnl A portable version of this function is already defined in general.m4sh dnl so there is no need for it here. # func_stripname prefix suffix name # strip PREFIX and SUFFIX off of NAME. # PREFIX and SUFFIX must not contain globbing or regex special # characters, hashes, percent signs, but SUFFIX may contain a leading # dot (in which case that matches only a dot). # func_strip_suffix prefix name func_stripname () { case ${2} in .*) func_stripname_result=`$ECHO "X${3}" \ | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;; *) func_stripname_result=`$ECHO "X${3}" \ | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;; esac } # sed scripts: my_sed_long_opt='1s/^\(-[[^=]]*\)=.*/\1/;q' my_sed_long_arg='1s/^-[[^=]]*=//' # func_opt_split func_opt_split () { func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"` func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"` } # func_lo2o object func_lo2o () { func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"` } # func_xform libobj-or-source func_xform () { func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[[^.]]*$/.lo/'` } # func_arith arithmetic-term... func_arith () { func_arith_result=`expr "$[@]"` } # func_len string # STRING may not start with a hyphen. func_len () { func_len_result=`expr "$[1]" : ".*" 2>/dev/null || echo $max_cmd_len` } _LT_EOF esac case $lt_shell_append in yes) cat << \_LT_EOF >> "$cfgfile" # func_append var value # Append VALUE to the end of shell variable VAR. func_append () { eval "$[1]+=\$[2]" } _LT_EOF ;; *) cat << \_LT_EOF >> "$cfgfile" # func_append var value # Append VALUE to the end of shell variable VAR. func_append () { eval "$[1]=\$$[1]\$[2]" } _LT_EOF ;; esac ]) libnih-1.0.3/m4/po.m40000644000175000017500000004460611461165270011116 00000000000000# po.m4 serial 15 (gettext-0.17) dnl Copyright (C) 1995-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl dnl This file can can be used in projects which are not available under dnl the GNU General Public License or the GNU Library General Public dnl License but which still want to provide support for the GNU gettext dnl functionality. dnl Please note that the actual code of the GNU gettext library is covered dnl by the GNU Library General Public License, and the rest of the GNU dnl gettext package package is covered by the GNU General Public License. dnl They are *not* in the public domain. dnl Authors: dnl Ulrich Drepper , 1995-2000. dnl Bruno Haible , 2000-2003. AC_PREREQ(2.50) dnl Checks for all prerequisites of the po subdirectory. AC_DEFUN([AM_PO_SUBDIRS], [ AC_REQUIRE([AC_PROG_MAKE_SET])dnl AC_REQUIRE([AC_PROG_INSTALL])dnl AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake AC_REQUIRE([AM_NLS])dnl dnl Release version of the gettext macros. This is used to ensure that dnl the gettext macros and po/Makefile.in.in are in sync. AC_SUBST([GETTEXT_MACRO_VERSION], [0.17]) dnl Perform the following tests also if --disable-nls has been given, dnl because they are needed for "make dist" to work. dnl Search for GNU msgfmt in the PATH. dnl The first test excludes Solaris msgfmt and early GNU msgfmt versions. dnl The second test excludes FreeBSD msgfmt. AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt, [$ac_dir/$ac_word --statistics /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 && (if $ac_dir/$ac_word --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)], :) AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT) dnl Test whether it is GNU msgfmt >= 0.15. changequote(,)dnl case `$MSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) MSGFMT_015=: ;; *) MSGFMT_015=$MSGFMT ;; esac changequote([,])dnl AC_SUBST([MSGFMT_015]) changequote(,)dnl case `$GMSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) GMSGFMT_015=: ;; *) GMSGFMT_015=$GMSGFMT ;; esac changequote([,])dnl AC_SUBST([GMSGFMT_015]) dnl Search for GNU xgettext 0.12 or newer in the PATH. dnl The first test excludes Solaris xgettext and early GNU xgettext versions. dnl The second test excludes FreeBSD xgettext. AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext, [$ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 && (if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)], :) dnl Remove leftover from FreeBSD xgettext call. rm -f messages.po dnl Test whether it is GNU xgettext >= 0.15. changequote(,)dnl case `$XGETTEXT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) XGETTEXT_015=: ;; *) XGETTEXT_015=$XGETTEXT ;; esac changequote([,])dnl AC_SUBST([XGETTEXT_015]) dnl Search for GNU msgmerge 0.11 or newer in the PATH. AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge, [$ac_dir/$ac_word --update -q /dev/null /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1], :) dnl Installation directories. dnl Autoconf >= 2.60 defines localedir. For older versions of autoconf, we dnl have to define it here, so that it can be used in po/Makefile. test -n "$localedir" || localedir='${datadir}/locale' AC_SUBST([localedir]) dnl Support for AM_XGETTEXT_OPTION. test -n "${XGETTEXT_EXTRA_OPTIONS+set}" || XGETTEXT_EXTRA_OPTIONS= AC_SUBST([XGETTEXT_EXTRA_OPTIONS]) AC_CONFIG_COMMANDS([po-directories], [[ for ac_file in $CONFIG_FILES; do # Support "outfile[:infile[:infile...]]" case "$ac_file" in *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; esac # PO directories have a Makefile.in generated from Makefile.in.in. case "$ac_file" in */Makefile.in) # Adjust a relative srcdir. ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'` ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`" ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'` # In autoconf-2.13 it is called $ac_given_srcdir. # In autoconf-2.50 it is called $srcdir. test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir" case "$ac_given_srcdir" in .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;; /*) top_srcdir="$ac_given_srcdir" ;; *) top_srcdir="$ac_dots$ac_given_srcdir" ;; esac # Treat a directory as a PO directory if and only if it has a # POTFILES.in file. This allows packages to have multiple PO # directories under different names or in different locations. if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then rm -f "$ac_dir/POTFILES" test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES" cat "$ac_given_srcdir/$ac_dir/POTFILES.in" | sed -e "/^#/d" -e "/^[ ]*\$/d" -e "s,.*, $top_srcdir/& \\\\," | sed -e "\$s/\(.*\) \\\\/\1/" > "$ac_dir/POTFILES" POMAKEFILEDEPS="POTFILES.in" # ALL_LINGUAS, POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES depend # on $ac_dir but don't depend on user-specified configuration # parameters. if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then # The LINGUAS file contains the set of available languages. if test -n "$OBSOLETE_ALL_LINGUAS"; then test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete" fi ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"` # Hide the ALL_LINGUAS assigment from automake < 1.5. eval 'ALL_LINGUAS''=$ALL_LINGUAS_' POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS" else # The set of available languages was given in configure.in. # Hide the ALL_LINGUAS assigment from automake < 1.5. eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS' fi # Compute POFILES # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po) # Compute UPDATEPOFILES # as $(foreach lang, $(ALL_LINGUAS), $(lang).po-update) # Compute DUMMYPOFILES # as $(foreach lang, $(ALL_LINGUAS), $(lang).nop) # Compute GMOFILES # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo) case "$ac_given_srcdir" in .) srcdirpre= ;; *) srcdirpre='$(srcdir)/' ;; esac POFILES= UPDATEPOFILES= DUMMYPOFILES= GMOFILES= for lang in $ALL_LINGUAS; do POFILES="$POFILES $srcdirpre$lang.po" UPDATEPOFILES="$UPDATEPOFILES $lang.po-update" DUMMYPOFILES="$DUMMYPOFILES $lang.nop" GMOFILES="$GMOFILES $srcdirpre$lang.gmo" done # CATALOGS depends on both $ac_dir and the user's LINGUAS # environment variable. INST_LINGUAS= if test -n "$ALL_LINGUAS"; then for presentlang in $ALL_LINGUAS; do useit=no if test "%UNSET%" != "$LINGUAS"; then desiredlanguages="$LINGUAS" else desiredlanguages="$ALL_LINGUAS" fi for desiredlang in $desiredlanguages; do # Use the presentlang catalog if desiredlang is # a. equal to presentlang, or # b. a variant of presentlang (because in this case, # presentlang can be used as a fallback for messages # which are not translated in the desiredlang catalog). case "$desiredlang" in "$presentlang"*) useit=yes;; esac done if test $useit = yes; then INST_LINGUAS="$INST_LINGUAS $presentlang" fi done fi CATALOGS= if test -n "$INST_LINGUAS"; then for lang in $INST_LINGUAS; do CATALOGS="$CATALOGS $lang.gmo" done fi test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile" sed -e "/^POTFILES =/r $ac_dir/POTFILES" -e "/^# Makevars/r $ac_given_srcdir/$ac_dir/Makevars" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@POMAKEFILEDEPS@|$POMAKEFILEDEPS|g" "$ac_dir/Makefile.in" > "$ac_dir/Makefile" for f in "$ac_given_srcdir/$ac_dir"/Rules-*; do if test -f "$f"; then case "$f" in *.orig | *.bak | *~) ;; *) cat "$f" >> "$ac_dir/Makefile" ;; esac fi done fi ;; esac done]], [# Capture the value of obsolete ALL_LINGUAS because we need it to compute # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it # from automake < 1.5. eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"' # Capture the value of LINGUAS because we need it to compute CATALOGS. LINGUAS="${LINGUAS-%UNSET%}" ]) ]) dnl Postprocesses a Makefile in a directory containing PO files. AC_DEFUN([AM_POSTPROCESS_PO_MAKEFILE], [ # When this code is run, in config.status, two variables have already been # set: # - OBSOLETE_ALL_LINGUAS is the value of LINGUAS set in configure.in, # - LINGUAS is the value of the environment variable LINGUAS at configure # time. changequote(,)dnl # Adjust a relative srcdir. ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'` ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`" ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'` # In autoconf-2.13 it is called $ac_given_srcdir. # In autoconf-2.50 it is called $srcdir. test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir" case "$ac_given_srcdir" in .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;; /*) top_srcdir="$ac_given_srcdir" ;; *) top_srcdir="$ac_dots$ac_given_srcdir" ;; esac # Find a way to echo strings without interpreting backslash. if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then gt_echo='echo' else if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then gt_echo='printf %s\n' else echo_func () { cat < "$ac_file.tmp" if grep -l '@TCLCATALOGS@' "$ac_file" > /dev/null; then # Add dependencies that cannot be formulated as a simple suffix rule. for lang in $ALL_LINGUAS; do frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` cat >> "$ac_file.tmp" < /dev/null; then # Add dependencies that cannot be formulated as a simple suffix rule. for lang in $ALL_LINGUAS; do frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'` cat >> "$ac_file.tmp" <> "$ac_file.tmp" <, 1996. AC_PREREQ(2.50) # Search path for a program which passes the given test. dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR, dnl TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]]) AC_DEFUN([AM_PATH_PROG_WITH_TEST], [ # Prepare PATH_SEPARATOR. # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then echo "#! /bin/sh" >conf$$.sh echo "exit 0" >>conf$$.sh chmod +x conf$$.sh if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then PATH_SEPARATOR=';' else PATH_SEPARATOR=: fi rm -f conf$$.sh fi # Find out how to test for executable files. Don't use a zero-byte file, # as systems may use methods other than mode bits to determine executability. cat >conf$$.file <<_ASEOF #! /bin/sh exit 0 _ASEOF chmod +x conf$$.file if test -x conf$$.file >/dev/null 2>&1; then ac_executable_p="test -x" else ac_executable_p="test -f" fi rm -f conf$$.file # Extract the first word of "$2", so it can be a program name with args. set dummy $2; ac_word=[$]2 AC_MSG_CHECKING([for $ac_word]) AC_CACHE_VAL(ac_cv_path_$1, [case "[$]$1" in [[\\/]]* | ?:[[\\/]]*) ac_cv_path_$1="[$]$1" # Let the user override the test with a path. ;; *) ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR for ac_dir in ifelse([$5], , $PATH, [$5]); do IFS="$ac_save_IFS" test -z "$ac_dir" && ac_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then echo "$as_me: trying $ac_dir/$ac_word..." >&AS_MESSAGE_LOG_FD if [$3]; then ac_cv_path_$1="$ac_dir/$ac_word$ac_exec_ext" break 2 fi fi done done IFS="$ac_save_IFS" dnl If no 4th arg is given, leave the cache variable unset, dnl so AC_PATH_PROGS will keep looking. ifelse([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4" ])dnl ;; esac])dnl $1="$ac_cv_path_$1" if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then AC_MSG_RESULT([$]$1) else AC_MSG_RESULT(no) fi AC_SUBST($1)dnl ]) libnih-1.0.3/m4/ltsugar.m40000644000175000017500000001042411461165274012154 00000000000000# ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- # # Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. # Written by Gary V. Vaughan, 2004 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # serial 6 ltsugar.m4 # This is to help aclocal find these macros, as it can't see m4_define. AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) # lt_join(SEP, ARG1, [ARG2...]) # ----------------------------- # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their # associated separator. # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier # versions in m4sugar had bugs. m4_define([lt_join], [m4_if([$#], [1], [], [$#], [2], [[$2]], [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) m4_define([_lt_join], [m4_if([$#$2], [2], [], [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) # lt_car(LIST) # lt_cdr(LIST) # ------------ # Manipulate m4 lists. # These macros are necessary as long as will still need to support # Autoconf-2.59 which quotes differently. m4_define([lt_car], [[$1]]) m4_define([lt_cdr], [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], [$#], 1, [], [m4_dquote(m4_shift($@))])]) m4_define([lt_unquote], $1) # lt_append(MACRO-NAME, STRING, [SEPARATOR]) # ------------------------------------------ # Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'. # Note that neither SEPARATOR nor STRING are expanded; they are appended # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). # No SEPARATOR is output if MACRO-NAME was previously undefined (different # than defined and empty). # # This macro is needed until we can rely on Autoconf 2.62, since earlier # versions of m4sugar mistakenly expanded SEPARATOR but not STRING. m4_define([lt_append], [m4_define([$1], m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) # ---------------------------------------------------------- # Produce a SEP delimited list of all paired combinations of elements of # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list # has the form PREFIXmINFIXSUFFIXn. # Needed until we can rely on m4_combine added in Autoconf 2.62. m4_define([lt_combine], [m4_if(m4_eval([$# > 3]), [1], [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl [[m4_foreach([_Lt_prefix], [$2], [m4_foreach([_Lt_suffix], ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) # ----------------------------------------------------------------------- # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. m4_define([lt_if_append_uniq], [m4_ifdef([$1], [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], [lt_append([$1], [$2], [$3])$4], [$5])], [lt_append([$1], [$2], [$3])$4])]) # lt_dict_add(DICT, KEY, VALUE) # ----------------------------- m4_define([lt_dict_add], [m4_define([$1($2)], [$3])]) # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) # -------------------------------------------- m4_define([lt_dict_add_subkey], [m4_define([$1($2:$3)], [$4])]) # lt_dict_fetch(DICT, KEY, [SUBKEY]) # ---------------------------------- m4_define([lt_dict_fetch], [m4_ifval([$3], m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) # ----------------------------------------------------------------- m4_define([lt_if_dict_fetch], [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], [$5], [$6])]) # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) # -------------------------------------------------------------- m4_define([lt_dict_filter], [m4_if([$5], [], [], [lt_join(m4_quote(m4_default([$4], [[, ]])), lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl ]) libnih-1.0.3/m4/inttypes-pri.m40000644000175000017500000000215211461165270013135 00000000000000# inttypes-pri.m4 serial 4 (gettext-0.16) dnl Copyright (C) 1997-2002, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. AC_PREREQ(2.52) # Define PRI_MACROS_BROKEN if exists and defines the PRI* # macros to non-string values. This is the case on AIX 4.3.3. AC_DEFUN([gt_INTTYPES_PRI], [ AC_CHECK_HEADERS([inttypes.h]) if test $ac_cv_header_inttypes_h = yes; then AC_CACHE_CHECK([whether the inttypes.h PRIxNN macros are broken], gt_cv_inttypes_pri_broken, [ AC_TRY_COMPILE([#include #ifdef PRId32 char *p = PRId32; #endif ], [], gt_cv_inttypes_pri_broken=no, gt_cv_inttypes_pri_broken=yes) ]) fi if test "$gt_cv_inttypes_pri_broken" = yes; then AC_DEFINE_UNQUOTED(PRI_MACROS_BROKEN, 1, [Define if exists and defines unusable PRI* macros.]) PRI_MACROS_BROKEN=1 else PRI_MACROS_BROKEN=0 fi AC_SUBST([PRI_MACROS_BROKEN]) ]) libnih-1.0.3/m4/lib-ld.m40000644000175000017500000000653111461165270011636 00000000000000# lib-ld.m4 serial 3 (gettext-0.13) dnl Copyright (C) 1996-2003 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl Subroutines of libtool.m4, dnl with replacements s/AC_/AC_LIB/ and s/lt_cv/acl_cv/ to avoid collision dnl with libtool.m4. dnl From libtool-1.4. Sets the variable with_gnu_ld to yes or no. AC_DEFUN([AC_LIB_PROG_LD_GNU], [AC_CACHE_CHECK([if the linker ($LD) is GNU ld], acl_cv_prog_gnu_ld, [# I'd rather use --version here, but apparently some GNU ld's only accept -v. case `$LD -v 2>&1 conf$$.sh echo "exit 0" >>conf$$.sh chmod +x conf$$.sh if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then PATH_SEPARATOR=';' else PATH_SEPARATOR=: fi rm -f conf$$.sh fi ac_prog=ld if test "$GCC" = yes; then # Check if gcc -print-prog-name=ld gives a path. AC_MSG_CHECKING([for ld used by GCC]) case $host in *-*-mingw*) # gcc leaves a trailing carriage return which upsets mingw ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; *) ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; esac case $ac_prog in # Accept absolute paths. [[\\/]* | [A-Za-z]:[\\/]*)] [re_direlt='/[^/][^/]*/\.\./'] # Canonicalize the path of ld ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'` while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` done test -z "$LD" && LD="$ac_prog" ;; "") # If it fails, then pretend we aren't using GCC. ac_prog=ld ;; *) # If it is relative, then search for the first ld in PATH. with_gnu_ld=unknown ;; esac elif test "$with_gnu_ld" = yes; then AC_MSG_CHECKING([for GNU ld]) else AC_MSG_CHECKING([for non-GNU ld]) fi AC_CACHE_VAL(acl_cv_path_LD, [if test -z "$LD"; then IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}" for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then acl_cv_path_LD="$ac_dir/$ac_prog" # Check to see if the program is GNU ld. I'd rather use --version, # but apparently some GNU ld's only accept -v. # Break only if it was the GNU/non-GNU ld that we prefer. case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in *GNU* | *'with BFD'*) test "$with_gnu_ld" != no && break ;; *) test "$with_gnu_ld" != yes && break ;; esac fi done IFS="$ac_save_ifs" else acl_cv_path_LD="$LD" # Let the user override the test with a path. fi]) LD="$acl_cv_path_LD" if test -n "$LD"; then AC_MSG_RESULT($LD) else AC_MSG_RESULT(no) fi test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH]) AC_LIB_PROG_LD_GNU ]) libnih-1.0.3/m4/wint_t.m40000644000175000017500000000170711461165270011777 00000000000000# wint_t.m4 serial 2 (gettext-0.17) dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. dnl Test whether has the 'wint_t' type. dnl Prerequisite: AC_PROG_CC AC_DEFUN([gt_TYPE_WINT_T], [ AC_CACHE_CHECK([for wint_t], gt_cv_c_wint_t, [AC_TRY_COMPILE([ /* Tru64 with Desktop Toolkit C has a bug: must be included before . BSD/OS 4.0.1 has a bug: , and must be included before . */ #include #include #include #include wint_t foo = (wchar_t)'\0';], , gt_cv_c_wint_t=yes, gt_cv_c_wint_t=no)]) if test $gt_cv_c_wint_t = yes; then AC_DEFINE(HAVE_WINT_T, 1, [Define if you have the 'wint_t' type.]) fi ]) libnih-1.0.3/m4/codeset.m40000644000175000017500000000136611461165270012122 00000000000000# codeset.m4 serial 2 (gettext-0.16) dnl Copyright (C) 2000-2002, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Bruno Haible. AC_DEFUN([AM_LANGINFO_CODESET], [ AC_CACHE_CHECK([for nl_langinfo and CODESET], am_cv_langinfo_codeset, [AC_TRY_LINK([#include ], [char* cs = nl_langinfo(CODESET); return !cs;], am_cv_langinfo_codeset=yes, am_cv_langinfo_codeset=no) ]) if test $am_cv_langinfo_codeset = yes; then AC_DEFINE(HAVE_LANGINFO_CODESET, 1, [Define if you have and nl_langinfo(CODESET).]) fi ]) libnih-1.0.3/m4/libnih.m40000644000175000017500000001725111445765555011757 00000000000000# libnih # # libnih.m4 - autoconf macros # # Copyright © 2010 Scott James Remnant . # Copyright © 2010 Canonical Ltd. # # This file is free software; the author gives unlimited permission to # copy and/or distribute it, with or without modifications, as long as # this notice is preserved. # This MUST be incremented for any changes to this file, otherwise aclocal # may overwrite the local copy in the libnih source tree with any installed # version. # serial 2 libnih.m4 # NIH_COMPILER_WARNINGS # --------------------- # Add configure option to enable additional compiler warnings and treat # them as errors. AC_DEFUN([NIH_COMPILER_WARNINGS], [AC_ARG_ENABLE(compiler-warnings, AS_HELP_STRING([--enable-compiler-warnings], [Enable additional compiler warnings]), [AS_IF([test "x$enable_compiler_warnings" = "xyes"], [AS_IF([test "x$GCC" = "xyes"], [CFLAGS="-Wall -Wextra -Wno-empty-body -Wno-missing-field-initializers -Wno-unused-parameter -Wformat-security -Werror -D_FORTIFY_SOURCE=2 $CFLAGS"]) AS_IF([test "x$GXX" = "xyes"], [CXXFLAGS="-Wall -Wextra -Wno-empty-body -Wno-missing-field-initializers -Wno-unused-parameter -Wformat-security -Werror -D_FORTIFY_SOURCE=2 $CXXFLAGS"])]) ])dnl ])# NIH_COMPILER_WARNINGS # NIH_COMPILER_OPTIMISATIONS # -------------------------- # Add configure option to disable optimisations. AC_DEFUN([NIH_COMPILER_OPTIMISATIONS], [AC_ARG_ENABLE(compiler-optimisations, AS_HELP_STRING([--disable-compiler-optimisations], [Disable compiler optimisations]), [AS_IF([test "x$enable_compiler_optimisations" = "xno"], [[CFLAGS=`echo "$CFLAGS" | sed -e "s/ -O[1-9s]*\b/ -O0/g"` CXXFLAGS=`echo "$CXXFLAGS" | sed -e "s/ -O[1-9s]*\b/ -O0/g"`]]) ])dnl ])# NIH_COMPILER_OPTIMISATIONS # NIH_LINKER_OPTIMISATIONS # ------------------------ # Add configure option to disable linker optimisations. AC_DEFUN([NIH_LINKER_OPTIMISATIONS], [AC_ARG_ENABLE(linker-optimisations, AS_HELP_STRING([--disable-linker-optimisations], [Disable linker optimisations]), [AS_IF([test "x$enable_linker_optimisations" = "xno"], [LDFLAGS=`echo "$LDFLAGS" | sed -e "s/ -Wl,-O[0-9]*\b//g"`], [LDFLAGS="$LDFLAGS -Wl,-O1"]) ])dnl ])# NIH_LINKER_OPTIMISATIONS # NIH_COMPILER_COVERAGE # --------------------- # Add configure option to enable coverage data. AC_DEFUN([NIH_COMPILER_COVERAGE], [AC_ARG_ENABLE(compiler-coverage, AS_HELP_STRING([--enable-compiler-coverage], [Enable generation of coverage data]), [AS_IF([test "x$enable_compiler_coverage" = "xyes"], [AS_IF([test "x$GCC" = "xyes"], [CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"]) AS_IF([test "x$GXX" = "xyes"], [CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage"])]) ])dnl ])# NIH_COMPILER_COVERAGE # NIH_LINKER_VERSION_SCRIPT # ------------------------- # Detect whether the linker supports version scripts AC_DEFUN([NIH_LINKER_VERSION_SCRIPT], [AC_CACHE_CHECK([for linker version script argument], [nih_cv_version_script], [nih_cv_version_script=none for nih_try_arg in "-Wl,--version-script"; do nih_old_libs="$LIBS" LIBS="$LIBS $nih_try_arg=conftest.ver" cat >conftest.ver < #include #include /* Variadic macro arguments */ #define variadic_macro(foo, ...) printf(foo, __VA_ARGS__) ], [ /* Compound initialisers */ struct { int a, b; } foo = { .a = 1, .b = 2 }; /* Boolean type */ bool bar = false; /* Specific size type */ uint32_t baz = 0; /* C99-style for-loop declarations */ for (int i = 0; i < 10; i++) continue; /* Magic __func__ variable */ printf("%s", __func__); ], [$1], [$2])dnl ])# NIH_TRY_C99 # NIH_C_C99 # --------- # Check whether the compiler can do C99, adding a compiler flag if # necessary. AC_DEFUN([NIH_C_C99], [AC_CACHE_CHECK([whether compiler supports C99 features], [nih_cv_c99], [NIH_TRY_C99([nih_cv_c99=yes], [nih_cv_c99=no])]) AS_IF([test "x$nih_cv_c99" = "xyes"], [AC_DEFINE([HAVE_C99], 1, [Define to 1 if the compiler supports C99.])], [AC_CACHE_CHECK([what argument makes compiler support C99 features], [nih_cv_c99_arg], [nih_cv_c99_arg=none nih_save_CC="$CC" for arg in "-std=gnu99" "-std=c99" "-c99"; do CC="$nih_save_CC $arg" NIH_TRY_C99([nih_arg_worked=yes], [nih_arg_worked=no]) CC="$nih_save_CC" AS_IF([test "x$nih_arg_worked" = "xyes"], [nih_cv_c99_arg="$arg"; break]) done]) AS_IF([test "x$nih_cv_c99_arg" != "xnone"], [CC="$CC $nih_cv_c99_arg" AC_DEFINE([HAVE_C99], 1)])])[]dnl ])# NIH_C_C99 # NIH_C_THREAD # ------------ # Check whether compiler supports __thread. AC_DEFUN([NIH_C_THREAD], [AC_ARG_ENABLE(threading, AS_HELP_STRING([--enable-threading], [Enable support for multi-threading]), [], [enable_threading=no])dnl AS_IF([test "x$enable_threading" != "xno" ], [AC_CACHE_CHECK([whether compiler supports __thread], [nih_cv_c_thread], [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int __thread a;]], [])], [nih_cv_c_thread=yes], [nih_cv_c_thread=no])]) AS_IF([test "x$nih_cv_c_thread" = "xno"], [AC_DEFINE([__thread],, [Define to empty if `__thread' is not supported.])])], [AC_DEFINE([__thread], )])dnl ])# NIH_C_THREAD # NIH_COPYRIGHT # -------------- # Wraps the Autoconf AC_COPYRIGHT but also defines PACKAGE_COPYRIGHT, # required for nih_main_init AC_DEFUN([NIH_COPYRIGHT], [AC_COPYRIGHT([$1]) m4_ifndef([NIH_PACKAGE_COPYRIGHT], [m4_bmatch([$1], [ ], [], [ m4_define([NIH_PACKAGE_COPYRIGHT], ["m4_bpatsubst([AS_ESCAPE([$1])], [©], [(C)])"]) AC_DEFINE([PACKAGE_COPYRIGHT], [NIH_PACKAGE_COPYRIGHT], [Define to the copyright message of this package.])])])dnl AC_SUBST([PACKAGE_COPYRIGHT], ["$1"]) ])# AC_COPYRIGHT # NIH_WITH_LOCAL_LIBNIH # --------------------- # Adds a configure option to build with a local libnih. AC_DEFUN([NIH_WITH_LOCAL_LIBNIH], [AC_ARG_WITH(local-libnih, AS_HELP_STRING([[[--with-local-libnih[=DIR]]]], [Use libnih from source tree DIR]), [AS_IF([test "x$with_local_libnih" != "xno"], [AS_IF([! test -f "$withval/nih/alloc.c"], [AC_MSG_ERROR([$withval doesn't look like a libnih source tree])]) nih_dir="`cd $withval && pwd`" NIH_CFLAGS="-I\"$nih_dir\"" NIH_LIBS="\"$nih_dir/nih/libnih.la\"" NIH_DBUS_CFLAGS="-I\"$nih_dir\"" NIH_DBUS_LIBS="\"$nih_dir/nih-dbus/libnih-dbus.la\"" NIH_DBUS_TOOL="\"$nih_dir/nih-dbus-tool/nih-dbus-tool\""])]) ])# NIH_WITH_LOCAL_LIBNIH libnih-1.0.3/m4/lcmessage.m40000644000175000017500000000240411461165270012431 00000000000000# lcmessage.m4 serial 4 (gettext-0.14.2) dnl Copyright (C) 1995-2002, 2004-2005 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl dnl This file can can be used in projects which are not available under dnl the GNU General Public License or the GNU Library General Public dnl License but which still want to provide support for the GNU gettext dnl functionality. dnl Please note that the actual code of the GNU gettext library is covered dnl by the GNU Library General Public License, and the rest of the GNU dnl gettext package package is covered by the GNU General Public License. dnl They are *not* in the public domain. dnl Authors: dnl Ulrich Drepper , 1995. # Check whether LC_MESSAGES is available in . AC_DEFUN([gt_LC_MESSAGES], [ AC_CACHE_CHECK([for LC_MESSAGES], gt_cv_val_LC_MESSAGES, [AC_TRY_LINK([#include ], [return LC_MESSAGES], gt_cv_val_LC_MESSAGES=yes, gt_cv_val_LC_MESSAGES=no)]) if test $gt_cv_val_LC_MESSAGES = yes; then AC_DEFINE(HAVE_LC_MESSAGES, 1, [Define if your file defines LC_MESSAGES.]) fi ]) libnih-1.0.3/intl/0000755000175000017500000000000011504742362010733 500000000000000libnih-1.0.3/intl/hash-string.c0000644000175000017500000000315111461165267013253 00000000000000/* Implements a string hashing function. Copyright (C) 1995, 1997, 1998, 2000, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif /* Specification. */ #include "hash-string.h" /* Defines the so called `hashpjw' function by P.J. Weinberger [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools, 1986, 1987 Bell Telephone Laboratories, Inc.] */ unsigned long int __hash_string (const char *str_param) { unsigned long int hval, g; const char *str = str_param; /* Compute the hash value for the given string. */ hval = 0; while (*str != '\0') { hval <<= 4; hval += (unsigned char) *str++; g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4)); if (g != 0) { hval ^= g >> (HASHWORDBITS - 8); hval ^= g; } } return hval; } libnih-1.0.3/intl/osdep.c0000644000175000017500000000174111461165270012133 00000000000000/* OS dependent parts of libintl. Copyright (C) 2001-2002, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #if defined __CYGWIN__ # include "intl-exports.c" #elif defined __EMX__ # include "os2compat.c" #else /* Avoid AIX compiler warning. */ typedef int dummy; #endif libnih-1.0.3/intl/gettext.c0000644000175000017500000000355411461165267012517 00000000000000/* Implementation of gettext(3) function. Copyright (C) 1995, 1997, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #ifdef _LIBC # define __need_NULL # include #else # include /* Just for NULL. */ #endif #include "gettextP.h" #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* @@ end of prolog @@ */ /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define GETTEXT __gettext # define DCGETTEXT INTUSE(__dcgettext) #else # define GETTEXT libintl_gettext # define DCGETTEXT libintl_dcgettext #endif /* Look up MSGID in the current default message catalog for the current LC_MESSAGES locale. If not found, returns MSGID itself (the default text). */ char * GETTEXT (const char *msgid) { return DCGETTEXT (NULL, msgid, LC_MESSAGES); } #ifdef _LIBC /* Alias for function name in GNU C Library. */ weak_alias (__gettext, gettext); #endif libnih-1.0.3/intl/localcharset.c0000644000175000017500000003031411461165267013471 00000000000000/* Determine a canonical name for the current locale's character encoding. Copyright (C) 2000-2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Bruno Haible . */ #include /* Specification. */ #include "localcharset.h" #include #include #include #include #if defined _WIN32 || defined __WIN32__ # define WIN32_NATIVE #endif #if defined __EMX__ /* Assume EMX program runs on OS/2, even if compiled under DOS. */ # define OS2 #endif #if !defined WIN32_NATIVE # if HAVE_LANGINFO_CODESET # include # else # if 0 /* see comment below */ # include # endif # endif # ifdef __CYGWIN__ # define WIN32_LEAN_AND_MEAN # include # endif #elif defined WIN32_NATIVE # define WIN32_LEAN_AND_MEAN # include #endif #if defined OS2 # define INCL_DOS # include #endif #if ENABLE_RELOCATABLE # include "relocatable.h" #else # define relocate(pathname) (pathname) #endif /* Get LIBDIR. */ #ifndef LIBDIR # include "configmake.h" #endif #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ /* Win32, Cygwin, OS/2, DOS */ # define ISSLASH(C) ((C) == '/' || (C) == '\\') #endif #ifndef DIRECTORY_SEPARATOR # define DIRECTORY_SEPARATOR '/' #endif #ifndef ISSLASH # define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR) #endif #if HAVE_DECL_GETC_UNLOCKED # undef getc # define getc getc_unlocked #endif /* The following static variable is declared 'volatile' to avoid a possible multithread problem in the function get_charset_aliases. If we are running in a threaded environment, and if two threads initialize 'charset_aliases' simultaneously, both will produce the same value, and everything will be ok if the two assignments to 'charset_aliases' are atomic. But I don't know what will happen if the two assignments mix. */ #if __STDC__ != 1 # define volatile /* empty */ #endif /* Pointer to the contents of the charset.alias file, if it has already been read, else NULL. Its format is: ALIAS_1 '\0' CANONICAL_1 '\0' ... ALIAS_n '\0' CANONICAL_n '\0' '\0' */ static const char * volatile charset_aliases; /* Return a pointer to the contents of the charset.alias file. */ static const char * get_charset_aliases (void) { const char *cp; cp = charset_aliases; if (cp == NULL) { #if !(defined VMS || defined WIN32_NATIVE || defined __CYGWIN__) FILE *fp; const char *dir; const char *base = "charset.alias"; char *file_name; /* Make it possible to override the charset.alias location. This is necessary for running the testsuite before "make install". */ dir = getenv ("CHARSETALIASDIR"); if (dir == NULL || dir[0] == '\0') dir = relocate (LIBDIR); /* Concatenate dir and base into freshly allocated file_name. */ { size_t dir_len = strlen (dir); size_t base_len = strlen (base); int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1])); file_name = (char *) malloc (dir_len + add_slash + base_len + 1); if (file_name != NULL) { memcpy (file_name, dir, dir_len); if (add_slash) file_name[dir_len] = DIRECTORY_SEPARATOR; memcpy (file_name + dir_len + add_slash, base, base_len + 1); } } if (file_name == NULL || (fp = fopen (file_name, "r")) == NULL) /* Out of memory or file not found, treat it as empty. */ cp = ""; else { /* Parse the file's contents. */ char *res_ptr = NULL; size_t res_size = 0; for (;;) { int c; char buf1[50+1]; char buf2[50+1]; size_t l1, l2; char *old_res_ptr; c = getc (fp); if (c == EOF) break; if (c == '\n' || c == ' ' || c == '\t') continue; if (c == '#') { /* Skip comment, to end of line. */ do c = getc (fp); while (!(c == EOF || c == '\n')); if (c == EOF) break; continue; } ungetc (c, fp); if (fscanf (fp, "%50s %50s", buf1, buf2) < 2) break; l1 = strlen (buf1); l2 = strlen (buf2); old_res_ptr = res_ptr; if (res_size == 0) { res_size = l1 + 1 + l2 + 1; res_ptr = (char *) malloc (res_size + 1); } else { res_size += l1 + 1 + l2 + 1; res_ptr = (char *) realloc (res_ptr, res_size + 1); } if (res_ptr == NULL) { /* Out of memory. */ res_size = 0; if (old_res_ptr != NULL) free (old_res_ptr); break; } strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); strcpy (res_ptr + res_size - (l2 + 1), buf2); } fclose (fp); if (res_size == 0) cp = ""; else { *(res_ptr + res_size) = '\0'; cp = res_ptr; } } if (file_name != NULL) free (file_name); #else # if defined VMS /* To avoid the troubles of an extra file charset.alias_vms in the sources of many GNU packages, simply inline the aliases here. */ /* The list of encodings is taken from the OpenVMS 7.3-1 documentation "Compaq C Run-Time Library Reference Manual for OpenVMS systems" section 10.7 "Handling Different Character Sets". */ cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" "ISO8859-2" "\0" "ISO-8859-2" "\0" "ISO8859-5" "\0" "ISO-8859-5" "\0" "ISO8859-7" "\0" "ISO-8859-7" "\0" "ISO8859-8" "\0" "ISO-8859-8" "\0" "ISO8859-9" "\0" "ISO-8859-9" "\0" /* Japanese */ "eucJP" "\0" "EUC-JP" "\0" "SJIS" "\0" "SHIFT_JIS" "\0" "DECKANJI" "\0" "DEC-KANJI" "\0" "SDECKANJI" "\0" "EUC-JP" "\0" /* Chinese */ "eucTW" "\0" "EUC-TW" "\0" "DECHANYU" "\0" "DEC-HANYU" "\0" "DECHANZI" "\0" "GB2312" "\0" /* Korean */ "DECKOREAN" "\0" "EUC-KR" "\0"; # endif # if defined WIN32_NATIVE || defined __CYGWIN__ /* To avoid the troubles of installing a separate file in the same directory as the DLL and of retrieving the DLL's directory at runtime, simply inline the aliases here. */ cp = "CP936" "\0" "GBK" "\0" "CP1361" "\0" "JOHAB" "\0" "CP20127" "\0" "ASCII" "\0" "CP20866" "\0" "KOI8-R" "\0" "CP20936" "\0" "GB2312" "\0" "CP21866" "\0" "KOI8-RU" "\0" "CP28591" "\0" "ISO-8859-1" "\0" "CP28592" "\0" "ISO-8859-2" "\0" "CP28593" "\0" "ISO-8859-3" "\0" "CP28594" "\0" "ISO-8859-4" "\0" "CP28595" "\0" "ISO-8859-5" "\0" "CP28596" "\0" "ISO-8859-6" "\0" "CP28597" "\0" "ISO-8859-7" "\0" "CP28598" "\0" "ISO-8859-8" "\0" "CP28599" "\0" "ISO-8859-9" "\0" "CP28605" "\0" "ISO-8859-15" "\0" "CP38598" "\0" "ISO-8859-8" "\0" "CP51932" "\0" "EUC-JP" "\0" "CP51936" "\0" "GB2312" "\0" "CP51949" "\0" "EUC-KR" "\0" "CP51950" "\0" "EUC-TW" "\0" "CP54936" "\0" "GB18030" "\0" "CP65001" "\0" "UTF-8" "\0"; # endif #endif charset_aliases = cp; } return cp; } /* Determine the current locale's character encoding, and canonicalize it into one of the canonical names listed in config.charset. The result must not be freed; it is statically allocated. If the canonical name cannot be determined, the result is a non-canonical name. */ #ifdef STATIC STATIC #endif const char * locale_charset (void) { const char *codeset; const char *aliases; #if !(defined WIN32_NATIVE || defined OS2) # if HAVE_LANGINFO_CODESET /* Most systems support nl_langinfo (CODESET) nowadays. */ codeset = nl_langinfo (CODESET); # ifdef __CYGWIN__ /* Cygwin 2006 does not have locales. nl_langinfo (CODESET) always returns "US-ASCII". As long as this is not fixed, return the suffix of the locale name from the environment variables (if present) or the codepage as a number. */ if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0) { const char *locale; static char buf[2 + 10 + 1]; locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { /* If the locale name contains an encoding after the dot, return it. */ const char *dot = strchr (locale, '.'); if (dot != NULL) { const char *modifier; dot++; /* Look for the possible @... trailer and remove it, if any. */ modifier = strchr (dot, '@'); if (modifier == NULL) return dot; if (modifier - dot < sizeof (buf)) { memcpy (buf, dot, modifier - dot); buf [modifier - dot] = '\0'; return buf; } } } /* Woe32 has a function returning the locale's codepage as a number. */ sprintf (buf, "CP%u", GetACP ()); codeset = buf; } # endif # else /* On old systems which lack it, use setlocale or getenv. */ const char *locale = NULL; /* But most old systems don't have a complete set of locales. Some (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't use setlocale here; it would return "C" when it doesn't support the locale name the user has set. */ # if 0 locale = setlocale (LC_CTYPE, NULL); # endif if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } } /* On some old systems, one used to set locale = "iso8859_1". On others, you set it to "language_COUNTRY.charset". In any case, we resolve it through the charset.alias file. */ codeset = locale; # endif #elif defined WIN32_NATIVE static char buf[2 + 10 + 1]; /* Woe32 has a function returning the locale's codepage as a number. */ sprintf (buf, "CP%u", GetACP ()); codeset = buf; #elif defined OS2 const char *locale; static char buf[2 + 10 + 1]; ULONG cp[3]; ULONG cplen; /* Allow user to override the codeset, as set in the operating system, with standard language environment variables. */ locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { /* If the locale name contains an encoding after the dot, return it. */ const char *dot = strchr (locale, '.'); if (dot != NULL) { const char *modifier; dot++; /* Look for the possible @... trailer and remove it, if any. */ modifier = strchr (dot, '@'); if (modifier == NULL) return dot; if (modifier - dot < sizeof (buf)) { memcpy (buf, dot, modifier - dot); buf [modifier - dot] = '\0'; return buf; } } /* Resolve through the charset.alias file. */ codeset = locale; } else { /* OS/2 has a function returning the locale's codepage as a number. */ if (DosQueryCp (sizeof (cp), cp, &cplen)) codeset = ""; else { sprintf (buf, "CP%u", cp[0]); codeset = buf; } } #endif if (codeset == NULL) /* The canonical name cannot be determined. */ codeset = ""; /* Resolve alias. */ for (aliases = get_charset_aliases (); *aliases != '\0'; aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) if (strcmp (codeset, aliases) == 0 || (aliases[0] == '*' && aliases[1] == '\0')) { codeset = aliases + strlen (aliases) + 1; break; } /* Don't return an empty string. GNU libc and GNU libiconv interpret the empty string as denoting "the locale's character encoding", thus GNU libiconv would call this function a second time. */ if (codeset[0] == '\0') codeset = "ASCII"; return codeset; } libnih-1.0.3/intl/printf-args.c0000644000175000017500000001336311461165270013260 00000000000000/* Decomposed printf argument list. Copyright (C) 1999, 2002-2003, 2005-2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* This file can be parametrized with the following macros: ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. PRINTF_FETCHARGS Name of the function to be defined. STATIC Set to 'static' to declare the function static. */ #ifndef PRINTF_FETCHARGS # include #endif /* Specification. */ #ifndef PRINTF_FETCHARGS # include "printf-args.h" #endif #ifdef STATIC STATIC #endif int PRINTF_FETCHARGS (va_list args, arguments *a) { size_t i; argument *ap; for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++) switch (ap->type) { case TYPE_SCHAR: ap->a.a_schar = va_arg (args, /*signed char*/ int); break; case TYPE_UCHAR: ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); break; case TYPE_SHORT: ap->a.a_short = va_arg (args, /*short*/ int); break; case TYPE_USHORT: ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); break; case TYPE_INT: ap->a.a_int = va_arg (args, int); break; case TYPE_UINT: ap->a.a_uint = va_arg (args, unsigned int); break; case TYPE_LONGINT: ap->a.a_longint = va_arg (args, long int); break; case TYPE_ULONGINT: ap->a.a_ulongint = va_arg (args, unsigned long int); break; #if HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: ap->a.a_longlongint = va_arg (args, long long int); break; case TYPE_ULONGLONGINT: ap->a.a_ulonglongint = va_arg (args, unsigned long long int); break; #endif case TYPE_DOUBLE: ap->a.a_double = va_arg (args, double); break; case TYPE_LONGDOUBLE: ap->a.a_longdouble = va_arg (args, long double); break; case TYPE_CHAR: ap->a.a_char = va_arg (args, int); break; #if HAVE_WINT_T case TYPE_WIDE_CHAR: /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by default argument promotions", this is not the case in mingw32, where wint_t is 'unsigned short'. */ ap->a.a_wide_char = (sizeof (wint_t) < sizeof (int) ? va_arg (args, int) : va_arg (args, wint_t)); break; #endif case TYPE_STRING: ap->a.a_string = va_arg (args, const char *); /* A null pointer is an invalid argument for "%s", but in practice it occurs quite frequently in printf statements that produce debug output. Use a fallback in this case. */ if (ap->a.a_string == NULL) ap->a.a_string = "(NULL)"; break; #if HAVE_WCHAR_T case TYPE_WIDE_STRING: ap->a.a_wide_string = va_arg (args, const wchar_t *); /* A null pointer is an invalid argument for "%ls", but in practice it occurs quite frequently in printf statements that produce debug output. Use a fallback in this case. */ if (ap->a.a_wide_string == NULL) { static const wchar_t wide_null_string[] = { (wchar_t)'(', (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L', (wchar_t)')', (wchar_t)0 }; ap->a.a_wide_string = wide_null_string; } break; #endif case TYPE_POINTER: ap->a.a_pointer = va_arg (args, void *); break; case TYPE_COUNT_SCHAR_POINTER: ap->a.a_count_schar_pointer = va_arg (args, signed char *); break; case TYPE_COUNT_SHORT_POINTER: ap->a.a_count_short_pointer = va_arg (args, short *); break; case TYPE_COUNT_INT_POINTER: ap->a.a_count_int_pointer = va_arg (args, int *); break; case TYPE_COUNT_LONGINT_POINTER: ap->a.a_count_longint_pointer = va_arg (args, long int *); break; #if HAVE_LONG_LONG_INT case TYPE_COUNT_LONGLONGINT_POINTER: ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); break; #endif #if ENABLE_UNISTDIO /* The unistdio extensions. */ case TYPE_U8_STRING: ap->a.a_u8_string = va_arg (args, const uint8_t *); /* A null pointer is an invalid argument for "%U", but in practice it occurs quite frequently in printf statements that produce debug output. Use a fallback in this case. */ if (ap->a.a_u8_string == NULL) { static const uint8_t u8_null_string[] = { '(', 'N', 'U', 'L', 'L', ')', 0 }; ap->a.a_u8_string = u8_null_string; } break; case TYPE_U16_STRING: ap->a.a_u16_string = va_arg (args, const uint16_t *); /* A null pointer is an invalid argument for "%lU", but in practice it occurs quite frequently in printf statements that produce debug output. Use a fallback in this case. */ if (ap->a.a_u16_string == NULL) { static const uint16_t u16_null_string[] = { '(', 'N', 'U', 'L', 'L', ')', 0 }; ap->a.a_u16_string = u16_null_string; } break; case TYPE_U32_STRING: ap->a.a_u32_string = va_arg (args, const uint32_t *); /* A null pointer is an invalid argument for "%llU", but in practice it occurs quite frequently in printf statements that produce debug output. Use a fallback in this case. */ if (ap->a.a_u32_string == NULL) { static const uint32_t u32_null_string[] = { '(', 'N', 'U', 'L', 'L', ')', 0 }; ap->a.a_u32_string = u32_null_string; } break; #endif default: /* Unknown type. */ return -1; } return 0; } libnih-1.0.3/intl/loadinfo.h0000644000175000017500000001211311461165267012622 00000000000000/* Copyright (C) 1996-1999, 2000-2003, 2005-2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1996. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _LOADINFO_H #define _LOADINFO_H 1 /* Declarations of locale dependent catalog lookup functions. Implemented in localealias.c Possibly replace a locale name by another. explodename.c Split a locale name into its various fields. l10nflist.c Generate a list of filenames of possible message catalogs. finddomain.c Find and open the relevant message catalogs. The main function _nl_find_domain() in finddomain.c is declared in gettextP.h. */ #ifndef internal_function # define internal_function #endif #ifndef LIBINTL_DLL_EXPORTED # define LIBINTL_DLL_EXPORTED #endif /* Tell the compiler when a conditional or integer expression is almost always true or almost always false. */ #ifndef HAVE_BUILTIN_EXPECT # define __builtin_expect(expr, val) (expr) #endif /* Separator in PATH like lists of pathnames. */ #if ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) || defined __EMX__ || defined __DJGPP__ /* Win32, OS/2, DOS */ # define PATH_SEPARATOR ';' #else /* Unix */ # define PATH_SEPARATOR ':' #endif /* Encoding of locale name parts. */ #define XPG_NORM_CODESET 1 #define XPG_CODESET 2 #define XPG_TERRITORY 4 #define XPG_MODIFIER 8 struct loaded_l10nfile { const char *filename; int decided; const void *data; struct loaded_l10nfile *next; struct loaded_l10nfile *successor[1]; }; /* Normalize codeset name. There is no standard for the codeset names. Normalization allows the user to use any of the common names. The return value is dynamically allocated and has to be freed by the caller. */ extern const char *_nl_normalize_codeset (const char *codeset, size_t name_len); /* Lookup a locale dependent file. *L10NFILE_LIST denotes a pool of lookup results of locale dependent files of the same kind, sorted in decreasing order of ->filename. DIRLIST and DIRLIST_LEN are an argz list of directories in which to look, containing at least one directory (i.e. DIRLIST_LEN > 0). MASK, LANGUAGE, TERRITORY, CODESET, NORMALIZED_CODESET, MODIFIER are the pieces of the locale name, as produced by _nl_explode_name(). FILENAME is the filename suffix. The return value is the lookup result, either found in *L10NFILE_LIST, or - if DO_ALLOCATE is nonzero - freshly allocated, or possibly NULL. If the return value is non-NULL, it is added to *L10NFILE_LIST, and its ->next field denotes the chaining inside *L10NFILE_LIST, and furthermore its ->successor[] field contains a list of other lookup results from which this lookup result inherits. */ extern struct loaded_l10nfile * _nl_make_l10nflist (struct loaded_l10nfile **l10nfile_list, const char *dirlist, size_t dirlist_len, int mask, const char *language, const char *territory, const char *codeset, const char *normalized_codeset, const char *modifier, const char *filename, int do_allocate); /* Lookup the real locale name for a locale alias NAME, or NULL if NAME is not a locale alias (but possibly a real locale name). The return value is statically allocated and must not be freed. */ /* Part of the libintl ABI only for the sake of the gettext.m4 macro. */ extern LIBINTL_DLL_EXPORTED const char *_nl_expand_alias (const char *name); /* Split a locale name NAME into its pieces: language, modifier, territory, codeset. NAME gets destructively modified: NUL bytes are inserted here and there. *LANGUAGE gets assigned NAME. Each of *MODIFIER, *TERRITORY, *CODESET gets assigned either a pointer into the old NAME string, or NULL. *NORMALIZED_CODESET gets assigned the expanded *CODESET, if it is different from *CODESET; this one is dynamically allocated and has to be freed by the caller. The return value is a bitmask, where each bit corresponds to one filled-in value: XPG_MODIFIER for *MODIFIER, XPG_TERRITORY for *TERRITORY, XPG_CODESET for *CODESET, XPG_NORM_CODESET for *NORMALIZED_CODESET. */ extern int _nl_explode_name (char *name, const char **language, const char **modifier, const char **territory, const char **codeset, const char **normalized_codeset); #endif /* loadinfo.h */ libnih-1.0.3/intl/dngettext.c0000644000175000017500000000354611461165267013042 00000000000000/* Implementation of the dngettext(3) function. Copyright (C) 1995-1997, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include "gettextP.h" #include #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* @@ end of prolog @@ */ /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define DNGETTEXT __dngettext # define DCNGETTEXT __dcngettext #else # define DNGETTEXT libintl_dngettext # define DCNGETTEXT libintl_dcngettext #endif /* Look up MSGID in the DOMAINNAME message catalog of the current LC_MESSAGES locale and skip message according to the plural form. */ char * DNGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n) { return DCNGETTEXT (domainname, msgid1, msgid2, n, LC_MESSAGES); } #ifdef _LIBC /* Alias for function name in GNU C Library. */ weak_alias (__dngettext, dngettext); #endif libnih-1.0.3/intl/loadmsgcat.c0000644000175000017500000010270011461165267013142 00000000000000/* Load needed message catalogs. Copyright (C) 1995-1999, 2000-2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Tell glibc's to provide a prototype for mempcpy(). This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include #include #ifdef __GNUC__ # undef alloca # define alloca __builtin_alloca # define HAVE_ALLOCA 1 #else # ifdef _MSC_VER # include # define alloca _alloca # else # if defined HAVE_ALLOCA_H || defined _LIBC # include # else # ifdef _AIX #pragma alloca # else # ifndef alloca char *alloca (); # endif # endif # endif # endif #endif #include #include #if defined HAVE_UNISTD_H || defined _LIBC # include #endif #ifdef _LIBC # include # include #endif #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \ || (defined _LIBC && defined _POSIX_MAPPED_FILES) # include # undef HAVE_MMAP # define HAVE_MMAP 1 #else # undef HAVE_MMAP #endif #if defined HAVE_STDINT_H_WITH_UINTMAX || defined _LIBC # include #endif #if defined HAVE_INTTYPES_H || defined _LIBC # include #endif #include "gmo.h" #include "gettextP.h" #include "hash-string.h" #include "plural-exp.h" #ifdef _LIBC # include "../locale/localeinfo.h" # include #endif /* Handle multi-threaded applications. */ #ifdef _LIBC # include #else # include "lock.h" #endif /* Provide fallback values for macros that ought to be defined in . Note that our fallback values need not be literal strings, because we don't use them with preprocessor string concatenation. */ #if !defined PRId8 || PRI_MACROS_BROKEN # undef PRId8 # define PRId8 "d" #endif #if !defined PRIi8 || PRI_MACROS_BROKEN # undef PRIi8 # define PRIi8 "i" #endif #if !defined PRIo8 || PRI_MACROS_BROKEN # undef PRIo8 # define PRIo8 "o" #endif #if !defined PRIu8 || PRI_MACROS_BROKEN # undef PRIu8 # define PRIu8 "u" #endif #if !defined PRIx8 || PRI_MACROS_BROKEN # undef PRIx8 # define PRIx8 "x" #endif #if !defined PRIX8 || PRI_MACROS_BROKEN # undef PRIX8 # define PRIX8 "X" #endif #if !defined PRId16 || PRI_MACROS_BROKEN # undef PRId16 # define PRId16 "d" #endif #if !defined PRIi16 || PRI_MACROS_BROKEN # undef PRIi16 # define PRIi16 "i" #endif #if !defined PRIo16 || PRI_MACROS_BROKEN # undef PRIo16 # define PRIo16 "o" #endif #if !defined PRIu16 || PRI_MACROS_BROKEN # undef PRIu16 # define PRIu16 "u" #endif #if !defined PRIx16 || PRI_MACROS_BROKEN # undef PRIx16 # define PRIx16 "x" #endif #if !defined PRIX16 || PRI_MACROS_BROKEN # undef PRIX16 # define PRIX16 "X" #endif #if !defined PRId32 || PRI_MACROS_BROKEN # undef PRId32 # define PRId32 "d" #endif #if !defined PRIi32 || PRI_MACROS_BROKEN # undef PRIi32 # define PRIi32 "i" #endif #if !defined PRIo32 || PRI_MACROS_BROKEN # undef PRIo32 # define PRIo32 "o" #endif #if !defined PRIu32 || PRI_MACROS_BROKEN # undef PRIu32 # define PRIu32 "u" #endif #if !defined PRIx32 || PRI_MACROS_BROKEN # undef PRIx32 # define PRIx32 "x" #endif #if !defined PRIX32 || PRI_MACROS_BROKEN # undef PRIX32 # define PRIX32 "X" #endif #if !defined PRId64 || PRI_MACROS_BROKEN # undef PRId64 # define PRId64 (sizeof (long) == 8 ? "ld" : "lld") #endif #if !defined PRIi64 || PRI_MACROS_BROKEN # undef PRIi64 # define PRIi64 (sizeof (long) == 8 ? "li" : "lli") #endif #if !defined PRIo64 || PRI_MACROS_BROKEN # undef PRIo64 # define PRIo64 (sizeof (long) == 8 ? "lo" : "llo") #endif #if !defined PRIu64 || PRI_MACROS_BROKEN # undef PRIu64 # define PRIu64 (sizeof (long) == 8 ? "lu" : "llu") #endif #if !defined PRIx64 || PRI_MACROS_BROKEN # undef PRIx64 # define PRIx64 (sizeof (long) == 8 ? "lx" : "llx") #endif #if !defined PRIX64 || PRI_MACROS_BROKEN # undef PRIX64 # define PRIX64 (sizeof (long) == 8 ? "lX" : "llX") #endif #if !defined PRIdLEAST8 || PRI_MACROS_BROKEN # undef PRIdLEAST8 # define PRIdLEAST8 "d" #endif #if !defined PRIiLEAST8 || PRI_MACROS_BROKEN # undef PRIiLEAST8 # define PRIiLEAST8 "i" #endif #if !defined PRIoLEAST8 || PRI_MACROS_BROKEN # undef PRIoLEAST8 # define PRIoLEAST8 "o" #endif #if !defined PRIuLEAST8 || PRI_MACROS_BROKEN # undef PRIuLEAST8 # define PRIuLEAST8 "u" #endif #if !defined PRIxLEAST8 || PRI_MACROS_BROKEN # undef PRIxLEAST8 # define PRIxLEAST8 "x" #endif #if !defined PRIXLEAST8 || PRI_MACROS_BROKEN # undef PRIXLEAST8 # define PRIXLEAST8 "X" #endif #if !defined PRIdLEAST16 || PRI_MACROS_BROKEN # undef PRIdLEAST16 # define PRIdLEAST16 "d" #endif #if !defined PRIiLEAST16 || PRI_MACROS_BROKEN # undef PRIiLEAST16 # define PRIiLEAST16 "i" #endif #if !defined PRIoLEAST16 || PRI_MACROS_BROKEN # undef PRIoLEAST16 # define PRIoLEAST16 "o" #endif #if !defined PRIuLEAST16 || PRI_MACROS_BROKEN # undef PRIuLEAST16 # define PRIuLEAST16 "u" #endif #if !defined PRIxLEAST16 || PRI_MACROS_BROKEN # undef PRIxLEAST16 # define PRIxLEAST16 "x" #endif #if !defined PRIXLEAST16 || PRI_MACROS_BROKEN # undef PRIXLEAST16 # define PRIXLEAST16 "X" #endif #if !defined PRIdLEAST32 || PRI_MACROS_BROKEN # undef PRIdLEAST32 # define PRIdLEAST32 "d" #endif #if !defined PRIiLEAST32 || PRI_MACROS_BROKEN # undef PRIiLEAST32 # define PRIiLEAST32 "i" #endif #if !defined PRIoLEAST32 || PRI_MACROS_BROKEN # undef PRIoLEAST32 # define PRIoLEAST32 "o" #endif #if !defined PRIuLEAST32 || PRI_MACROS_BROKEN # undef PRIuLEAST32 # define PRIuLEAST32 "u" #endif #if !defined PRIxLEAST32 || PRI_MACROS_BROKEN # undef PRIxLEAST32 # define PRIxLEAST32 "x" #endif #if !defined PRIXLEAST32 || PRI_MACROS_BROKEN # undef PRIXLEAST32 # define PRIXLEAST32 "X" #endif #if !defined PRIdLEAST64 || PRI_MACROS_BROKEN # undef PRIdLEAST64 # define PRIdLEAST64 PRId64 #endif #if !defined PRIiLEAST64 || PRI_MACROS_BROKEN # undef PRIiLEAST64 # define PRIiLEAST64 PRIi64 #endif #if !defined PRIoLEAST64 || PRI_MACROS_BROKEN # undef PRIoLEAST64 # define PRIoLEAST64 PRIo64 #endif #if !defined PRIuLEAST64 || PRI_MACROS_BROKEN # undef PRIuLEAST64 # define PRIuLEAST64 PRIu64 #endif #if !defined PRIxLEAST64 || PRI_MACROS_BROKEN # undef PRIxLEAST64 # define PRIxLEAST64 PRIx64 #endif #if !defined PRIXLEAST64 || PRI_MACROS_BROKEN # undef PRIXLEAST64 # define PRIXLEAST64 PRIX64 #endif #if !defined PRIdFAST8 || PRI_MACROS_BROKEN # undef PRIdFAST8 # define PRIdFAST8 "d" #endif #if !defined PRIiFAST8 || PRI_MACROS_BROKEN # undef PRIiFAST8 # define PRIiFAST8 "i" #endif #if !defined PRIoFAST8 || PRI_MACROS_BROKEN # undef PRIoFAST8 # define PRIoFAST8 "o" #endif #if !defined PRIuFAST8 || PRI_MACROS_BROKEN # undef PRIuFAST8 # define PRIuFAST8 "u" #endif #if !defined PRIxFAST8 || PRI_MACROS_BROKEN # undef PRIxFAST8 # define PRIxFAST8 "x" #endif #if !defined PRIXFAST8 || PRI_MACROS_BROKEN # undef PRIXFAST8 # define PRIXFAST8 "X" #endif #if !defined PRIdFAST16 || PRI_MACROS_BROKEN # undef PRIdFAST16 # define PRIdFAST16 "d" #endif #if !defined PRIiFAST16 || PRI_MACROS_BROKEN # undef PRIiFAST16 # define PRIiFAST16 "i" #endif #if !defined PRIoFAST16 || PRI_MACROS_BROKEN # undef PRIoFAST16 # define PRIoFAST16 "o" #endif #if !defined PRIuFAST16 || PRI_MACROS_BROKEN # undef PRIuFAST16 # define PRIuFAST16 "u" #endif #if !defined PRIxFAST16 || PRI_MACROS_BROKEN # undef PRIxFAST16 # define PRIxFAST16 "x" #endif #if !defined PRIXFAST16 || PRI_MACROS_BROKEN # undef PRIXFAST16 # define PRIXFAST16 "X" #endif #if !defined PRIdFAST32 || PRI_MACROS_BROKEN # undef PRIdFAST32 # define PRIdFAST32 "d" #endif #if !defined PRIiFAST32 || PRI_MACROS_BROKEN # undef PRIiFAST32 # define PRIiFAST32 "i" #endif #if !defined PRIoFAST32 || PRI_MACROS_BROKEN # undef PRIoFAST32 # define PRIoFAST32 "o" #endif #if !defined PRIuFAST32 || PRI_MACROS_BROKEN # undef PRIuFAST32 # define PRIuFAST32 "u" #endif #if !defined PRIxFAST32 || PRI_MACROS_BROKEN # undef PRIxFAST32 # define PRIxFAST32 "x" #endif #if !defined PRIXFAST32 || PRI_MACROS_BROKEN # undef PRIXFAST32 # define PRIXFAST32 "X" #endif #if !defined PRIdFAST64 || PRI_MACROS_BROKEN # undef PRIdFAST64 # define PRIdFAST64 PRId64 #endif #if !defined PRIiFAST64 || PRI_MACROS_BROKEN # undef PRIiFAST64 # define PRIiFAST64 PRIi64 #endif #if !defined PRIoFAST64 || PRI_MACROS_BROKEN # undef PRIoFAST64 # define PRIoFAST64 PRIo64 #endif #if !defined PRIuFAST64 || PRI_MACROS_BROKEN # undef PRIuFAST64 # define PRIuFAST64 PRIu64 #endif #if !defined PRIxFAST64 || PRI_MACROS_BROKEN # undef PRIxFAST64 # define PRIxFAST64 PRIx64 #endif #if !defined PRIXFAST64 || PRI_MACROS_BROKEN # undef PRIXFAST64 # define PRIXFAST64 PRIX64 #endif #if !defined PRIdMAX || PRI_MACROS_BROKEN # undef PRIdMAX # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld") #endif #if !defined PRIiMAX || PRI_MACROS_BROKEN # undef PRIiMAX # define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli") #endif #if !defined PRIoMAX || PRI_MACROS_BROKEN # undef PRIoMAX # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo") #endif #if !defined PRIuMAX || PRI_MACROS_BROKEN # undef PRIuMAX # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu") #endif #if !defined PRIxMAX || PRI_MACROS_BROKEN # undef PRIxMAX # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx") #endif #if !defined PRIXMAX || PRI_MACROS_BROKEN # undef PRIXMAX # define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX") #endif #if !defined PRIdPTR || PRI_MACROS_BROKEN # undef PRIdPTR # define PRIdPTR \ (sizeof (void *) == sizeof (long) ? "ld" : \ sizeof (void *) == sizeof (int) ? "d" : \ "lld") #endif #if !defined PRIiPTR || PRI_MACROS_BROKEN # undef PRIiPTR # define PRIiPTR \ (sizeof (void *) == sizeof (long) ? "li" : \ sizeof (void *) == sizeof (int) ? "i" : \ "lli") #endif #if !defined PRIoPTR || PRI_MACROS_BROKEN # undef PRIoPTR # define PRIoPTR \ (sizeof (void *) == sizeof (long) ? "lo" : \ sizeof (void *) == sizeof (int) ? "o" : \ "llo") #endif #if !defined PRIuPTR || PRI_MACROS_BROKEN # undef PRIuPTR # define PRIuPTR \ (sizeof (void *) == sizeof (long) ? "lu" : \ sizeof (void *) == sizeof (int) ? "u" : \ "llu") #endif #if !defined PRIxPTR || PRI_MACROS_BROKEN # undef PRIxPTR # define PRIxPTR \ (sizeof (void *) == sizeof (long) ? "lx" : \ sizeof (void *) == sizeof (int) ? "x" : \ "llx") #endif #if !defined PRIXPTR || PRI_MACROS_BROKEN # undef PRIXPTR # define PRIXPTR \ (sizeof (void *) == sizeof (long) ? "lX" : \ sizeof (void *) == sizeof (int) ? "X" : \ "llX") #endif /* @@ end of prolog @@ */ #ifdef _LIBC /* Rename the non ISO C functions. This is required by the standard because some ISO C functions will require linking with this object file and the name space must not be polluted. */ # define open(name, flags) open_not_cancel_2 (name, flags) # define close(fd) close_not_cancel_no_status (fd) # define read(fd, buf, n) read_not_cancel (fd, buf, n) # define mmap(addr, len, prot, flags, fd, offset) \ __mmap (addr, len, prot, flags, fd, offset) # define munmap(addr, len) __munmap (addr, len) #endif /* For those losing systems which don't have `alloca' we have to add some additional code emulating it. */ #ifdef HAVE_ALLOCA # define freea(p) /* nothing */ #else # define alloca(n) malloc (n) # define freea(p) free (p) #endif /* For systems that distinguish between text and binary I/O. O_BINARY is usually declared in . */ #if !defined O_BINARY && defined _O_BINARY /* For MSC-compatible compilers. */ # define O_BINARY _O_BINARY # define O_TEXT _O_TEXT #endif #ifdef __BEOS__ /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */ # undef O_BINARY # undef O_TEXT #endif /* On reasonable systems, binary I/O is the default. */ #ifndef O_BINARY # define O_BINARY 0 #endif /* We need a sign, whether a new catalog was loaded, which can be associated with all translations. This is important if the translations are cached by one of GCC's features. */ int _nl_msg_cat_cntr; /* Expand a system dependent string segment. Return NULL if unsupported. */ static const char * get_sysdep_segment_value (const char *name) { /* Test for an ISO C 99 section 7.8.1 format string directive. Syntax: P R I { d | i | o | u | x | X } { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */ /* We don't use a table of 14 times 6 'const char *' strings here, because data relocations cost startup time. */ if (name[0] == 'P' && name[1] == 'R' && name[2] == 'I') { if (name[3] == 'd' || name[3] == 'i' || name[3] == 'o' || name[3] == 'u' || name[3] == 'x' || name[3] == 'X') { if (name[4] == '8' && name[5] == '\0') { if (name[3] == 'd') return PRId8; if (name[3] == 'i') return PRIi8; if (name[3] == 'o') return PRIo8; if (name[3] == 'u') return PRIu8; if (name[3] == 'x') return PRIx8; if (name[3] == 'X') return PRIX8; abort (); } if (name[4] == '1' && name[5] == '6' && name[6] == '\0') { if (name[3] == 'd') return PRId16; if (name[3] == 'i') return PRIi16; if (name[3] == 'o') return PRIo16; if (name[3] == 'u') return PRIu16; if (name[3] == 'x') return PRIx16; if (name[3] == 'X') return PRIX16; abort (); } if (name[4] == '3' && name[5] == '2' && name[6] == '\0') { if (name[3] == 'd') return PRId32; if (name[3] == 'i') return PRIi32; if (name[3] == 'o') return PRIo32; if (name[3] == 'u') return PRIu32; if (name[3] == 'x') return PRIx32; if (name[3] == 'X') return PRIX32; abort (); } if (name[4] == '6' && name[5] == '4' && name[6] == '\0') { if (name[3] == 'd') return PRId64; if (name[3] == 'i') return PRIi64; if (name[3] == 'o') return PRIo64; if (name[3] == 'u') return PRIu64; if (name[3] == 'x') return PRIx64; if (name[3] == 'X') return PRIX64; abort (); } if (name[4] == 'L' && name[5] == 'E' && name[6] == 'A' && name[7] == 'S' && name[8] == 'T') { if (name[9] == '8' && name[10] == '\0') { if (name[3] == 'd') return PRIdLEAST8; if (name[3] == 'i') return PRIiLEAST8; if (name[3] == 'o') return PRIoLEAST8; if (name[3] == 'u') return PRIuLEAST8; if (name[3] == 'x') return PRIxLEAST8; if (name[3] == 'X') return PRIXLEAST8; abort (); } if (name[9] == '1' && name[10] == '6' && name[11] == '\0') { if (name[3] == 'd') return PRIdLEAST16; if (name[3] == 'i') return PRIiLEAST16; if (name[3] == 'o') return PRIoLEAST16; if (name[3] == 'u') return PRIuLEAST16; if (name[3] == 'x') return PRIxLEAST16; if (name[3] == 'X') return PRIXLEAST16; abort (); } if (name[9] == '3' && name[10] == '2' && name[11] == '\0') { if (name[3] == 'd') return PRIdLEAST32; if (name[3] == 'i') return PRIiLEAST32; if (name[3] == 'o') return PRIoLEAST32; if (name[3] == 'u') return PRIuLEAST32; if (name[3] == 'x') return PRIxLEAST32; if (name[3] == 'X') return PRIXLEAST32; abort (); } if (name[9] == '6' && name[10] == '4' && name[11] == '\0') { if (name[3] == 'd') return PRIdLEAST64; if (name[3] == 'i') return PRIiLEAST64; if (name[3] == 'o') return PRIoLEAST64; if (name[3] == 'u') return PRIuLEAST64; if (name[3] == 'x') return PRIxLEAST64; if (name[3] == 'X') return PRIXLEAST64; abort (); } } if (name[4] == 'F' && name[5] == 'A' && name[6] == 'S' && name[7] == 'T') { if (name[8] == '8' && name[9] == '\0') { if (name[3] == 'd') return PRIdFAST8; if (name[3] == 'i') return PRIiFAST8; if (name[3] == 'o') return PRIoFAST8; if (name[3] == 'u') return PRIuFAST8; if (name[3] == 'x') return PRIxFAST8; if (name[3] == 'X') return PRIXFAST8; abort (); } if (name[8] == '1' && name[9] == '6' && name[10] == '\0') { if (name[3] == 'd') return PRIdFAST16; if (name[3] == 'i') return PRIiFAST16; if (name[3] == 'o') return PRIoFAST16; if (name[3] == 'u') return PRIuFAST16; if (name[3] == 'x') return PRIxFAST16; if (name[3] == 'X') return PRIXFAST16; abort (); } if (name[8] == '3' && name[9] == '2' && name[10] == '\0') { if (name[3] == 'd') return PRIdFAST32; if (name[3] == 'i') return PRIiFAST32; if (name[3] == 'o') return PRIoFAST32; if (name[3] == 'u') return PRIuFAST32; if (name[3] == 'x') return PRIxFAST32; if (name[3] == 'X') return PRIXFAST32; abort (); } if (name[8] == '6' && name[9] == '4' && name[10] == '\0') { if (name[3] == 'd') return PRIdFAST64; if (name[3] == 'i') return PRIiFAST64; if (name[3] == 'o') return PRIoFAST64; if (name[3] == 'u') return PRIuFAST64; if (name[3] == 'x') return PRIxFAST64; if (name[3] == 'X') return PRIXFAST64; abort (); } } if (name[4] == 'M' && name[5] == 'A' && name[6] == 'X' && name[7] == '\0') { if (name[3] == 'd') return PRIdMAX; if (name[3] == 'i') return PRIiMAX; if (name[3] == 'o') return PRIoMAX; if (name[3] == 'u') return PRIuMAX; if (name[3] == 'x') return PRIxMAX; if (name[3] == 'X') return PRIXMAX; abort (); } if (name[4] == 'P' && name[5] == 'T' && name[6] == 'R' && name[7] == '\0') { if (name[3] == 'd') return PRIdPTR; if (name[3] == 'i') return PRIiPTR; if (name[3] == 'o') return PRIoPTR; if (name[3] == 'u') return PRIuPTR; if (name[3] == 'x') return PRIxPTR; if (name[3] == 'X') return PRIXPTR; abort (); } } } /* Test for a glibc specific printf() format directive flag. */ if (name[0] == 'I' && name[1] == '\0') { #if defined _LIBC || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) /* The 'I' flag, in numeric format directives, replaces ASCII digits with the 'outdigits' defined in the LC_CTYPE locale facet. This is used for Farsi (Persian) and maybe Arabic. */ return "I"; #else return ""; #endif } /* Other system dependent strings are not valid. */ return NULL; } /* Load the message catalogs specified by FILENAME. If it is no valid message catalog do nothing. */ void internal_function _nl_load_domain (struct loaded_l10nfile *domain_file, struct binding *domainbinding) { __libc_lock_define_initialized_recursive (static, lock) int fd = -1; size_t size; #ifdef _LIBC struct stat64 st; #else struct stat st; #endif struct mo_file_header *data = (struct mo_file_header *) -1; int use_mmap = 0; struct loaded_domain *domain; int revision; const char *nullentry; size_t nullentrylen; __libc_lock_lock_recursive (lock); if (domain_file->decided != 0) { /* There are two possibilities: + this is the same thread calling again during this initialization via _nl_find_msg. We have initialized everything this call needs. + this is another thread which tried to initialize this object. Not necessary anymore since if the lock is available this is finished. */ goto done; } domain_file->decided = -1; domain_file->data = NULL; /* Note that it would be useless to store domainbinding in domain_file because domainbinding might be == NULL now but != NULL later (after a call to bind_textdomain_codeset). */ /* If the record does not represent a valid locale the FILENAME might be NULL. This can happen when according to the given specification the locale file name is different for XPG and CEN syntax. */ if (domain_file->filename == NULL) goto out; /* Try to open the addressed file. */ fd = open (domain_file->filename, O_RDONLY | O_BINARY); if (fd == -1) goto out; /* We must know about the size of the file. */ if ( #ifdef _LIBC __builtin_expect (fstat64 (fd, &st) != 0, 0) #else __builtin_expect (fstat (fd, &st) != 0, 0) #endif || __builtin_expect ((size = (size_t) st.st_size) != st.st_size, 0) || __builtin_expect (size < sizeof (struct mo_file_header), 0)) /* Something went wrong. */ goto out; #ifdef HAVE_MMAP /* Now we are ready to load the file. If mmap() is available we try this first. If not available or it failed we try to load it. */ data = (struct mo_file_header *) mmap (NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); if (__builtin_expect (data != (struct mo_file_header *) -1, 1)) { /* mmap() call was successful. */ close (fd); fd = -1; use_mmap = 1; } #endif /* If the data is not yet available (i.e. mmap'ed) we try to load it manually. */ if (data == (struct mo_file_header *) -1) { size_t to_read; char *read_ptr; data = (struct mo_file_header *) malloc (size); if (data == NULL) goto out; to_read = size; read_ptr = (char *) data; do { long int nb = (long int) read (fd, read_ptr, to_read); if (nb <= 0) { #ifdef EINTR if (nb == -1 && errno == EINTR) continue; #endif goto out; } read_ptr += nb; to_read -= nb; } while (to_read > 0); close (fd); fd = -1; } /* Using the magic number we can test whether it really is a message catalog file. */ if (__builtin_expect (data->magic != _MAGIC && data->magic != _MAGIC_SWAPPED, 0)) { /* The magic number is wrong: not a message catalog file. */ #ifdef HAVE_MMAP if (use_mmap) munmap ((caddr_t) data, size); else #endif free (data); goto out; } domain = (struct loaded_domain *) malloc (sizeof (struct loaded_domain)); if (domain == NULL) goto out; domain_file->data = domain; domain->data = (char *) data; domain->use_mmap = use_mmap; domain->mmap_size = size; domain->must_swap = data->magic != _MAGIC; domain->malloced = NULL; /* Fill in the information about the available tables. */ revision = W (domain->must_swap, data->revision); /* We support only the major revisions 0 and 1. */ switch (revision >> 16) { case 0: case 1: domain->nstrings = W (domain->must_swap, data->nstrings); domain->orig_tab = (const struct string_desc *) ((char *) data + W (domain->must_swap, data->orig_tab_offset)); domain->trans_tab = (const struct string_desc *) ((char *) data + W (domain->must_swap, data->trans_tab_offset)); domain->hash_size = W (domain->must_swap, data->hash_tab_size); domain->hash_tab = (domain->hash_size > 2 ? (const nls_uint32 *) ((char *) data + W (domain->must_swap, data->hash_tab_offset)) : NULL); domain->must_swap_hash_tab = domain->must_swap; /* Now dispatch on the minor revision. */ switch (revision & 0xffff) { case 0: domain->n_sysdep_strings = 0; domain->orig_sysdep_tab = NULL; domain->trans_sysdep_tab = NULL; break; case 1: default: { nls_uint32 n_sysdep_strings; if (domain->hash_tab == NULL) /* This is invalid. These minor revisions need a hash table. */ goto invalid; n_sysdep_strings = W (domain->must_swap, data->n_sysdep_strings); if (n_sysdep_strings > 0) { nls_uint32 n_sysdep_segments; const struct sysdep_segment *sysdep_segments; const char **sysdep_segment_values; const nls_uint32 *orig_sysdep_tab; const nls_uint32 *trans_sysdep_tab; nls_uint32 n_inmem_sysdep_strings; size_t memneed; char *mem; struct sysdep_string_desc *inmem_orig_sysdep_tab; struct sysdep_string_desc *inmem_trans_sysdep_tab; nls_uint32 *inmem_hash_tab; unsigned int i, j; /* Get the values of the system dependent segments. */ n_sysdep_segments = W (domain->must_swap, data->n_sysdep_segments); sysdep_segments = (const struct sysdep_segment *) ((char *) data + W (domain->must_swap, data->sysdep_segments_offset)); sysdep_segment_values = (const char **) alloca (n_sysdep_segments * sizeof (const char *)); for (i = 0; i < n_sysdep_segments; i++) { const char *name = (char *) data + W (domain->must_swap, sysdep_segments[i].offset); nls_uint32 namelen = W (domain->must_swap, sysdep_segments[i].length); if (!(namelen > 0 && name[namelen - 1] == '\0')) { freea (sysdep_segment_values); goto invalid; } sysdep_segment_values[i] = get_sysdep_segment_value (name); } orig_sysdep_tab = (const nls_uint32 *) ((char *) data + W (domain->must_swap, data->orig_sysdep_tab_offset)); trans_sysdep_tab = (const nls_uint32 *) ((char *) data + W (domain->must_swap, data->trans_sysdep_tab_offset)); /* Compute the amount of additional memory needed for the system dependent strings and the augmented hash table. At the same time, also drop string pairs which refer to an undefined system dependent segment. */ n_inmem_sysdep_strings = 0; memneed = domain->hash_size * sizeof (nls_uint32); for (i = 0; i < n_sysdep_strings; i++) { int valid = 1; size_t needs[2]; for (j = 0; j < 2; j++) { const struct sysdep_string *sysdep_string = (const struct sysdep_string *) ((char *) data + W (domain->must_swap, j == 0 ? orig_sysdep_tab[i] : trans_sysdep_tab[i])); size_t need = 0; const struct segment_pair *p = sysdep_string->segments; if (W (domain->must_swap, p->sysdepref) != SEGMENTS_END) for (p = sysdep_string->segments;; p++) { nls_uint32 sysdepref; need += W (domain->must_swap, p->segsize); sysdepref = W (domain->must_swap, p->sysdepref); if (sysdepref == SEGMENTS_END) break; if (sysdepref >= n_sysdep_segments) { /* Invalid. */ freea (sysdep_segment_values); goto invalid; } if (sysdep_segment_values[sysdepref] == NULL) { /* This particular string pair is invalid. */ valid = 0; break; } need += strlen (sysdep_segment_values[sysdepref]); } needs[j] = need; if (!valid) break; } if (valid) { n_inmem_sysdep_strings++; memneed += needs[0] + needs[1]; } } memneed += 2 * n_inmem_sysdep_strings * sizeof (struct sysdep_string_desc); if (n_inmem_sysdep_strings > 0) { unsigned int k; /* Allocate additional memory. */ mem = (char *) malloc (memneed); if (mem == NULL) goto invalid; domain->malloced = mem; inmem_orig_sysdep_tab = (struct sysdep_string_desc *) mem; mem += n_inmem_sysdep_strings * sizeof (struct sysdep_string_desc); inmem_trans_sysdep_tab = (struct sysdep_string_desc *) mem; mem += n_inmem_sysdep_strings * sizeof (struct sysdep_string_desc); inmem_hash_tab = (nls_uint32 *) mem; mem += domain->hash_size * sizeof (nls_uint32); /* Compute the system dependent strings. */ k = 0; for (i = 0; i < n_sysdep_strings; i++) { int valid = 1; for (j = 0; j < 2; j++) { const struct sysdep_string *sysdep_string = (const struct sysdep_string *) ((char *) data + W (domain->must_swap, j == 0 ? orig_sysdep_tab[i] : trans_sysdep_tab[i])); const struct segment_pair *p = sysdep_string->segments; if (W (domain->must_swap, p->sysdepref) != SEGMENTS_END) for (p = sysdep_string->segments;; p++) { nls_uint32 sysdepref; sysdepref = W (domain->must_swap, p->sysdepref); if (sysdepref == SEGMENTS_END) break; if (sysdep_segment_values[sysdepref] == NULL) { /* This particular string pair is invalid. */ valid = 0; break; } } if (!valid) break; } if (valid) { for (j = 0; j < 2; j++) { const struct sysdep_string *sysdep_string = (const struct sysdep_string *) ((char *) data + W (domain->must_swap, j == 0 ? orig_sysdep_tab[i] : trans_sysdep_tab[i])); const char *static_segments = (char *) data + W (domain->must_swap, sysdep_string->offset); const struct segment_pair *p = sysdep_string->segments; /* Concatenate the segments, and fill inmem_orig_sysdep_tab[k] (for j == 0) and inmem_trans_sysdep_tab[k] (for j == 1). */ struct sysdep_string_desc *inmem_tab_entry = (j == 0 ? inmem_orig_sysdep_tab : inmem_trans_sysdep_tab) + k; if (W (domain->must_swap, p->sysdepref) == SEGMENTS_END) { /* Only one static segment. */ inmem_tab_entry->length = W (domain->must_swap, p->segsize); inmem_tab_entry->pointer = static_segments; } else { inmem_tab_entry->pointer = mem; for (p = sysdep_string->segments;; p++) { nls_uint32 segsize = W (domain->must_swap, p->segsize); nls_uint32 sysdepref = W (domain->must_swap, p->sysdepref); size_t n; if (segsize > 0) { memcpy (mem, static_segments, segsize); mem += segsize; static_segments += segsize; } if (sysdepref == SEGMENTS_END) break; n = strlen (sysdep_segment_values[sysdepref]); memcpy (mem, sysdep_segment_values[sysdepref], n); mem += n; } inmem_tab_entry->length = mem - inmem_tab_entry->pointer; } } k++; } } if (k != n_inmem_sysdep_strings) abort (); /* Compute the augmented hash table. */ for (i = 0; i < domain->hash_size; i++) inmem_hash_tab[i] = W (domain->must_swap_hash_tab, domain->hash_tab[i]); for (i = 0; i < n_inmem_sysdep_strings; i++) { const char *msgid = inmem_orig_sysdep_tab[i].pointer; nls_uint32 hash_val = __hash_string (msgid); nls_uint32 idx = hash_val % domain->hash_size; nls_uint32 incr = 1 + (hash_val % (domain->hash_size - 2)); for (;;) { if (inmem_hash_tab[idx] == 0) { /* Hash table entry is empty. Use it. */ inmem_hash_tab[idx] = 1 + domain->nstrings + i; break; } if (idx >= domain->hash_size - incr) idx -= domain->hash_size - incr; else idx += incr; } } domain->n_sysdep_strings = n_inmem_sysdep_strings; domain->orig_sysdep_tab = inmem_orig_sysdep_tab; domain->trans_sysdep_tab = inmem_trans_sysdep_tab; domain->hash_tab = inmem_hash_tab; domain->must_swap_hash_tab = 0; } else { domain->n_sysdep_strings = 0; domain->orig_sysdep_tab = NULL; domain->trans_sysdep_tab = NULL; } freea (sysdep_segment_values); } else { domain->n_sysdep_strings = 0; domain->orig_sysdep_tab = NULL; domain->trans_sysdep_tab = NULL; } } break; } break; default: /* This is an invalid revision. */ invalid: /* This is an invalid .mo file. */ if (domain->malloced) free (domain->malloced); #ifdef HAVE_MMAP if (use_mmap) munmap ((caddr_t) data, size); else #endif free (data); free (domain); domain_file->data = NULL; goto out; } /* No caches of converted translations so far. */ domain->conversions = NULL; domain->nconversions = 0; gl_rwlock_init (domain->conversions_lock); /* Get the header entry and look for a plural specification. */ #ifdef IN_LIBGLOCALE nullentry = _nl_find_msg (domain_file, domainbinding, NULL, "", &nullentrylen); #else nullentry = _nl_find_msg (domain_file, domainbinding, "", 0, &nullentrylen); #endif EXTRACT_PLURAL_EXPRESSION (nullentry, &domain->plural, &domain->nplurals); out: if (fd != -1) close (fd); domain_file->decided = 1; done: __libc_lock_unlock_recursive (lock); } #ifdef _LIBC void internal_function __libc_freeres_fn_section _nl_unload_domain (struct loaded_domain *domain) { size_t i; if (domain->plural != &__gettext_germanic_plural) __gettext_free_exp ((struct expression *) domain->plural); for (i = 0; i < domain->nconversions; i++) { struct converted_domain *convd = &domain->conversions[i]; free (convd->encoding); if (convd->conv_tab != NULL && convd->conv_tab != (char **) -1) free (convd->conv_tab); if (convd->conv != (__gconv_t) -1) __gconv_close (convd->conv); } if (domain->conversions != NULL) free (domain->conversions); __libc_rwlock_fini (domain->conversions_lock); if (domain->malloced) free (domain->malloced); # ifdef _POSIX_MAPPED_FILES if (domain->use_mmap) munmap ((caddr_t) domain->data, domain->mmap_size); else # endif /* _POSIX_MAPPED_FILES */ free ((void *) domain->data); free (domain); } #endif libnih-1.0.3/intl/plural-exp.h0000644000175000017500000001013111461165270013110 00000000000000/* Expression parsing and evaluation for plural form selection. Copyright (C) 2000-2003, 2005-2007 Free Software Foundation, Inc. Written by Ulrich Drepper , 2000. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _PLURAL_EXP_H #define _PLURAL_EXP_H #ifndef internal_function # define internal_function #endif #ifndef attribute_hidden # define attribute_hidden #endif #ifdef __cplusplus extern "C" { #endif enum expression_operator { /* Without arguments: */ var, /* The variable "n". */ num, /* Decimal number. */ /* Unary operators: */ lnot, /* Logical NOT. */ /* Binary operators: */ mult, /* Multiplication. */ divide, /* Division. */ module, /* Modulo operation. */ plus, /* Addition. */ minus, /* Subtraction. */ less_than, /* Comparison. */ greater_than, /* Comparison. */ less_or_equal, /* Comparison. */ greater_or_equal, /* Comparison. */ equal, /* Comparison for equality. */ not_equal, /* Comparison for inequality. */ land, /* Logical AND. */ lor, /* Logical OR. */ /* Ternary operators: */ qmop /* Question mark operator. */ }; /* This is the representation of the expressions to determine the plural form. */ struct expression { int nargs; /* Number of arguments. */ enum expression_operator operation; union { unsigned long int num; /* Number value for `num'. */ struct expression *args[3]; /* Up to three arguments. */ } val; }; /* This is the data structure to pass information to the parser and get the result in a thread-safe way. */ struct parse_args { const char *cp; struct expression *res; }; /* Names for the libintl functions are a problem. This source code is used 1. in the GNU C Library library, 2. in the GNU libintl library, 3. in the GNU gettext tools. The function names in each situation must be different, to allow for binary incompatible changes in 'struct expression'. Furthermore, 1. in the GNU C Library library, the names have a __ prefix, 2.+3. in the GNU libintl library and in the GNU gettext tools, the names must follow ANSI C and not start with __. So we have to distinguish the three cases. */ #ifdef _LIBC # define FREE_EXPRESSION __gettext_free_exp # define PLURAL_PARSE __gettextparse # define GERMANIC_PLURAL __gettext_germanic_plural # define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural #elif defined (IN_LIBINTL) # define FREE_EXPRESSION libintl_gettext_free_exp # define PLURAL_PARSE libintl_gettextparse # define GERMANIC_PLURAL libintl_gettext_germanic_plural # define EXTRACT_PLURAL_EXPRESSION libintl_gettext_extract_plural #else # define FREE_EXPRESSION free_plural_expression # define PLURAL_PARSE parse_plural_expression # define GERMANIC_PLURAL germanic_plural # define EXTRACT_PLURAL_EXPRESSION extract_plural_expression #endif extern void FREE_EXPRESSION (struct expression *exp) internal_function; extern int PLURAL_PARSE (void *arg); extern struct expression GERMANIC_PLURAL attribute_hidden; extern void EXTRACT_PLURAL_EXPRESSION (const char *nullentry, const struct expression **pluralp, unsigned long int *npluralsp) internal_function; #if !defined (_LIBC) && !defined (IN_LIBINTL) && !defined (IN_LIBGLOCALE) extern unsigned long int plural_eval (const struct expression *pexp, unsigned long int n); #endif #ifdef __cplusplus } #endif #endif /* _PLURAL_EXP_H */ libnih-1.0.3/intl/bindtextdom.c0000644000175000017500000002137211461165267013352 00000000000000/* Implementation of the bindtextdomain(3) function Copyright (C) 1995-1998, 2000-2003, 2005-2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include "gettextP.h" #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* Handle multi-threaded applications. */ #ifdef _LIBC # include # define gl_rwlock_define __libc_rwlock_define # define gl_rwlock_wrlock __libc_rwlock_wrlock # define gl_rwlock_unlock __libc_rwlock_unlock #else # include "lock.h" #endif /* Some compilers, like SunOS4 cc, don't have offsetof in . */ #ifndef offsetof # define offsetof(type,ident) ((size_t)&(((type*)0)->ident)) #endif /* @@ end of prolog @@ */ /* Lock variable to protect the global data in the gettext implementation. */ gl_rwlock_define (extern, _nl_state_lock attribute_hidden) /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define BINDTEXTDOMAIN __bindtextdomain # define BIND_TEXTDOMAIN_CODESET __bind_textdomain_codeset # ifndef strdup # define strdup(str) __strdup (str) # endif #else # define BINDTEXTDOMAIN libintl_bindtextdomain # define BIND_TEXTDOMAIN_CODESET libintl_bind_textdomain_codeset #endif /* Specifies the directory name *DIRNAMEP and the output codeset *CODESETP to be used for the DOMAINNAME message catalog. If *DIRNAMEP or *CODESETP is NULL, the corresponding attribute is not modified, only the current value is returned. If DIRNAMEP or CODESETP is NULL, the corresponding attribute is neither modified nor returned. */ static void set_binding_values (const char *domainname, const char **dirnamep, const char **codesetp) { struct binding *binding; int modified; /* Some sanity checks. */ if (domainname == NULL || domainname[0] == '\0') { if (dirnamep) *dirnamep = NULL; if (codesetp) *codesetp = NULL; return; } gl_rwlock_wrlock (_nl_state_lock); modified = 0; for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next) { int compare = strcmp (domainname, binding->domainname); if (compare == 0) /* We found it! */ break; if (compare < 0) { /* It is not in the list. */ binding = NULL; break; } } if (binding != NULL) { if (dirnamep) { const char *dirname = *dirnamep; if (dirname == NULL) /* The current binding has be to returned. */ *dirnamep = binding->dirname; else { /* The domain is already bound. If the new value and the old one are equal we simply do nothing. Otherwise replace the old binding. */ char *result = binding->dirname; if (strcmp (dirname, result) != 0) { if (strcmp (dirname, _nl_default_dirname) == 0) result = (char *) _nl_default_dirname; else { #if defined _LIBC || defined HAVE_STRDUP result = strdup (dirname); #else size_t len = strlen (dirname) + 1; result = (char *) malloc (len); if (__builtin_expect (result != NULL, 1)) memcpy (result, dirname, len); #endif } if (__builtin_expect (result != NULL, 1)) { if (binding->dirname != _nl_default_dirname) free (binding->dirname); binding->dirname = result; modified = 1; } } *dirnamep = result; } } if (codesetp) { const char *codeset = *codesetp; if (codeset == NULL) /* The current binding has be to returned. */ *codesetp = binding->codeset; else { /* The domain is already bound. If the new value and the old one are equal we simply do nothing. Otherwise replace the old binding. */ char *result = binding->codeset; if (result == NULL || strcmp (codeset, result) != 0) { #if defined _LIBC || defined HAVE_STRDUP result = strdup (codeset); #else size_t len = strlen (codeset) + 1; result = (char *) malloc (len); if (__builtin_expect (result != NULL, 1)) memcpy (result, codeset, len); #endif if (__builtin_expect (result != NULL, 1)) { if (binding->codeset != NULL) free (binding->codeset); binding->codeset = result; modified = 1; } } *codesetp = result; } } } else if ((dirnamep == NULL || *dirnamep == NULL) && (codesetp == NULL || *codesetp == NULL)) { /* Simply return the default values. */ if (dirnamep) *dirnamep = _nl_default_dirname; if (codesetp) *codesetp = NULL; } else { /* We have to create a new binding. */ size_t len = strlen (domainname) + 1; struct binding *new_binding = (struct binding *) malloc (offsetof (struct binding, domainname) + len); if (__builtin_expect (new_binding == NULL, 0)) goto failed; memcpy (new_binding->domainname, domainname, len); if (dirnamep) { const char *dirname = *dirnamep; if (dirname == NULL) /* The default value. */ dirname = _nl_default_dirname; else { if (strcmp (dirname, _nl_default_dirname) == 0) dirname = _nl_default_dirname; else { char *result; #if defined _LIBC || defined HAVE_STRDUP result = strdup (dirname); if (__builtin_expect (result == NULL, 0)) goto failed_dirname; #else size_t len = strlen (dirname) + 1; result = (char *) malloc (len); if (__builtin_expect (result == NULL, 0)) goto failed_dirname; memcpy (result, dirname, len); #endif dirname = result; } } *dirnamep = dirname; new_binding->dirname = (char *) dirname; } else /* The default value. */ new_binding->dirname = (char *) _nl_default_dirname; if (codesetp) { const char *codeset = *codesetp; if (codeset != NULL) { char *result; #if defined _LIBC || defined HAVE_STRDUP result = strdup (codeset); if (__builtin_expect (result == NULL, 0)) goto failed_codeset; #else size_t len = strlen (codeset) + 1; result = (char *) malloc (len); if (__builtin_expect (result == NULL, 0)) goto failed_codeset; memcpy (result, codeset, len); #endif codeset = result; } *codesetp = codeset; new_binding->codeset = (char *) codeset; } else new_binding->codeset = NULL; /* Now enqueue it. */ if (_nl_domain_bindings == NULL || strcmp (domainname, _nl_domain_bindings->domainname) < 0) { new_binding->next = _nl_domain_bindings; _nl_domain_bindings = new_binding; } else { binding = _nl_domain_bindings; while (binding->next != NULL && strcmp (domainname, binding->next->domainname) > 0) binding = binding->next; new_binding->next = binding->next; binding->next = new_binding; } modified = 1; /* Here we deal with memory allocation failures. */ if (0) { failed_codeset: if (new_binding->dirname != _nl_default_dirname) free (new_binding->dirname); failed_dirname: free (new_binding); failed: if (dirnamep) *dirnamep = NULL; if (codesetp) *codesetp = NULL; } } /* If we modified any binding, we flush the caches. */ if (modified) ++_nl_msg_cat_cntr; gl_rwlock_unlock (_nl_state_lock); } /* Specify that the DOMAINNAME message catalog will be found in DIRNAME rather than in the system locale data base. */ char * BINDTEXTDOMAIN (const char *domainname, const char *dirname) { set_binding_values (domainname, &dirname, NULL); return (char *) dirname; } /* Specify the character encoding in which the messages from the DOMAINNAME message catalog will be returned. */ char * BIND_TEXTDOMAIN_CODESET (const char *domainname, const char *codeset) { set_binding_values (domainname, NULL, &codeset); return (char *) codeset; } #ifdef _LIBC /* Aliases for function names in GNU C Library. */ weak_alias (__bindtextdomain, bindtextdomain); weak_alias (__bind_textdomain_codeset, bind_textdomain_codeset); #endif libnih-1.0.3/intl/vasnprintf.h0000644000175000017500000000544311461165270013223 00000000000000/* vsprintf with automatic memory allocation. Copyright (C) 2002-2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _VASNPRINTF_H #define _VASNPRINTF_H /* Get va_list. */ #include /* Get size_t. */ #include #ifndef __attribute__ /* This feature is available in gcc versions 2.5 and later. */ # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ # define __attribute__(Spec) /* empty */ # endif /* The __-protected variants of `format' and `printf' attributes are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) # define __format__ format # define __printf__ printf # endif #endif #ifdef __cplusplus extern "C" { #endif /* Write formatted output to a string dynamically allocated with malloc(). You can pass a preallocated buffer for the result in RESULTBUF and its size in *LENGTHP; otherwise you pass RESULTBUF = NULL. If successful, return the address of the string (this may be = RESULTBUF if no dynamic memory allocation was necessary) and set *LENGTHP to the number of resulting bytes, excluding the trailing NUL. Upon error, set errno and return NULL. When dynamic memory allocation occurs, the preallocated buffer is left alone (with possibly modified contents). This makes it possible to use a statically allocated or stack-allocated buffer, like this: char buf[100]; size_t len = sizeof (buf); char *output = vasnprintf (buf, &len, format, args); if (output == NULL) ... error handling ...; else { ... use the output string ...; if (output != buf) free (output); } */ extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) __attribute__ ((__format__ (__printf__, 3, 4))); extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) __attribute__ ((__format__ (__printf__, 3, 0))); #ifdef __cplusplus } #endif #endif /* _VASNPRINTF_H */ libnih-1.0.3/intl/VERSION0000644000175000017500000000004611461165267011730 00000000000000GNU gettext library from gettext-0.17 libnih-1.0.3/intl/localename.c0000644000175000017500000012457111461165267013136 00000000000000/* Determine name of the currently selected locale. Copyright (C) 1995-1999, 2000-2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Ulrich Drepper , 1995. */ /* Win32 code written by Tor Lillqvist . */ /* MacOS X code written by Bruno Haible . */ #include /* Specification. */ #ifdef IN_LIBINTL # include "gettextP.h" #else # include "localename.h" #endif #include #include #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE # include # include # if HAVE_CFLOCALECOPYCURRENT # include # elif HAVE_CFPREFERENCESCOPYAPPVALUE # include # endif #endif #if defined _WIN32 || defined __WIN32__ # define WIN32_NATIVE #endif #ifdef WIN32_NATIVE # define WIN32_LEAN_AND_MEAN # include /* List of language codes, sorted by value: 0x01 LANG_ARABIC 0x02 LANG_BULGARIAN 0x03 LANG_CATALAN 0x04 LANG_CHINESE 0x05 LANG_CZECH 0x06 LANG_DANISH 0x07 LANG_GERMAN 0x08 LANG_GREEK 0x09 LANG_ENGLISH 0x0a LANG_SPANISH 0x0b LANG_FINNISH 0x0c LANG_FRENCH 0x0d LANG_HEBREW 0x0e LANG_HUNGARIAN 0x0f LANG_ICELANDIC 0x10 LANG_ITALIAN 0x11 LANG_JAPANESE 0x12 LANG_KOREAN 0x13 LANG_DUTCH 0x14 LANG_NORWEGIAN 0x15 LANG_POLISH 0x16 LANG_PORTUGUESE 0x17 LANG_RHAETO_ROMANCE 0x18 LANG_ROMANIAN 0x19 LANG_RUSSIAN 0x1a LANG_CROATIAN == LANG_SERBIAN 0x1b LANG_SLOVAK 0x1c LANG_ALBANIAN 0x1d LANG_SWEDISH 0x1e LANG_THAI 0x1f LANG_TURKISH 0x20 LANG_URDU 0x21 LANG_INDONESIAN 0x22 LANG_UKRAINIAN 0x23 LANG_BELARUSIAN 0x24 LANG_SLOVENIAN 0x25 LANG_ESTONIAN 0x26 LANG_LATVIAN 0x27 LANG_LITHUANIAN 0x28 LANG_TAJIK 0x29 LANG_FARSI 0x2a LANG_VIETNAMESE 0x2b LANG_ARMENIAN 0x2c LANG_AZERI 0x2d LANG_BASQUE 0x2e LANG_SORBIAN 0x2f LANG_MACEDONIAN 0x30 LANG_SUTU 0x31 LANG_TSONGA 0x32 LANG_TSWANA 0x33 LANG_VENDA 0x34 LANG_XHOSA 0x35 LANG_ZULU 0x36 LANG_AFRIKAANS 0x37 LANG_GEORGIAN 0x38 LANG_FAEROESE 0x39 LANG_HINDI 0x3a LANG_MALTESE 0x3b LANG_SAAMI 0x3c LANG_GAELIC 0x3d LANG_YIDDISH 0x3e LANG_MALAY 0x3f LANG_KAZAK 0x40 LANG_KYRGYZ 0x41 LANG_SWAHILI 0x42 LANG_TURKMEN 0x43 LANG_UZBEK 0x44 LANG_TATAR 0x45 LANG_BENGALI 0x46 LANG_PUNJABI 0x47 LANG_GUJARATI 0x48 LANG_ORIYA 0x49 LANG_TAMIL 0x4a LANG_TELUGU 0x4b LANG_KANNADA 0x4c LANG_MALAYALAM 0x4d LANG_ASSAMESE 0x4e LANG_MARATHI 0x4f LANG_SANSKRIT 0x50 LANG_MONGOLIAN 0x51 LANG_TIBETAN 0x52 LANG_WELSH 0x53 LANG_CAMBODIAN 0x54 LANG_LAO 0x55 LANG_BURMESE 0x56 LANG_GALICIAN 0x57 LANG_KONKANI 0x58 LANG_MANIPURI 0x59 LANG_SINDHI 0x5a LANG_SYRIAC 0x5b LANG_SINHALESE 0x5c LANG_CHEROKEE 0x5d LANG_INUKTITUT 0x5e LANG_AMHARIC 0x5f LANG_TAMAZIGHT 0x60 LANG_KASHMIRI 0x61 LANG_NEPALI 0x62 LANG_FRISIAN 0x63 LANG_PASHTO 0x64 LANG_TAGALOG 0x65 LANG_DIVEHI 0x66 LANG_EDO 0x67 LANG_FULFULDE 0x68 LANG_HAUSA 0x69 LANG_IBIBIO 0x6a LANG_YORUBA 0x70 LANG_IGBO 0x71 LANG_KANURI 0x72 LANG_OROMO 0x73 LANG_TIGRINYA 0x74 LANG_GUARANI 0x75 LANG_HAWAIIAN 0x76 LANG_LATIN 0x77 LANG_SOMALI 0x78 LANG_YI 0x79 LANG_PAPIAMENTU */ /* Mingw headers don't have latest language and sublanguage codes. */ # ifndef LANG_AFRIKAANS # define LANG_AFRIKAANS 0x36 # endif # ifndef LANG_ALBANIAN # define LANG_ALBANIAN 0x1c # endif # ifndef LANG_AMHARIC # define LANG_AMHARIC 0x5e # endif # ifndef LANG_ARABIC # define LANG_ARABIC 0x01 # endif # ifndef LANG_ARMENIAN # define LANG_ARMENIAN 0x2b # endif # ifndef LANG_ASSAMESE # define LANG_ASSAMESE 0x4d # endif # ifndef LANG_AZERI # define LANG_AZERI 0x2c # endif # ifndef LANG_BASQUE # define LANG_BASQUE 0x2d # endif # ifndef LANG_BELARUSIAN # define LANG_BELARUSIAN 0x23 # endif # ifndef LANG_BENGALI # define LANG_BENGALI 0x45 # endif # ifndef LANG_BURMESE # define LANG_BURMESE 0x55 # endif # ifndef LANG_CAMBODIAN # define LANG_CAMBODIAN 0x53 # endif # ifndef LANG_CATALAN # define LANG_CATALAN 0x03 # endif # ifndef LANG_CHEROKEE # define LANG_CHEROKEE 0x5c # endif # ifndef LANG_DIVEHI # define LANG_DIVEHI 0x65 # endif # ifndef LANG_EDO # define LANG_EDO 0x66 # endif # ifndef LANG_ESTONIAN # define LANG_ESTONIAN 0x25 # endif # ifndef LANG_FAEROESE # define LANG_FAEROESE 0x38 # endif # ifndef LANG_FARSI # define LANG_FARSI 0x29 # endif # ifndef LANG_FRISIAN # define LANG_FRISIAN 0x62 # endif # ifndef LANG_FULFULDE # define LANG_FULFULDE 0x67 # endif # ifndef LANG_GAELIC # define LANG_GAELIC 0x3c # endif # ifndef LANG_GALICIAN # define LANG_GALICIAN 0x56 # endif # ifndef LANG_GEORGIAN # define LANG_GEORGIAN 0x37 # endif # ifndef LANG_GUARANI # define LANG_GUARANI 0x74 # endif # ifndef LANG_GUJARATI # define LANG_GUJARATI 0x47 # endif # ifndef LANG_HAUSA # define LANG_HAUSA 0x68 # endif # ifndef LANG_HAWAIIAN # define LANG_HAWAIIAN 0x75 # endif # ifndef LANG_HEBREW # define LANG_HEBREW 0x0d # endif # ifndef LANG_HINDI # define LANG_HINDI 0x39 # endif # ifndef LANG_IBIBIO # define LANG_IBIBIO 0x69 # endif # ifndef LANG_IGBO # define LANG_IGBO 0x70 # endif # ifndef LANG_INDONESIAN # define LANG_INDONESIAN 0x21 # endif # ifndef LANG_INUKTITUT # define LANG_INUKTITUT 0x5d # endif # ifndef LANG_KANNADA # define LANG_KANNADA 0x4b # endif # ifndef LANG_KANURI # define LANG_KANURI 0x71 # endif # ifndef LANG_KASHMIRI # define LANG_KASHMIRI 0x60 # endif # ifndef LANG_KAZAK # define LANG_KAZAK 0x3f # endif # ifndef LANG_KONKANI # define LANG_KONKANI 0x57 # endif # ifndef LANG_KYRGYZ # define LANG_KYRGYZ 0x40 # endif # ifndef LANG_LAO # define LANG_LAO 0x54 # endif # ifndef LANG_LATIN # define LANG_LATIN 0x76 # endif # ifndef LANG_LATVIAN # define LANG_LATVIAN 0x26 # endif # ifndef LANG_LITHUANIAN # define LANG_LITHUANIAN 0x27 # endif # ifndef LANG_MACEDONIAN # define LANG_MACEDONIAN 0x2f # endif # ifndef LANG_MALAY # define LANG_MALAY 0x3e # endif # ifndef LANG_MALAYALAM # define LANG_MALAYALAM 0x4c # endif # ifndef LANG_MALTESE # define LANG_MALTESE 0x3a # endif # ifndef LANG_MANIPURI # define LANG_MANIPURI 0x58 # endif # ifndef LANG_MARATHI # define LANG_MARATHI 0x4e # endif # ifndef LANG_MONGOLIAN # define LANG_MONGOLIAN 0x50 # endif # ifndef LANG_NEPALI # define LANG_NEPALI 0x61 # endif # ifndef LANG_ORIYA # define LANG_ORIYA 0x48 # endif # ifndef LANG_OROMO # define LANG_OROMO 0x72 # endif # ifndef LANG_PAPIAMENTU # define LANG_PAPIAMENTU 0x79 # endif # ifndef LANG_PASHTO # define LANG_PASHTO 0x63 # endif # ifndef LANG_PUNJABI # define LANG_PUNJABI 0x46 # endif # ifndef LANG_RHAETO_ROMANCE # define LANG_RHAETO_ROMANCE 0x17 # endif # ifndef LANG_SAAMI # define LANG_SAAMI 0x3b # endif # ifndef LANG_SANSKRIT # define LANG_SANSKRIT 0x4f # endif # ifndef LANG_SERBIAN # define LANG_SERBIAN 0x1a # endif # ifndef LANG_SINDHI # define LANG_SINDHI 0x59 # endif # ifndef LANG_SINHALESE # define LANG_SINHALESE 0x5b # endif # ifndef LANG_SLOVAK # define LANG_SLOVAK 0x1b # endif # ifndef LANG_SOMALI # define LANG_SOMALI 0x77 # endif # ifndef LANG_SORBIAN # define LANG_SORBIAN 0x2e # endif # ifndef LANG_SUTU # define LANG_SUTU 0x30 # endif # ifndef LANG_SWAHILI # define LANG_SWAHILI 0x41 # endif # ifndef LANG_SYRIAC # define LANG_SYRIAC 0x5a # endif # ifndef LANG_TAGALOG # define LANG_TAGALOG 0x64 # endif # ifndef LANG_TAJIK # define LANG_TAJIK 0x28 # endif # ifndef LANG_TAMAZIGHT # define LANG_TAMAZIGHT 0x5f # endif # ifndef LANG_TAMIL # define LANG_TAMIL 0x49 # endif # ifndef LANG_TATAR # define LANG_TATAR 0x44 # endif # ifndef LANG_TELUGU # define LANG_TELUGU 0x4a # endif # ifndef LANG_THAI # define LANG_THAI 0x1e # endif # ifndef LANG_TIBETAN # define LANG_TIBETAN 0x51 # endif # ifndef LANG_TIGRINYA # define LANG_TIGRINYA 0x73 # endif # ifndef LANG_TSONGA # define LANG_TSONGA 0x31 # endif # ifndef LANG_TSWANA # define LANG_TSWANA 0x32 # endif # ifndef LANG_TURKMEN # define LANG_TURKMEN 0x42 # endif # ifndef LANG_UKRAINIAN # define LANG_UKRAINIAN 0x22 # endif # ifndef LANG_URDU # define LANG_URDU 0x20 # endif # ifndef LANG_UZBEK # define LANG_UZBEK 0x43 # endif # ifndef LANG_VENDA # define LANG_VENDA 0x33 # endif # ifndef LANG_VIETNAMESE # define LANG_VIETNAMESE 0x2a # endif # ifndef LANG_WELSH # define LANG_WELSH 0x52 # endif # ifndef LANG_XHOSA # define LANG_XHOSA 0x34 # endif # ifndef LANG_YI # define LANG_YI 0x78 # endif # ifndef LANG_YIDDISH # define LANG_YIDDISH 0x3d # endif # ifndef LANG_YORUBA # define LANG_YORUBA 0x6a # endif # ifndef LANG_ZULU # define LANG_ZULU 0x35 # endif # ifndef SUBLANG_ARABIC_SAUDI_ARABIA # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01 # endif # ifndef SUBLANG_ARABIC_IRAQ # define SUBLANG_ARABIC_IRAQ 0x02 # endif # ifndef SUBLANG_ARABIC_EGYPT # define SUBLANG_ARABIC_EGYPT 0x03 # endif # ifndef SUBLANG_ARABIC_LIBYA # define SUBLANG_ARABIC_LIBYA 0x04 # endif # ifndef SUBLANG_ARABIC_ALGERIA # define SUBLANG_ARABIC_ALGERIA 0x05 # endif # ifndef SUBLANG_ARABIC_MOROCCO # define SUBLANG_ARABIC_MOROCCO 0x06 # endif # ifndef SUBLANG_ARABIC_TUNISIA # define SUBLANG_ARABIC_TUNISIA 0x07 # endif # ifndef SUBLANG_ARABIC_OMAN # define SUBLANG_ARABIC_OMAN 0x08 # endif # ifndef SUBLANG_ARABIC_YEMEN # define SUBLANG_ARABIC_YEMEN 0x09 # endif # ifndef SUBLANG_ARABIC_SYRIA # define SUBLANG_ARABIC_SYRIA 0x0a # endif # ifndef SUBLANG_ARABIC_JORDAN # define SUBLANG_ARABIC_JORDAN 0x0b # endif # ifndef SUBLANG_ARABIC_LEBANON # define SUBLANG_ARABIC_LEBANON 0x0c # endif # ifndef SUBLANG_ARABIC_KUWAIT # define SUBLANG_ARABIC_KUWAIT 0x0d # endif # ifndef SUBLANG_ARABIC_UAE # define SUBLANG_ARABIC_UAE 0x0e # endif # ifndef SUBLANG_ARABIC_BAHRAIN # define SUBLANG_ARABIC_BAHRAIN 0x0f # endif # ifndef SUBLANG_ARABIC_QATAR # define SUBLANG_ARABIC_QATAR 0x10 # endif # ifndef SUBLANG_AZERI_LATIN # define SUBLANG_AZERI_LATIN 0x01 # endif # ifndef SUBLANG_AZERI_CYRILLIC # define SUBLANG_AZERI_CYRILLIC 0x02 # endif # ifndef SUBLANG_BENGALI_INDIA # define SUBLANG_BENGALI_INDIA 0x01 # endif # ifndef SUBLANG_BENGALI_BANGLADESH # define SUBLANG_BENGALI_BANGLADESH 0x02 # endif # ifndef SUBLANG_CHINESE_MACAU # define SUBLANG_CHINESE_MACAU 0x05 # endif # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07 # endif # ifndef SUBLANG_ENGLISH_JAMAICA # define SUBLANG_ENGLISH_JAMAICA 0x08 # endif # ifndef SUBLANG_ENGLISH_CARIBBEAN # define SUBLANG_ENGLISH_CARIBBEAN 0x09 # endif # ifndef SUBLANG_ENGLISH_BELIZE # define SUBLANG_ENGLISH_BELIZE 0x0a # endif # ifndef SUBLANG_ENGLISH_TRINIDAD # define SUBLANG_ENGLISH_TRINIDAD 0x0b # endif # ifndef SUBLANG_ENGLISH_ZIMBABWE # define SUBLANG_ENGLISH_ZIMBABWE 0x0c # endif # ifndef SUBLANG_ENGLISH_PHILIPPINES # define SUBLANG_ENGLISH_PHILIPPINES 0x0d # endif # ifndef SUBLANG_ENGLISH_INDONESIA # define SUBLANG_ENGLISH_INDONESIA 0x0e # endif # ifndef SUBLANG_ENGLISH_HONGKONG # define SUBLANG_ENGLISH_HONGKONG 0x0f # endif # ifndef SUBLANG_ENGLISH_INDIA # define SUBLANG_ENGLISH_INDIA 0x10 # endif # ifndef SUBLANG_ENGLISH_MALAYSIA # define SUBLANG_ENGLISH_MALAYSIA 0x11 # endif # ifndef SUBLANG_ENGLISH_SINGAPORE # define SUBLANG_ENGLISH_SINGAPORE 0x12 # endif # ifndef SUBLANG_FRENCH_LUXEMBOURG # define SUBLANG_FRENCH_LUXEMBOURG 0x05 # endif # ifndef SUBLANG_FRENCH_MONACO # define SUBLANG_FRENCH_MONACO 0x06 # endif # ifndef SUBLANG_FRENCH_WESTINDIES # define SUBLANG_FRENCH_WESTINDIES 0x07 # endif # ifndef SUBLANG_FRENCH_REUNION # define SUBLANG_FRENCH_REUNION 0x08 # endif # ifndef SUBLANG_FRENCH_CONGO # define SUBLANG_FRENCH_CONGO 0x09 # endif # ifndef SUBLANG_FRENCH_SENEGAL # define SUBLANG_FRENCH_SENEGAL 0x0a # endif # ifndef SUBLANG_FRENCH_CAMEROON # define SUBLANG_FRENCH_CAMEROON 0x0b # endif # ifndef SUBLANG_FRENCH_COTEDIVOIRE # define SUBLANG_FRENCH_COTEDIVOIRE 0x0c # endif # ifndef SUBLANG_FRENCH_MALI # define SUBLANG_FRENCH_MALI 0x0d # endif # ifndef SUBLANG_FRENCH_MOROCCO # define SUBLANG_FRENCH_MOROCCO 0x0e # endif # ifndef SUBLANG_FRENCH_HAITI # define SUBLANG_FRENCH_HAITI 0x0f # endif # ifndef SUBLANG_GERMAN_LUXEMBOURG # define SUBLANG_GERMAN_LUXEMBOURG 0x04 # endif # ifndef SUBLANG_GERMAN_LIECHTENSTEIN # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05 # endif # ifndef SUBLANG_KASHMIRI_INDIA # define SUBLANG_KASHMIRI_INDIA 0x02 # endif # ifndef SUBLANG_MALAY_MALAYSIA # define SUBLANG_MALAY_MALAYSIA 0x01 # endif # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02 # endif # ifndef SUBLANG_NEPALI_INDIA # define SUBLANG_NEPALI_INDIA 0x02 # endif # ifndef SUBLANG_PUNJABI_INDIA # define SUBLANG_PUNJABI_INDIA 0x01 # endif # ifndef SUBLANG_PUNJABI_PAKISTAN # define SUBLANG_PUNJABI_PAKISTAN 0x02 # endif # ifndef SUBLANG_ROMANIAN_ROMANIA # define SUBLANG_ROMANIAN_ROMANIA 0x01 # endif # ifndef SUBLANG_ROMANIAN_MOLDOVA # define SUBLANG_ROMANIAN_MOLDOVA 0x02 # endif # ifndef SUBLANG_SERBIAN_LATIN # define SUBLANG_SERBIAN_LATIN 0x02 # endif # ifndef SUBLANG_SERBIAN_CYRILLIC # define SUBLANG_SERBIAN_CYRILLIC 0x03 # endif # ifndef SUBLANG_SINDHI_PAKISTAN # define SUBLANG_SINDHI_PAKISTAN 0x01 # endif # ifndef SUBLANG_SINDHI_AFGHANISTAN # define SUBLANG_SINDHI_AFGHANISTAN 0x02 # endif # ifndef SUBLANG_SPANISH_GUATEMALA # define SUBLANG_SPANISH_GUATEMALA 0x04 # endif # ifndef SUBLANG_SPANISH_COSTA_RICA # define SUBLANG_SPANISH_COSTA_RICA 0x05 # endif # ifndef SUBLANG_SPANISH_PANAMA # define SUBLANG_SPANISH_PANAMA 0x06 # endif # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07 # endif # ifndef SUBLANG_SPANISH_VENEZUELA # define SUBLANG_SPANISH_VENEZUELA 0x08 # endif # ifndef SUBLANG_SPANISH_COLOMBIA # define SUBLANG_SPANISH_COLOMBIA 0x09 # endif # ifndef SUBLANG_SPANISH_PERU # define SUBLANG_SPANISH_PERU 0x0a # endif # ifndef SUBLANG_SPANISH_ARGENTINA # define SUBLANG_SPANISH_ARGENTINA 0x0b # endif # ifndef SUBLANG_SPANISH_ECUADOR # define SUBLANG_SPANISH_ECUADOR 0x0c # endif # ifndef SUBLANG_SPANISH_CHILE # define SUBLANG_SPANISH_CHILE 0x0d # endif # ifndef SUBLANG_SPANISH_URUGUAY # define SUBLANG_SPANISH_URUGUAY 0x0e # endif # ifndef SUBLANG_SPANISH_PARAGUAY # define SUBLANG_SPANISH_PARAGUAY 0x0f # endif # ifndef SUBLANG_SPANISH_BOLIVIA # define SUBLANG_SPANISH_BOLIVIA 0x10 # endif # ifndef SUBLANG_SPANISH_EL_SALVADOR # define SUBLANG_SPANISH_EL_SALVADOR 0x11 # endif # ifndef SUBLANG_SPANISH_HONDURAS # define SUBLANG_SPANISH_HONDURAS 0x12 # endif # ifndef SUBLANG_SPANISH_NICARAGUA # define SUBLANG_SPANISH_NICARAGUA 0x13 # endif # ifndef SUBLANG_SPANISH_PUERTO_RICO # define SUBLANG_SPANISH_PUERTO_RICO 0x14 # endif # ifndef SUBLANG_SWEDISH_FINLAND # define SUBLANG_SWEDISH_FINLAND 0x02 # endif # ifndef SUBLANG_TAMAZIGHT_ARABIC # define SUBLANG_TAMAZIGHT_ARABIC 0x01 # endif # ifndef SUBLANG_TAMAZIGHT_ALGERIA_LATIN # define SUBLANG_TAMAZIGHT_ALGERIA_LATIN 0x02 # endif # ifndef SUBLANG_TIGRINYA_ETHIOPIA # define SUBLANG_TIGRINYA_ETHIOPIA 0x01 # endif # ifndef SUBLANG_TIGRINYA_ERITREA # define SUBLANG_TIGRINYA_ERITREA 0x02 # endif # ifndef SUBLANG_URDU_PAKISTAN # define SUBLANG_URDU_PAKISTAN 0x01 # endif # ifndef SUBLANG_URDU_INDIA # define SUBLANG_URDU_INDIA 0x02 # endif # ifndef SUBLANG_UZBEK_LATIN # define SUBLANG_UZBEK_LATIN 0x01 # endif # ifndef SUBLANG_UZBEK_CYRILLIC # define SUBLANG_UZBEK_CYRILLIC 0x02 # endif #endif # if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */ /* Canonicalize a MacOS X locale name to a Unix locale name. NAME is a sufficiently large buffer. On input, it contains the MacOS X locale name. On output, it contains the Unix locale name. */ # if !defined IN_LIBINTL static # endif void gl_locale_name_canonicalize (char *name) { /* This conversion is based on a posting by Deborah GoldSmith on 2005-03-08, http://lists.apple.com/archives/carbon-dev/2005/Mar/msg00293.html */ /* Convert legacy (NeXTstep inherited) English names to Unix (ISO 639 and ISO 3166) names. Prior to MacOS X 10.3, there is no API for doing this. Therefore we do it ourselves, using a table based on the results of the MacOS X 10.3.8 function CFLocaleCreateCanonicalLocaleIdentifierFromString(). */ typedef struct { const char legacy[21+1]; const char unixy[5+1]; } legacy_entry; static const legacy_entry legacy_table[] = { { "Afrikaans", "af" }, { "Albanian", "sq" }, { "Amharic", "am" }, { "Arabic", "ar" }, { "Armenian", "hy" }, { "Assamese", "as" }, { "Aymara", "ay" }, { "Azerbaijani", "az" }, { "Basque", "eu" }, { "Belarusian", "be" }, { "Belorussian", "be" }, { "Bengali", "bn" }, { "Brazilian Portugese", "pt_BR" }, { "Brazilian Portuguese", "pt_BR" }, { "Breton", "br" }, { "Bulgarian", "bg" }, { "Burmese", "my" }, { "Byelorussian", "be" }, { "Catalan", "ca" }, { "Chewa", "ny" }, { "Chichewa", "ny" }, { "Chinese", "zh" }, { "Chinese, Simplified", "zh_CN" }, { "Chinese, Traditional", "zh_TW" }, { "Chinese, Tradtional", "zh_TW" }, { "Croatian", "hr" }, { "Czech", "cs" }, { "Danish", "da" }, { "Dutch", "nl" }, { "Dzongkha", "dz" }, { "English", "en" }, { "Esperanto", "eo" }, { "Estonian", "et" }, { "Faroese", "fo" }, { "Farsi", "fa" }, { "Finnish", "fi" }, { "Flemish", "nl_BE" }, { "French", "fr" }, { "Galician", "gl" }, { "Gallegan", "gl" }, { "Georgian", "ka" }, { "German", "de" }, { "Greek", "el" }, { "Greenlandic", "kl" }, { "Guarani", "gn" }, { "Gujarati", "gu" }, { "Hawaiian", "haw" }, /* Yes, "haw", not "cpe". */ { "Hebrew", "he" }, { "Hindi", "hi" }, { "Hungarian", "hu" }, { "Icelandic", "is" }, { "Indonesian", "id" }, { "Inuktitut", "iu" }, { "Irish", "ga" }, { "Italian", "it" }, { "Japanese", "ja" }, { "Javanese", "jv" }, { "Kalaallisut", "kl" }, { "Kannada", "kn" }, { "Kashmiri", "ks" }, { "Kazakh", "kk" }, { "Khmer", "km" }, { "Kinyarwanda", "rw" }, { "Kirghiz", "ky" }, { "Korean", "ko" }, { "Kurdish", "ku" }, { "Latin", "la" }, { "Latvian", "lv" }, { "Lithuanian", "lt" }, { "Macedonian", "mk" }, { "Malagasy", "mg" }, { "Malay", "ms" }, { "Malayalam", "ml" }, { "Maltese", "mt" }, { "Manx", "gv" }, { "Marathi", "mr" }, { "Moldavian", "mo" }, { "Mongolian", "mn" }, { "Nepali", "ne" }, { "Norwegian", "nb" }, /* Yes, "nb", not the obsolete "no". */ { "Nyanja", "ny" }, { "Nynorsk", "nn" }, { "Oriya", "or" }, { "Oromo", "om" }, { "Panjabi", "pa" }, { "Pashto", "ps" }, { "Persian", "fa" }, { "Polish", "pl" }, { "Portuguese", "pt" }, { "Portuguese, Brazilian", "pt_BR" }, { "Punjabi", "pa" }, { "Pushto", "ps" }, { "Quechua", "qu" }, { "Romanian", "ro" }, { "Ruanda", "rw" }, { "Rundi", "rn" }, { "Russian", "ru" }, { "Sami", "se_NO" }, /* Not just "se". */ { "Sanskrit", "sa" }, { "Scottish", "gd" }, { "Serbian", "sr" }, { "Simplified Chinese", "zh_CN" }, { "Sindhi", "sd" }, { "Sinhalese", "si" }, { "Slovak", "sk" }, { "Slovenian", "sl" }, { "Somali", "so" }, { "Spanish", "es" }, { "Sundanese", "su" }, { "Swahili", "sw" }, { "Swedish", "sv" }, { "Tagalog", "tl" }, { "Tajik", "tg" }, { "Tajiki", "tg" }, { "Tamil", "ta" }, { "Tatar", "tt" }, { "Telugu", "te" }, { "Thai", "th" }, { "Tibetan", "bo" }, { "Tigrinya", "ti" }, { "Tongan", "to" }, { "Traditional Chinese", "zh_TW" }, { "Turkish", "tr" }, { "Turkmen", "tk" }, { "Uighur", "ug" }, { "Ukrainian", "uk" }, { "Urdu", "ur" }, { "Uzbek", "uz" }, { "Vietnamese", "vi" }, { "Welsh", "cy" }, { "Yiddish", "yi" } }; /* Convert new-style locale names with language tags (ISO 639 and ISO 15924) to Unix (ISO 639 and ISO 3166) names. */ typedef struct { const char langtag[7+1]; const char unixy[12+1]; } langtag_entry; static const langtag_entry langtag_table[] = { /* MacOS X has "az-Arab", "az-Cyrl", "az-Latn". The default script for az on Unix is Latin. */ { "az-Latn", "az" }, /* MacOS X has "ga-dots". Does not yet exist on Unix. */ { "ga-dots", "ga" }, /* MacOS X has "kk-Cyrl". Does not yet exist on Unix. */ /* MacOS X has "mn-Cyrl", "mn-Mong". The default script for mn on Unix is Cyrillic. */ { "mn-Cyrl", "mn" }, /* MacOS X has "ms-Arab", "ms-Latn". The default script for ms on Unix is Latin. */ { "ms-Latn", "ms" }, /* MacOS X has "tg-Cyrl". The default script for tg on Unix is Cyrillic. */ { "tg-Cyrl", "tg" }, /* MacOS X has "tk-Cyrl". Does not yet exist on Unix. */ /* MacOS X has "tt-Cyrl". The default script for tt on Unix is Cyrillic. */ { "tt-Cyrl", "tt" }, /* MacOS X has "zh-Hans", "zh-Hant". Country codes are used to distinguish these on Unix. */ { "zh-Hans", "zh_CN" }, { "zh-Hant", "zh_TW" } }; /* Convert script names (ISO 15924) to Unix conventions. See http://www.unicode.org/iso15924/iso15924-codes.html */ typedef struct { const char script[4+1]; const char unixy[9+1]; } script_entry; static const script_entry script_table[] = { { "Arab", "arabic" }, { "Cyrl", "cyrillic" }, { "Mong", "mongolian" } }; /* Step 1: Convert using legacy_table. */ if (name[0] >= 'A' && name[0] <= 'Z') { unsigned int i1, i2; i1 = 0; i2 = sizeof (legacy_table) / sizeof (legacy_entry); while (i2 - i1 > 1) { /* At this point we know that if name occurs in legacy_table, its index must be >= i1 and < i2. */ unsigned int i = (i1 + i2) >> 1; const legacy_entry *p = &legacy_table[i]; if (strcmp (name, p->legacy) < 0) i2 = i; else i1 = i; } if (strcmp (name, legacy_table[i1].legacy) == 0) { strcpy (name, legacy_table[i1].unixy); return; } } /* Step 2: Convert using langtag_table and script_table. */ if (strlen (name) == 7 && name[2] == '-') { unsigned int i1, i2; i1 = 0; i2 = sizeof (langtag_table) / sizeof (langtag_entry); while (i2 - i1 > 1) { /* At this point we know that if name occurs in langtag_table, its index must be >= i1 and < i2. */ unsigned int i = (i1 + i2) >> 1; const langtag_entry *p = &langtag_table[i]; if (strcmp (name, p->langtag) < 0) i2 = i; else i1 = i; } if (strcmp (name, langtag_table[i1].langtag) == 0) { strcpy (name, langtag_table[i1].unixy); return; } i1 = 0; i2 = sizeof (script_table) / sizeof (script_entry); while (i2 - i1 > 1) { /* At this point we know that if (name + 3) occurs in script_table, its index must be >= i1 and < i2. */ unsigned int i = (i1 + i2) >> 1; const script_entry *p = &script_table[i]; if (strcmp (name + 3, p->script) < 0) i2 = i; else i1 = i; } if (strcmp (name + 3, script_table[i1].script) == 0) { name[2] = '@'; strcpy (name + 3, script_table[i1].unixy); return; } } /* Step 3: Convert new-style dash to Unix underscore. */ { char *p; for (p = name; *p != '\0'; p++) if (*p == '-') *p = '_'; } } #endif /* XPG3 defines the result of 'setlocale (category, NULL)' as: "Directs 'setlocale()' to query 'category' and return the current setting of 'local'." However it does not specify the exact format. Neither do SUSV2 and ISO C 99. So we can use this feature only on selected systems (e.g. those using GNU C Library). */ #if defined _LIBC || (defined __GLIBC__ && __GLIBC__ >= 2) # define HAVE_LOCALE_NULL #endif /* Determine the current locale's name, and canonicalize it into XPG syntax language[_territory][.codeset][@modifier] The codeset part in the result is not reliable; the locale_charset() should be used for codeset information instead. The result must not be freed; it is statically allocated. */ const char * gl_locale_name_posix (int category, const char *categoryname) { /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'. On some systems this can be done by the 'setlocale' function itself. */ #if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL return setlocale (category, NULL); #else const char *retval; /* Setting of LC_ALL overrides all other. */ retval = getenv ("LC_ALL"); if (retval != NULL && retval[0] != '\0') return retval; /* Next comes the name of the desired category. */ retval = getenv (categoryname); if (retval != NULL && retval[0] != '\0') return retval; /* Last possibility is the LANG environment variable. */ retval = getenv ("LANG"); if (retval != NULL && retval[0] != '\0') return retval; return NULL; #endif } const char * gl_locale_name_default (void) { /* POSIX:2001 says: "All implementations shall define a locale as the default locale, to be invoked when no environment variables are set, or set to the empty string. This default locale can be the POSIX locale or any other implementation-defined locale. Some implementations may provide facilities for local installation administrators to set the default locale, customizing it for each location. POSIX:2001 does not require such a facility. */ #if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined(WIN32_NATIVE)) /* The system does not have a way of setting the locale, other than the POSIX specified environment variables. We use C as default locale. */ return "C"; #else /* Return an XPG style locale name language[_territory][@modifier]. Don't even bother determining the codeset; it's not useful in this context, because message catalogs are not specific to a single codeset. */ # if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */ { /* Cache the locale name, since CoreFoundation calls are expensive. */ static const char *cached_localename; if (cached_localename == NULL) { char namebuf[256]; # if HAVE_CFLOCALECOPYCURRENT /* MacOS X 10.3 or newer */ CFLocaleRef locale = CFLocaleCopyCurrent (); CFStringRef name = CFLocaleGetIdentifier (locale); if (CFStringGetCString (name, namebuf, sizeof(namebuf), kCFStringEncodingASCII)) { gl_locale_name_canonicalize (namebuf); cached_localename = strdup (namebuf); } CFRelease (locale); # elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */ CFTypeRef value = CFPreferencesCopyAppValue (CFSTR ("AppleLocale"), kCFPreferencesCurrentApplication); if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID () && CFStringGetCString ((CFStringRef)value, namebuf, sizeof(namebuf), kCFStringEncodingASCII)) { gl_locale_name_canonicalize (namebuf); cached_localename = strdup (namebuf); } # endif if (cached_localename == NULL) cached_localename = "C"; } return cached_localename; } # endif # if defined(WIN32_NATIVE) /* WIN32, not Cygwin */ { LCID lcid; LANGID langid; int primary, sub; /* Use native Win32 API locale ID. */ lcid = GetThreadLocale (); /* Strip off the sorting rules, keep only the language part. */ langid = LANGIDFROMLCID (lcid); /* Split into language and territory part. */ primary = PRIMARYLANGID (langid); sub = SUBLANGID (langid); /* Dispatch on language. See also http://www.unicode.org/unicode/onlinedat/languages.html . For details about languages, see http://www.ethnologue.com/ . */ switch (primary) { case LANG_AFRIKAANS: return "af_ZA"; case LANG_ALBANIAN: return "sq_AL"; case LANG_AMHARIC: return "am_ET"; case LANG_ARABIC: switch (sub) { case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA"; case SUBLANG_ARABIC_IRAQ: return "ar_IQ"; case SUBLANG_ARABIC_EGYPT: return "ar_EG"; case SUBLANG_ARABIC_LIBYA: return "ar_LY"; case SUBLANG_ARABIC_ALGERIA: return "ar_DZ"; case SUBLANG_ARABIC_MOROCCO: return "ar_MA"; case SUBLANG_ARABIC_TUNISIA: return "ar_TN"; case SUBLANG_ARABIC_OMAN: return "ar_OM"; case SUBLANG_ARABIC_YEMEN: return "ar_YE"; case SUBLANG_ARABIC_SYRIA: return "ar_SY"; case SUBLANG_ARABIC_JORDAN: return "ar_JO"; case SUBLANG_ARABIC_LEBANON: return "ar_LB"; case SUBLANG_ARABIC_KUWAIT: return "ar_KW"; case SUBLANG_ARABIC_UAE: return "ar_AE"; case SUBLANG_ARABIC_BAHRAIN: return "ar_BH"; case SUBLANG_ARABIC_QATAR: return "ar_QA"; } return "ar"; case LANG_ARMENIAN: return "hy_AM"; case LANG_ASSAMESE: return "as_IN"; case LANG_AZERI: switch (sub) { /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */ case SUBLANG_AZERI_LATIN: return "az_AZ@latin"; case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic"; } return "az"; case LANG_BASQUE: switch (sub) { case SUBLANG_DEFAULT: return "eu_ES"; } return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */ case LANG_BELARUSIAN: return "be_BY"; case LANG_BENGALI: switch (sub) { case SUBLANG_BENGALI_INDIA: return "bn_IN"; case SUBLANG_BENGALI_BANGLADESH: return "bn_BD"; } return "bn"; case LANG_BULGARIAN: return "bg_BG"; case LANG_BURMESE: return "my_MM"; case LANG_CAMBODIAN: return "km_KH"; case LANG_CATALAN: return "ca_ES"; case LANG_CHEROKEE: return "chr_US"; case LANG_CHINESE: switch (sub) { case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW"; case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN"; case SUBLANG_CHINESE_HONGKONG: return "zh_HK"; case SUBLANG_CHINESE_SINGAPORE: return "zh_SG"; case SUBLANG_CHINESE_MACAU: return "zh_MO"; } return "zh"; case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN * What used to be called Serbo-Croatian * should really now be two separate * languages because of political reasons. * (Says tml, who knows nothing about Serbian * or Croatian.) * (I can feel those flames coming already.) */ switch (sub) { case SUBLANG_DEFAULT: return "hr_HR"; case SUBLANG_SERBIAN_LATIN: return "sr_CS"; case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic"; } return "hr"; case LANG_CZECH: return "cs_CZ"; case LANG_DANISH: return "da_DK"; case LANG_DIVEHI: return "dv_MV"; case LANG_DUTCH: switch (sub) { case SUBLANG_DUTCH: return "nl_NL"; case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE"; } return "nl"; case LANG_EDO: return "bin_NG"; case LANG_ENGLISH: switch (sub) { /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought * English was the language spoken in England. * Oh well. */ case SUBLANG_ENGLISH_US: return "en_US"; case SUBLANG_ENGLISH_UK: return "en_GB"; case SUBLANG_ENGLISH_AUS: return "en_AU"; case SUBLANG_ENGLISH_CAN: return "en_CA"; case SUBLANG_ENGLISH_NZ: return "en_NZ"; case SUBLANG_ENGLISH_EIRE: return "en_IE"; case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA"; case SUBLANG_ENGLISH_JAMAICA: return "en_JM"; case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */ case SUBLANG_ENGLISH_BELIZE: return "en_BZ"; case SUBLANG_ENGLISH_TRINIDAD: return "en_TT"; case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW"; case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH"; case SUBLANG_ENGLISH_INDONESIA: return "en_ID"; case SUBLANG_ENGLISH_HONGKONG: return "en_HK"; case SUBLANG_ENGLISH_INDIA: return "en_IN"; case SUBLANG_ENGLISH_MALAYSIA: return "en_MY"; case SUBLANG_ENGLISH_SINGAPORE: return "en_SG"; } return "en"; case LANG_ESTONIAN: return "et_EE"; case LANG_FAEROESE: return "fo_FO"; case LANG_FARSI: return "fa_IR"; case LANG_FINNISH: return "fi_FI"; case LANG_FRENCH: switch (sub) { case SUBLANG_FRENCH: return "fr_FR"; case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE"; case SUBLANG_FRENCH_CANADIAN: return "fr_CA"; case SUBLANG_FRENCH_SWISS: return "fr_CH"; case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU"; case SUBLANG_FRENCH_MONACO: return "fr_MC"; case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */ case SUBLANG_FRENCH_REUNION: return "fr_RE"; case SUBLANG_FRENCH_CONGO: return "fr_CG"; case SUBLANG_FRENCH_SENEGAL: return "fr_SN"; case SUBLANG_FRENCH_CAMEROON: return "fr_CM"; case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI"; case SUBLANG_FRENCH_MALI: return "fr_ML"; case SUBLANG_FRENCH_MOROCCO: return "fr_MA"; case SUBLANG_FRENCH_HAITI: return "fr_HT"; } return "fr"; case LANG_FRISIAN: return "fy_NL"; case LANG_FULFULDE: /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin. */ return "ff_NG"; case LANG_GAELIC: switch (sub) { case 0x01: /* SCOTTISH */ return "gd_GB"; case 0x02: /* IRISH */ return "ga_IE"; } return "C"; case LANG_GALICIAN: return "gl_ES"; case LANG_GEORGIAN: return "ka_GE"; case LANG_GERMAN: switch (sub) { case SUBLANG_GERMAN: return "de_DE"; case SUBLANG_GERMAN_SWISS: return "de_CH"; case SUBLANG_GERMAN_AUSTRIAN: return "de_AT"; case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU"; case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI"; } return "de"; case LANG_GREEK: return "el_GR"; case LANG_GUARANI: return "gn_PY"; case LANG_GUJARATI: return "gu_IN"; case LANG_HAUSA: return "ha_NG"; case LANG_HAWAIIAN: /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers) or Hawaii Creole English ("cpe_US", 600000 speakers)? */ return "cpe_US"; case LANG_HEBREW: return "he_IL"; case LANG_HINDI: return "hi_IN"; case LANG_HUNGARIAN: return "hu_HU"; case LANG_IBIBIO: return "nic_NG"; case LANG_ICELANDIC: return "is_IS"; case LANG_IGBO: return "ig_NG"; case LANG_INDONESIAN: return "id_ID"; case LANG_INUKTITUT: return "iu_CA"; case LANG_ITALIAN: switch (sub) { case SUBLANG_ITALIAN: return "it_IT"; case SUBLANG_ITALIAN_SWISS: return "it_CH"; } return "it"; case LANG_JAPANESE: return "ja_JP"; case LANG_KANNADA: return "kn_IN"; case LANG_KANURI: return "kr_NG"; case LANG_KASHMIRI: switch (sub) { case SUBLANG_DEFAULT: return "ks_PK"; case SUBLANG_KASHMIRI_INDIA: return "ks_IN"; } return "ks"; case LANG_KAZAK: return "kk_KZ"; case LANG_KONKANI: /* FIXME: Adjust this when such locales appear on Unix. */ return "kok_IN"; case LANG_KOREAN: return "ko_KR"; case LANG_KYRGYZ: return "ky_KG"; case LANG_LAO: return "lo_LA"; case LANG_LATIN: return "la_VA"; case LANG_LATVIAN: return "lv_LV"; case LANG_LITHUANIAN: return "lt_LT"; case LANG_MACEDONIAN: return "mk_MK"; case LANG_MALAY: switch (sub) { case SUBLANG_MALAY_MALAYSIA: return "ms_MY"; case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN"; } return "ms"; case LANG_MALAYALAM: return "ml_IN"; case LANG_MALTESE: return "mt_MT"; case LANG_MANIPURI: /* FIXME: Adjust this when such locales appear on Unix. */ return "mni_IN"; case LANG_MARATHI: return "mr_IN"; case LANG_MONGOLIAN: switch (sub) { case SUBLANG_DEFAULT: return "mn_MN"; } return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */ case LANG_NEPALI: switch (sub) { case SUBLANG_DEFAULT: return "ne_NP"; case SUBLANG_NEPALI_INDIA: return "ne_IN"; } return "ne"; case LANG_NORWEGIAN: switch (sub) { case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO"; case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO"; } return "no"; case LANG_ORIYA: return "or_IN"; case LANG_OROMO: return "om_ET"; case LANG_PAPIAMENTU: return "pap_AN"; case LANG_PASHTO: return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */ case LANG_POLISH: return "pl_PL"; case LANG_PORTUGUESE: switch (sub) { case SUBLANG_PORTUGUESE: return "pt_PT"; /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT. Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */ case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR"; } return "pt"; case LANG_PUNJABI: switch (sub) { case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */ case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */ } return "pa"; case LANG_RHAETO_ROMANCE: return "rm_CH"; case LANG_ROMANIAN: switch (sub) { case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO"; case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD"; } return "ro"; case LANG_RUSSIAN: switch (sub) { case SUBLANG_DEFAULT: return "ru_RU"; } return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */ case LANG_SAAMI: /* actually Northern Sami */ return "se_NO"; case LANG_SANSKRIT: return "sa_IN"; case LANG_SINDHI: switch (sub) { case SUBLANG_SINDHI_PAKISTAN: return "sd_PK"; case SUBLANG_SINDHI_AFGHANISTAN: return "sd_AF"; } return "sd"; case LANG_SINHALESE: return "si_LK"; case LANG_SLOVAK: return "sk_SK"; case LANG_SLOVENIAN: return "sl_SI"; case LANG_SOMALI: return "so_SO"; case LANG_SORBIAN: /* FIXME: Adjust this when such locales appear on Unix. */ return "wen_DE"; case LANG_SPANISH: switch (sub) { case SUBLANG_SPANISH: return "es_ES"; case SUBLANG_SPANISH_MEXICAN: return "es_MX"; case SUBLANG_SPANISH_MODERN: return "es_ES@modern"; /* not seen on Unix */ case SUBLANG_SPANISH_GUATEMALA: return "es_GT"; case SUBLANG_SPANISH_COSTA_RICA: return "es_CR"; case SUBLANG_SPANISH_PANAMA: return "es_PA"; case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO"; case SUBLANG_SPANISH_VENEZUELA: return "es_VE"; case SUBLANG_SPANISH_COLOMBIA: return "es_CO"; case SUBLANG_SPANISH_PERU: return "es_PE"; case SUBLANG_SPANISH_ARGENTINA: return "es_AR"; case SUBLANG_SPANISH_ECUADOR: return "es_EC"; case SUBLANG_SPANISH_CHILE: return "es_CL"; case SUBLANG_SPANISH_URUGUAY: return "es_UY"; case SUBLANG_SPANISH_PARAGUAY: return "es_PY"; case SUBLANG_SPANISH_BOLIVIA: return "es_BO"; case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV"; case SUBLANG_SPANISH_HONDURAS: return "es_HN"; case SUBLANG_SPANISH_NICARAGUA: return "es_NI"; case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR"; } return "es"; case LANG_SUTU: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */ case LANG_SWAHILI: return "sw_KE"; case LANG_SWEDISH: switch (sub) { case SUBLANG_DEFAULT: return "sv_SE"; case SUBLANG_SWEDISH_FINLAND: return "sv_FI"; } return "sv"; case LANG_SYRIAC: return "syr_TR"; /* An extinct language. */ case LANG_TAGALOG: return "tl_PH"; case LANG_TAJIK: return "tg_TJ"; case LANG_TAMAZIGHT: switch (sub) { /* FIXME: Adjust this when Tamazight locales appear on Unix. */ case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic"; case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return "ber_DZ@latin"; } return "ber_MA"; case LANG_TAMIL: switch (sub) { case SUBLANG_DEFAULT: return "ta_IN"; } return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */ case LANG_TATAR: return "tt_RU"; case LANG_TELUGU: return "te_IN"; case LANG_THAI: return "th_TH"; case LANG_TIBETAN: return "bo_CN"; case LANG_TIGRINYA: switch (sub) { case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET"; case SUBLANG_TIGRINYA_ERITREA: return "ti_ER"; } return "ti"; case LANG_TSONGA: return "ts_ZA"; case LANG_TSWANA: return "tn_BW"; case LANG_TURKISH: return "tr_TR"; case LANG_TURKMEN: return "tk_TM"; case LANG_UKRAINIAN: return "uk_UA"; case LANG_URDU: switch (sub) { case SUBLANG_URDU_PAKISTAN: return "ur_PK"; case SUBLANG_URDU_INDIA: return "ur_IN"; } return "ur"; case LANG_UZBEK: switch (sub) { case SUBLANG_UZBEK_LATIN: return "uz_UZ"; case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic"; } return "uz"; case LANG_VENDA: return "ve_ZA"; case LANG_VIETNAMESE: return "vi_VN"; case LANG_WELSH: return "cy_GB"; case LANG_XHOSA: return "xh_ZA"; case LANG_YI: return "sit_CN"; case LANG_YIDDISH: return "yi_IL"; case LANG_YORUBA: return "yo_NG"; case LANG_ZULU: return "zu_ZA"; default: return "C"; } } # endif #endif } const char * gl_locale_name (int category, const char *categoryname) { const char *retval; retval = gl_locale_name_posix (category, categoryname); if (retval != NULL) return retval; return gl_locale_name_default (); } libnih-1.0.3/intl/export.h0000644000175000017500000000023511461165267012352 00000000000000 #if @HAVE_VISIBILITY@ && BUILDING_LIBINTL #define LIBINTL_DLL_EXPORTED __attribute__((__visibility__("default"))) #else #define LIBINTL_DLL_EXPORTED #endif libnih-1.0.3/intl/plural-exp.c0000644000175000017500000000773211461165270013120 00000000000000/* Expression parsing for plural form selection. Copyright (C) 2000-2001, 2003, 2005-2007 Free Software Foundation, Inc. Written by Ulrich Drepper , 2000. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include "plural-exp.h" #if (defined __GNUC__ && !(__APPLE_CC__ > 1) && !defined __cplusplus) \ || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) /* These structs are the constant expression for the germanic plural form determination. It represents the expression "n != 1". */ static const struct expression plvar = { .nargs = 0, .operation = var, }; static const struct expression plone = { .nargs = 0, .operation = num, .val = { .num = 1 } }; struct expression GERMANIC_PLURAL = { .nargs = 2, .operation = not_equal, .val = { .args = { [0] = (struct expression *) &plvar, [1] = (struct expression *) &plone } } }; # define INIT_GERMANIC_PLURAL() #else /* For compilers without support for ISO C 99 struct/union initializers: Initialization at run-time. */ static struct expression plvar; static struct expression plone; struct expression GERMANIC_PLURAL; static void init_germanic_plural () { if (plone.val.num == 0) { plvar.nargs = 0; plvar.operation = var; plone.nargs = 0; plone.operation = num; plone.val.num = 1; GERMANIC_PLURAL.nargs = 2; GERMANIC_PLURAL.operation = not_equal; GERMANIC_PLURAL.val.args[0] = &plvar; GERMANIC_PLURAL.val.args[1] = &plone; } } # define INIT_GERMANIC_PLURAL() init_germanic_plural () #endif void internal_function EXTRACT_PLURAL_EXPRESSION (const char *nullentry, const struct expression **pluralp, unsigned long int *npluralsp) { if (nullentry != NULL) { const char *plural; const char *nplurals; plural = strstr (nullentry, "plural="); nplurals = strstr (nullentry, "nplurals="); if (plural == NULL || nplurals == NULL) goto no_plural; else { char *endp; unsigned long int n; struct parse_args args; /* First get the number. */ nplurals += 9; while (*nplurals != '\0' && isspace ((unsigned char) *nplurals)) ++nplurals; if (!(*nplurals >= '0' && *nplurals <= '9')) goto no_plural; #if defined HAVE_STRTOUL || defined _LIBC n = strtoul (nplurals, &endp, 10); #else for (endp = nplurals, n = 0; *endp >= '0' && *endp <= '9'; endp++) n = n * 10 + (*endp - '0'); #endif if (nplurals == endp) goto no_plural; *npluralsp = n; /* Due to the restrictions bison imposes onto the interface of the scanner function we have to put the input string and the result passed up from the parser into the same structure which address is passed down to the parser. */ plural += 7; args.cp = plural; if (PLURAL_PARSE (&args) != 0) goto no_plural; *pluralp = args.res; } } else { /* By default we are using the Germanic form: singular form only for `one', the plural form otherwise. Yes, this is also what English is using since English is a Germanic language. */ no_plural: INIT_GERMANIC_PLURAL (); *pluralp = &GERMANIC_PLURAL; *npluralsp = 2; } } libnih-1.0.3/intl/tsearch.h0000644000175000017500000000536611461165270012466 00000000000000/* Binary tree data structure. Copyright (C) 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _TSEARCH_H #define _TSEARCH_H #if HAVE_TSEARCH /* Get tseach(), tfind(), tdelete(), twalk() declarations. */ #include #else #ifdef __cplusplus extern "C" { #endif /* See , for details. */ typedef enum { preorder, postorder, endorder, leaf } VISIT; /* Searches an element in the tree *VROOTP that compares equal to KEY. If one is found, it is returned. Otherwise, a new element equal to KEY is inserted in the tree and is returned. */ extern void * tsearch (const void *key, void **vrootp, int (*compar) (const void *, const void *)); /* Searches an element in the tree *VROOTP that compares equal to KEY. If one is found, it is returned. Otherwise, NULL is returned. */ extern void * tfind (const void *key, void *const *vrootp, int (*compar) (const void *, const void *)); /* Searches an element in the tree *VROOTP that compares equal to KEY. If one is found, it is removed from the tree, and its parent node is returned. Otherwise, NULL is returned. */ extern void * tdelete (const void *key, void **vrootp, int (*compar) (const void *, const void *)); /* Perform a depth-first, left-to-right traversal of the tree VROOT. The ACTION function is called: - for non-leaf nodes: 3 times, before the left subtree traversal, after the left subtree traversal but before the right subtree traversal, and after the right subtree traversal, - for leaf nodes: once. The arguments passed to ACTION are: 1. the node; it can be casted to a 'const void * const *', i.e. into a pointer to the key, 2. an indicator which visit of the node this is, 3. the level of the node in the tree (0 for the root). */ extern void twalk (const void *vroot, void (*action) (const void *, VISIT, int)); #ifdef __cplusplus } #endif #endif #endif /* _TSEARCH_H */ libnih-1.0.3/intl/langprefs.c0000644000175000017500000000737511461165267013021 00000000000000/* Determine the user's language preferences. Copyright (C) 2004-2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Bruno Haible . */ #ifdef HAVE_CONFIG_H # include #endif #include #if HAVE_CFPREFERENCESCOPYAPPVALUE # include # include # include # include # include extern void _nl_locale_name_canonicalize (char *name); #endif /* Determine the user's language preferences, as a colon separated list of locale names in XPG syntax language[_territory][.codeset][@modifier] The result must not be freed; it is statically allocated. The LANGUAGE environment variable does not need to be considered; it is already taken into account by the caller. */ const char * _nl_language_preferences_default (void) { #if HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */ { /* Cache the preferences list, since CoreFoundation calls are expensive. */ static const char *cached_languages; static int cache_initialized; if (!cache_initialized) { CFTypeRef preferences = CFPreferencesCopyAppValue (CFSTR ("AppleLanguages"), kCFPreferencesCurrentApplication); if (preferences != NULL && CFGetTypeID (preferences) == CFArrayGetTypeID ()) { CFArrayRef prefArray = (CFArrayRef)preferences; int n = CFArrayGetCount (prefArray); char buf[256]; size_t size = 0; int i; for (i = 0; i < n; i++) { CFTypeRef element = CFArrayGetValueAtIndex (prefArray, i); if (element != NULL && CFGetTypeID (element) == CFStringGetTypeID () && CFStringGetCString ((CFStringRef)element, buf, sizeof (buf), kCFStringEncodingASCII)) { _nl_locale_name_canonicalize (buf); size += strlen (buf) + 1; /* Most GNU programs use msgids in English and don't ship an en.mo message catalog. Therefore when we see "en" in the preferences list, arrange for gettext() to return the msgid, and ignore all further elements of the preferences list. */ if (strcmp (buf, "en") == 0) break; } else break; } if (size > 0) { char *languages = (char *) malloc (size); if (languages != NULL) { char *p = languages; for (i = 0; i < n; i++) { CFTypeRef element = CFArrayGetValueAtIndex (prefArray, i); if (element != NULL && CFGetTypeID (element) == CFStringGetTypeID () && CFStringGetCString ((CFStringRef)element, buf, sizeof (buf), kCFStringEncodingASCII)) { _nl_locale_name_canonicalize (buf); strcpy (p, buf); p += strlen (buf); *p++ = ':'; if (strcmp (buf, "en") == 0) break; } else break; } *--p = '\0'; cached_languages = languages; } } } cache_initialized = 1; } if (cached_languages != NULL) return cached_languages; } #endif return NULL; } libnih-1.0.3/intl/locale.alias0000644000175000017500000000510611461165267013134 00000000000000# Locale name alias data base. # Copyright (C) 1996-2001,2003,2007 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. # The format of this file is the same as for the corresponding file of # the X Window System, which normally can be found in # /usr/lib/X11/locale/locale.alias # A single line contains two fields: an alias and a substitution value. # All entries are case independent. # Note: This file is obsolete and is kept around for the time being for # backward compatibility. Nobody should rely on the names defined here. # Locales should always be specified by their full name. # Packages using this file: bokmal nb_NO.ISO-8859-1 bokml nb_NO.ISO-8859-1 catalan ca_ES.ISO-8859-1 croatian hr_HR.ISO-8859-2 czech cs_CZ.ISO-8859-2 danish da_DK.ISO-8859-1 dansk da_DK.ISO-8859-1 deutsch de_DE.ISO-8859-1 dutch nl_NL.ISO-8859-1 eesti et_EE.ISO-8859-1 estonian et_EE.ISO-8859-1 finnish fi_FI.ISO-8859-1 franais fr_FR.ISO-8859-1 french fr_FR.ISO-8859-1 galego gl_ES.ISO-8859-1 galician gl_ES.ISO-8859-1 german de_DE.ISO-8859-1 greek el_GR.ISO-8859-7 hebrew he_IL.ISO-8859-8 hrvatski hr_HR.ISO-8859-2 hungarian hu_HU.ISO-8859-2 icelandic is_IS.ISO-8859-1 italian it_IT.ISO-8859-1 japanese ja_JP.eucJP japanese.euc ja_JP.eucJP ja_JP ja_JP.eucJP ja_JP.ujis ja_JP.eucJP japanese.sjis ja_JP.SJIS korean ko_KR.eucKR korean.euc ko_KR.eucKR ko_KR ko_KR.eucKR lithuanian lt_LT.ISO-8859-13 no_NO nb_NO.ISO-8859-1 no_NO.ISO-8859-1 nb_NO.ISO-8859-1 norwegian nb_NO.ISO-8859-1 nynorsk nn_NO.ISO-8859-1 polish pl_PL.ISO-8859-2 portuguese pt_PT.ISO-8859-1 romanian ro_RO.ISO-8859-2 russian ru_RU.ISO-8859-5 slovak sk_SK.ISO-8859-2 slovene sl_SI.ISO-8859-2 slovenian sl_SI.ISO-8859-2 spanish es_ES.ISO-8859-1 swedish sv_SE.ISO-8859-1 thai th_TH.TIS-620 turkish tr_TR.ISO-8859-9 libnih-1.0.3/intl/libgnuintl.h.in0000644000175000017500000003415311461165267013613 00000000000000/* Message catalogs for internationalization. Copyright (C) 1995-1997, 2000-2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _LIBINTL_H #define _LIBINTL_H 1 #include /* The LC_MESSAGES locale category is the category used by the functions gettext() and dgettext(). It is specified in POSIX, but not in ANSI C. On systems that don't define it, use an arbitrary value instead. On Solaris, defines __LOCALE_H (or _LOCALE_H in Solaris 2.5) then includes (i.e. this file!) and then only defines LC_MESSAGES. To avoid a redefinition warning, don't define LC_MESSAGES in this case. */ #if !defined LC_MESSAGES && !(defined __LOCALE_H || (defined _LOCALE_H && defined __sun)) # define LC_MESSAGES 1729 #endif /* We define an additional symbol to signal that we use the GNU implementation of gettext. */ #define __USE_GNU_GETTEXT 1 /* Provide information about the supported file formats. Returns the maximum minor revision number supported for a given major revision. */ #define __GNU_GETTEXT_SUPPORTED_REVISION(major) \ ((major) == 0 || (major) == 1 ? 1 : -1) /* Resolve a platform specific conflict on DJGPP. GNU gettext takes precedence over _conio_gettext. */ #ifdef __DJGPP__ # undef gettext #endif #ifdef __cplusplus extern "C" { #endif /* Version number: (major<<16) + (minor<<8) + subminor */ #define LIBINTL_VERSION 0x001100 extern int libintl_version; /* We redirect the functions to those prefixed with "libintl_". This is necessary, because some systems define gettext/textdomain/... in the C library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer). If we used the unprefixed names, there would be cases where the definition in the C library would override the one in the libintl.so shared library. Recall that on ELF systems, the symbols are looked up in the following order: 1. in the executable, 2. in the shared libraries specified on the link command line, in order, 3. in the dependencies of the shared libraries specified on the link command line, 4. in the dlopen()ed shared libraries, in the order in which they were dlopen()ed. The definition in the C library would override the one in libintl.so if either * -lc is given on the link command line and -lintl isn't, or * -lc is given on the link command line before -lintl, or * libintl.so is a dependency of a dlopen()ed shared library but not linked to the executable at link time. Since Solaris gettext() behaves differently than GNU gettext(), this would be unacceptable. The redirection happens by default through macros in C, so that &gettext is independent of the compilation unit, but through inline functions in C++, in order not to interfere with the name mangling of class fields or class methods called 'gettext'. */ /* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS. If he doesn't, we choose the method. A third possible method is _INTL_REDIRECT_ASM, supported only by GCC. */ #if !(defined _INTL_REDIRECT_INLINE || defined _INTL_REDIRECT_MACROS) # if __GNUC__ >= 2 && !(__APPLE_CC__ > 1) && !defined __MINGW32__ && !(__GNUC__ == 2 && defined _AIX) && (defined __STDC__ || defined __cplusplus) # define _INTL_REDIRECT_ASM # else # ifdef __cplusplus # define _INTL_REDIRECT_INLINE # else # define _INTL_REDIRECT_MACROS # endif # endif #endif /* Auxiliary macros. */ #ifdef _INTL_REDIRECT_ASM # define _INTL_ASM(cname) __asm__ (_INTL_ASMNAME (__USER_LABEL_PREFIX__, #cname)) # define _INTL_ASMNAME(prefix,cnamestring) _INTL_STRINGIFY (prefix) cnamestring # define _INTL_STRINGIFY(prefix) #prefix #else # define _INTL_ASM(cname) #endif /* _INTL_MAY_RETURN_STRING_ARG(n) declares that the given function may return its n-th argument literally. This enables GCC to warn for example about printf (gettext ("foo %y")). */ #if __GNUC__ >= 3 && !(__APPLE_CC__ > 1 && defined __cplusplus) # define _INTL_MAY_RETURN_STRING_ARG(n) __attribute__ ((__format_arg__ (n))) #else # define _INTL_MAY_RETURN_STRING_ARG(n) #endif /* Look up MSGID in the current default message catalog for the current LC_MESSAGES locale. If not found, returns MSGID itself (the default text). */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_gettext (const char *__msgid) _INTL_MAY_RETURN_STRING_ARG (1); static inline char *gettext (const char *__msgid) { return libintl_gettext (__msgid); } #else #ifdef _INTL_REDIRECT_MACROS # define gettext libintl_gettext #endif extern char *gettext (const char *__msgid) _INTL_ASM (libintl_gettext) _INTL_MAY_RETURN_STRING_ARG (1); #endif /* Look up MSGID in the DOMAINNAME message catalog for the current LC_MESSAGES locale. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_dgettext (const char *__domainname, const char *__msgid) _INTL_MAY_RETURN_STRING_ARG (2); static inline char *dgettext (const char *__domainname, const char *__msgid) { return libintl_dgettext (__domainname, __msgid); } #else #ifdef _INTL_REDIRECT_MACROS # define dgettext libintl_dgettext #endif extern char *dgettext (const char *__domainname, const char *__msgid) _INTL_ASM (libintl_dgettext) _INTL_MAY_RETURN_STRING_ARG (2); #endif /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY locale. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_dcgettext (const char *__domainname, const char *__msgid, int __category) _INTL_MAY_RETURN_STRING_ARG (2); static inline char *dcgettext (const char *__domainname, const char *__msgid, int __category) { return libintl_dcgettext (__domainname, __msgid, __category); } #else #ifdef _INTL_REDIRECT_MACROS # define dcgettext libintl_dcgettext #endif extern char *dcgettext (const char *__domainname, const char *__msgid, int __category) _INTL_ASM (libintl_dcgettext) _INTL_MAY_RETURN_STRING_ARG (2); #endif /* Similar to `gettext' but select the plural form corresponding to the number N. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2, unsigned long int __n) _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); static inline char *ngettext (const char *__msgid1, const char *__msgid2, unsigned long int __n) { return libintl_ngettext (__msgid1, __msgid2, __n); } #else #ifdef _INTL_REDIRECT_MACROS # define ngettext libintl_ngettext #endif extern char *ngettext (const char *__msgid1, const char *__msgid2, unsigned long int __n) _INTL_ASM (libintl_ngettext) _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); #endif /* Similar to `dgettext' but select the plural form corresponding to the number N. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_dngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n) _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); static inline char *dngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n) { return libintl_dngettext (__domainname, __msgid1, __msgid2, __n); } #else #ifdef _INTL_REDIRECT_MACROS # define dngettext libintl_dngettext #endif extern char *dngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n) _INTL_ASM (libintl_dngettext) _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); #endif /* Similar to `dcgettext' but select the plural form corresponding to the number N. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_dcngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n, int __category) _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); static inline char *dcngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n, int __category) { return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category); } #else #ifdef _INTL_REDIRECT_MACROS # define dcngettext libintl_dcngettext #endif extern char *dcngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n, int __category) _INTL_ASM (libintl_dcngettext) _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); #endif #ifndef IN_LIBGLOCALE /* Set the current default message catalog to DOMAINNAME. If DOMAINNAME is null, return the current default. If DOMAINNAME is "", reset to the default of "messages". */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_textdomain (const char *__domainname); static inline char *textdomain (const char *__domainname) { return libintl_textdomain (__domainname); } #else #ifdef _INTL_REDIRECT_MACROS # define textdomain libintl_textdomain #endif extern char *textdomain (const char *__domainname) _INTL_ASM (libintl_textdomain); #endif /* Specify that the DOMAINNAME message catalog will be found in DIRNAME rather than in the system locale data base. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_bindtextdomain (const char *__domainname, const char *__dirname); static inline char *bindtextdomain (const char *__domainname, const char *__dirname) { return libintl_bindtextdomain (__domainname, __dirname); } #else #ifdef _INTL_REDIRECT_MACROS # define bindtextdomain libintl_bindtextdomain #endif extern char *bindtextdomain (const char *__domainname, const char *__dirname) _INTL_ASM (libintl_bindtextdomain); #endif /* Specify the character encoding in which the messages from the DOMAINNAME message catalog will be returned. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_bind_textdomain_codeset (const char *__domainname, const char *__codeset); static inline char *bind_textdomain_codeset (const char *__domainname, const char *__codeset) { return libintl_bind_textdomain_codeset (__domainname, __codeset); } #else #ifdef _INTL_REDIRECT_MACROS # define bind_textdomain_codeset libintl_bind_textdomain_codeset #endif extern char *bind_textdomain_codeset (const char *__domainname, const char *__codeset) _INTL_ASM (libintl_bind_textdomain_codeset); #endif #endif /* IN_LIBGLOCALE */ /* Support for format strings with positions in *printf(), following the POSIX/XSI specification. Note: These replacements for the *printf() functions are visible only in source files that #include or #include "gettext.h". Packages that use *printf() in source files that don't refer to _() or gettext() but for which the format string could be the return value of _() or gettext() need to add this #include. Oh well. */ #if !@HAVE_POSIX_PRINTF@ #include #include /* Get va_list. */ #if __STDC__ || defined __cplusplus || defined _MSC_VER # include #else # include #endif #undef fprintf #define fprintf libintl_fprintf extern int fprintf (FILE *, const char *, ...); #undef vfprintf #define vfprintf libintl_vfprintf extern int vfprintf (FILE *, const char *, va_list); #undef printf #if defined __NetBSD__ || defined __BEOS__ || defined __CYGWIN__ || defined __MINGW32__ /* Don't break __attribute__((format(printf,M,N))). This redefinition is only possible because the libc in NetBSD, Cygwin, mingw does not have a function __printf__. */ # define libintl_printf __printf__ #endif #define printf libintl_printf extern int printf (const char *, ...); #undef vprintf #define vprintf libintl_vprintf extern int vprintf (const char *, va_list); #undef sprintf #define sprintf libintl_sprintf extern int sprintf (char *, const char *, ...); #undef vsprintf #define vsprintf libintl_vsprintf extern int vsprintf (char *, const char *, va_list); #if @HAVE_SNPRINTF@ #undef snprintf #define snprintf libintl_snprintf extern int snprintf (char *, size_t, const char *, ...); #undef vsnprintf #define vsnprintf libintl_vsnprintf extern int vsnprintf (char *, size_t, const char *, va_list); #endif #if @HAVE_ASPRINTF@ #undef asprintf #define asprintf libintl_asprintf extern int asprintf (char **, const char *, ...); #undef vasprintf #define vasprintf libintl_vasprintf extern int vasprintf (char **, const char *, va_list); #endif #if @HAVE_WPRINTF@ #undef fwprintf #define fwprintf libintl_fwprintf extern int fwprintf (FILE *, const wchar_t *, ...); #undef vfwprintf #define vfwprintf libintl_vfwprintf extern int vfwprintf (FILE *, const wchar_t *, va_list); #undef wprintf #define wprintf libintl_wprintf extern int wprintf (const wchar_t *, ...); #undef vwprintf #define vwprintf libintl_vwprintf extern int vwprintf (const wchar_t *, va_list); #undef swprintf #define swprintf libintl_swprintf extern int swprintf (wchar_t *, size_t, const wchar_t *, ...); #undef vswprintf #define vswprintf libintl_vswprintf extern int vswprintf (wchar_t *, size_t, const wchar_t *, va_list); #endif #endif /* Support for relocatable packages. */ /* Sets the original and the current installation prefix of the package. Relocation simply replaces a pathname starting with the original prefix by the corresponding pathname with the current prefix instead. Both prefixes should be directory names without trailing slash (i.e. use "" instead of "/"). */ #define libintl_set_relocation_prefix libintl_set_relocation_prefix extern void libintl_set_relocation_prefix (const char *orig_prefix, const char *curr_prefix); #ifdef __cplusplus } #endif #endif /* libintl.h */ libnih-1.0.3/intl/plural.y0000644000175000017500000001657611461165270012362 00000000000000%{ /* Expression parsing for plural form selection. Copyright (C) 2000-2001, 2003, 2005-2006 Free Software Foundation, Inc. Written by Ulrich Drepper , 2000. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* For bison < 2.0, the bison generated parser uses alloca. AIX 3 forces us to put this declaration at the beginning of the file. The declaration in bison's skeleton file comes too late. This must come before because may include arbitrary system headers. This can go away once the AM_INTL_SUBDIR macro requires bison >= 2.0. */ #if defined _AIX && !defined __GNUC__ #pragma alloca #endif #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include "plural-exp.h" /* The main function generated by the parser is called __gettextparse, but we want it to be called PLURAL_PARSE. */ #ifndef _LIBC # define __gettextparse PLURAL_PARSE #endif #define YYLEX_PARAM &((struct parse_args *) arg)->cp #define YYPARSE_PARAM arg %} %pure_parser %expect 7 %union { unsigned long int num; enum expression_operator op; struct expression *exp; } %{ /* Prototypes for local functions. */ static int yylex (YYSTYPE *lval, const char **pexp); static void yyerror (const char *str); /* Allocation of expressions. */ static struct expression * new_exp (int nargs, enum expression_operator op, struct expression * const *args) { int i; struct expression *newp; /* If any of the argument could not be malloc'ed, just return NULL. */ for (i = nargs - 1; i >= 0; i--) if (args[i] == NULL) goto fail; /* Allocate a new expression. */ newp = (struct expression *) malloc (sizeof (*newp)); if (newp != NULL) { newp->nargs = nargs; newp->operation = op; for (i = nargs - 1; i >= 0; i--) newp->val.args[i] = args[i]; return newp; } fail: for (i = nargs - 1; i >= 0; i--) FREE_EXPRESSION (args[i]); return NULL; } static inline struct expression * new_exp_0 (enum expression_operator op) { return new_exp (0, op, NULL); } static inline struct expression * new_exp_1 (enum expression_operator op, struct expression *right) { struct expression *args[1]; args[0] = right; return new_exp (1, op, args); } static struct expression * new_exp_2 (enum expression_operator op, struct expression *left, struct expression *right) { struct expression *args[2]; args[0] = left; args[1] = right; return new_exp (2, op, args); } static inline struct expression * new_exp_3 (enum expression_operator op, struct expression *bexp, struct expression *tbranch, struct expression *fbranch) { struct expression *args[3]; args[0] = bexp; args[1] = tbranch; args[2] = fbranch; return new_exp (3, op, args); } %} /* This declares that all operators have the same associativity and the precedence order as in C. See [Harbison, Steele: C, A Reference Manual]. There is no unary minus and no bitwise operators. Operators with the same syntactic behaviour have been merged into a single token, to save space in the array generated by bison. */ %right '?' /* ? */ %left '|' /* || */ %left '&' /* && */ %left EQUOP2 /* == != */ %left CMPOP2 /* < > <= >= */ %left ADDOP2 /* + - */ %left MULOP2 /* * / % */ %right '!' /* ! */ %token EQUOP2 CMPOP2 ADDOP2 MULOP2 %token NUMBER %type exp %% start: exp { if ($1 == NULL) YYABORT; ((struct parse_args *) arg)->res = $1; } ; exp: exp '?' exp ':' exp { $$ = new_exp_3 (qmop, $1, $3, $5); } | exp '|' exp { $$ = new_exp_2 (lor, $1, $3); } | exp '&' exp { $$ = new_exp_2 (land, $1, $3); } | exp EQUOP2 exp { $$ = new_exp_2 ($2, $1, $3); } | exp CMPOP2 exp { $$ = new_exp_2 ($2, $1, $3); } | exp ADDOP2 exp { $$ = new_exp_2 ($2, $1, $3); } | exp MULOP2 exp { $$ = new_exp_2 ($2, $1, $3); } | '!' exp { $$ = new_exp_1 (lnot, $2); } | 'n' { $$ = new_exp_0 (var); } | NUMBER { if (($$ = new_exp_0 (num)) != NULL) $$->val.num = $1; } | '(' exp ')' { $$ = $2; } ; %% void internal_function FREE_EXPRESSION (struct expression *exp) { if (exp == NULL) return; /* Handle the recursive case. */ switch (exp->nargs) { case 3: FREE_EXPRESSION (exp->val.args[2]); /* FALLTHROUGH */ case 2: FREE_EXPRESSION (exp->val.args[1]); /* FALLTHROUGH */ case 1: FREE_EXPRESSION (exp->val.args[0]); /* FALLTHROUGH */ default: break; } free (exp); } static int yylex (YYSTYPE *lval, const char **pexp) { const char *exp = *pexp; int result; while (1) { if (exp[0] == '\0') { *pexp = exp; return YYEOF; } if (exp[0] != ' ' && exp[0] != '\t') break; ++exp; } result = *exp++; switch (result) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { unsigned long int n = result - '0'; while (exp[0] >= '0' && exp[0] <= '9') { n *= 10; n += exp[0] - '0'; ++exp; } lval->num = n; result = NUMBER; } break; case '=': if (exp[0] == '=') { ++exp; lval->op = equal; result = EQUOP2; } else result = YYERRCODE; break; case '!': if (exp[0] == '=') { ++exp; lval->op = not_equal; result = EQUOP2; } break; case '&': case '|': if (exp[0] == result) ++exp; else result = YYERRCODE; break; case '<': if (exp[0] == '=') { ++exp; lval->op = less_or_equal; } else lval->op = less_than; result = CMPOP2; break; case '>': if (exp[0] == '=') { ++exp; lval->op = greater_or_equal; } else lval->op = greater_than; result = CMPOP2; break; case '*': lval->op = mult; result = MULOP2; break; case '/': lval->op = divide; result = MULOP2; break; case '%': lval->op = module; result = MULOP2; break; case '+': lval->op = plus; result = ADDOP2; break; case '-': lval->op = minus; result = ADDOP2; break; case 'n': case '?': case ':': case '(': case ')': /* Nothing, just return the character. */ break; case ';': case '\n': case '\0': /* Be safe and let the user call this function again. */ --exp; result = YYEOF; break; default: result = YYERRCODE; #if YYDEBUG != 0 --exp; #endif break; } *pexp = exp; return result; } static void yyerror (const char *str) { /* Do nothing. We don't print error messages here. */ } libnih-1.0.3/intl/dcngettext.c0000644000175000017500000000347411461165267013205 00000000000000/* Implementation of the dcngettext(3) function. Copyright (C) 1995-1999, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include "gettextP.h" #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* @@ end of prolog @@ */ /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define DCNGETTEXT __dcngettext # define DCIGETTEXT __dcigettext #else # define DCNGETTEXT libintl_dcngettext # define DCIGETTEXT libintl_dcigettext #endif /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY locale. */ char * DCNGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n, int category) { return DCIGETTEXT (domainname, msgid1, msgid2, 1, n, category); } #ifdef _LIBC /* Alias for function name in GNU C Library. */ weak_alias (__dcngettext, dcngettext); #endif libnih-1.0.3/intl/lock.h0000644000175000017500000012735611461165267011777 00000000000000/* Locking in multithreaded situations. Copyright (C) 2005-2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Bruno Haible , 2005. Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h, gthr-win32.h. */ /* This file contains locking primitives for use with a given thread library. It does not contain primitives for creating threads or for other synchronization primitives. Normal (non-recursive) locks: Type: gl_lock_t Declaration: gl_lock_define(extern, name) Initializer: gl_lock_define_initialized(, name) Initialization: gl_lock_init (name); Taking the lock: gl_lock_lock (name); Releasing the lock: gl_lock_unlock (name); De-initialization: gl_lock_destroy (name); Read-Write (non-recursive) locks: Type: gl_rwlock_t Declaration: gl_rwlock_define(extern, name) Initializer: gl_rwlock_define_initialized(, name) Initialization: gl_rwlock_init (name); Taking the lock: gl_rwlock_rdlock (name); gl_rwlock_wrlock (name); Releasing the lock: gl_rwlock_unlock (name); De-initialization: gl_rwlock_destroy (name); Recursive locks: Type: gl_recursive_lock_t Declaration: gl_recursive_lock_define(extern, name) Initializer: gl_recursive_lock_define_initialized(, name) Initialization: gl_recursive_lock_init (name); Taking the lock: gl_recursive_lock_lock (name); Releasing the lock: gl_recursive_lock_unlock (name); De-initialization: gl_recursive_lock_destroy (name); Once-only execution: Type: gl_once_t Initializer: gl_once_define(extern, name) Execution: gl_once (name, initfunction); */ #ifndef _LOCK_H #define _LOCK_H /* ========================================================================= */ #if USE_POSIX_THREADS /* Use the POSIX threads library. */ # include # include # ifdef __cplusplus extern "C" { # endif # if PTHREAD_IN_USE_DETECTION_HARD /* The pthread_in_use() detection needs to be done at runtime. */ # define pthread_in_use() \ glthread_in_use () extern int glthread_in_use (void); # endif # if USE_POSIX_THREADS_WEAK /* Use weak references to the POSIX threads library. */ /* Weak references avoid dragging in external libraries if the other parts of the program don't use them. Here we use them, because we don't want every program that uses libintl to depend on libpthread. This assumes that libpthread would not be loaded after libintl; i.e. if libintl is loaded first, by an executable that does not depend on libpthread, and then a module is dynamically loaded that depends on libpthread, libintl will not be multithread-safe. */ /* The way to test at runtime whether libpthread is present is to test whether a function pointer's value, such as &pthread_mutex_init, is non-NULL. However, some versions of GCC have a bug through which, in PIC mode, &foo != NULL always evaluates to true if there is a direct call to foo(...) in the same function. To avoid this, we test the address of a function in libpthread that we don't use. */ # pragma weak pthread_mutex_init # pragma weak pthread_mutex_lock # pragma weak pthread_mutex_unlock # pragma weak pthread_mutex_destroy # pragma weak pthread_rwlock_init # pragma weak pthread_rwlock_rdlock # pragma weak pthread_rwlock_wrlock # pragma weak pthread_rwlock_unlock # pragma weak pthread_rwlock_destroy # pragma weak pthread_once # pragma weak pthread_cond_init # pragma weak pthread_cond_wait # pragma weak pthread_cond_signal # pragma weak pthread_cond_broadcast # pragma weak pthread_cond_destroy # pragma weak pthread_mutexattr_init # pragma weak pthread_mutexattr_settype # pragma weak pthread_mutexattr_destroy # ifndef pthread_self # pragma weak pthread_self # endif # if !PTHREAD_IN_USE_DETECTION_HARD # pragma weak pthread_cancel # define pthread_in_use() (pthread_cancel != NULL) # endif # else # if !PTHREAD_IN_USE_DETECTION_HARD # define pthread_in_use() 1 # endif # endif /* -------------------------- gl_lock_t datatype -------------------------- */ typedef pthread_mutex_t gl_lock_t; # define gl_lock_define(STORAGECLASS, NAME) \ STORAGECLASS pthread_mutex_t NAME; # define gl_lock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS pthread_mutex_t NAME = gl_lock_initializer; # define gl_lock_initializer \ PTHREAD_MUTEX_INITIALIZER # define gl_lock_init(NAME) \ do \ { \ if (pthread_in_use () && pthread_mutex_init (&NAME, NULL) != 0) \ abort (); \ } \ while (0) # define gl_lock_lock(NAME) \ do \ { \ if (pthread_in_use () && pthread_mutex_lock (&NAME) != 0) \ abort (); \ } \ while (0) # define gl_lock_unlock(NAME) \ do \ { \ if (pthread_in_use () && pthread_mutex_unlock (&NAME) != 0) \ abort (); \ } \ while (0) # define gl_lock_destroy(NAME) \ do \ { \ if (pthread_in_use () && pthread_mutex_destroy (&NAME) != 0) \ abort (); \ } \ while (0) /* ------------------------- gl_rwlock_t datatype ------------------------- */ # if HAVE_PTHREAD_RWLOCK # ifdef PTHREAD_RWLOCK_INITIALIZER typedef pthread_rwlock_t gl_rwlock_t; # define gl_rwlock_define(STORAGECLASS, NAME) \ STORAGECLASS pthread_rwlock_t NAME; # define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS pthread_rwlock_t NAME = gl_rwlock_initializer; # define gl_rwlock_initializer \ PTHREAD_RWLOCK_INITIALIZER # define gl_rwlock_init(NAME) \ do \ { \ if (pthread_in_use () && pthread_rwlock_init (&NAME, NULL) != 0) \ abort (); \ } \ while (0) # define gl_rwlock_rdlock(NAME) \ do \ { \ if (pthread_in_use () && pthread_rwlock_rdlock (&NAME) != 0) \ abort (); \ } \ while (0) # define gl_rwlock_wrlock(NAME) \ do \ { \ if (pthread_in_use () && pthread_rwlock_wrlock (&NAME) != 0) \ abort (); \ } \ while (0) # define gl_rwlock_unlock(NAME) \ do \ { \ if (pthread_in_use () && pthread_rwlock_unlock (&NAME) != 0) \ abort (); \ } \ while (0) # define gl_rwlock_destroy(NAME) \ do \ { \ if (pthread_in_use () && pthread_rwlock_destroy (&NAME) != 0) \ abort (); \ } \ while (0) # else typedef struct { int initialized; pthread_mutex_t guard; /* protects the initialization */ pthread_rwlock_t rwlock; /* read-write lock */ } gl_rwlock_t; # define gl_rwlock_define(STORAGECLASS, NAME) \ STORAGECLASS gl_rwlock_t NAME; # define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; # define gl_rwlock_initializer \ { 0, PTHREAD_MUTEX_INITIALIZER } # define gl_rwlock_init(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_rwlock_init (&NAME); \ } \ while (0) # define gl_rwlock_rdlock(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_rwlock_rdlock (&NAME); \ } \ while (0) # define gl_rwlock_wrlock(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_rwlock_wrlock (&NAME); \ } \ while (0) # define gl_rwlock_unlock(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_rwlock_unlock (&NAME); \ } \ while (0) # define gl_rwlock_destroy(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_rwlock_destroy (&NAME); \ } \ while (0) extern void glthread_rwlock_init (gl_rwlock_t *lock); extern void glthread_rwlock_rdlock (gl_rwlock_t *lock); extern void glthread_rwlock_wrlock (gl_rwlock_t *lock); extern void glthread_rwlock_unlock (gl_rwlock_t *lock); extern void glthread_rwlock_destroy (gl_rwlock_t *lock); # endif # else typedef struct { pthread_mutex_t lock; /* protects the remaining fields */ pthread_cond_t waiting_readers; /* waiting readers */ pthread_cond_t waiting_writers; /* waiting writers */ unsigned int waiting_writers_count; /* number of waiting writers */ int runcount; /* number of readers running, or -1 when a writer runs */ } gl_rwlock_t; # define gl_rwlock_define(STORAGECLASS, NAME) \ STORAGECLASS gl_rwlock_t NAME; # define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; # define gl_rwlock_initializer \ { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0 } # define gl_rwlock_init(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_rwlock_init (&NAME); \ } \ while (0) # define gl_rwlock_rdlock(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_rwlock_rdlock (&NAME); \ } \ while (0) # define gl_rwlock_wrlock(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_rwlock_wrlock (&NAME); \ } \ while (0) # define gl_rwlock_unlock(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_rwlock_unlock (&NAME); \ } \ while (0) # define gl_rwlock_destroy(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_rwlock_destroy (&NAME); \ } \ while (0) extern void glthread_rwlock_init (gl_rwlock_t *lock); extern void glthread_rwlock_rdlock (gl_rwlock_t *lock); extern void glthread_rwlock_wrlock (gl_rwlock_t *lock); extern void glthread_rwlock_unlock (gl_rwlock_t *lock); extern void glthread_rwlock_destroy (gl_rwlock_t *lock); # endif /* --------------------- gl_recursive_lock_t datatype --------------------- */ # if HAVE_PTHREAD_MUTEX_RECURSIVE # if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP typedef pthread_mutex_t gl_recursive_lock_t; # define gl_recursive_lock_define(STORAGECLASS, NAME) \ STORAGECLASS pthread_mutex_t NAME; # define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS pthread_mutex_t NAME = gl_recursive_lock_initializer; # ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER # define gl_recursive_lock_initializer \ PTHREAD_RECURSIVE_MUTEX_INITIALIZER # else # define gl_recursive_lock_initializer \ PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP # endif # define gl_recursive_lock_init(NAME) \ do \ { \ if (pthread_in_use () && pthread_mutex_init (&NAME, NULL) != 0) \ abort (); \ } \ while (0) # define gl_recursive_lock_lock(NAME) \ do \ { \ if (pthread_in_use () && pthread_mutex_lock (&NAME) != 0) \ abort (); \ } \ while (0) # define gl_recursive_lock_unlock(NAME) \ do \ { \ if (pthread_in_use () && pthread_mutex_unlock (&NAME) != 0) \ abort (); \ } \ while (0) # define gl_recursive_lock_destroy(NAME) \ do \ { \ if (pthread_in_use () && pthread_mutex_destroy (&NAME) != 0) \ abort (); \ } \ while (0) # else typedef struct { pthread_mutex_t recmutex; /* recursive mutex */ pthread_mutex_t guard; /* protects the initialization */ int initialized; } gl_recursive_lock_t; # define gl_recursive_lock_define(STORAGECLASS, NAME) \ STORAGECLASS gl_recursive_lock_t NAME; # define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; # define gl_recursive_lock_initializer \ { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, 0 } # define gl_recursive_lock_init(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_recursive_lock_init (&NAME); \ } \ while (0) # define gl_recursive_lock_lock(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_recursive_lock_lock (&NAME); \ } \ while (0) # define gl_recursive_lock_unlock(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_recursive_lock_unlock (&NAME); \ } \ while (0) # define gl_recursive_lock_destroy(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_recursive_lock_destroy (&NAME); \ } \ while (0) extern void glthread_recursive_lock_init (gl_recursive_lock_t *lock); extern void glthread_recursive_lock_lock (gl_recursive_lock_t *lock); extern void glthread_recursive_lock_unlock (gl_recursive_lock_t *lock); extern void glthread_recursive_lock_destroy (gl_recursive_lock_t *lock); # endif # else /* Old versions of POSIX threads on Solaris did not have recursive locks. We have to implement them ourselves. */ typedef struct { pthread_mutex_t mutex; pthread_t owner; unsigned long depth; } gl_recursive_lock_t; # define gl_recursive_lock_define(STORAGECLASS, NAME) \ STORAGECLASS gl_recursive_lock_t NAME; # define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; # define gl_recursive_lock_initializer \ { PTHREAD_MUTEX_INITIALIZER, (pthread_t) 0, 0 } # define gl_recursive_lock_init(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_recursive_lock_init (&NAME); \ } \ while (0) # define gl_recursive_lock_lock(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_recursive_lock_lock (&NAME); \ } \ while (0) # define gl_recursive_lock_unlock(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_recursive_lock_unlock (&NAME); \ } \ while (0) # define gl_recursive_lock_destroy(NAME) \ do \ { \ if (pthread_in_use ()) \ glthread_recursive_lock_destroy (&NAME); \ } \ while (0) extern void glthread_recursive_lock_init (gl_recursive_lock_t *lock); extern void glthread_recursive_lock_lock (gl_recursive_lock_t *lock); extern void glthread_recursive_lock_unlock (gl_recursive_lock_t *lock); extern void glthread_recursive_lock_destroy (gl_recursive_lock_t *lock); # endif /* -------------------------- gl_once_t datatype -------------------------- */ typedef pthread_once_t gl_once_t; # define gl_once_define(STORAGECLASS, NAME) \ STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT; # define gl_once(NAME, INITFUNCTION) \ do \ { \ if (pthread_in_use ()) \ { \ if (pthread_once (&NAME, INITFUNCTION) != 0) \ abort (); \ } \ else \ { \ if (glthread_once_singlethreaded (&NAME)) \ INITFUNCTION (); \ } \ } \ while (0) extern int glthread_once_singlethreaded (pthread_once_t *once_control); # ifdef __cplusplus } # endif #endif /* ========================================================================= */ #if USE_PTH_THREADS /* Use the GNU Pth threads library. */ # include # include # ifdef __cplusplus extern "C" { # endif # if USE_PTH_THREADS_WEAK /* Use weak references to the GNU Pth threads library. */ # pragma weak pth_mutex_init # pragma weak pth_mutex_acquire # pragma weak pth_mutex_release # pragma weak pth_rwlock_init # pragma weak pth_rwlock_acquire # pragma weak pth_rwlock_release # pragma weak pth_once # pragma weak pth_cancel # define pth_in_use() (pth_cancel != NULL) # else # define pth_in_use() 1 # endif /* -------------------------- gl_lock_t datatype -------------------------- */ typedef pth_mutex_t gl_lock_t; # define gl_lock_define(STORAGECLASS, NAME) \ STORAGECLASS pth_mutex_t NAME; # define gl_lock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS pth_mutex_t NAME = gl_lock_initializer; # define gl_lock_initializer \ PTH_MUTEX_INIT # define gl_lock_init(NAME) \ do \ { \ if (pth_in_use() && !pth_mutex_init (&NAME)) \ abort (); \ } \ while (0) # define gl_lock_lock(NAME) \ do \ { \ if (pth_in_use() && !pth_mutex_acquire (&NAME, 0, NULL)) \ abort (); \ } \ while (0) # define gl_lock_unlock(NAME) \ do \ { \ if (pth_in_use() && !pth_mutex_release (&NAME)) \ abort (); \ } \ while (0) # define gl_lock_destroy(NAME) \ (void)(&NAME) /* ------------------------- gl_rwlock_t datatype ------------------------- */ typedef pth_rwlock_t gl_rwlock_t; # define gl_rwlock_define(STORAGECLASS, NAME) \ STORAGECLASS pth_rwlock_t NAME; # define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS pth_rwlock_t NAME = gl_rwlock_initializer; # define gl_rwlock_initializer \ PTH_RWLOCK_INIT # define gl_rwlock_init(NAME) \ do \ { \ if (pth_in_use() && !pth_rwlock_init (&NAME)) \ abort (); \ } \ while (0) # define gl_rwlock_rdlock(NAME) \ do \ { \ if (pth_in_use() \ && !pth_rwlock_acquire (&NAME, PTH_RWLOCK_RD, 0, NULL)) \ abort (); \ } \ while (0) # define gl_rwlock_wrlock(NAME) \ do \ { \ if (pth_in_use() \ && !pth_rwlock_acquire (&NAME, PTH_RWLOCK_RW, 0, NULL)) \ abort (); \ } \ while (0) # define gl_rwlock_unlock(NAME) \ do \ { \ if (pth_in_use() && !pth_rwlock_release (&NAME)) \ abort (); \ } \ while (0) # define gl_rwlock_destroy(NAME) \ (void)(&NAME) /* --------------------- gl_recursive_lock_t datatype --------------------- */ /* In Pth, mutexes are recursive by default. */ typedef pth_mutex_t gl_recursive_lock_t; # define gl_recursive_lock_define(STORAGECLASS, NAME) \ STORAGECLASS pth_mutex_t NAME; # define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS pth_mutex_t NAME = gl_recursive_lock_initializer; # define gl_recursive_lock_initializer \ PTH_MUTEX_INIT # define gl_recursive_lock_init(NAME) \ do \ { \ if (pth_in_use() && !pth_mutex_init (&NAME)) \ abort (); \ } \ while (0) # define gl_recursive_lock_lock(NAME) \ do \ { \ if (pth_in_use() && !pth_mutex_acquire (&NAME, 0, NULL)) \ abort (); \ } \ while (0) # define gl_recursive_lock_unlock(NAME) \ do \ { \ if (pth_in_use() && !pth_mutex_release (&NAME)) \ abort (); \ } \ while (0) # define gl_recursive_lock_destroy(NAME) \ (void)(&NAME) /* -------------------------- gl_once_t datatype -------------------------- */ typedef pth_once_t gl_once_t; # define gl_once_define(STORAGECLASS, NAME) \ STORAGECLASS pth_once_t NAME = PTH_ONCE_INIT; # define gl_once(NAME, INITFUNCTION) \ do \ { \ if (pth_in_use ()) \ { \ void (*gl_once_temp) (void) = INITFUNCTION; \ if (!pth_once (&NAME, glthread_once_call, &gl_once_temp)) \ abort (); \ } \ else \ { \ if (glthread_once_singlethreaded (&NAME)) \ INITFUNCTION (); \ } \ } \ while (0) extern void glthread_once_call (void *arg); extern int glthread_once_singlethreaded (pth_once_t *once_control); # ifdef __cplusplus } # endif #endif /* ========================================================================= */ #if USE_SOLARIS_THREADS /* Use the old Solaris threads library. */ # include # include # include # ifdef __cplusplus extern "C" { # endif # if USE_SOLARIS_THREADS_WEAK /* Use weak references to the old Solaris threads library. */ # pragma weak mutex_init # pragma weak mutex_lock # pragma weak mutex_unlock # pragma weak mutex_destroy # pragma weak rwlock_init # pragma weak rw_rdlock # pragma weak rw_wrlock # pragma weak rw_unlock # pragma weak rwlock_destroy # pragma weak thr_self # pragma weak thr_suspend # define thread_in_use() (thr_suspend != NULL) # else # define thread_in_use() 1 # endif /* -------------------------- gl_lock_t datatype -------------------------- */ typedef mutex_t gl_lock_t; # define gl_lock_define(STORAGECLASS, NAME) \ STORAGECLASS mutex_t NAME; # define gl_lock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS mutex_t NAME = gl_lock_initializer; # define gl_lock_initializer \ DEFAULTMUTEX # define gl_lock_init(NAME) \ do \ { \ if (thread_in_use () && mutex_init (&NAME, USYNC_THREAD, NULL) != 0) \ abort (); \ } \ while (0) # define gl_lock_lock(NAME) \ do \ { \ if (thread_in_use () && mutex_lock (&NAME) != 0) \ abort (); \ } \ while (0) # define gl_lock_unlock(NAME) \ do \ { \ if (thread_in_use () && mutex_unlock (&NAME) != 0) \ abort (); \ } \ while (0) # define gl_lock_destroy(NAME) \ do \ { \ if (thread_in_use () && mutex_destroy (&NAME) != 0) \ abort (); \ } \ while (0) /* ------------------------- gl_rwlock_t datatype ------------------------- */ typedef rwlock_t gl_rwlock_t; # define gl_rwlock_define(STORAGECLASS, NAME) \ STORAGECLASS rwlock_t NAME; # define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS rwlock_t NAME = gl_rwlock_initializer; # define gl_rwlock_initializer \ DEFAULTRWLOCK # define gl_rwlock_init(NAME) \ do \ { \ if (thread_in_use () && rwlock_init (&NAME, USYNC_THREAD, NULL) != 0) \ abort (); \ } \ while (0) # define gl_rwlock_rdlock(NAME) \ do \ { \ if (thread_in_use () && rw_rdlock (&NAME) != 0) \ abort (); \ } \ while (0) # define gl_rwlock_wrlock(NAME) \ do \ { \ if (thread_in_use () && rw_wrlock (&NAME) != 0) \ abort (); \ } \ while (0) # define gl_rwlock_unlock(NAME) \ do \ { \ if (thread_in_use () && rw_unlock (&NAME) != 0) \ abort (); \ } \ while (0) # define gl_rwlock_destroy(NAME) \ do \ { \ if (thread_in_use () && rwlock_destroy (&NAME) != 0) \ abort (); \ } \ while (0) /* --------------------- gl_recursive_lock_t datatype --------------------- */ /* Old Solaris threads did not have recursive locks. We have to implement them ourselves. */ typedef struct { mutex_t mutex; thread_t owner; unsigned long depth; } gl_recursive_lock_t; # define gl_recursive_lock_define(STORAGECLASS, NAME) \ STORAGECLASS gl_recursive_lock_t NAME; # define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; # define gl_recursive_lock_initializer \ { DEFAULTMUTEX, (thread_t) 0, 0 } # define gl_recursive_lock_init(NAME) \ do \ { \ if (thread_in_use ()) \ glthread_recursive_lock_init (&NAME); \ } \ while (0) # define gl_recursive_lock_lock(NAME) \ do \ { \ if (thread_in_use ()) \ glthread_recursive_lock_lock (&NAME); \ } \ while (0) # define gl_recursive_lock_unlock(NAME) \ do \ { \ if (thread_in_use ()) \ glthread_recursive_lock_unlock (&NAME); \ } \ while (0) # define gl_recursive_lock_destroy(NAME) \ do \ { \ if (thread_in_use ()) \ glthread_recursive_lock_destroy (&NAME); \ } \ while (0) extern void glthread_recursive_lock_init (gl_recursive_lock_t *lock); extern void glthread_recursive_lock_lock (gl_recursive_lock_t *lock); extern void glthread_recursive_lock_unlock (gl_recursive_lock_t *lock); extern void glthread_recursive_lock_destroy (gl_recursive_lock_t *lock); /* -------------------------- gl_once_t datatype -------------------------- */ typedef struct { volatile int inited; mutex_t mutex; } gl_once_t; # define gl_once_define(STORAGECLASS, NAME) \ STORAGECLASS gl_once_t NAME = { 0, DEFAULTMUTEX }; # define gl_once(NAME, INITFUNCTION) \ do \ { \ if (thread_in_use ()) \ { \ glthread_once (&NAME, INITFUNCTION); \ } \ else \ { \ if (glthread_once_singlethreaded (&NAME)) \ INITFUNCTION (); \ } \ } \ while (0) extern void glthread_once (gl_once_t *once_control, void (*initfunction) (void)); extern int glthread_once_singlethreaded (gl_once_t *once_control); # ifdef __cplusplus } # endif #endif /* ========================================================================= */ #if USE_WIN32_THREADS # include # ifdef __cplusplus extern "C" { # endif /* We can use CRITICAL_SECTION directly, rather than the Win32 Event, Mutex, Semaphore types, because - we need only to synchronize inside a single process (address space), not inter-process locking, - we don't need to support trylock operations. (TryEnterCriticalSection does not work on Windows 95/98/ME. Packages that need trylock usually define their own mutex type.) */ /* There is no way to statically initialize a CRITICAL_SECTION. It needs to be done lazily, once only. For this we need spinlocks. */ typedef struct { volatile int done; volatile long started; } gl_spinlock_t; /* -------------------------- gl_lock_t datatype -------------------------- */ typedef struct { gl_spinlock_t guard; /* protects the initialization */ CRITICAL_SECTION lock; } gl_lock_t; # define gl_lock_define(STORAGECLASS, NAME) \ STORAGECLASS gl_lock_t NAME; # define gl_lock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS gl_lock_t NAME = gl_lock_initializer; # define gl_lock_initializer \ { { 0, -1 } } # define gl_lock_init(NAME) \ glthread_lock_init (&NAME) # define gl_lock_lock(NAME) \ glthread_lock_lock (&NAME) # define gl_lock_unlock(NAME) \ glthread_lock_unlock (&NAME) # define gl_lock_destroy(NAME) \ glthread_lock_destroy (&NAME) extern void glthread_lock_init (gl_lock_t *lock); extern void glthread_lock_lock (gl_lock_t *lock); extern void glthread_lock_unlock (gl_lock_t *lock); extern void glthread_lock_destroy (gl_lock_t *lock); /* ------------------------- gl_rwlock_t datatype ------------------------- */ /* It is impossible to implement read-write locks using plain locks, without introducing an extra thread dedicated to managing read-write locks. Therefore here we need to use the low-level Event type. */ typedef struct { HANDLE *array; /* array of waiting threads, each represented by an event */ unsigned int count; /* number of waiting threads */ unsigned int alloc; /* length of allocated array */ unsigned int offset; /* index of first waiting thread in array */ } gl_waitqueue_t; typedef struct { gl_spinlock_t guard; /* protects the initialization */ CRITICAL_SECTION lock; /* protects the remaining fields */ gl_waitqueue_t waiting_readers; /* waiting readers */ gl_waitqueue_t waiting_writers; /* waiting writers */ int runcount; /* number of readers running, or -1 when a writer runs */ } gl_rwlock_t; # define gl_rwlock_define(STORAGECLASS, NAME) \ STORAGECLASS gl_rwlock_t NAME; # define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; # define gl_rwlock_initializer \ { { 0, -1 } } # define gl_rwlock_init(NAME) \ glthread_rwlock_init (&NAME) # define gl_rwlock_rdlock(NAME) \ glthread_rwlock_rdlock (&NAME) # define gl_rwlock_wrlock(NAME) \ glthread_rwlock_wrlock (&NAME) # define gl_rwlock_unlock(NAME) \ glthread_rwlock_unlock (&NAME) # define gl_rwlock_destroy(NAME) \ glthread_rwlock_destroy (&NAME) extern void glthread_rwlock_init (gl_rwlock_t *lock); extern void glthread_rwlock_rdlock (gl_rwlock_t *lock); extern void glthread_rwlock_wrlock (gl_rwlock_t *lock); extern void glthread_rwlock_unlock (gl_rwlock_t *lock); extern void glthread_rwlock_destroy (gl_rwlock_t *lock); /* --------------------- gl_recursive_lock_t datatype --------------------- */ /* The Win32 documentation says that CRITICAL_SECTION already implements a recursive lock. But we need not rely on it: It's easy to implement a recursive lock without this assumption. */ typedef struct { gl_spinlock_t guard; /* protects the initialization */ DWORD owner; unsigned long depth; CRITICAL_SECTION lock; } gl_recursive_lock_t; # define gl_recursive_lock_define(STORAGECLASS, NAME) \ STORAGECLASS gl_recursive_lock_t NAME; # define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; # define gl_recursive_lock_initializer \ { { 0, -1 }, 0, 0 } # define gl_recursive_lock_init(NAME) \ glthread_recursive_lock_init (&NAME) # define gl_recursive_lock_lock(NAME) \ glthread_recursive_lock_lock (&NAME) # define gl_recursive_lock_unlock(NAME) \ glthread_recursive_lock_unlock (&NAME) # define gl_recursive_lock_destroy(NAME) \ glthread_recursive_lock_destroy (&NAME) extern void glthread_recursive_lock_init (gl_recursive_lock_t *lock); extern void glthread_recursive_lock_lock (gl_recursive_lock_t *lock); extern void glthread_recursive_lock_unlock (gl_recursive_lock_t *lock); extern void glthread_recursive_lock_destroy (gl_recursive_lock_t *lock); /* -------------------------- gl_once_t datatype -------------------------- */ typedef struct { volatile int inited; volatile long started; CRITICAL_SECTION lock; } gl_once_t; # define gl_once_define(STORAGECLASS, NAME) \ STORAGECLASS gl_once_t NAME = { -1, -1 }; # define gl_once(NAME, INITFUNCTION) \ glthread_once (&NAME, INITFUNCTION) extern void glthread_once (gl_once_t *once_control, void (*initfunction) (void)); # ifdef __cplusplus } # endif #endif /* ========================================================================= */ #if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WIN32_THREADS) /* Provide dummy implementation if threads are not supported. */ /* -------------------------- gl_lock_t datatype -------------------------- */ typedef int gl_lock_t; # define gl_lock_define(STORAGECLASS, NAME) # define gl_lock_define_initialized(STORAGECLASS, NAME) # define gl_lock_init(NAME) # define gl_lock_lock(NAME) # define gl_lock_unlock(NAME) /* ------------------------- gl_rwlock_t datatype ------------------------- */ typedef int gl_rwlock_t; # define gl_rwlock_define(STORAGECLASS, NAME) # define gl_rwlock_define_initialized(STORAGECLASS, NAME) # define gl_rwlock_init(NAME) # define gl_rwlock_rdlock(NAME) # define gl_rwlock_wrlock(NAME) # define gl_rwlock_unlock(NAME) /* --------------------- gl_recursive_lock_t datatype --------------------- */ typedef int gl_recursive_lock_t; # define gl_recursive_lock_define(STORAGECLASS, NAME) # define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) # define gl_recursive_lock_init(NAME) # define gl_recursive_lock_lock(NAME) # define gl_recursive_lock_unlock(NAME) /* -------------------------- gl_once_t datatype -------------------------- */ typedef int gl_once_t; # define gl_once_define(STORAGECLASS, NAME) \ STORAGECLASS gl_once_t NAME = 0; # define gl_once(NAME, INITFUNCTION) \ do \ { \ if (NAME == 0) \ { \ NAME = ~ 0; \ INITFUNCTION (); \ } \ } \ while (0) #endif /* ========================================================================= */ #endif /* _LOCK_H */ libnih-1.0.3/intl/hash-string.h0000644000175000017500000000256611461165267013271 00000000000000/* Description of GNU message catalog format: string hashing function. Copyright (C) 1995, 1997-1998, 2000-2003, 2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* @@ end of prolog @@ */ /* We assume to have `unsigned long int' value with at least 32 bits. */ #define HASHWORDBITS 32 #ifndef _LIBC # ifdef IN_LIBINTL # define __hash_string libintl_hash_string # else # define __hash_string hash_string # endif #endif /* Defines the so called `hashpjw' function by P.J. Weinberger [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools, 1986, 1987 Bell Telephone Laboratories, Inc.] */ extern unsigned long int __hash_string (const char *str_param); libnih-1.0.3/intl/ref-add.sin0000644000175000017500000000210511461165270012665 00000000000000# Add this package to a list of references stored in a text file. # # Copyright (C) 2000 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. # # Written by Bruno Haible . # /^# Packages using this file: / { s/# Packages using this file:// ta :a s/ @PACKAGE@ / @PACKAGE@ / tb s/ $/ @PACKAGE@ / :b s/^/# Packages using this file:/ } libnih-1.0.3/intl/relocatable.h0000644000175000017500000000543211461165270013304 00000000000000/* Provide relocatable packages. Copyright (C) 2003, 2005 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _RELOCATABLE_H #define _RELOCATABLE_H #ifdef __cplusplus extern "C" { #endif /* This can be enabled through the configure --enable-relocatable option. */ #if ENABLE_RELOCATABLE /* When building a DLL, we must export some functions. Note that because this is a private .h file, we don't need to use __declspec(dllimport) in any case. */ #if HAVE_VISIBILITY && BUILDING_DLL # define RELOCATABLE_DLL_EXPORTED __attribute__((__visibility__("default"))) #elif defined _MSC_VER && BUILDING_DLL # define RELOCATABLE_DLL_EXPORTED __declspec(dllexport) #else # define RELOCATABLE_DLL_EXPORTED #endif /* Sets the original and the current installation prefix of the package. Relocation simply replaces a pathname starting with the original prefix by the corresponding pathname with the current prefix instead. Both prefixes should be directory names without trailing slash (i.e. use "" instead of "/"). */ extern RELOCATABLE_DLL_EXPORTED void set_relocation_prefix (const char *orig_prefix, const char *curr_prefix); /* Returns the pathname, relocated according to the current installation directory. */ extern const char * relocate (const char *pathname); /* Memory management: relocate() leaks memory, because it has to construct a fresh pathname. If this is a problem because your program calls relocate() frequently, think about caching the result. */ /* Convenience function: Computes the current installation prefix, based on the original installation prefix, the original installation directory of a particular file, and the current pathname of this file. Returns NULL upon failure. */ extern const char * compute_curr_prefix (const char *orig_installprefix, const char *orig_installdir, const char *curr_pathname); #else /* By default, we use the hardwired pathnames. */ #define relocate(pathname) (pathname) #endif #ifdef __cplusplus } #endif #endif /* _RELOCATABLE_H */ libnih-1.0.3/intl/eval-plural.h0000644000175000017500000000534211461165267013261 00000000000000/* Plural expression evaluation. Copyright (C) 2000-2003, 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef STATIC #define STATIC static #endif /* Evaluate the plural expression and return an index value. */ STATIC unsigned long int internal_function plural_eval (const struct expression *pexp, unsigned long int n) { switch (pexp->nargs) { case 0: switch (pexp->operation) { case var: return n; case num: return pexp->val.num; default: break; } /* NOTREACHED */ break; case 1: { /* pexp->operation must be lnot. */ unsigned long int arg = plural_eval (pexp->val.args[0], n); return ! arg; } case 2: { unsigned long int leftarg = plural_eval (pexp->val.args[0], n); if (pexp->operation == lor) return leftarg || plural_eval (pexp->val.args[1], n); else if (pexp->operation == land) return leftarg && plural_eval (pexp->val.args[1], n); else { unsigned long int rightarg = plural_eval (pexp->val.args[1], n); switch (pexp->operation) { case mult: return leftarg * rightarg; case divide: #if !INTDIV0_RAISES_SIGFPE if (rightarg == 0) raise (SIGFPE); #endif return leftarg / rightarg; case module: #if !INTDIV0_RAISES_SIGFPE if (rightarg == 0) raise (SIGFPE); #endif return leftarg % rightarg; case plus: return leftarg + rightarg; case minus: return leftarg - rightarg; case less_than: return leftarg < rightarg; case greater_than: return leftarg > rightarg; case less_or_equal: return leftarg <= rightarg; case greater_or_equal: return leftarg >= rightarg; case equal: return leftarg == rightarg; case not_equal: return leftarg != rightarg; default: break; } } /* NOTREACHED */ break; } case 3: { /* pexp->operation must be qmop. */ unsigned long int boolarg = plural_eval (pexp->val.args[0], n); return plural_eval (pexp->val.args[boolarg ? 1 : 2], n); } } /* NOTREACHED */ return 0; } libnih-1.0.3/intl/printf-args.h0000644000175000017500000000662111461165270013264 00000000000000/* Decomposed printf argument list. Copyright (C) 1999, 2002-2003, 2006-2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _PRINTF_ARGS_H #define _PRINTF_ARGS_H /* This file can be parametrized with the following macros: ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. PRINTF_FETCHARGS Name of the function to be declared. STATIC Set to 'static' to declare the function static. */ /* Default parameters. */ #ifndef PRINTF_FETCHARGS # define PRINTF_FETCHARGS printf_fetchargs #endif /* Get size_t. */ #include /* Get wchar_t. */ #if HAVE_WCHAR_T # include #endif /* Get wint_t. */ #if HAVE_WINT_T # include #endif /* Get va_list. */ #include /* Argument types */ typedef enum { TYPE_NONE, TYPE_SCHAR, TYPE_UCHAR, TYPE_SHORT, TYPE_USHORT, TYPE_INT, TYPE_UINT, TYPE_LONGINT, TYPE_ULONGINT, #if HAVE_LONG_LONG_INT TYPE_LONGLONGINT, TYPE_ULONGLONGINT, #endif TYPE_DOUBLE, TYPE_LONGDOUBLE, TYPE_CHAR, #if HAVE_WINT_T TYPE_WIDE_CHAR, #endif TYPE_STRING, #if HAVE_WCHAR_T TYPE_WIDE_STRING, #endif TYPE_POINTER, TYPE_COUNT_SCHAR_POINTER, TYPE_COUNT_SHORT_POINTER, TYPE_COUNT_INT_POINTER, TYPE_COUNT_LONGINT_POINTER #if HAVE_LONG_LONG_INT , TYPE_COUNT_LONGLONGINT_POINTER #endif #if ENABLE_UNISTDIO /* The unistdio extensions. */ , TYPE_U8_STRING , TYPE_U16_STRING , TYPE_U32_STRING #endif } arg_type; /* Polymorphic argument */ typedef struct { arg_type type; union { signed char a_schar; unsigned char a_uchar; short a_short; unsigned short a_ushort; int a_int; unsigned int a_uint; long int a_longint; unsigned long int a_ulongint; #if HAVE_LONG_LONG_INT long long int a_longlongint; unsigned long long int a_ulonglongint; #endif float a_float; double a_double; long double a_longdouble; int a_char; #if HAVE_WINT_T wint_t a_wide_char; #endif const char* a_string; #if HAVE_WCHAR_T const wchar_t* a_wide_string; #endif void* a_pointer; signed char * a_count_schar_pointer; short * a_count_short_pointer; int * a_count_int_pointer; long int * a_count_longint_pointer; #if HAVE_LONG_LONG_INT long long int * a_count_longlongint_pointer; #endif #if ENABLE_UNISTDIO /* The unistdio extensions. */ const uint8_t * a_u8_string; const uint16_t * a_u16_string; const uint32_t * a_u32_string; #endif } a; } argument; typedef struct { size_t count; argument *arg; } arguments; /* Fetch the arguments, putting them into a. */ #ifdef STATIC STATIC #else extern #endif int PRINTF_FETCHARGS (va_list args, arguments *a); #endif /* _PRINTF_ARGS_H */ libnih-1.0.3/intl/dcgettext.c0000644000175000017500000000342111461165267013017 00000000000000/* Implementation of the dcgettext(3) function. Copyright (C) 1995-1999, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include "gettextP.h" #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* @@ end of prolog @@ */ /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define DCGETTEXT __dcgettext # define DCIGETTEXT __dcigettext #else # define DCGETTEXT libintl_dcgettext # define DCIGETTEXT libintl_dcigettext #endif /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY locale. */ char * DCGETTEXT (const char *domainname, const char *msgid, int category) { return DCIGETTEXT (domainname, msgid, NULL, 0, 0, category); } #ifdef _LIBC /* Alias for function name in GNU C Library. */ INTDEF(__dcgettext) weak_alias (__dcgettext, dcgettext); #endif libnih-1.0.3/intl/localealias.c0000644000175000017500000002454611461165267013310 00000000000000/* Handle aliases for locale names. Copyright (C) 1995-1999, 2000-2001, 2003, 2005-2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Tell glibc's to provide a prototype for mempcpy(). This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #ifdef HAVE_CONFIG_H # include #endif #include #include #if defined _LIBC || defined HAVE___FSETLOCKING # include #endif #include #ifdef __GNUC__ # undef alloca # define alloca __builtin_alloca # define HAVE_ALLOCA 1 #else # ifdef _MSC_VER # include # define alloca _alloca # else # if defined HAVE_ALLOCA_H || defined _LIBC # include # else # ifdef _AIX #pragma alloca # else # ifndef alloca char *alloca (); # endif # endif # endif # endif #endif #include #include #include "gettextP.h" #if ENABLE_RELOCATABLE # include "relocatable.h" #else # define relocate(pathname) (pathname) #endif /* @@ end of prolog @@ */ #ifdef _LIBC /* Rename the non ANSI C functions. This is required by the standard because some ANSI C functions will require linking with this object file and the name space must not be polluted. */ # define strcasecmp __strcasecmp # ifndef mempcpy # define mempcpy __mempcpy # endif # define HAVE_MEMPCPY 1 # define HAVE___FSETLOCKING 1 #endif /* Handle multi-threaded applications. */ #ifdef _LIBC # include #else # include "lock.h" #endif #ifndef internal_function # define internal_function #endif /* Some optimizations for glibc. */ #ifdef _LIBC # define FEOF(fp) feof_unlocked (fp) # define FGETS(buf, n, fp) fgets_unlocked (buf, n, fp) #else # define FEOF(fp) feof (fp) # define FGETS(buf, n, fp) fgets (buf, n, fp) #endif /* For those losing systems which don't have `alloca' we have to add some additional code emulating it. */ #ifdef HAVE_ALLOCA # define freea(p) /* nothing */ #else # define alloca(n) malloc (n) # define freea(p) free (p) #endif #if defined _LIBC_REENTRANT || HAVE_DECL_FGETS_UNLOCKED # undef fgets # define fgets(buf, len, s) fgets_unlocked (buf, len, s) #endif #if defined _LIBC_REENTRANT || HAVE_DECL_FEOF_UNLOCKED # undef feof # define feof(s) feof_unlocked (s) #endif __libc_lock_define_initialized (static, lock) struct alias_map { const char *alias; const char *value; }; #ifndef _LIBC # define libc_freeres_ptr(decl) decl #endif libc_freeres_ptr (static char *string_space); static size_t string_space_act; static size_t string_space_max; libc_freeres_ptr (static struct alias_map *map); static size_t nmap; static size_t maxmap; /* Prototypes for local functions. */ static size_t read_alias_file (const char *fname, int fname_len) internal_function; static int extend_alias_table (void); static int alias_compare (const struct alias_map *map1, const struct alias_map *map2); const char * _nl_expand_alias (const char *name) { static const char *locale_alias_path; struct alias_map *retval; const char *result = NULL; size_t added; __libc_lock_lock (lock); if (locale_alias_path == NULL) locale_alias_path = LOCALE_ALIAS_PATH; do { struct alias_map item; item.alias = name; if (nmap > 0) retval = (struct alias_map *) bsearch (&item, map, nmap, sizeof (struct alias_map), (int (*) (const void *, const void *) ) alias_compare); else retval = NULL; /* We really found an alias. Return the value. */ if (retval != NULL) { result = retval->value; break; } /* Perhaps we can find another alias file. */ added = 0; while (added == 0 && locale_alias_path[0] != '\0') { const char *start; while (locale_alias_path[0] == PATH_SEPARATOR) ++locale_alias_path; start = locale_alias_path; while (locale_alias_path[0] != '\0' && locale_alias_path[0] != PATH_SEPARATOR) ++locale_alias_path; if (start < locale_alias_path) added = read_alias_file (start, locale_alias_path - start); } } while (added != 0); __libc_lock_unlock (lock); return result; } static size_t internal_function read_alias_file (const char *fname, int fname_len) { FILE *fp; char *full_fname; size_t added; static const char aliasfile[] = "/locale.alias"; full_fname = (char *) alloca (fname_len + sizeof aliasfile); #ifdef HAVE_MEMPCPY mempcpy (mempcpy (full_fname, fname, fname_len), aliasfile, sizeof aliasfile); #else memcpy (full_fname, fname, fname_len); memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile); #endif #ifdef _LIBC /* Note the file is opened with cancellation in the I/O functions disabled. */ fp = fopen (relocate (full_fname), "rc"); #else fp = fopen (relocate (full_fname), "r"); #endif freea (full_fname); if (fp == NULL) return 0; #ifdef HAVE___FSETLOCKING /* No threads present. */ __fsetlocking (fp, FSETLOCKING_BYCALLER); #endif added = 0; while (!FEOF (fp)) { /* It is a reasonable approach to use a fix buffer here because a) we are only interested in the first two fields b) these fields must be usable as file names and so must not be that long We avoid a multi-kilobyte buffer here since this would use up stack space which we might not have if the program ran out of memory. */ char buf[400]; char *alias; char *value; char *cp; int complete_line; if (FGETS (buf, sizeof buf, fp) == NULL) /* EOF reached. */ break; /* Determine whether the line is complete. */ complete_line = strchr (buf, '\n') != NULL; cp = buf; /* Ignore leading white space. */ while (isspace ((unsigned char) cp[0])) ++cp; /* A leading '#' signals a comment line. */ if (cp[0] != '\0' && cp[0] != '#') { alias = cp++; while (cp[0] != '\0' && !isspace ((unsigned char) cp[0])) ++cp; /* Terminate alias name. */ if (cp[0] != '\0') *cp++ = '\0'; /* Now look for the beginning of the value. */ while (isspace ((unsigned char) cp[0])) ++cp; if (cp[0] != '\0') { value = cp++; while (cp[0] != '\0' && !isspace ((unsigned char) cp[0])) ++cp; /* Terminate value. */ if (cp[0] == '\n') { /* This has to be done to make the following test for the end of line possible. We are looking for the terminating '\n' which do not overwrite here. */ *cp++ = '\0'; *cp = '\n'; } else if (cp[0] != '\0') *cp++ = '\0'; #ifdef IN_LIBGLOCALE /* glibc's locale.alias contains entries for ja_JP and ko_KR that make it impossible to use a Japanese or Korean UTF-8 locale under the name "ja_JP" or "ko_KR". Ignore these entries. */ if (strchr (alias, '_') == NULL) #endif { size_t alias_len; size_t value_len; if (nmap >= maxmap) if (__builtin_expect (extend_alias_table (), 0)) goto out; alias_len = strlen (alias) + 1; value_len = strlen (value) + 1; if (string_space_act + alias_len + value_len > string_space_max) { /* Increase size of memory pool. */ size_t new_size = (string_space_max + (alias_len + value_len > 1024 ? alias_len + value_len : 1024)); char *new_pool = (char *) realloc (string_space, new_size); if (new_pool == NULL) goto out; if (__builtin_expect (string_space != new_pool, 0)) { size_t i; for (i = 0; i < nmap; i++) { map[i].alias += new_pool - string_space; map[i].value += new_pool - string_space; } } string_space = new_pool; string_space_max = new_size; } map[nmap].alias = (const char *) memcpy (&string_space[string_space_act], alias, alias_len); string_space_act += alias_len; map[nmap].value = (const char *) memcpy (&string_space[string_space_act], value, value_len); string_space_act += value_len; ++nmap; ++added; } } } /* Possibly not the whole line fits into the buffer. Ignore the rest of the line. */ if (! complete_line) do if (FGETS (buf, sizeof buf, fp) == NULL) /* Make sure the inner loop will be left. The outer loop will exit at the `feof' test. */ break; while (strchr (buf, '\n') == NULL); } out: /* Should we test for ferror()? I think we have to silently ignore errors. --drepper */ fclose (fp); if (added > 0) qsort (map, nmap, sizeof (struct alias_map), (int (*) (const void *, const void *)) alias_compare); return added; } static int extend_alias_table () { size_t new_size; struct alias_map *new_map; new_size = maxmap == 0 ? 100 : 2 * maxmap; new_map = (struct alias_map *) realloc (map, (new_size * sizeof (struct alias_map))); if (new_map == NULL) /* Simply don't extend: we don't have any more core. */ return -1; map = new_map; maxmap = new_size; return 0; } static int alias_compare (const struct alias_map *map1, const struct alias_map *map2) { #if defined _LIBC || defined HAVE_STRCASECMP return strcasecmp (map1->alias, map2->alias); #else const unsigned char *p1 = (const unsigned char *) map1->alias; const unsigned char *p2 = (const unsigned char *) map2->alias; unsigned char c1, c2; if (p1 == p2) return 0; do { /* I know this seems to be odd but the tolower() function in some systems libc cannot handle nonalpha characters. */ c1 = isupper (*p1) ? tolower (*p1) : *p1; c2 = isupper (*p2) ? tolower (*p2) : *p2; if (c1 == '\0') break; ++p1; ++p2; } while (c1 == c2); return c1 - c2; #endif } libnih-1.0.3/intl/wprintf-parse.h0000644000175000017500000000426311461165270013631 00000000000000/* Parse printf format string. Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _WPRINTF_PARSE_H #define _WPRINTF_PARSE_H #include "printf-args.h" /* Flags */ #define FLAG_GROUP 1 /* ' flag */ #define FLAG_LEFT 2 /* - flag */ #define FLAG_SHOWSIGN 4 /* + flag */ #define FLAG_SPACE 8 /* space flag */ #define FLAG_ALT 16 /* # flag */ #define FLAG_ZERO 32 /* arg_index value indicating that no argument is consumed. */ #define ARG_NONE (~(size_t)0) /* A parsed directive. */ typedef struct { const wchar_t* dir_start; const wchar_t* dir_end; int flags; const wchar_t* width_start; const wchar_t* width_end; size_t width_arg_index; const wchar_t* precision_start; const wchar_t* precision_end; size_t precision_arg_index; wchar_t conversion; /* d i o u x X f e E g G c s p n U % but not C S */ size_t arg_index; } wchar_t_directive; /* A parsed format string. */ typedef struct { size_t count; wchar_t_directive *dir; size_t max_width_length; size_t max_precision_length; } wchar_t_directives; /* Parses the format string. Fills in the number N of directives, and fills in directives[0], ..., directives[N-1], and sets directives[N].dir_start to the end of the format string. Also fills in the arg_type fields of the arguments and the needed count of arguments. */ #ifdef STATIC STATIC #else extern #endif int wprintf_parse (const wchar_t *format, wchar_t_directives *d, arguments *a); #endif /* _WPRINTF_PARSE_H */ libnih-1.0.3/intl/intl-compat.c0000644000175000017500000000662411461165267013263 00000000000000/* intl-compat.c - Stub functions to call gettext functions from GNU gettext Library. Copyright (C) 1995, 2000-2003, 2005 Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include "gettextP.h" /* @@ end of prolog @@ */ /* This file redirects the gettext functions (without prefix) to those defined in the included GNU libintl library (with "libintl_" prefix). It is compiled into libintl in order to make the AM_GNU_GETTEXT test of gettext <= 0.11.2 work with the libintl library >= 0.11.3 which has the redirections primarily in the include file. It is also compiled into libgnuintl so that libgnuintl.so can be used as LD_PRELOADable library on glibc systems, to provide the extra features that the functions in the libc don't have (namely, logging). */ #undef gettext #undef dgettext #undef dcgettext #undef ngettext #undef dngettext #undef dcngettext #undef textdomain #undef bindtextdomain #undef bind_textdomain_codeset /* When building a DLL, we must export some functions. Note that because the functions are only defined for binary backward compatibility, we don't need to use __declspec(dllimport) in any case. */ #if HAVE_VISIBILITY && BUILDING_DLL # define DLL_EXPORTED __attribute__((__visibility__("default"))) #elif defined _MSC_VER && BUILDING_DLL # define DLL_EXPORTED __declspec(dllexport) #else # define DLL_EXPORTED #endif DLL_EXPORTED char * gettext (const char *msgid) { return libintl_gettext (msgid); } DLL_EXPORTED char * dgettext (const char *domainname, const char *msgid) { return libintl_dgettext (domainname, msgid); } DLL_EXPORTED char * dcgettext (const char *domainname, const char *msgid, int category) { return libintl_dcgettext (domainname, msgid, category); } DLL_EXPORTED char * ngettext (const char *msgid1, const char *msgid2, unsigned long int n) { return libintl_ngettext (msgid1, msgid2, n); } DLL_EXPORTED char * dngettext (const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n) { return libintl_dngettext (domainname, msgid1, msgid2, n); } DLL_EXPORTED char * dcngettext (const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n, int category) { return libintl_dcngettext (domainname, msgid1, msgid2, n, category); } DLL_EXPORTED char * textdomain (const char *domainname) { return libintl_textdomain (domainname); } DLL_EXPORTED char * bindtextdomain (const char *domainname, const char *dirname) { return libintl_bindtextdomain (domainname, dirname); } DLL_EXPORTED char * bind_textdomain_codeset (const char *domainname, const char *codeset) { return libintl_bind_textdomain_codeset (domainname, codeset); } libnih-1.0.3/intl/libintl.rc0000644000175000017500000000323311461165267012644 00000000000000/* Resources for intl.dll */ #include VS_VERSION_INFO VERSIONINFO FILEVERSION PACKAGE_VERSION_MAJOR,PACKAGE_VERSION_MINOR,PACKAGE_VERSION_SUBMINOR,0 PRODUCTVERSION PACKAGE_VERSION_MAJOR,PACKAGE_VERSION_MINOR,PACKAGE_VERSION_SUBMINOR,0 FILEFLAGSMASK 0x3fL /* VS_FFI_FILEFLAGSMASK */ #ifdef _DEBUG FILEFLAGS 0x1L /* VS_FF_DEBUG */ #else FILEFLAGS 0x0L #endif FILEOS 0x10004L /* VOS_DOS_WINDOWS32 */ FILETYPE 0x2L /* VFT_DLL */ FILESUBTYPE 0x0L /* VFT2_UNKNOWN */ BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "04090000" /* Lang = US English, Charset = ASCII */ BEGIN VALUE "Comments", "This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\0" VALUE "CompanyName", "Free Software Foundation\0" VALUE "FileDescription", "LGPLed libintl for Windows NT/2000/XP/Vista and Windows 95/98/ME\0" VALUE "FileVersion", PACKAGE_VERSION_STRING "\0" VALUE "InternalName", "intl.dll\0" VALUE "LegalCopyright", "Copyright (C) 1995-2007\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "intl.dll\0" VALUE "ProductName", "libintl: accessing NLS message catalogs\0" VALUE "ProductVersion", PACKAGE_VERSION_STRING "\0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x0409, 0 /* US English, ASCII */ END END libnih-1.0.3/intl/Makefile.in0000644000175000017500000005041311461165267012730 00000000000000# Makefile for directory with message catalog handling library of GNU gettext # Copyright (C) 1995-1998, 2000-2007 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. PACKAGE = @PACKAGE@ VERSION = @VERSION@ SHELL = /bin/sh srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = .. # The VPATH variables allows builds with $builddir != $srcdir, assuming a # 'make' program that supports VPATH (such as GNU make). This line is removed # by autoconf automatically when "$(srcdir)" = ".". # In this directory, the VPATH handling is particular: # 1. If INTL_LIBTOOL_SUFFIX_PREFIX is 'l' (indicating a build with libtool), # the .c -> .lo rules carefully use $(srcdir), so that VPATH can be omitted. # 2. If PACKAGE = gettext-tools, VPATH _must_ be omitted, because otherwise # 'make' does the wrong thing if GNU gettext was configured with # "./configure --srcdir=`pwd`", namely it gets confused by the .lo and .la # files it finds in srcdir = ../../gettext-runtime/intl. VPATH = $(srcdir) prefix = @prefix@ exec_prefix = @exec_prefix@ transform = @program_transform_name@ libdir = @libdir@ includedir = @includedir@ datarootdir = @datarootdir@ datadir = @datadir@ localedir = $(datadir)/locale gettextsrcdir = $(datadir)/gettext/intl aliaspath = $(localedir) subdir = intl INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ # We use $(mkdir_p). # In automake <= 1.9.x, $(mkdir_p) is defined either as "mkdir -p --" or as # "$(mkinstalldirs)" or as "$(install_sh) -d". For these automake versions, # @install_sh@ does not start with $(SHELL), so we add it. # In automake >= 1.10, @mkdir_p@ is derived from ${MKDIR_P}, which is defined # either as "/path/to/mkdir -p" or ".../install-sh -c -d". For these automake # versions, $(mkinstalldirs) and $(install_sh) are unused. mkinstalldirs = $(SHELL) @install_sh@ -d install_sh = $(SHELL) @install_sh@ MKDIR_P = @MKDIR_P@ mkdir_p = @mkdir_p@ l = @INTL_LIBTOOL_SUFFIX_PREFIX@ AR = ar CC = @CC@ LIBTOOL = @LIBTOOL@ RANLIB = @RANLIB@ YACC = @INTLBISON@ -y -d YFLAGS = --name-prefix=__gettext WINDRES = @WINDRES@ # -DBUILDING_LIBINTL: Change expansion of LIBINTL_DLL_EXPORTED macro. # -DBUILDING_DLL: Change expansion of RELOCATABLE_DLL_EXPORTED macro. DEFS = -DLOCALEDIR=\"$(localedir)\" -DLOCALE_ALIAS_PATH=\"$(aliaspath)\" \ -DLIBDIR=\"$(libdir)\" -DBUILDING_LIBINTL -DBUILDING_DLL -DIN_LIBINTL \ -DENABLE_RELOCATABLE=1 -DIN_LIBRARY -DINSTALLDIR=\"$(libdir)\" -DNO_XMALLOC \ -Dset_relocation_prefix=libintl_set_relocation_prefix \ -Drelocate=libintl_relocate \ -DDEPENDS_ON_LIBICONV=1 @DEFS@ CPPFLAGS = @CPPFLAGS@ CFLAGS = @CFLAGS@ @CFLAG_VISIBILITY@ LDFLAGS = @LDFLAGS@ $(LDFLAGS_@WOE32DLL@) LDFLAGS_yes = -Wl,--export-all-symbols LDFLAGS_no = LIBS = @LIBS@ COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(XCFLAGS) HEADERS = \ gmo.h \ gettextP.h \ hash-string.h \ loadinfo.h \ plural-exp.h \ eval-plural.h \ localcharset.h \ lock.h \ relocatable.h \ tsearch.h tsearch.c \ xsize.h \ printf-args.h printf-args.c \ printf-parse.h wprintf-parse.h printf-parse.c \ vasnprintf.h vasnwprintf.h vasnprintf.c \ os2compat.h \ libgnuintl.h.in SOURCES = \ bindtextdom.c \ dcgettext.c \ dgettext.c \ gettext.c \ finddomain.c \ hash-string.c \ loadmsgcat.c \ localealias.c \ textdomain.c \ l10nflist.c \ explodename.c \ dcigettext.c \ dcngettext.c \ dngettext.c \ ngettext.c \ plural.y \ plural-exp.c \ localcharset.c \ lock.c \ relocatable.c \ langprefs.c \ localename.c \ log.c \ printf.c \ version.c \ osdep.c \ os2compat.c \ intl-exports.c \ intl-compat.c OBJECTS = \ bindtextdom.$lo \ dcgettext.$lo \ dgettext.$lo \ gettext.$lo \ finddomain.$lo \ hash-string.$lo \ loadmsgcat.$lo \ localealias.$lo \ textdomain.$lo \ l10nflist.$lo \ explodename.$lo \ dcigettext.$lo \ dcngettext.$lo \ dngettext.$lo \ ngettext.$lo \ plural.$lo \ plural-exp.$lo \ localcharset.$lo \ lock.$lo \ relocatable.$lo \ langprefs.$lo \ localename.$lo \ log.$lo \ printf.$lo \ version.$lo \ osdep.$lo \ intl-compat.$lo OBJECTS_RES_yes = libintl.res OBJECTS_RES_no = DISTFILES.common = Makefile.in \ config.charset locale.alias ref-add.sin ref-del.sin export.h libintl.rc \ $(HEADERS) $(SOURCES) DISTFILES.generated = plural.c DISTFILES.normal = VERSION DISTFILES.gettext = COPYING.LIB-2.0 COPYING.LIB-2.1 libintl.glibc README.woe32 DISTFILES.obsolete = xopen-msg.sed linux-msg.sed po2tbl.sed.in cat-compat.c \ COPYING.LIB-2 gettext.h libgettext.h plural-eval.c libgnuintl.h \ libgnuintl.h_vms Makefile.vms libgnuintl.h.msvc-static \ libgnuintl.h.msvc-shared Makefile.msvc all: all-@USE_INCLUDED_LIBINTL@ all-yes: libintl.$la libintl.h charset.alias ref-add.sed ref-del.sed all-no: all-no-@BUILD_INCLUDED_LIBINTL@ all-no-yes: libgnuintl.$la all-no-no: libintl.a libgnuintl.a: $(OBJECTS) rm -f $@ $(AR) cru $@ $(OBJECTS) $(RANLIB) $@ libintl.la libgnuintl.la: $(OBJECTS) $(OBJECTS_RES_@WOE32@) $(LIBTOOL) --mode=link \ $(CC) $(CPPFLAGS) $(CFLAGS) $(XCFLAGS) $(LDFLAGS) -o $@ \ $(OBJECTS) @LTLIBICONV@ @INTL_MACOSX_LIBS@ $(LIBS) @LTLIBTHREAD@ @LTLIBC@ \ $(OBJECTS_RES_@WOE32@) \ -version-info $(LTV_CURRENT):$(LTV_REVISION):$(LTV_AGE) \ -rpath $(libdir) \ -no-undefined # Libtool's library version information for libintl. # Before making a gettext release, the gettext maintainer must change this # according to the libtool documentation, section "Library interface versions". # Maintainers of other packages that include the intl directory must *not* # change these values. LTV_CURRENT=8 LTV_REVISION=2 LTV_AGE=0 .SUFFIXES: .SUFFIXES: .c .y .o .lo .sin .sed .c.o: $(COMPILE) $< .y.c: $(YACC) $(YFLAGS) --output $@ $< rm -f $*.h bindtextdom.lo: $(srcdir)/bindtextdom.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/bindtextdom.c dcgettext.lo: $(srcdir)/dcgettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dcgettext.c dgettext.lo: $(srcdir)/dgettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dgettext.c gettext.lo: $(srcdir)/gettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/gettext.c finddomain.lo: $(srcdir)/finddomain.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/finddomain.c hash-string.lo: $(srcdir)/hash-string.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/hash-string.c loadmsgcat.lo: $(srcdir)/loadmsgcat.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/loadmsgcat.c localealias.lo: $(srcdir)/localealias.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/localealias.c textdomain.lo: $(srcdir)/textdomain.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/textdomain.c l10nflist.lo: $(srcdir)/l10nflist.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/l10nflist.c explodename.lo: $(srcdir)/explodename.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/explodename.c dcigettext.lo: $(srcdir)/dcigettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dcigettext.c dcngettext.lo: $(srcdir)/dcngettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dcngettext.c dngettext.lo: $(srcdir)/dngettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dngettext.c ngettext.lo: $(srcdir)/ngettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/ngettext.c plural.lo: $(srcdir)/plural.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/plural.c plural-exp.lo: $(srcdir)/plural-exp.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/plural-exp.c localcharset.lo: $(srcdir)/localcharset.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/localcharset.c lock.lo: $(srcdir)/lock.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/lock.c relocatable.lo: $(srcdir)/relocatable.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/relocatable.c langprefs.lo: $(srcdir)/langprefs.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/langprefs.c localename.lo: $(srcdir)/localename.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/localename.c log.lo: $(srcdir)/log.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/log.c printf.lo: $(srcdir)/printf.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/printf.c version.lo: $(srcdir)/version.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/version.c osdep.lo: $(srcdir)/osdep.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/osdep.c intl-compat.lo: $(srcdir)/intl-compat.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/intl-compat.c # This rule is executed only on Woe32 systems. # The following sed expressions come from the windres-options script. They are # inlined here, so that they can be written in a Makefile without requiring a # temporary file. They must contain literal newlines rather than semicolons, # so that they work with the sed-3.02 that is shipped with MSYS. We can use # GNU bash's $'\n' syntax to obtain such a newline. libintl.res: $(srcdir)/libintl.rc nl=$$'\n'; \ sed_extract_major='/^[0-9]/{'$${nl}'s/^\([0-9]*\).*/\1/p'$${nl}q$${nl}'}'$${nl}'c\'$${nl}0$${nl}q; \ sed_extract_minor='/^[0-9][0-9]*[.][0-9]/{'$${nl}'s/^[0-9]*[.]\([0-9]*\).*/\1/p'$${nl}q$${nl}'}'$${nl}'c\'$${nl}0$${nl}q; \ sed_extract_subminor='/^[0-9][0-9]*[.][0-9][0-9]*[.][0-9]/{'$${nl}'s/^[0-9]*[.][0-9]*[.]\([0-9]*\).*/\1/p'$${nl}q$${nl}'}'$${nl}'c\'$${nl}0$${nl}q; \ $(WINDRES) \ "-DPACKAGE_VERSION_STRING=\\\"$(VERSION)\\\"" \ "-DPACKAGE_VERSION_MAJOR="`echo '$(VERSION)' | sed -n -e "$$sed_extract_major"` \ "-DPACKAGE_VERSION_MINOR="`echo '$(VERSION)' | sed -n -e "$$sed_extract_minor"` \ "-DPACKAGE_VERSION_SUBMINOR="`echo '$(VERSION)' | sed -n -e "$$sed_extract_subminor"` \ -i $(srcdir)/libintl.rc -o libintl.res --output-format=coff ref-add.sed: $(srcdir)/ref-add.sin sed -e '/^#/d' -e 's/@''PACKAGE''@/@PACKAGE@/g' $(srcdir)/ref-add.sin > t-ref-add.sed mv t-ref-add.sed ref-add.sed ref-del.sed: $(srcdir)/ref-del.sin sed -e '/^#/d' -e 's/@''PACKAGE''@/@PACKAGE@/g' $(srcdir)/ref-del.sin > t-ref-del.sed mv t-ref-del.sed ref-del.sed INCLUDES = -I. -I$(srcdir) -I.. libgnuintl.h: $(srcdir)/libgnuintl.h.in sed -e '/IN_LIBGLOCALE/d' \ -e 's,@''HAVE_POSIX_PRINTF''@,@HAVE_POSIX_PRINTF@,g' \ -e 's,@''HAVE_ASPRINTF''@,@HAVE_ASPRINTF@,g' \ -e 's,@''HAVE_SNPRINTF''@,@HAVE_SNPRINTF@,g' \ -e 's,@''HAVE_WPRINTF''@,@HAVE_WPRINTF@,g' \ < $(srcdir)/libgnuintl.h.in \ | if test '@WOE32DLL@' = yes; then \ sed -e 's/extern \([^()]*\);/extern __declspec (dllimport) \1;/'; \ else \ cat; \ fi \ | sed -e 's/extern \([^"]\)/extern LIBINTL_DLL_EXPORTED \1/' \ -e "/#define _LIBINTL_H/r $(srcdir)/export.h" \ | sed -e 's,@''HAVE_VISIBILITY''@,@HAVE_VISIBILITY@,g' \ > libgnuintl.h libintl.h: $(srcdir)/libgnuintl.h.in sed -e '/IN_LIBGLOCALE/d' \ -e 's,@''HAVE_POSIX_PRINTF''@,@HAVE_POSIX_PRINTF@,g' \ -e 's,@''HAVE_ASPRINTF''@,@HAVE_ASPRINTF@,g' \ -e 's,@''HAVE_SNPRINTF''@,@HAVE_SNPRINTF@,g' \ -e 's,@''HAVE_WPRINTF''@,@HAVE_WPRINTF@,g' \ < $(srcdir)/libgnuintl.h.in > libintl.h charset.alias: $(srcdir)/config.charset $(SHELL) $(srcdir)/config.charset '@host@' > t-$@ mv t-$@ $@ check: all # We must not install the libintl.h/libintl.a files if we are on a # system which has the GNU gettext() function in its C library or in a # separate library. # If you want to use the one which comes with this version of the # package, you have to use `configure --with-included-gettext'. install: install-exec install-data install-exec: all if { test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; } \ && test '@USE_INCLUDED_LIBINTL@' = yes; then \ $(mkdir_p) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir); \ $(INSTALL_DATA) libintl.h $(DESTDIR)$(includedir)/libintl.h; \ $(LIBTOOL) --mode=install \ $(INSTALL_DATA) libintl.$la $(DESTDIR)$(libdir)/libintl.$la; \ if test "@RELOCATABLE@" = yes; then \ dependencies=`sed -n -e 's,^dependency_libs=\(.*\),\1,p' < $(DESTDIR)$(libdir)/libintl.la | sed -e "s,^',," -e "s,'\$$,,"`; \ if test -n "$$dependencies"; then \ rm -f $(DESTDIR)$(libdir)/libintl.la; \ fi; \ fi; \ else \ : ; \ fi if test "$(PACKAGE)" = "gettext-tools" \ && test '@USE_INCLUDED_LIBINTL@' = no \ && test @GLIBC2@ != no; then \ $(mkdir_p) $(DESTDIR)$(libdir); \ $(LIBTOOL) --mode=install \ $(INSTALL_DATA) libgnuintl.$la $(DESTDIR)$(libdir)/libgnuintl.$la; \ rm -f $(DESTDIR)$(libdir)/preloadable_libintl.so; \ $(INSTALL_DATA) $(DESTDIR)$(libdir)/libgnuintl.so $(DESTDIR)$(libdir)/preloadable_libintl.so; \ $(LIBTOOL) --mode=uninstall \ rm -f $(DESTDIR)$(libdir)/libgnuintl.$la; \ else \ : ; \ fi if test '@USE_INCLUDED_LIBINTL@' = yes; then \ test @GLIBC21@ != no || $(mkdir_p) $(DESTDIR)$(libdir); \ temp=$(DESTDIR)$(libdir)/t-charset.alias; \ dest=$(DESTDIR)$(libdir)/charset.alias; \ if test -f $(DESTDIR)$(libdir)/charset.alias; then \ orig=$(DESTDIR)$(libdir)/charset.alias; \ sed -f ref-add.sed $$orig > $$temp; \ $(INSTALL_DATA) $$temp $$dest; \ rm -f $$temp; \ else \ if test @GLIBC21@ = no; then \ orig=charset.alias; \ sed -f ref-add.sed $$orig > $$temp; \ $(INSTALL_DATA) $$temp $$dest; \ rm -f $$temp; \ fi; \ fi; \ $(mkdir_p) $(DESTDIR)$(localedir); \ test -f $(DESTDIR)$(localedir)/locale.alias \ && orig=$(DESTDIR)$(localedir)/locale.alias \ || orig=$(srcdir)/locale.alias; \ temp=$(DESTDIR)$(localedir)/t-locale.alias; \ dest=$(DESTDIR)$(localedir)/locale.alias; \ sed -f ref-add.sed $$orig > $$temp; \ $(INSTALL_DATA) $$temp $$dest; \ rm -f $$temp; \ else \ : ; \ fi install-data: all if test "$(PACKAGE)" = "gettext-tools"; then \ $(mkdir_p) $(DESTDIR)$(gettextsrcdir); \ $(INSTALL_DATA) VERSION $(DESTDIR)$(gettextsrcdir)/VERSION; \ $(INSTALL_DATA) ChangeLog.inst $(DESTDIR)$(gettextsrcdir)/ChangeLog; \ dists="COPYING.LIB-2.0 COPYING.LIB-2.1 $(DISTFILES.common)"; \ for file in $$dists; do \ $(INSTALL_DATA) $(srcdir)/$$file \ $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ chmod a+x $(DESTDIR)$(gettextsrcdir)/config.charset; \ dists="$(DISTFILES.generated)"; \ for file in $$dists; do \ if test -f $$file; then dir=.; else dir=$(srcdir); fi; \ $(INSTALL_DATA) $$dir/$$file \ $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ dists="$(DISTFILES.obsolete)"; \ for file in $$dists; do \ rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ else \ : ; \ fi install-strip: install install-dvi install-html install-info install-ps install-pdf: installdirs: if { test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; } \ && test '@USE_INCLUDED_LIBINTL@' = yes; then \ $(mkdir_p) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir); \ else \ : ; \ fi if test "$(PACKAGE)" = "gettext-tools" \ && test '@USE_INCLUDED_LIBINTL@' = no \ && test @GLIBC2@ != no; then \ $(mkdir_p) $(DESTDIR)$(libdir); \ else \ : ; \ fi if test '@USE_INCLUDED_LIBINTL@' = yes; then \ test @GLIBC21@ != no || $(mkdir_p) $(DESTDIR)$(libdir); \ $(mkdir_p) $(DESTDIR)$(localedir); \ else \ : ; \ fi if test "$(PACKAGE)" = "gettext-tools"; then \ $(mkdir_p) $(DESTDIR)$(gettextsrcdir); \ else \ : ; \ fi # Define this as empty until I found a useful application. installcheck: uninstall: if { test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; } \ && test '@USE_INCLUDED_LIBINTL@' = yes; then \ rm -f $(DESTDIR)$(includedir)/libintl.h; \ $(LIBTOOL) --mode=uninstall \ rm -f $(DESTDIR)$(libdir)/libintl.$la; \ else \ : ; \ fi if test "$(PACKAGE)" = "gettext-tools" \ && test '@USE_INCLUDED_LIBINTL@' = no \ && test @GLIBC2@ != no; then \ rm -f $(DESTDIR)$(libdir)/preloadable_libintl.so; \ else \ : ; \ fi if test '@USE_INCLUDED_LIBINTL@' = yes; then \ if test -f $(DESTDIR)$(libdir)/charset.alias; then \ temp=$(DESTDIR)$(libdir)/t-charset.alias; \ dest=$(DESTDIR)$(libdir)/charset.alias; \ sed -f ref-del.sed $$dest > $$temp; \ if grep '^# Packages using this file: $$' $$temp > /dev/null; then \ rm -f $$dest; \ else \ $(INSTALL_DATA) $$temp $$dest; \ fi; \ rm -f $$temp; \ fi; \ if test -f $(DESTDIR)$(localedir)/locale.alias; then \ temp=$(DESTDIR)$(localedir)/t-locale.alias; \ dest=$(DESTDIR)$(localedir)/locale.alias; \ sed -f ref-del.sed $$dest > $$temp; \ if grep '^# Packages using this file: $$' $$temp > /dev/null; then \ rm -f $$dest; \ else \ $(INSTALL_DATA) $$temp $$dest; \ fi; \ rm -f $$temp; \ fi; \ else \ : ; \ fi if test "$(PACKAGE)" = "gettext-tools"; then \ for file in VERSION ChangeLog COPYING.LIB-2.0 COPYING.LIB-2.1 $(DISTFILES.common) $(DISTFILES.generated); do \ rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ else \ : ; \ fi info dvi ps pdf html: $(OBJECTS): ../config.h libgnuintl.h bindtextdom.$lo dcgettext.$lo dcigettext.$lo dcngettext.$lo dgettext.$lo dngettext.$lo finddomain.$lo gettext.$lo intl-compat.$lo loadmsgcat.$lo localealias.$lo ngettext.$lo textdomain.$lo: $(srcdir)/gettextP.h $(srcdir)/gmo.h $(srcdir)/loadinfo.h hash-string.$lo dcigettext.$lo loadmsgcat.$lo: $(srcdir)/hash-string.h explodename.$lo l10nflist.$lo: $(srcdir)/loadinfo.h dcigettext.$lo loadmsgcat.$lo plural.$lo plural-exp.$lo: $(srcdir)/plural-exp.h dcigettext.$lo: $(srcdir)/eval-plural.h localcharset.$lo: $(srcdir)/localcharset.h bindtextdom.$lo dcigettext.$lo finddomain.$lo loadmsgcat.$lo localealias.$lo lock.$lo log.$lo: $(srcdir)/lock.h localealias.$lo localcharset.$lo relocatable.$lo: $(srcdir)/relocatable.h printf.$lo: $(srcdir)/printf-args.h $(srcdir)/printf-args.c $(srcdir)/printf-parse.h $(srcdir)/wprintf-parse.h $(srcdir)/xsize.h $(srcdir)/printf-parse.c $(srcdir)/vasnprintf.h $(srcdir)/vasnwprintf.h $(srcdir)/vasnprintf.c # A bison-2.1 generated plural.c includes if ENABLE_NLS. PLURAL_DEPS_yes = libintl.h PLURAL_DEPS_no = plural.$lo: $(PLURAL_DEPS_@USE_INCLUDED_LIBINTL@) tags: TAGS TAGS: $(HEADERS) $(SOURCES) here=`pwd`; cd $(srcdir) && etags -o $$here/TAGS $(HEADERS) $(SOURCES) ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) here=`pwd`; cd $(srcdir) && ctags -o $$here/CTAGS $(HEADERS) $(SOURCES) id: ID ID: $(HEADERS) $(SOURCES) here=`pwd`; cd $(srcdir) && mkid -f$$here/ID $(HEADERS) $(SOURCES) mostlyclean: rm -f *.a *.la *.o *.obj *.lo libintl.res core core.* rm -f libgnuintl.h libintl.h charset.alias ref-add.sed ref-del.sed rm -f -r .libs _libs clean: mostlyclean distclean: clean rm -f Makefile ID TAGS if test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; then \ rm -f ChangeLog.inst $(DISTFILES.normal); \ else \ : ; \ fi maintainer-clean: distclean @echo "This command is intended for maintainers to use;" @echo "it deletes files that may require special tools to rebuild." # GNU gettext needs not contain the file `VERSION' but contains some # other files which should not be distributed in other packages. distdir = ../$(PACKAGE)-$(VERSION)/$(subdir) dist distdir: Makefile if test "$(PACKAGE)" = "gettext-tools"; then \ : ; \ else \ if test "$(PACKAGE)" = "gettext-runtime"; then \ additional="$(DISTFILES.gettext)"; \ else \ additional="$(DISTFILES.normal)"; \ fi; \ $(MAKE) $(DISTFILES.common) $(DISTFILES.generated) $$additional; \ for file in ChangeLog $(DISTFILES.common) $(DISTFILES.generated) $$additional; do \ if test -f $$file; then dir=.; else dir=$(srcdir); fi; \ cp -p $$dir/$$file $(distdir) || test $$file = Makefile.in || exit 1; \ done; \ fi Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status cd $(top_builddir) && $(SHELL) ./config.status # This would be more efficient, but doesn't work any more with autoconf-2.57, # when AC_CONFIG_FILES([intl/Makefile:somedir/Makefile.in]) is used. # cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ # Tell versions [3.59,3.63) of GNU make not to export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: libnih-1.0.3/intl/vasnprintf.c0000644000175000017500000035070311461165270013220 00000000000000/* vsprintf with automatic memory allocation. Copyright (C) 1999, 2002-2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* This file can be parametrized with the following macros: VASNPRINTF The name of the function being defined. FCHAR_T The element type of the format string. DCHAR_T The element type of the destination (result) string. FCHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters in the format string are ASCII. MUST be set if FCHAR_T and DCHAR_T are not the same type. DIRECTIVE Structure denoting a format directive. Depends on FCHAR_T. DIRECTIVES Structure denoting the set of format directives of a format string. Depends on FCHAR_T. PRINTF_PARSE Function that parses a format string. Depends on FCHAR_T. DCHAR_CPY memcpy like function for DCHAR_T[] arrays. DCHAR_SET memset like function for DCHAR_T[] arrays. DCHAR_MBSNLEN mbsnlen like function for DCHAR_T[] arrays. SNPRINTF The system's snprintf (or similar) function. This may be either snprintf or swprintf. TCHAR_T The element type of the argument and result string of the said SNPRINTF function. This may be either char or wchar_t. The code exploits that sizeof (TCHAR_T) | sizeof (DCHAR_T) and alignof (TCHAR_T) <= alignof (DCHAR_T). DCHAR_IS_TCHAR Set to 1 if DCHAR_T and TCHAR_T are the same type. DCHAR_CONV_FROM_ENCODING A function to convert from char[] to DCHAR[]. DCHAR_IS_UINT8_T Set to 1 if DCHAR_T is uint8_t. DCHAR_IS_UINT16_T Set to 1 if DCHAR_T is uint16_t. DCHAR_IS_UINT32_T Set to 1 if DCHAR_T is uint32_t. */ /* Tell glibc's to provide a prototype for snprintf(). This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #ifndef VASNPRINTF # include #endif #ifndef IN_LIBINTL # include #endif /* Specification. */ #ifndef VASNPRINTF # if WIDE_CHAR_VERSION # include "vasnwprintf.h" # else # include "vasnprintf.h" # endif #endif #include /* localeconv() */ #include /* snprintf(), sprintf() */ #include /* abort(), malloc(), realloc(), free() */ #include /* memcpy(), strlen() */ #include /* errno */ #include /* CHAR_BIT */ #include /* DBL_MAX_EXP, LDBL_MAX_EXP */ #if HAVE_NL_LANGINFO # include #endif #ifndef VASNPRINTF # if WIDE_CHAR_VERSION # include "wprintf-parse.h" # else # include "printf-parse.h" # endif #endif /* Checked size_t computations. */ #include "xsize.h" #if (NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL # include # include "float+.h" #endif #if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL # include # include "isnan.h" #endif #if (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) && !defined IN_LIBINTL # include # include "isnanl-nolibm.h" # include "fpucw.h" #endif #if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL # include # include "isnan.h" # include "printf-frexp.h" #endif #if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL # include # include "isnanl-nolibm.h" # include "printf-frexpl.h" # include "fpucw.h" #endif /* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ #ifndef EOVERFLOW # define EOVERFLOW E2BIG #endif #if HAVE_WCHAR_T # if HAVE_WCSLEN # define local_wcslen wcslen # else /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid a dependency towards this library, here is a local substitute. Define this substitute only once, even if this file is included twice in the same compilation unit. */ # ifndef local_wcslen_defined # define local_wcslen_defined 1 static size_t local_wcslen (const wchar_t *s) { const wchar_t *ptr; for (ptr = s; *ptr != (wchar_t) 0; ptr++) ; return ptr - s; } # endif # endif #endif /* Default parameters. */ #ifndef VASNPRINTF # if WIDE_CHAR_VERSION # define VASNPRINTF vasnwprintf # define FCHAR_T wchar_t # define DCHAR_T wchar_t # define TCHAR_T wchar_t # define DCHAR_IS_TCHAR 1 # define DIRECTIVE wchar_t_directive # define DIRECTIVES wchar_t_directives # define PRINTF_PARSE wprintf_parse # define DCHAR_CPY wmemcpy # else # define VASNPRINTF vasnprintf # define FCHAR_T char # define DCHAR_T char # define TCHAR_T char # define DCHAR_IS_TCHAR 1 # define DIRECTIVE char_directive # define DIRECTIVES char_directives # define PRINTF_PARSE printf_parse # define DCHAR_CPY memcpy # endif #endif #if WIDE_CHAR_VERSION /* TCHAR_T is wchar_t. */ # define USE_SNPRINTF 1 # if HAVE_DECL__SNWPRINTF /* On Windows, the function swprintf() has a different signature than on Unix; we use the _snwprintf() function instead. */ # define SNPRINTF _snwprintf # else /* Unix. */ # define SNPRINTF swprintf # endif #else /* TCHAR_T is char. */ # /* Use snprintf if it exists under the name 'snprintf' or '_snprintf'. But don't use it on BeOS, since BeOS snprintf produces no output if the size argument is >= 0x3000000. */ # if (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF) && !defined __BEOS__ # define USE_SNPRINTF 1 # else # define USE_SNPRINTF 0 # endif # if HAVE_DECL__SNPRINTF /* Windows. */ # define SNPRINTF _snprintf # else /* Unix. */ # define SNPRINTF snprintf /* Here we need to call the native snprintf, not rpl_snprintf. */ # undef snprintf # endif #endif /* Here we need to call the native sprintf, not rpl_sprintf. */ #undef sprintf #if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL /* Determine the decimal-point character according to the current locale. */ # ifndef decimal_point_char_defined # define decimal_point_char_defined 1 static char decimal_point_char () { const char *point; /* Determine it in a multithread-safe way. We know nl_langinfo is multithread-safe on glibc systems, but is not required to be multithread- safe by POSIX. sprintf(), however, is multithread-safe. localeconv() is rarely multithread-safe. */ # if HAVE_NL_LANGINFO && __GLIBC__ point = nl_langinfo (RADIXCHAR); # elif 1 char pointbuf[5]; sprintf (pointbuf, "%#.0f", 1.0); point = &pointbuf[1]; # else point = localeconv () -> decimal_point; # endif /* The decimal point is always a single byte: either '.' or ','. */ return (point[0] != '\0' ? point[0] : '.'); } # endif #endif #if NEED_PRINTF_INFINITE_DOUBLE && !NEED_PRINTF_DOUBLE && !defined IN_LIBINTL /* Equivalent to !isfinite(x) || x == 0, but does not require libm. */ static int is_infinite_or_zero (double x) { return isnan (x) || x + x == x; } #endif #if NEED_PRINTF_INFINITE_LONG_DOUBLE && !NEED_PRINTF_LONG_DOUBLE && !defined IN_LIBINTL /* Equivalent to !isfinite(x), but does not require libm. */ static int is_infinitel (long double x) { return isnanl (x) || (x + x == x && x != 0.0L); } #endif #if (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL /* Converting 'long double' to decimal without rare rounding bugs requires real bignums. We use the naming conventions of GNU gmp, but vastly simpler (and slower) algorithms. */ typedef unsigned int mp_limb_t; # define GMP_LIMB_BITS 32 typedef int mp_limb_verify[2 * (sizeof (mp_limb_t) * CHAR_BIT == GMP_LIMB_BITS) - 1]; typedef unsigned long long mp_twolimb_t; # define GMP_TWOLIMB_BITS 64 typedef int mp_twolimb_verify[2 * (sizeof (mp_twolimb_t) * CHAR_BIT == GMP_TWOLIMB_BITS) - 1]; /* Representation of a bignum >= 0. */ typedef struct { size_t nlimbs; mp_limb_t *limbs; /* Bits in little-endian order, allocated with malloc(). */ } mpn_t; /* Compute the product of two bignums >= 0. Return the allocated memory in case of success, NULL in case of memory allocation failure. */ static void * multiply (mpn_t src1, mpn_t src2, mpn_t *dest) { const mp_limb_t *p1; const mp_limb_t *p2; size_t len1; size_t len2; if (src1.nlimbs <= src2.nlimbs) { len1 = src1.nlimbs; p1 = src1.limbs; len2 = src2.nlimbs; p2 = src2.limbs; } else { len1 = src2.nlimbs; p1 = src2.limbs; len2 = src1.nlimbs; p2 = src1.limbs; } /* Now 0 <= len1 <= len2. */ if (len1 == 0) { /* src1 or src2 is zero. */ dest->nlimbs = 0; dest->limbs = (mp_limb_t *) malloc (1); } else { /* Here 1 <= len1 <= len2. */ size_t dlen; mp_limb_t *dp; size_t k, i, j; dlen = len1 + len2; dp = (mp_limb_t *) malloc (dlen * sizeof (mp_limb_t)); if (dp == NULL) return NULL; for (k = len2; k > 0; ) dp[--k] = 0; for (i = 0; i < len1; i++) { mp_limb_t digit1 = p1[i]; mp_twolimb_t carry = 0; for (j = 0; j < len2; j++) { mp_limb_t digit2 = p2[j]; carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; carry += dp[i + j]; dp[i + j] = (mp_limb_t) carry; carry = carry >> GMP_LIMB_BITS; } dp[i + len2] = (mp_limb_t) carry; } /* Normalise. */ while (dlen > 0 && dp[dlen - 1] == 0) dlen--; dest->nlimbs = dlen; dest->limbs = dp; } return dest->limbs; } /* Compute the quotient of a bignum a >= 0 and a bignum b > 0. a is written as a = q * b + r with 0 <= r < b. q is the quotient, r the remainder. Finally, round-to-even is performed: If r > b/2 or if r = b/2 and q is odd, q is incremented. Return the allocated memory in case of success, NULL in case of memory allocation failure. */ static void * divide (mpn_t a, mpn_t b, mpn_t *q) { /* Algorithm: First normalise a and b: a=[a[m-1],...,a[0]], b=[b[n-1],...,b[0]] with m>=0 and n>0 (in base beta = 2^GMP_LIMB_BITS). If m=n=1, perform a single-precision division: r:=0, j:=m, while j>0 do {Here (q[m-1]*beta^(m-1)+...+q[j]*beta^j) * b[0] + r*beta^j = = a[m-1]*beta^(m-1)+...+a[j]*beta^j und 0<=r=n>1, perform a multiple-precision division: We have a/b < beta^(m-n+1). s:=intDsize-1-(hightest bit in b[n-1]), 0<=s=beta/2. For j=m-n,...,0: {Here 0 <= r < b*beta^(j+1).} Compute q* : q* := floor((r[j+n]*beta+r[j+n-1])/b[n-1]). In case of overflow (q* >= beta) set q* := beta-1. Compute c2 := ((r[j+n]*beta+r[j+n-1]) - q* * b[n-1])*beta + r[j+n-2] and c3 := b[n-2] * q*. {We have 0 <= c2 < 2*beta^2, even 0 <= c2 < beta^2 if no overflow occurred. Furthermore 0 <= c3 < beta^2. If there was overflow and r[j+n]*beta+r[j+n-1] - q* * b[n-1] >= beta, i.e. c2 >= beta^2, the next test can be skipped.} While c3 > c2, {Here 0 <= c2 < c3 < beta^2} Put q* := q* - 1, c2 := c2 + b[n-1]*beta, c3 := c3 - b[n-2]. If q* > 0: Put r := r - b * q* * beta^j. In detail: [r[n+j],...,r[j]] := [r[n+j],...,r[j]] - q* * [b[n-1],...,b[0]]. hence: u:=0, for i:=0 to n-1 do u := u + q* * b[i], r[j+i]:=r[j+i]-(u mod beta) (+ beta, if carry), u:=u div beta (+ 1, if carry in subtraction) r[n+j]:=r[n+j]-u. {Since always u = (q* * [b[i-1],...,b[0]] div beta^i) + 1 < q* + 1 <= beta, the carry u does not overflow.} If a negative carry occurs, put q* := q* - 1 and [r[n+j],...,r[j]] := [r[n+j],...,r[j]] + [0,b[n-1],...,b[0]]. Set q[j] := q*. Normalise [q[m-n],..,q[0]]; this yields the quotient q. Shift [r[n-1],...,r[0]] right by s bits and normalise; this yields the rest r. The room for q[j] can be allocated at the memory location of r[n+j]. Finally, round-to-even: Shift r left by 1 bit. If r > b or if r = b and q[0] is odd, q := q+1. */ const mp_limb_t *a_ptr = a.limbs; size_t a_len = a.nlimbs; const mp_limb_t *b_ptr = b.limbs; size_t b_len = b.nlimbs; mp_limb_t *roomptr; mp_limb_t *tmp_roomptr = NULL; mp_limb_t *q_ptr; size_t q_len; mp_limb_t *r_ptr; size_t r_len; /* Allocate room for a_len+2 digits. (Need a_len+1 digits for the real division and 1 more digit for the final rounding of q.) */ roomptr = (mp_limb_t *) malloc ((a_len + 2) * sizeof (mp_limb_t)); if (roomptr == NULL) return NULL; /* Normalise a. */ while (a_len > 0 && a_ptr[a_len - 1] == 0) a_len--; /* Normalise b. */ for (;;) { if (b_len == 0) /* Division by zero. */ abort (); if (b_ptr[b_len - 1] == 0) b_len--; else break; } /* Here m = a_len >= 0 and n = b_len > 0. */ if (a_len < b_len) { /* m beta^(m-2) <= a/b < beta^m */ r_ptr = roomptr; q_ptr = roomptr + 1; { mp_limb_t den = b_ptr[0]; mp_limb_t remainder = 0; const mp_limb_t *sourceptr = a_ptr + a_len; mp_limb_t *destptr = q_ptr + a_len; size_t count; for (count = a_len; count > 0; count--) { mp_twolimb_t num = ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr; *--destptr = num / den; remainder = num % den; } /* Normalise and store r. */ if (remainder > 0) { r_ptr[0] = remainder; r_len = 1; } else r_len = 0; /* Normalise q. */ q_len = a_len; if (q_ptr[q_len - 1] == 0) q_len--; } } else { /* n>1: multiple precision division. beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==> beta^(m-n-1) <= a/b < beta^(m-n+1). */ /* Determine s. */ size_t s; { mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ s = 31; if (msd >= 0x10000) { msd = msd >> 16; s -= 16; } if (msd >= 0x100) { msd = msd >> 8; s -= 8; } if (msd >= 0x10) { msd = msd >> 4; s -= 4; } if (msd >= 0x4) { msd = msd >> 2; s -= 2; } if (msd >= 0x2) { msd = msd >> 1; s -= 1; } } /* 0 <= s < GMP_LIMB_BITS. Copy b, shifting it left by s bits. */ if (s > 0) { tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t)); if (tmp_roomptr == NULL) { free (roomptr); return NULL; } { const mp_limb_t *sourceptr = b_ptr; mp_limb_t *destptr = tmp_roomptr; mp_twolimb_t accu = 0; size_t count; for (count = b_len; count > 0; count--) { accu += (mp_twolimb_t) *sourceptr++ << s; *destptr++ = (mp_limb_t) accu; accu = accu >> GMP_LIMB_BITS; } /* accu must be zero, since that was how s was determined. */ if (accu != 0) abort (); } b_ptr = tmp_roomptr; } /* Copy a, shifting it left by s bits, yields r. Memory layout: At the beginning: r = roomptr[0..a_len], at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */ r_ptr = roomptr; if (s == 0) { memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t)); r_ptr[a_len] = 0; } else { const mp_limb_t *sourceptr = a_ptr; mp_limb_t *destptr = r_ptr; mp_twolimb_t accu = 0; size_t count; for (count = a_len; count > 0; count--) { accu += (mp_twolimb_t) *sourceptr++ << s; *destptr++ = (mp_limb_t) accu; accu = accu >> GMP_LIMB_BITS; } *destptr++ = (mp_limb_t) accu; } q_ptr = roomptr + b_len; q_len = a_len - b_len + 1; /* q will have m-n+1 limbs */ { size_t j = a_len - b_len; /* m-n */ mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */ mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */ mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */ ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd; /* Division loop, traversed m-n+1 times. j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */ for (;;) { mp_limb_t q_star; mp_limb_t c1; if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */ { /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */ mp_twolimb_t num = ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS) | r_ptr[j + b_len - 1]; q_star = num / b_msd; c1 = num % b_msd; } else { /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */ q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */ /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) {<= beta !}. If yes, jump directly to the subtraction loop. (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */ if (r_ptr[j + b_len] > b_msd || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd) /* r[j+n] >= b[n-1]+1 or r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a carry. */ goto subtract; } /* q_star = q*, c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, 0, decrease it by b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2 this can happen only twice. */ if (c3 > c2) { q_star = q_star - 1; /* q* := q* - 1 */ if (c3 - c2 > b_msdd) q_star = q_star - 1; /* q* := q* - 1 */ } } if (q_star > 0) subtract: { /* Subtract r := r - b * q* * beta^j. */ mp_limb_t cr; { const mp_limb_t *sourceptr = b_ptr; mp_limb_t *destptr = r_ptr + j; mp_twolimb_t carry = 0; size_t count; for (count = b_len; count > 0; count--) { /* Here 0 <= carry <= q*. */ carry = carry + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++ + (mp_limb_t) ~(*destptr); /* Here 0 <= carry <= beta*q* + beta-1. */ *destptr++ = ~(mp_limb_t) carry; carry = carry >> GMP_LIMB_BITS; /* <= q* */ } cr = (mp_limb_t) carry; } /* Subtract cr from r_ptr[j + b_len], then forget about r_ptr[j + b_len]. */ if (cr > r_ptr[j + b_len]) { /* Subtraction gave a carry. */ q_star = q_star - 1; /* q* := q* - 1 */ /* Add b back. */ { const mp_limb_t *sourceptr = b_ptr; mp_limb_t *destptr = r_ptr + j; mp_limb_t carry = 0; size_t count; for (count = b_len; count > 0; count--) { mp_limb_t source1 = *sourceptr++; mp_limb_t source2 = *destptr; *destptr++ = source1 + source2 + carry; carry = (carry ? source1 >= (mp_limb_t) ~source2 : source1 > (mp_limb_t) ~source2); } } /* Forget about the carry and about r[j+n]. */ } } /* q* is determined. Store it as q[j]. */ q_ptr[j] = q_star; if (j == 0) break; j--; } } r_len = b_len; /* Normalise q. */ if (q_ptr[q_len - 1] == 0) q_len--; # if 0 /* Not needed here, since we need r only to compare it with b/2, and b is shifted left by s bits. */ /* Shift r right by s bits. */ if (s > 0) { mp_limb_t ptr = r_ptr + r_len; mp_twolimb_t accu = 0; size_t count; for (count = r_len; count > 0; count--) { accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS; accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s); *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS); } } # endif /* Normalise r. */ while (r_len > 0 && r_ptr[r_len - 1] == 0) r_len--; } /* Compare r << 1 with b. */ if (r_len > b_len) goto increment_q; { size_t i; for (i = b_len;;) { mp_limb_t r_i = (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0) | (i < r_len ? r_ptr[i] << 1 : 0); mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0); if (r_i > b_i) goto increment_q; if (r_i < b_i) goto keep_q; if (i == 0) break; i--; } } if (q_len > 0 && ((q_ptr[0] & 1) != 0)) /* q is odd. */ increment_q: { size_t i; for (i = 0; i < q_len; i++) if (++(q_ptr[i]) != 0) goto keep_q; q_ptr[q_len++] = 1; } keep_q: if (tmp_roomptr != NULL) free (tmp_roomptr); q->limbs = q_ptr; q->nlimbs = q_len; return roomptr; } /* Convert a bignum a >= 0, multiplied with 10^extra_zeroes, to decimal representation. Destroys the contents of a. Return the allocated memory - containing the decimal digits in low-to-high order, terminated with a NUL character - in case of success, NULL in case of memory allocation failure. */ static char * convert_to_decimal (mpn_t a, size_t extra_zeroes) { mp_limb_t *a_ptr = a.limbs; size_t a_len = a.nlimbs; /* 0.03345 is slightly larger than log(2)/(9*log(10)). */ size_t c_len = 9 * ((size_t)(a_len * (GMP_LIMB_BITS * 0.03345f)) + 1); char *c_ptr = (char *) malloc (xsum (c_len, extra_zeroes)); if (c_ptr != NULL) { char *d_ptr = c_ptr; for (; extra_zeroes > 0; extra_zeroes--) *d_ptr++ = '0'; while (a_len > 0) { /* Divide a by 10^9, in-place. */ mp_limb_t remainder = 0; mp_limb_t *ptr = a_ptr + a_len; size_t count; for (count = a_len; count > 0; count--) { mp_twolimb_t num = ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr; *ptr = num / 1000000000; remainder = num % 1000000000; } /* Store the remainder as 9 decimal digits. */ for (count = 9; count > 0; count--) { *d_ptr++ = '0' + (remainder % 10); remainder = remainder / 10; } /* Normalize a. */ if (a_ptr[a_len - 1] == 0) a_len--; } /* Remove leading zeroes. */ while (d_ptr > c_ptr && d_ptr[-1] == '0') d_ptr--; /* But keep at least one zero. */ if (d_ptr == c_ptr) *d_ptr++ = '0'; /* Terminate the string. */ *d_ptr = '\0'; } return c_ptr; } # if NEED_PRINTF_LONG_DOUBLE /* Assuming x is finite and >= 0: write x as x = 2^e * m, where m is a bignum. Return the allocated memory in case of success, NULL in case of memory allocation failure. */ static void * decode_long_double (long double x, int *ep, mpn_t *mp) { mpn_t m; int exp; long double y; size_t i; /* Allocate memory for result. */ m.nlimbs = (LDBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS; m.limbs = (mp_limb_t *) malloc (m.nlimbs * sizeof (mp_limb_t)); if (m.limbs == NULL) return NULL; /* Split into exponential part and mantissa. */ y = frexpl (x, &exp); if (!(y >= 0.0L && y < 1.0L)) abort (); /* x = 2^exp * y = 2^(exp - LDBL_MANT_BIT) * (y * LDBL_MANT_BIT), and the latter is an integer. */ /* Convert the mantissa (y * LDBL_MANT_BIT) to a sequence of limbs. I'm not sure whether it's safe to cast a 'long double' value between 2^31 and 2^32 to 'unsigned int', therefore play safe and cast only 'long double' values between 0 and 2^16 (to 'unsigned int' or 'int', doesn't matter). */ # if (LDBL_MANT_BIT % GMP_LIMB_BITS) != 0 # if (LDBL_MANT_BIT % GMP_LIMB_BITS) > GMP_LIMB_BITS / 2 { mp_limb_t hi, lo; y *= (mp_limb_t) 1 << (LDBL_MANT_BIT % (GMP_LIMB_BITS / 2)); hi = (int) y; y -= hi; if (!(y >= 0.0L && y < 1.0L)) abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0L && y < 1.0L)) abort (); m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; } # else { mp_limb_t d; y *= (mp_limb_t) 1 << (LDBL_MANT_BIT % GMP_LIMB_BITS); d = (int) y; y -= d; if (!(y >= 0.0L && y < 1.0L)) abort (); m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = d; } # endif # endif for (i = LDBL_MANT_BIT / GMP_LIMB_BITS; i > 0; ) { mp_limb_t hi, lo; y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); hi = (int) y; y -= hi; if (!(y >= 0.0L && y < 1.0L)) abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0L && y < 1.0L)) abort (); m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; } if (!(y == 0.0L)) abort (); /* Normalise. */ while (m.nlimbs > 0 && m.limbs[m.nlimbs - 1] == 0) m.nlimbs--; *mp = m; *ep = exp - LDBL_MANT_BIT; return m.limbs; } # endif # if NEED_PRINTF_DOUBLE /* Assuming x is finite and >= 0: write x as x = 2^e * m, where m is a bignum. Return the allocated memory in case of success, NULL in case of memory allocation failure. */ static void * decode_double (double x, int *ep, mpn_t *mp) { mpn_t m; int exp; double y; size_t i; /* Allocate memory for result. */ m.nlimbs = (DBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS; m.limbs = (mp_limb_t *) malloc (m.nlimbs * sizeof (mp_limb_t)); if (m.limbs == NULL) return NULL; /* Split into exponential part and mantissa. */ y = frexp (x, &exp); if (!(y >= 0.0 && y < 1.0)) abort (); /* x = 2^exp * y = 2^(exp - DBL_MANT_BIT) * (y * DBL_MANT_BIT), and the latter is an integer. */ /* Convert the mantissa (y * DBL_MANT_BIT) to a sequence of limbs. I'm not sure whether it's safe to cast a 'double' value between 2^31 and 2^32 to 'unsigned int', therefore play safe and cast only 'double' values between 0 and 2^16 (to 'unsigned int' or 'int', doesn't matter). */ # if (DBL_MANT_BIT % GMP_LIMB_BITS) != 0 # if (DBL_MANT_BIT % GMP_LIMB_BITS) > GMP_LIMB_BITS / 2 { mp_limb_t hi, lo; y *= (mp_limb_t) 1 << (DBL_MANT_BIT % (GMP_LIMB_BITS / 2)); hi = (int) y; y -= hi; if (!(y >= 0.0 && y < 1.0)) abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0 && y < 1.0)) abort (); m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; } # else { mp_limb_t d; y *= (mp_limb_t) 1 << (DBL_MANT_BIT % GMP_LIMB_BITS); d = (int) y; y -= d; if (!(y >= 0.0 && y < 1.0)) abort (); m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = d; } # endif # endif for (i = DBL_MANT_BIT / GMP_LIMB_BITS; i > 0; ) { mp_limb_t hi, lo; y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); hi = (int) y; y -= hi; if (!(y >= 0.0 && y < 1.0)) abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0 && y < 1.0)) abort (); m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; } if (!(y == 0.0)) abort (); /* Normalise. */ while (m.nlimbs > 0 && m.limbs[m.nlimbs - 1] == 0) m.nlimbs--; *mp = m; *ep = exp - DBL_MANT_BIT; return m.limbs; } # endif /* Assuming x = 2^e * m is finite and >= 0, and n is an integer: Returns the decimal representation of round (x * 10^n). Return the allocated memory - containing the decimal digits in low-to-high order, terminated with a NUL character - in case of success, NULL in case of memory allocation failure. */ static char * scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n) { int s; size_t extra_zeroes; unsigned int abs_n; unsigned int abs_s; mp_limb_t *pow5_ptr; size_t pow5_len; unsigned int s_limbs; unsigned int s_bits; mpn_t pow5; mpn_t z; void *z_memory; char *digits; if (memory == NULL) return NULL; /* x = 2^e * m, hence y = round (2^e * 10^n * m) = round (2^(e+n) * 5^n * m) = round (2^s * 5^n * m). */ s = e + n; extra_zeroes = 0; /* Factor out a common power of 10 if possible. */ if (s > 0 && n > 0) { extra_zeroes = (s < n ? s : n); s -= extra_zeroes; n -= extra_zeroes; } /* Here y = round (2^s * 5^n * m) * 10^extra_zeroes. Before converting to decimal, we need to compute z = round (2^s * 5^n * m). */ /* Compute 5^|n|, possibly shifted by |s| bits if n and s have the same sign. 2.322 is slightly larger than log(5)/log(2). */ abs_n = (n >= 0 ? n : -n); abs_s = (s >= 0 ? s : -s); pow5_ptr = (mp_limb_t *) malloc (((int)(abs_n * (2.322f / GMP_LIMB_BITS)) + 1 + abs_s / GMP_LIMB_BITS + 1) * sizeof (mp_limb_t)); if (pow5_ptr == NULL) { free (memory); return NULL; } /* Initialize with 1. */ pow5_ptr[0] = 1; pow5_len = 1; /* Multiply with 5^|n|. */ if (abs_n > 0) { static mp_limb_t const small_pow5[13 + 1] = { 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, 48828125, 244140625, 1220703125 }; unsigned int n13; for (n13 = 0; n13 <= abs_n; n13 += 13) { mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13]; size_t j; mp_twolimb_t carry = 0; for (j = 0; j < pow5_len; j++) { mp_limb_t digit2 = pow5_ptr[j]; carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; pow5_ptr[j] = (mp_limb_t) carry; carry = carry >> GMP_LIMB_BITS; } if (carry > 0) pow5_ptr[pow5_len++] = (mp_limb_t) carry; } } s_limbs = abs_s / GMP_LIMB_BITS; s_bits = abs_s % GMP_LIMB_BITS; if (n >= 0 ? s >= 0 : s <= 0) { /* Multiply with 2^|s|. */ if (s_bits > 0) { mp_limb_t *ptr = pow5_ptr; mp_twolimb_t accu = 0; size_t count; for (count = pow5_len; count > 0; count--) { accu += (mp_twolimb_t) *ptr << s_bits; *ptr++ = (mp_limb_t) accu; accu = accu >> GMP_LIMB_BITS; } if (accu > 0) { *ptr = (mp_limb_t) accu; pow5_len++; } } if (s_limbs > 0) { size_t count; for (count = pow5_len; count > 0;) { count--; pow5_ptr[s_limbs + count] = pow5_ptr[count]; } for (count = s_limbs; count > 0;) { count--; pow5_ptr[count] = 0; } pow5_len += s_limbs; } pow5.limbs = pow5_ptr; pow5.nlimbs = pow5_len; if (n >= 0) { /* Multiply m with pow5. No division needed. */ z_memory = multiply (m, pow5, &z); } else { /* Divide m by pow5 and round. */ z_memory = divide (m, pow5, &z); } } else { pow5.limbs = pow5_ptr; pow5.nlimbs = pow5_len; if (n >= 0) { /* n >= 0, s < 0. Multiply m with pow5, then divide by 2^|s|. */ mpn_t numerator; mpn_t denominator; void *tmp_memory; tmp_memory = multiply (m, pow5, &numerator); if (tmp_memory == NULL) { free (pow5_ptr); free (memory); return NULL; } /* Construct 2^|s|. */ { mp_limb_t *ptr = pow5_ptr + pow5_len; size_t i; for (i = 0; i < s_limbs; i++) ptr[i] = 0; ptr[s_limbs] = (mp_limb_t) 1 << s_bits; denominator.limbs = ptr; denominator.nlimbs = s_limbs + 1; } z_memory = divide (numerator, denominator, &z); free (tmp_memory); } else { /* n < 0, s > 0. Multiply m with 2^s, then divide by pow5. */ mpn_t numerator; mp_limb_t *num_ptr; num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1) * sizeof (mp_limb_t)); if (num_ptr == NULL) { free (pow5_ptr); free (memory); return NULL; } { mp_limb_t *destptr = num_ptr; { size_t i; for (i = 0; i < s_limbs; i++) *destptr++ = 0; } if (s_bits > 0) { const mp_limb_t *sourceptr = m.limbs; mp_twolimb_t accu = 0; size_t count; for (count = m.nlimbs; count > 0; count--) { accu += (mp_twolimb_t) *sourceptr++ << s_bits; *destptr++ = (mp_limb_t) accu; accu = accu >> GMP_LIMB_BITS; } if (accu > 0) *destptr++ = (mp_limb_t) accu; } else { const mp_limb_t *sourceptr = m.limbs; size_t count; for (count = m.nlimbs; count > 0; count--) *destptr++ = *sourceptr++; } numerator.limbs = num_ptr; numerator.nlimbs = destptr - num_ptr; } z_memory = divide (numerator, pow5, &z); free (num_ptr); } } free (pow5_ptr); free (memory); /* Here y = round (x * 10^n) = z * 10^extra_zeroes. */ if (z_memory == NULL) return NULL; digits = convert_to_decimal (z, extra_zeroes); free (z_memory); return digits; } # if NEED_PRINTF_LONG_DOUBLE /* Assuming x is finite and >= 0, and n is an integer: Returns the decimal representation of round (x * 10^n). Return the allocated memory - containing the decimal digits in low-to-high order, terminated with a NUL character - in case of success, NULL in case of memory allocation failure. */ static char * scale10_round_decimal_long_double (long double x, int n) { int e; mpn_t m; void *memory = decode_long_double (x, &e, &m); return scale10_round_decimal_decoded (e, m, memory, n); } # endif # if NEED_PRINTF_DOUBLE /* Assuming x is finite and >= 0, and n is an integer: Returns the decimal representation of round (x * 10^n). Return the allocated memory - containing the decimal digits in low-to-high order, terminated with a NUL character - in case of success, NULL in case of memory allocation failure. */ static char * scale10_round_decimal_double (double x, int n) { int e; mpn_t m; void *memory = decode_double (x, &e, &m); return scale10_round_decimal_decoded (e, m, memory, n); } # endif # if NEED_PRINTF_LONG_DOUBLE /* Assuming x is finite and > 0: Return an approximation for n with 10^n <= x < 10^(n+1). The approximation is usually the right n, but may be off by 1 sometimes. */ static int floorlog10l (long double x) { int exp; long double y; double z; double l; /* Split into exponential part and mantissa. */ y = frexpl (x, &exp); if (!(y >= 0.0L && y < 1.0L)) abort (); if (y == 0.0L) return INT_MIN; if (y < 0.5L) { while (y < (1.0L / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2)))) { y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); exp -= GMP_LIMB_BITS; } if (y < (1.0L / (1 << 16))) { y *= 1.0L * (1 << 16); exp -= 16; } if (y < (1.0L / (1 << 8))) { y *= 1.0L * (1 << 8); exp -= 8; } if (y < (1.0L / (1 << 4))) { y *= 1.0L * (1 << 4); exp -= 4; } if (y < (1.0L / (1 << 2))) { y *= 1.0L * (1 << 2); exp -= 2; } if (y < (1.0L / (1 << 1))) { y *= 1.0L * (1 << 1); exp -= 1; } } if (!(y >= 0.5L && y < 1.0L)) abort (); /* Compute an approximation for l = log2(x) = exp + log2(y). */ l = exp; z = y; if (z < 0.70710678118654752444) { z *= 1.4142135623730950488; l -= 0.5; } if (z < 0.8408964152537145431) { z *= 1.1892071150027210667; l -= 0.25; } if (z < 0.91700404320467123175) { z *= 1.0905077326652576592; l -= 0.125; } if (z < 0.9576032806985736469) { z *= 1.0442737824274138403; l -= 0.0625; } /* Now 0.95 <= z <= 1.01. */ z = 1 - z; /* log(1-z) = - z - z^2/2 - z^3/3 - z^4/4 - ... Four terms are enough to get an approximation with error < 10^-7. */ l -= z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25))); /* Finally multiply with log(2)/log(10), yields an approximation for log10(x). */ l *= 0.30102999566398119523; /* Round down to the next integer. */ return (int) l + (l < 0 ? -1 : 0); } # endif # if NEED_PRINTF_DOUBLE /* Assuming x is finite and > 0: Return an approximation for n with 10^n <= x < 10^(n+1). The approximation is usually the right n, but may be off by 1 sometimes. */ static int floorlog10 (double x) { int exp; double y; double z; double l; /* Split into exponential part and mantissa. */ y = frexp (x, &exp); if (!(y >= 0.0 && y < 1.0)) abort (); if (y == 0.0) return INT_MIN; if (y < 0.5) { while (y < (1.0 / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2)))) { y *= 1.0 * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); exp -= GMP_LIMB_BITS; } if (y < (1.0 / (1 << 16))) { y *= 1.0 * (1 << 16); exp -= 16; } if (y < (1.0 / (1 << 8))) { y *= 1.0 * (1 << 8); exp -= 8; } if (y < (1.0 / (1 << 4))) { y *= 1.0 * (1 << 4); exp -= 4; } if (y < (1.0 / (1 << 2))) { y *= 1.0 * (1 << 2); exp -= 2; } if (y < (1.0 / (1 << 1))) { y *= 1.0 * (1 << 1); exp -= 1; } } if (!(y >= 0.5 && y < 1.0)) abort (); /* Compute an approximation for l = log2(x) = exp + log2(y). */ l = exp; z = y; if (z < 0.70710678118654752444) { z *= 1.4142135623730950488; l -= 0.5; } if (z < 0.8408964152537145431) { z *= 1.1892071150027210667; l -= 0.25; } if (z < 0.91700404320467123175) { z *= 1.0905077326652576592; l -= 0.125; } if (z < 0.9576032806985736469) { z *= 1.0442737824274138403; l -= 0.0625; } /* Now 0.95 <= z <= 1.01. */ z = 1 - z; /* log(1-z) = - z - z^2/2 - z^3/3 - z^4/4 - ... Four terms are enough to get an approximation with error < 10^-7. */ l -= z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25))); /* Finally multiply with log(2)/log(10), yields an approximation for log10(x). */ l *= 0.30102999566398119523; /* Round down to the next integer. */ return (int) l + (l < 0 ? -1 : 0); } # endif #endif DCHAR_T * VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, const FCHAR_T *format, va_list args) { DIRECTIVES d; arguments a; if (PRINTF_PARSE (format, &d, &a) < 0) /* errno is already set. */ return NULL; #define CLEANUP() \ free (d.dir); \ if (a.arg) \ free (a.arg); if (PRINTF_FETCHARGS (args, &a) < 0) { CLEANUP (); errno = EINVAL; return NULL; } { size_t buf_neededlength; TCHAR_T *buf; TCHAR_T *buf_malloced; const FCHAR_T *cp; size_t i; DIRECTIVE *dp; /* Output string accumulator. */ DCHAR_T *result; size_t allocated; size_t length; /* Allocate a small buffer that will hold a directive passed to sprintf or snprintf. */ buf_neededlength = xsum4 (7, d.max_width_length, d.max_precision_length, 6); #if HAVE_ALLOCA if (buf_neededlength < 4000 / sizeof (TCHAR_T)) { buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T)); buf_malloced = NULL; } else #endif { size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T)); if (size_overflow_p (buf_memsize)) goto out_of_memory_1; buf = (TCHAR_T *) malloc (buf_memsize); if (buf == NULL) goto out_of_memory_1; buf_malloced = buf; } if (resultbuf != NULL) { result = resultbuf; allocated = *lengthp; } else { result = NULL; allocated = 0; } length = 0; /* Invariants: result is either == resultbuf or == NULL or malloc-allocated. If length > 0, then result != NULL. */ /* Ensures that allocated >= needed. Aborts through a jump to out_of_memory if needed is SIZE_MAX or otherwise too big. */ #define ENSURE_ALLOCATION(needed) \ if ((needed) > allocated) \ { \ size_t memory_size; \ DCHAR_T *memory; \ \ allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ if ((needed) > allocated) \ allocated = (needed); \ memory_size = xtimes (allocated, sizeof (DCHAR_T)); \ if (size_overflow_p (memory_size)) \ goto out_of_memory; \ if (result == resultbuf || result == NULL) \ memory = (DCHAR_T *) malloc (memory_size); \ else \ memory = (DCHAR_T *) realloc (result, memory_size); \ if (memory == NULL) \ goto out_of_memory; \ if (result == resultbuf && length > 0) \ DCHAR_CPY (memory, result, length); \ result = memory; \ } for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) { if (cp != dp->dir_start) { size_t n = dp->dir_start - cp; size_t augmented_length = xsum (length, n); ENSURE_ALLOCATION (augmented_length); /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we need that the format string contains only ASCII characters if FCHAR_T and DCHAR_T are not the same type. */ if (sizeof (FCHAR_T) == sizeof (DCHAR_T)) { DCHAR_CPY (result + length, (const DCHAR_T *) cp, n); length = augmented_length; } else { do result[length++] = (unsigned char) *cp++; while (--n > 0); } } if (i == d.count) break; /* Execute a single directive. */ if (dp->conversion == '%') { size_t augmented_length; if (!(dp->arg_index == ARG_NONE)) abort (); augmented_length = xsum (length, 1); ENSURE_ALLOCATION (augmented_length); result[length] = '%'; length = augmented_length; } else { if (!(dp->arg_index != ARG_NONE)) abort (); if (dp->conversion == 'n') { switch (a.arg[dp->arg_index].type) { case TYPE_COUNT_SCHAR_POINTER: *a.arg[dp->arg_index].a.a_count_schar_pointer = length; break; case TYPE_COUNT_SHORT_POINTER: *a.arg[dp->arg_index].a.a_count_short_pointer = length; break; case TYPE_COUNT_INT_POINTER: *a.arg[dp->arg_index].a.a_count_int_pointer = length; break; case TYPE_COUNT_LONGINT_POINTER: *a.arg[dp->arg_index].a.a_count_longint_pointer = length; break; #if HAVE_LONG_LONG_INT case TYPE_COUNT_LONGLONGINT_POINTER: *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; break; #endif default: abort (); } } #if ENABLE_UNISTDIO /* The unistdio extensions. */ else if (dp->conversion == 'U') { arg_type type = a.arg[dp->arg_index].type; int flags = dp->flags; int has_width; size_t width; int has_precision; size_t precision; has_width = 0; width = 0; if (dp->width_start != dp->width_end) { if (dp->width_arg_index != ARG_NONE) { int arg; if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) abort (); arg = a.arg[dp->width_arg_index].a.a_int; if (arg < 0) { /* "A negative field width is taken as a '-' flag followed by a positive field width." */ flags |= FLAG_LEFT; width = (unsigned int) (-arg); } else width = arg; } else { const FCHAR_T *digitp = dp->width_start; do width = xsum (xtimes (width, 10), *digitp++ - '0'); while (digitp != dp->width_end); } has_width = 1; } has_precision = 0; precision = 0; if (dp->precision_start != dp->precision_end) { if (dp->precision_arg_index != ARG_NONE) { int arg; if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) abort (); arg = a.arg[dp->precision_arg_index].a.a_int; /* "A negative precision is taken as if the precision were omitted." */ if (arg >= 0) { precision = arg; has_precision = 1; } } else { const FCHAR_T *digitp = dp->precision_start + 1; precision = 0; while (digitp != dp->precision_end) precision = xsum (xtimes (precision, 10), *digitp++ - '0'); has_precision = 1; } } switch (type) { case TYPE_U8_STRING: { const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string; const uint8_t *arg_end; size_t characters; if (has_precision) { /* Use only PRECISION characters, from the left. */ arg_end = arg; characters = 0; for (; precision > 0; precision--) { int count = u8_strmblen (arg_end); if (count == 0) break; if (count < 0) { if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); errno = EILSEQ; return NULL; } arg_end += count; characters++; } } else if (has_width) { /* Use the entire string, and count the number of characters. */ arg_end = arg; characters = 0; for (;;) { int count = u8_strmblen (arg_end); if (count == 0) break; if (count < 0) { if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); errno = EILSEQ; return NULL; } arg_end += count; characters++; } } else { /* Use the entire string. */ arg_end = arg + u8_strlen (arg); /* The number of characters doesn't matter. */ characters = 0; } if (has_width && width > characters && !(dp->flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); DCHAR_SET (result + length, ' ', n); length += n; } # if DCHAR_IS_UINT8_T { size_t n = arg_end - arg; ENSURE_ALLOCATION (xsum (length, n)); DCHAR_CPY (result + length, arg, n); length += n; } # else { /* Convert. */ DCHAR_T *converted = result + length; size_t converted_len = allocated - length; # if DCHAR_IS_TCHAR /* Convert from UTF-8 to locale encoding. */ if (u8_conv_to_encoding (locale_charset (), iconveh_question_mark, arg, arg_end - arg, NULL, &converted, &converted_len) < 0) # else /* Convert from UTF-8 to UTF-16/UTF-32. */ converted = U8_TO_DCHAR (arg, arg_end - arg, converted, &converted_len); if (converted == NULL) # endif { int saved_errno = errno; if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); errno = saved_errno; return NULL; } if (converted != result + length) { ENSURE_ALLOCATION (xsum (length, converted_len)); DCHAR_CPY (result + length, converted, converted_len); free (converted); } length += converted_len; } # endif if (has_width && width > characters && (dp->flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); DCHAR_SET (result + length, ' ', n); length += n; } } break; case TYPE_U16_STRING: { const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string; const uint16_t *arg_end; size_t characters; if (has_precision) { /* Use only PRECISION characters, from the left. */ arg_end = arg; characters = 0; for (; precision > 0; precision--) { int count = u16_strmblen (arg_end); if (count == 0) break; if (count < 0) { if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); errno = EILSEQ; return NULL; } arg_end += count; characters++; } } else if (has_width) { /* Use the entire string, and count the number of characters. */ arg_end = arg; characters = 0; for (;;) { int count = u16_strmblen (arg_end); if (count == 0) break; if (count < 0) { if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); errno = EILSEQ; return NULL; } arg_end += count; characters++; } } else { /* Use the entire string. */ arg_end = arg + u16_strlen (arg); /* The number of characters doesn't matter. */ characters = 0; } if (has_width && width > characters && !(dp->flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); DCHAR_SET (result + length, ' ', n); length += n; } # if DCHAR_IS_UINT16_T { size_t n = arg_end - arg; ENSURE_ALLOCATION (xsum (length, n)); DCHAR_CPY (result + length, arg, n); length += n; } # else { /* Convert. */ DCHAR_T *converted = result + length; size_t converted_len = allocated - length; # if DCHAR_IS_TCHAR /* Convert from UTF-16 to locale encoding. */ if (u16_conv_to_encoding (locale_charset (), iconveh_question_mark, arg, arg_end - arg, NULL, &converted, &converted_len) < 0) # else /* Convert from UTF-16 to UTF-8/UTF-32. */ converted = U16_TO_DCHAR (arg, arg_end - arg, converted, &converted_len); if (converted == NULL) # endif { int saved_errno = errno; if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); errno = saved_errno; return NULL; } if (converted != result + length) { ENSURE_ALLOCATION (xsum (length, converted_len)); DCHAR_CPY (result + length, converted, converted_len); free (converted); } length += converted_len; } # endif if (has_width && width > characters && (dp->flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); DCHAR_SET (result + length, ' ', n); length += n; } } break; case TYPE_U32_STRING: { const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string; const uint32_t *arg_end; size_t characters; if (has_precision) { /* Use only PRECISION characters, from the left. */ arg_end = arg; characters = 0; for (; precision > 0; precision--) { int count = u32_strmblen (arg_end); if (count == 0) break; if (count < 0) { if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); errno = EILSEQ; return NULL; } arg_end += count; characters++; } } else if (has_width) { /* Use the entire string, and count the number of characters. */ arg_end = arg; characters = 0; for (;;) { int count = u32_strmblen (arg_end); if (count == 0) break; if (count < 0) { if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); errno = EILSEQ; return NULL; } arg_end += count; characters++; } } else { /* Use the entire string. */ arg_end = arg + u32_strlen (arg); /* The number of characters doesn't matter. */ characters = 0; } if (has_width && width > characters && !(dp->flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); DCHAR_SET (result + length, ' ', n); length += n; } # if DCHAR_IS_UINT32_T { size_t n = arg_end - arg; ENSURE_ALLOCATION (xsum (length, n)); DCHAR_CPY (result + length, arg, n); length += n; } # else { /* Convert. */ DCHAR_T *converted = result + length; size_t converted_len = allocated - length; # if DCHAR_IS_TCHAR /* Convert from UTF-32 to locale encoding. */ if (u32_conv_to_encoding (locale_charset (), iconveh_question_mark, arg, arg_end - arg, NULL, &converted, &converted_len) < 0) # else /* Convert from UTF-32 to UTF-8/UTF-16. */ converted = U32_TO_DCHAR (arg, arg_end - arg, converted, &converted_len); if (converted == NULL) # endif { int saved_errno = errno; if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); errno = saved_errno; return NULL; } if (converted != result + length) { ENSURE_ALLOCATION (xsum (length, converted_len)); DCHAR_CPY (result + length, converted, converted_len); free (converted); } length += converted_len; } # endif if (has_width && width > characters && (dp->flags & FLAG_LEFT)) { size_t n = width - characters; ENSURE_ALLOCATION (xsum (length, n)); DCHAR_SET (result + length, ' ', n); length += n; } } break; default: abort (); } } #endif #if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL else if ((dp->conversion == 'a' || dp->conversion == 'A') # if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE)) && (0 # if NEED_PRINTF_DOUBLE || a.arg[dp->arg_index].type == TYPE_DOUBLE # endif # if NEED_PRINTF_LONG_DOUBLE || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE # endif ) # endif ) { arg_type type = a.arg[dp->arg_index].type; int flags = dp->flags; int has_width; size_t width; int has_precision; size_t precision; size_t tmp_length; DCHAR_T tmpbuf[700]; DCHAR_T *tmp; DCHAR_T *pad_ptr; DCHAR_T *p; has_width = 0; width = 0; if (dp->width_start != dp->width_end) { if (dp->width_arg_index != ARG_NONE) { int arg; if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) abort (); arg = a.arg[dp->width_arg_index].a.a_int; if (arg < 0) { /* "A negative field width is taken as a '-' flag followed by a positive field width." */ flags |= FLAG_LEFT; width = (unsigned int) (-arg); } else width = arg; } else { const FCHAR_T *digitp = dp->width_start; do width = xsum (xtimes (width, 10), *digitp++ - '0'); while (digitp != dp->width_end); } has_width = 1; } has_precision = 0; precision = 0; if (dp->precision_start != dp->precision_end) { if (dp->precision_arg_index != ARG_NONE) { int arg; if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) abort (); arg = a.arg[dp->precision_arg_index].a.a_int; /* "A negative precision is taken as if the precision were omitted." */ if (arg >= 0) { precision = arg; has_precision = 1; } } else { const FCHAR_T *digitp = dp->precision_start + 1; precision = 0; while (digitp != dp->precision_end) precision = xsum (xtimes (precision, 10), *digitp++ - '0'); has_precision = 1; } } /* Allocate a temporary buffer of sufficient size. */ if (type == TYPE_LONGDOUBLE) tmp_length = (unsigned int) ((LDBL_DIG + 1) * 0.831 /* decimal -> hexadecimal */ ) + 1; /* turn floor into ceil */ else tmp_length = (unsigned int) ((DBL_DIG + 1) * 0.831 /* decimal -> hexadecimal */ ) + 1; /* turn floor into ceil */ if (tmp_length < precision) tmp_length = precision; /* Account for sign, decimal point etc. */ tmp_length = xsum (tmp_length, 12); if (tmp_length < width) tmp_length = width; tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) tmp = tmpbuf; else { size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); if (size_overflow_p (tmp_memsize)) /* Overflow, would lead to out of memory. */ goto out_of_memory; tmp = (DCHAR_T *) malloc (tmp_memsize); if (tmp == NULL) /* Out of memory. */ goto out_of_memory; } pad_ptr = NULL; p = tmp; if (type == TYPE_LONGDOUBLE) { # if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE long double arg = a.arg[dp->arg_index].a.a_longdouble; if (isnanl (arg)) { if (dp->conversion == 'A') { *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; } else { *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; } } else { int sign = 0; DECL_LONG_DOUBLE_ROUNDING BEGIN_LONG_DOUBLE_ROUNDING (); if (signbit (arg)) /* arg < 0.0L or negative zero */ { sign = -1; arg = -arg; } if (sign < 0) *p++ = '-'; else if (flags & FLAG_SHOWSIGN) *p++ = '+'; else if (flags & FLAG_SPACE) *p++ = ' '; if (arg > 0.0L && arg + arg == arg) { if (dp->conversion == 'A') { *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; } else { *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; } } else { int exponent; long double mantissa; if (arg > 0.0L) mantissa = printf_frexpl (arg, &exponent); else { exponent = 0; mantissa = 0.0L; } if (has_precision && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1) { /* Round the mantissa. */ long double tail = mantissa; size_t q; for (q = precision; ; q--) { int digit = (int) tail; tail -= digit; if (q == 0) { if (digit & 1 ? tail >= 0.5L : tail > 0.5L) tail = 1 - tail; else tail = - tail; break; } tail *= 16.0L; } if (tail != 0.0L) for (q = precision; q > 0; q--) tail *= 0.0625L; mantissa += tail; } *p++ = '0'; *p++ = dp->conversion - 'A' + 'X'; pad_ptr = p; { int digit; digit = (int) mantissa; mantissa -= digit; *p++ = '0' + digit; if ((flags & FLAG_ALT) || mantissa > 0.0L || precision > 0) { *p++ = decimal_point_char (); /* This loop terminates because we assume that FLT_RADIX is a power of 2. */ while (mantissa > 0.0L) { mantissa *= 16.0L; digit = (int) mantissa; mantissa -= digit; *p++ = digit + (digit < 10 ? '0' : dp->conversion - 10); if (precision > 0) precision--; } while (precision > 0) { *p++ = '0'; precision--; } } } *p++ = dp->conversion - 'A' + 'P'; # if WIDE_CHAR_VERSION { static const wchar_t decimal_format[] = { '%', '+', 'd', '\0' }; SNPRINTF (p, 6 + 1, decimal_format, exponent); } while (*p != '\0') p++; # else if (sizeof (DCHAR_T) == 1) { sprintf ((char *) p, "%+d", exponent); while (*p != '\0') p++; } else { char expbuf[6 + 1]; const char *ep; sprintf (expbuf, "%+d", exponent); for (ep = expbuf; (*p = *ep) != '\0'; ep++) p++; } # endif } END_LONG_DOUBLE_ROUNDING (); } # else abort (); # endif } else { # if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE double arg = a.arg[dp->arg_index].a.a_double; if (isnan (arg)) { if (dp->conversion == 'A') { *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; } else { *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; } } else { int sign = 0; if (signbit (arg)) /* arg < 0.0 or negative zero */ { sign = -1; arg = -arg; } if (sign < 0) *p++ = '-'; else if (flags & FLAG_SHOWSIGN) *p++ = '+'; else if (flags & FLAG_SPACE) *p++ = ' '; if (arg > 0.0 && arg + arg == arg) { if (dp->conversion == 'A') { *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; } else { *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; } } else { int exponent; double mantissa; if (arg > 0.0) mantissa = printf_frexp (arg, &exponent); else { exponent = 0; mantissa = 0.0; } if (has_precision && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1) { /* Round the mantissa. */ double tail = mantissa; size_t q; for (q = precision; ; q--) { int digit = (int) tail; tail -= digit; if (q == 0) { if (digit & 1 ? tail >= 0.5 : tail > 0.5) tail = 1 - tail; else tail = - tail; break; } tail *= 16.0; } if (tail != 0.0) for (q = precision; q > 0; q--) tail *= 0.0625; mantissa += tail; } *p++ = '0'; *p++ = dp->conversion - 'A' + 'X'; pad_ptr = p; { int digit; digit = (int) mantissa; mantissa -= digit; *p++ = '0' + digit; if ((flags & FLAG_ALT) || mantissa > 0.0 || precision > 0) { *p++ = decimal_point_char (); /* This loop terminates because we assume that FLT_RADIX is a power of 2. */ while (mantissa > 0.0) { mantissa *= 16.0; digit = (int) mantissa; mantissa -= digit; *p++ = digit + (digit < 10 ? '0' : dp->conversion - 10); if (precision > 0) precision--; } while (precision > 0) { *p++ = '0'; precision--; } } } *p++ = dp->conversion - 'A' + 'P'; # if WIDE_CHAR_VERSION { static const wchar_t decimal_format[] = { '%', '+', 'd', '\0' }; SNPRINTF (p, 6 + 1, decimal_format, exponent); } while (*p != '\0') p++; # else if (sizeof (DCHAR_T) == 1) { sprintf ((char *) p, "%+d", exponent); while (*p != '\0') p++; } else { char expbuf[6 + 1]; const char *ep; sprintf (expbuf, "%+d", exponent); for (ep = expbuf; (*p = *ep) != '\0'; ep++) p++; } # endif } } # else abort (); # endif } /* The generated string now extends from tmp to p, with the zero padding insertion point being at pad_ptr. */ if (has_width && p - tmp < width) { size_t pad = width - (p - tmp); DCHAR_T *end = p + pad; if (flags & FLAG_LEFT) { /* Pad with spaces on the right. */ for (; pad > 0; pad--) *p++ = ' '; } else if ((flags & FLAG_ZERO) && pad_ptr != NULL) { /* Pad with zeroes. */ DCHAR_T *q = end; while (p > pad_ptr) *--q = *--p; for (; pad > 0; pad--) *p++ = '0'; } else { /* Pad with spaces on the left. */ DCHAR_T *q = end; while (p > tmp) *--q = *--p; for (; pad > 0; pad--) *p++ = ' '; } p = end; } { size_t count = p - tmp; if (count >= tmp_length) /* tmp_length was incorrectly calculated - fix the code above! */ abort (); /* Make room for the result. */ if (count >= allocated - length) { size_t n = xsum (length, count); ENSURE_ALLOCATION (n); } /* Append the result. */ memcpy (result + length, tmp, count * sizeof (DCHAR_T)); if (tmp != tmpbuf) free (tmp); length += count; } } #endif #if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL else if ((dp->conversion == 'f' || dp->conversion == 'F' || dp->conversion == 'e' || dp->conversion == 'E' || dp->conversion == 'g' || dp->conversion == 'G' || dp->conversion == 'a' || dp->conversion == 'A') && (0 # if NEED_PRINTF_DOUBLE || a.arg[dp->arg_index].type == TYPE_DOUBLE # elif NEED_PRINTF_INFINITE_DOUBLE || (a.arg[dp->arg_index].type == TYPE_DOUBLE /* The systems (mingw) which produce wrong output for Inf, -Inf, and NaN also do so for -0.0. Therefore we treat this case here as well. */ && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double)) # endif # if NEED_PRINTF_LONG_DOUBLE || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE # elif NEED_PRINTF_INFINITE_LONG_DOUBLE || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE /* Some systems produce wrong output for Inf, -Inf, and NaN. */ && is_infinitel (a.arg[dp->arg_index].a.a_longdouble)) # endif )) { # if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) arg_type type = a.arg[dp->arg_index].type; # endif int flags = dp->flags; int has_width; size_t width; int has_precision; size_t precision; size_t tmp_length; DCHAR_T tmpbuf[700]; DCHAR_T *tmp; DCHAR_T *pad_ptr; DCHAR_T *p; has_width = 0; width = 0; if (dp->width_start != dp->width_end) { if (dp->width_arg_index != ARG_NONE) { int arg; if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) abort (); arg = a.arg[dp->width_arg_index].a.a_int; if (arg < 0) { /* "A negative field width is taken as a '-' flag followed by a positive field width." */ flags |= FLAG_LEFT; width = (unsigned int) (-arg); } else width = arg; } else { const FCHAR_T *digitp = dp->width_start; do width = xsum (xtimes (width, 10), *digitp++ - '0'); while (digitp != dp->width_end); } has_width = 1; } has_precision = 0; precision = 0; if (dp->precision_start != dp->precision_end) { if (dp->precision_arg_index != ARG_NONE) { int arg; if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) abort (); arg = a.arg[dp->precision_arg_index].a.a_int; /* "A negative precision is taken as if the precision were omitted." */ if (arg >= 0) { precision = arg; has_precision = 1; } } else { const FCHAR_T *digitp = dp->precision_start + 1; precision = 0; while (digitp != dp->precision_end) precision = xsum (xtimes (precision, 10), *digitp++ - '0'); has_precision = 1; } } /* POSIX specifies the default precision to be 6 for %f, %F, %e, %E, but not for %g, %G. Implementations appear to use the same default precision also for %g, %G. */ if (!has_precision) precision = 6; /* Allocate a temporary buffer of sufficient size. */ # if NEED_PRINTF_DOUBLE && NEED_PRINTF_LONG_DOUBLE tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1); # elif NEED_PRINTF_INFINITE_DOUBLE && NEED_PRINTF_LONG_DOUBLE tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0); # elif NEED_PRINTF_LONG_DOUBLE tmp_length = LDBL_DIG + 1; # elif NEED_PRINTF_DOUBLE tmp_length = DBL_DIG + 1; # else tmp_length = 0; # endif if (tmp_length < precision) tmp_length = precision; # if NEED_PRINTF_LONG_DOUBLE # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE if (type == TYPE_LONGDOUBLE) # endif if (dp->conversion == 'f' || dp->conversion == 'F') { long double arg = a.arg[dp->arg_index].a.a_longdouble; if (!(isnanl (arg) || arg + arg == arg)) { /* arg is finite and nonzero. */ int exponent = floorlog10l (arg < 0 ? -arg : arg); if (exponent >= 0 && tmp_length < exponent + precision) tmp_length = exponent + precision; } } # endif # if NEED_PRINTF_DOUBLE # if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE if (type == TYPE_DOUBLE) # endif if (dp->conversion == 'f' || dp->conversion == 'F') { double arg = a.arg[dp->arg_index].a.a_double; if (!(isnan (arg) || arg + arg == arg)) { /* arg is finite and nonzero. */ int exponent = floorlog10 (arg < 0 ? -arg : arg); if (exponent >= 0 && tmp_length < exponent + precision) tmp_length = exponent + precision; } } # endif /* Account for sign, decimal point etc. */ tmp_length = xsum (tmp_length, 12); if (tmp_length < width) tmp_length = width; tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) tmp = tmpbuf; else { size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); if (size_overflow_p (tmp_memsize)) /* Overflow, would lead to out of memory. */ goto out_of_memory; tmp = (DCHAR_T *) malloc (tmp_memsize); if (tmp == NULL) /* Out of memory. */ goto out_of_memory; } pad_ptr = NULL; p = tmp; # if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE if (type == TYPE_LONGDOUBLE) # endif { long double arg = a.arg[dp->arg_index].a.a_longdouble; if (isnanl (arg)) { if (dp->conversion >= 'A' && dp->conversion <= 'Z') { *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; } else { *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; } } else { int sign = 0; DECL_LONG_DOUBLE_ROUNDING BEGIN_LONG_DOUBLE_ROUNDING (); if (signbit (arg)) /* arg < 0.0L or negative zero */ { sign = -1; arg = -arg; } if (sign < 0) *p++ = '-'; else if (flags & FLAG_SHOWSIGN) *p++ = '+'; else if (flags & FLAG_SPACE) *p++ = ' '; if (arg > 0.0L && arg + arg == arg) { if (dp->conversion >= 'A' && dp->conversion <= 'Z') { *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; } else { *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; } } else { # if NEED_PRINTF_LONG_DOUBLE pad_ptr = p; if (dp->conversion == 'f' || dp->conversion == 'F') { char *digits; size_t ndigits; digits = scale10_round_decimal_long_double (arg, precision); if (digits == NULL) { END_LONG_DOUBLE_ROUNDING (); goto out_of_memory; } ndigits = strlen (digits); if (ndigits > precision) do { --ndigits; *p++ = digits[ndigits]; } while (ndigits > precision); else *p++ = '0'; /* Here ndigits <= precision. */ if ((flags & FLAG_ALT) || precision > 0) { *p++ = decimal_point_char (); for (; precision > ndigits; precision--) *p++ = '0'; while (ndigits > 0) { --ndigits; *p++ = digits[ndigits]; } } free (digits); } else if (dp->conversion == 'e' || dp->conversion == 'E') { int exponent; if (arg == 0.0L) { exponent = 0; *p++ = '0'; if ((flags & FLAG_ALT) || precision > 0) { *p++ = decimal_point_char (); for (; precision > 0; precision--) *p++ = '0'; } } else { /* arg > 0.0L. */ int adjusted; char *digits; size_t ndigits; exponent = floorlog10l (arg); adjusted = 0; for (;;) { digits = scale10_round_decimal_long_double (arg, (int)precision - exponent); if (digits == NULL) { END_LONG_DOUBLE_ROUNDING (); goto out_of_memory; } ndigits = strlen (digits); if (ndigits == precision + 1) break; if (ndigits < precision || ndigits > precision + 2) /* The exponent was not guessed precisely enough. */ abort (); if (adjusted) /* None of two values of exponent is the right one. Prevent an endless loop. */ abort (); free (digits); if (ndigits == precision) exponent -= 1; else exponent += 1; adjusted = 1; } /* Here ndigits = precision+1. */ *p++ = digits[--ndigits]; if ((flags & FLAG_ALT) || precision > 0) { *p++ = decimal_point_char (); while (ndigits > 0) { --ndigits; *p++ = digits[ndigits]; } } free (digits); } *p++ = dp->conversion; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION { static const wchar_t decimal_format[] = { '%', '+', '.', '2', 'd', '\0' }; SNPRINTF (p, 6 + 1, decimal_format, exponent); } while (*p != '\0') p++; # else if (sizeof (DCHAR_T) == 1) { sprintf ((char *) p, "%+.2d", exponent); while (*p != '\0') p++; } else { char expbuf[6 + 1]; const char *ep; sprintf (expbuf, "%+.2d", exponent); for (ep = expbuf; (*p = *ep) != '\0'; ep++) p++; } # endif } else if (dp->conversion == 'g' || dp->conversion == 'G') { if (precision == 0) precision = 1; /* precision >= 1. */ if (arg == 0.0L) /* The exponent is 0, >= -4, < precision. Use fixed-point notation. */ { size_t ndigits = precision; /* Number of trailing zeroes that have to be dropped. */ size_t nzeroes = (flags & FLAG_ALT ? 0 : precision - 1); --ndigits; *p++ = '0'; if ((flags & FLAG_ALT) || ndigits > nzeroes) { *p++ = decimal_point_char (); while (ndigits > nzeroes) { --ndigits; *p++ = '0'; } } } else { /* arg > 0.0L. */ int exponent; int adjusted; char *digits; size_t ndigits; size_t nzeroes; exponent = floorlog10l (arg); adjusted = 0; for (;;) { digits = scale10_round_decimal_long_double (arg, (int)(precision - 1) - exponent); if (digits == NULL) { END_LONG_DOUBLE_ROUNDING (); goto out_of_memory; } ndigits = strlen (digits); if (ndigits == precision) break; if (ndigits < precision - 1 || ndigits > precision + 1) /* The exponent was not guessed precisely enough. */ abort (); if (adjusted) /* None of two values of exponent is the right one. Prevent an endless loop. */ abort (); free (digits); if (ndigits < precision) exponent -= 1; else exponent += 1; adjusted = 1; } /* Here ndigits = precision. */ /* Determine the number of trailing zeroes that have to be dropped. */ nzeroes = 0; if ((flags & FLAG_ALT) == 0) while (nzeroes < ndigits && digits[nzeroes] == '0') nzeroes++; /* The exponent is now determined. */ if (exponent >= -4 && exponent < (long)precision) { /* Fixed-point notation: max(exponent,0)+1 digits, then the decimal point, then the remaining digits without trailing zeroes. */ if (exponent >= 0) { size_t count = exponent + 1; /* Note: count <= precision = ndigits. */ for (; count > 0; count--) *p++ = digits[--ndigits]; if ((flags & FLAG_ALT) || ndigits > nzeroes) { *p++ = decimal_point_char (); while (ndigits > nzeroes) { --ndigits; *p++ = digits[ndigits]; } } } else { size_t count = -exponent - 1; *p++ = '0'; *p++ = decimal_point_char (); for (; count > 0; count--) *p++ = '0'; while (ndigits > nzeroes) { --ndigits; *p++ = digits[ndigits]; } } } else { /* Exponential notation. */ *p++ = digits[--ndigits]; if ((flags & FLAG_ALT) || ndigits > nzeroes) { *p++ = decimal_point_char (); while (ndigits > nzeroes) { --ndigits; *p++ = digits[ndigits]; } } *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION { static const wchar_t decimal_format[] = { '%', '+', '.', '2', 'd', '\0' }; SNPRINTF (p, 6 + 1, decimal_format, exponent); } while (*p != '\0') p++; # else if (sizeof (DCHAR_T) == 1) { sprintf ((char *) p, "%+.2d", exponent); while (*p != '\0') p++; } else { char expbuf[6 + 1]; const char *ep; sprintf (expbuf, "%+.2d", exponent); for (ep = expbuf; (*p = *ep) != '\0'; ep++) p++; } # endif } free (digits); } } else abort (); # else /* arg is finite. */ abort (); # endif } END_LONG_DOUBLE_ROUNDING (); } } # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE else # endif # endif # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE { double arg = a.arg[dp->arg_index].a.a_double; if (isnan (arg)) { if (dp->conversion >= 'A' && dp->conversion <= 'Z') { *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; } else { *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; } } else { int sign = 0; if (signbit (arg)) /* arg < 0.0 or negative zero */ { sign = -1; arg = -arg; } if (sign < 0) *p++ = '-'; else if (flags & FLAG_SHOWSIGN) *p++ = '+'; else if (flags & FLAG_SPACE) *p++ = ' '; if (arg > 0.0 && arg + arg == arg) { if (dp->conversion >= 'A' && dp->conversion <= 'Z') { *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; } else { *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; } } else { # if NEED_PRINTF_DOUBLE pad_ptr = p; if (dp->conversion == 'f' || dp->conversion == 'F') { char *digits; size_t ndigits; digits = scale10_round_decimal_double (arg, precision); if (digits == NULL) goto out_of_memory; ndigits = strlen (digits); if (ndigits > precision) do { --ndigits; *p++ = digits[ndigits]; } while (ndigits > precision); else *p++ = '0'; /* Here ndigits <= precision. */ if ((flags & FLAG_ALT) || precision > 0) { *p++ = decimal_point_char (); for (; precision > ndigits; precision--) *p++ = '0'; while (ndigits > 0) { --ndigits; *p++ = digits[ndigits]; } } free (digits); } else if (dp->conversion == 'e' || dp->conversion == 'E') { int exponent; if (arg == 0.0) { exponent = 0; *p++ = '0'; if ((flags & FLAG_ALT) || precision > 0) { *p++ = decimal_point_char (); for (; precision > 0; precision--) *p++ = '0'; } } else { /* arg > 0.0. */ int adjusted; char *digits; size_t ndigits; exponent = floorlog10 (arg); adjusted = 0; for (;;) { digits = scale10_round_decimal_double (arg, (int)precision - exponent); if (digits == NULL) goto out_of_memory; ndigits = strlen (digits); if (ndigits == precision + 1) break; if (ndigits < precision || ndigits > precision + 2) /* The exponent was not guessed precisely enough. */ abort (); if (adjusted) /* None of two values of exponent is the right one. Prevent an endless loop. */ abort (); free (digits); if (ndigits == precision) exponent -= 1; else exponent += 1; adjusted = 1; } /* Here ndigits = precision+1. */ *p++ = digits[--ndigits]; if ((flags & FLAG_ALT) || precision > 0) { *p++ = decimal_point_char (); while (ndigits > 0) { --ndigits; *p++ = digits[ndigits]; } } free (digits); } *p++ = dp->conversion; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION { static const wchar_t decimal_format[] = /* Produce the same number of exponent digits as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ { '%', '+', '.', '3', 'd', '\0' }; # else { '%', '+', '.', '2', 'd', '\0' }; # endif SNPRINTF (p, 6 + 1, decimal_format, exponent); } while (*p != '\0') p++; # else { static const char decimal_format[] = /* Produce the same number of exponent digits as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ "%+.3d"; # else "%+.2d"; # endif if (sizeof (DCHAR_T) == 1) { sprintf ((char *) p, decimal_format, exponent); while (*p != '\0') p++; } else { char expbuf[6 + 1]; const char *ep; sprintf (expbuf, decimal_format, exponent); for (ep = expbuf; (*p = *ep) != '\0'; ep++) p++; } } # endif } else if (dp->conversion == 'g' || dp->conversion == 'G') { if (precision == 0) precision = 1; /* precision >= 1. */ if (arg == 0.0) /* The exponent is 0, >= -4, < precision. Use fixed-point notation. */ { size_t ndigits = precision; /* Number of trailing zeroes that have to be dropped. */ size_t nzeroes = (flags & FLAG_ALT ? 0 : precision - 1); --ndigits; *p++ = '0'; if ((flags & FLAG_ALT) || ndigits > nzeroes) { *p++ = decimal_point_char (); while (ndigits > nzeroes) { --ndigits; *p++ = '0'; } } } else { /* arg > 0.0. */ int exponent; int adjusted; char *digits; size_t ndigits; size_t nzeroes; exponent = floorlog10 (arg); adjusted = 0; for (;;) { digits = scale10_round_decimal_double (arg, (int)(precision - 1) - exponent); if (digits == NULL) goto out_of_memory; ndigits = strlen (digits); if (ndigits == precision) break; if (ndigits < precision - 1 || ndigits > precision + 1) /* The exponent was not guessed precisely enough. */ abort (); if (adjusted) /* None of two values of exponent is the right one. Prevent an endless loop. */ abort (); free (digits); if (ndigits < precision) exponent -= 1; else exponent += 1; adjusted = 1; } /* Here ndigits = precision. */ /* Determine the number of trailing zeroes that have to be dropped. */ nzeroes = 0; if ((flags & FLAG_ALT) == 0) while (nzeroes < ndigits && digits[nzeroes] == '0') nzeroes++; /* The exponent is now determined. */ if (exponent >= -4 && exponent < (long)precision) { /* Fixed-point notation: max(exponent,0)+1 digits, then the decimal point, then the remaining digits without trailing zeroes. */ if (exponent >= 0) { size_t count = exponent + 1; /* Note: count <= precision = ndigits. */ for (; count > 0; count--) *p++ = digits[--ndigits]; if ((flags & FLAG_ALT) || ndigits > nzeroes) { *p++ = decimal_point_char (); while (ndigits > nzeroes) { --ndigits; *p++ = digits[ndigits]; } } } else { size_t count = -exponent - 1; *p++ = '0'; *p++ = decimal_point_char (); for (; count > 0; count--) *p++ = '0'; while (ndigits > nzeroes) { --ndigits; *p++ = digits[ndigits]; } } } else { /* Exponential notation. */ *p++ = digits[--ndigits]; if ((flags & FLAG_ALT) || ndigits > nzeroes) { *p++ = decimal_point_char (); while (ndigits > nzeroes) { --ndigits; *p++ = digits[ndigits]; } } *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION { static const wchar_t decimal_format[] = /* Produce the same number of exponent digits as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ { '%', '+', '.', '3', 'd', '\0' }; # else { '%', '+', '.', '2', 'd', '\0' }; # endif SNPRINTF (p, 6 + 1, decimal_format, exponent); } while (*p != '\0') p++; # else { static const char decimal_format[] = /* Produce the same number of exponent digits as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ "%+.3d"; # else "%+.2d"; # endif if (sizeof (DCHAR_T) == 1) { sprintf ((char *) p, decimal_format, exponent); while (*p != '\0') p++; } else { char expbuf[6 + 1]; const char *ep; sprintf (expbuf, decimal_format, exponent); for (ep = expbuf; (*p = *ep) != '\0'; ep++) p++; } } # endif } free (digits); } } else abort (); # else /* arg is finite. */ if (!(arg == 0.0)) abort (); pad_ptr = p; if (dp->conversion == 'f' || dp->conversion == 'F') { *p++ = '0'; if ((flags & FLAG_ALT) || precision > 0) { *p++ = decimal_point_char (); for (; precision > 0; precision--) *p++ = '0'; } } else if (dp->conversion == 'e' || dp->conversion == 'E') { *p++ = '0'; if ((flags & FLAG_ALT) || precision > 0) { *p++ = decimal_point_char (); for (; precision > 0; precision--) *p++ = '0'; } *p++ = dp->conversion; /* 'e' or 'E' */ *p++ = '+'; /* Produce the same number of exponent digits as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ *p++ = '0'; # endif *p++ = '0'; *p++ = '0'; } else if (dp->conversion == 'g' || dp->conversion == 'G') { *p++ = '0'; if (flags & FLAG_ALT) { size_t ndigits = (precision > 0 ? precision - 1 : 0); *p++ = decimal_point_char (); for (; ndigits > 0; --ndigits) *p++ = '0'; } } else abort (); # endif } } } # endif /* The generated string now extends from tmp to p, with the zero padding insertion point being at pad_ptr. */ if (has_width && p - tmp < width) { size_t pad = width - (p - tmp); DCHAR_T *end = p + pad; if (flags & FLAG_LEFT) { /* Pad with spaces on the right. */ for (; pad > 0; pad--) *p++ = ' '; } else if ((flags & FLAG_ZERO) && pad_ptr != NULL) { /* Pad with zeroes. */ DCHAR_T *q = end; while (p > pad_ptr) *--q = *--p; for (; pad > 0; pad--) *p++ = '0'; } else { /* Pad with spaces on the left. */ DCHAR_T *q = end; while (p > tmp) *--q = *--p; for (; pad > 0; pad--) *p++ = ' '; } p = end; } { size_t count = p - tmp; if (count >= tmp_length) /* tmp_length was incorrectly calculated - fix the code above! */ abort (); /* Make room for the result. */ if (count >= allocated - length) { size_t n = xsum (length, count); ENSURE_ALLOCATION (n); } /* Append the result. */ memcpy (result + length, tmp, count * sizeof (DCHAR_T)); if (tmp != tmpbuf) free (tmp); length += count; } } #endif else { arg_type type = a.arg[dp->arg_index].type; int flags = dp->flags; #if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION int has_width; size_t width; #endif #if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION int has_precision; size_t precision; #endif #if NEED_PRINTF_UNBOUNDED_PRECISION int prec_ourselves; #else # define prec_ourselves 0 #endif #if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION int pad_ourselves; #else # define pad_ourselves 0 #endif TCHAR_T *fbp; unsigned int prefix_count; int prefixes[2]; #if !USE_SNPRINTF size_t tmp_length; TCHAR_T tmpbuf[700]; TCHAR_T *tmp; #endif #if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION has_width = 0; width = 0; if (dp->width_start != dp->width_end) { if (dp->width_arg_index != ARG_NONE) { int arg; if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) abort (); arg = a.arg[dp->width_arg_index].a.a_int; if (arg < 0) { /* "A negative field width is taken as a '-' flag followed by a positive field width." */ flags |= FLAG_LEFT; width = (unsigned int) (-arg); } else width = arg; } else { const FCHAR_T *digitp = dp->width_start; do width = xsum (xtimes (width, 10), *digitp++ - '0'); while (digitp != dp->width_end); } has_width = 1; } #endif #if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION has_precision = 0; precision = 6; if (dp->precision_start != dp->precision_end) { if (dp->precision_arg_index != ARG_NONE) { int arg; if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) abort (); arg = a.arg[dp->precision_arg_index].a.a_int; /* "A negative precision is taken as if the precision were omitted." */ if (arg >= 0) { precision = arg; has_precision = 1; } } else { const FCHAR_T *digitp = dp->precision_start + 1; precision = 0; while (digitp != dp->precision_end) precision = xsum (xtimes (precision, 10), *digitp++ - '0'); has_precision = 1; } } #endif #if !USE_SNPRINTF /* Allocate a temporary buffer of sufficient size for calling sprintf. */ { switch (dp->conversion) { case 'd': case 'i': case 'u': # if HAVE_LONG_LONG_INT if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) tmp_length = (unsigned int) (sizeof (unsigned long long) * CHAR_BIT * 0.30103 /* binary -> decimal */ ) + 1; /* turn floor into ceil */ else # endif if (type == TYPE_LONGINT || type == TYPE_ULONGINT) tmp_length = (unsigned int) (sizeof (unsigned long) * CHAR_BIT * 0.30103 /* binary -> decimal */ ) + 1; /* turn floor into ceil */ else tmp_length = (unsigned int) (sizeof (unsigned int) * CHAR_BIT * 0.30103 /* binary -> decimal */ ) + 1; /* turn floor into ceil */ if (tmp_length < precision) tmp_length = precision; /* Multiply by 2, as an estimate for FLAG_GROUP. */ tmp_length = xsum (tmp_length, tmp_length); /* Add 1, to account for a leading sign. */ tmp_length = xsum (tmp_length, 1); break; case 'o': # if HAVE_LONG_LONG_INT if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) tmp_length = (unsigned int) (sizeof (unsigned long long) * CHAR_BIT * 0.333334 /* binary -> octal */ ) + 1; /* turn floor into ceil */ else # endif if (type == TYPE_LONGINT || type == TYPE_ULONGINT) tmp_length = (unsigned int) (sizeof (unsigned long) * CHAR_BIT * 0.333334 /* binary -> octal */ ) + 1; /* turn floor into ceil */ else tmp_length = (unsigned int) (sizeof (unsigned int) * CHAR_BIT * 0.333334 /* binary -> octal */ ) + 1; /* turn floor into ceil */ if (tmp_length < precision) tmp_length = precision; /* Add 1, to account for a leading sign. */ tmp_length = xsum (tmp_length, 1); break; case 'x': case 'X': # if HAVE_LONG_LONG_INT if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) tmp_length = (unsigned int) (sizeof (unsigned long long) * CHAR_BIT * 0.25 /* binary -> hexadecimal */ ) + 1; /* turn floor into ceil */ else # endif if (type == TYPE_LONGINT || type == TYPE_ULONGINT) tmp_length = (unsigned int) (sizeof (unsigned long) * CHAR_BIT * 0.25 /* binary -> hexadecimal */ ) + 1; /* turn floor into ceil */ else tmp_length = (unsigned int) (sizeof (unsigned int) * CHAR_BIT * 0.25 /* binary -> hexadecimal */ ) + 1; /* turn floor into ceil */ if (tmp_length < precision) tmp_length = precision; /* Add 2, to account for a leading sign or alternate form. */ tmp_length = xsum (tmp_length, 2); break; case 'f': case 'F': if (type == TYPE_LONGDOUBLE) tmp_length = (unsigned int) (LDBL_MAX_EXP * 0.30103 /* binary -> decimal */ * 2 /* estimate for FLAG_GROUP */ ) + 1 /* turn floor into ceil */ + 10; /* sign, decimal point etc. */ else tmp_length = (unsigned int) (DBL_MAX_EXP * 0.30103 /* binary -> decimal */ * 2 /* estimate for FLAG_GROUP */ ) + 1 /* turn floor into ceil */ + 10; /* sign, decimal point etc. */ tmp_length = xsum (tmp_length, precision); break; case 'e': case 'E': case 'g': case 'G': tmp_length = 12; /* sign, decimal point, exponent etc. */ tmp_length = xsum (tmp_length, precision); break; case 'a': case 'A': if (type == TYPE_LONGDOUBLE) tmp_length = (unsigned int) (LDBL_DIG * 0.831 /* decimal -> hexadecimal */ ) + 1; /* turn floor into ceil */ else tmp_length = (unsigned int) (DBL_DIG * 0.831 /* decimal -> hexadecimal */ ) + 1; /* turn floor into ceil */ if (tmp_length < precision) tmp_length = precision; /* Account for sign, decimal point etc. */ tmp_length = xsum (tmp_length, 12); break; case 'c': # if HAVE_WINT_T && !WIDE_CHAR_VERSION if (type == TYPE_WIDE_CHAR) tmp_length = MB_CUR_MAX; else # endif tmp_length = 1; break; case 's': # if HAVE_WCHAR_T if (type == TYPE_WIDE_STRING) { tmp_length = local_wcslen (a.arg[dp->arg_index].a.a_wide_string); # if !WIDE_CHAR_VERSION tmp_length = xtimes (tmp_length, MB_CUR_MAX); # endif } else # endif tmp_length = strlen (a.arg[dp->arg_index].a.a_string); break; case 'p': tmp_length = (unsigned int) (sizeof (void *) * CHAR_BIT * 0.25 /* binary -> hexadecimal */ ) + 1 /* turn floor into ceil */ + 2; /* account for leading 0x */ break; default: abort (); } # if ENABLE_UNISTDIO /* Padding considers the number of characters, therefore the number of elements after padding may be > max (tmp_length, width) but is certainly <= tmp_length + width. */ tmp_length = xsum (tmp_length, width); # else /* Padding considers the number of elements, says POSIX. */ if (tmp_length < width) tmp_length = width; # endif tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ } if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T)) tmp = tmpbuf; else { size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T)); if (size_overflow_p (tmp_memsize)) /* Overflow, would lead to out of memory. */ goto out_of_memory; tmp = (TCHAR_T *) malloc (tmp_memsize); if (tmp == NULL) /* Out of memory. */ goto out_of_memory; } #endif /* Decide whether to handle the precision ourselves. */ #if NEED_PRINTF_UNBOUNDED_PRECISION switch (dp->conversion) { case 'd': case 'i': case 'u': case 'o': case 'x': case 'X': case 'p': prec_ourselves = has_precision && (precision > 0); break; default: prec_ourselves = 0; break; } #endif /* Decide whether to perform the padding ourselves. */ #if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION switch (dp->conversion) { # if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need to perform the padding after this conversion. Functions with unistdio extensions perform the padding based on character count rather than element count. */ case 'c': case 's': # endif # if NEED_PRINTF_FLAG_ZERO case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': case 'a': case 'A': # endif pad_ourselves = 1; break; default: pad_ourselves = prec_ourselves; break; } #endif /* Construct the format string for calling snprintf or sprintf. */ fbp = buf; *fbp++ = '%'; #if NEED_PRINTF_FLAG_GROUPING /* The underlying implementation doesn't support the ' flag. Produce no grouping characters in this case; this is acceptable because the grouping is locale dependent. */ #else if (flags & FLAG_GROUP) *fbp++ = '\''; #endif if (flags & FLAG_LEFT) *fbp++ = '-'; if (flags & FLAG_SHOWSIGN) *fbp++ = '+'; if (flags & FLAG_SPACE) *fbp++ = ' '; if (flags & FLAG_ALT) *fbp++ = '#'; if (!pad_ourselves) { if (flags & FLAG_ZERO) *fbp++ = '0'; if (dp->width_start != dp->width_end) { size_t n = dp->width_end - dp->width_start; /* The width specification is known to consist only of standard ASCII characters. */ if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) { memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T)); fbp += n; } else { const FCHAR_T *mp = dp->width_start; do *fbp++ = (unsigned char) *mp++; while (--n > 0); } } } if (!prec_ourselves) { if (dp->precision_start != dp->precision_end) { size_t n = dp->precision_end - dp->precision_start; /* The precision specification is known to consist only of standard ASCII characters. */ if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) { memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T)); fbp += n; } else { const FCHAR_T *mp = dp->precision_start; do *fbp++ = (unsigned char) *mp++; while (--n > 0); } } } switch (type) { #if HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: case TYPE_ULONGLONGINT: # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ *fbp++ = 'I'; *fbp++ = '6'; *fbp++ = '4'; break; # else *fbp++ = 'l'; /*FALLTHROUGH*/ # endif #endif case TYPE_LONGINT: case TYPE_ULONGINT: #if HAVE_WINT_T case TYPE_WIDE_CHAR: #endif #if HAVE_WCHAR_T case TYPE_WIDE_STRING: #endif *fbp++ = 'l'; break; case TYPE_LONGDOUBLE: *fbp++ = 'L'; break; default: break; } #if NEED_PRINTF_DIRECTIVE_F if (dp->conversion == 'F') *fbp = 'f'; else #endif *fbp = dp->conversion; #if USE_SNPRINTF # if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) fbp[1] = '%'; fbp[2] = 'n'; fbp[3] = '\0'; # else /* On glibc2 systems from glibc >= 2.3 - probably also older ones - we know that snprintf's returns value conforms to ISO C 99: the gl_SNPRINTF_DIRECTIVE_N test passes. Therefore we can avoid using %n in this situation. On glibc2 systems from 2004-10-18 or newer, the use of %n in format strings in writable memory may crash the program (if compiled with _FORTIFY_SOURCE=2), so we should avoid it in this situation. */ fbp[1] = '\0'; # endif #else fbp[1] = '\0'; #endif /* Construct the arguments for calling snprintf or sprintf. */ prefix_count = 0; if (!pad_ourselves && dp->width_arg_index != ARG_NONE) { if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) abort (); prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; } if (dp->precision_arg_index != ARG_NONE) { if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) abort (); prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; } #if USE_SNPRINTF /* The SNPRINTF result is appended after result[0..length]. The latter is an array of DCHAR_T; SNPRINTF appends an array of TCHAR_T to it. This is possible because sizeof (TCHAR_T) divides sizeof (DCHAR_T) and alignof (TCHAR_T) <= alignof (DCHAR_T). */ # define TCHARS_PER_DCHAR (sizeof (DCHAR_T) / sizeof (TCHAR_T)) /* Prepare checking whether snprintf returns the count via %n. */ ENSURE_ALLOCATION (xsum (length, 1)); *(TCHAR_T *) (result + length) = '\0'; #endif for (;;) { int count = -1; #if USE_SNPRINTF int retcount = 0; size_t maxlen = allocated - length; /* SNPRINTF can fail if its second argument is > INT_MAX. */ if (maxlen > INT_MAX / TCHARS_PER_DCHAR) maxlen = INT_MAX / TCHARS_PER_DCHAR; maxlen = maxlen * TCHARS_PER_DCHAR; # define SNPRINTF_BUF(arg) \ switch (prefix_count) \ { \ case 0: \ retcount = SNPRINTF ((TCHAR_T *) (result + length), \ maxlen, buf, \ arg, &count); \ break; \ case 1: \ retcount = SNPRINTF ((TCHAR_T *) (result + length), \ maxlen, buf, \ prefixes[0], arg, &count); \ break; \ case 2: \ retcount = SNPRINTF ((TCHAR_T *) (result + length), \ maxlen, buf, \ prefixes[0], prefixes[1], arg, \ &count); \ break; \ default: \ abort (); \ } #else # define SNPRINTF_BUF(arg) \ switch (prefix_count) \ { \ case 0: \ count = sprintf (tmp, buf, arg); \ break; \ case 1: \ count = sprintf (tmp, buf, prefixes[0], arg); \ break; \ case 2: \ count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ arg); \ break; \ default: \ abort (); \ } #endif switch (type) { case TYPE_SCHAR: { int arg = a.arg[dp->arg_index].a.a_schar; SNPRINTF_BUF (arg); } break; case TYPE_UCHAR: { unsigned int arg = a.arg[dp->arg_index].a.a_uchar; SNPRINTF_BUF (arg); } break; case TYPE_SHORT: { int arg = a.arg[dp->arg_index].a.a_short; SNPRINTF_BUF (arg); } break; case TYPE_USHORT: { unsigned int arg = a.arg[dp->arg_index].a.a_ushort; SNPRINTF_BUF (arg); } break; case TYPE_INT: { int arg = a.arg[dp->arg_index].a.a_int; SNPRINTF_BUF (arg); } break; case TYPE_UINT: { unsigned int arg = a.arg[dp->arg_index].a.a_uint; SNPRINTF_BUF (arg); } break; case TYPE_LONGINT: { long int arg = a.arg[dp->arg_index].a.a_longint; SNPRINTF_BUF (arg); } break; case TYPE_ULONGINT: { unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; SNPRINTF_BUF (arg); } break; #if HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: { long long int arg = a.arg[dp->arg_index].a.a_longlongint; SNPRINTF_BUF (arg); } break; case TYPE_ULONGLONGINT: { unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; SNPRINTF_BUF (arg); } break; #endif case TYPE_DOUBLE: { double arg = a.arg[dp->arg_index].a.a_double; SNPRINTF_BUF (arg); } break; case TYPE_LONGDOUBLE: { long double arg = a.arg[dp->arg_index].a.a_longdouble; SNPRINTF_BUF (arg); } break; case TYPE_CHAR: { int arg = a.arg[dp->arg_index].a.a_char; SNPRINTF_BUF (arg); } break; #if HAVE_WINT_T case TYPE_WIDE_CHAR: { wint_t arg = a.arg[dp->arg_index].a.a_wide_char; SNPRINTF_BUF (arg); } break; #endif case TYPE_STRING: { const char *arg = a.arg[dp->arg_index].a.a_string; SNPRINTF_BUF (arg); } break; #if HAVE_WCHAR_T case TYPE_WIDE_STRING: { const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; SNPRINTF_BUF (arg); } break; #endif case TYPE_POINTER: { void *arg = a.arg[dp->arg_index].a.a_pointer; SNPRINTF_BUF (arg); } break; default: abort (); } #if USE_SNPRINTF /* Portability: Not all implementations of snprintf() are ISO C 99 compliant. Determine the number of bytes that snprintf() has produced or would have produced. */ if (count >= 0) { /* Verify that snprintf() has NUL-terminated its result. */ if (count < maxlen && ((TCHAR_T *) (result + length)) [count] != '\0') abort (); /* Portability hack. */ if (retcount > count) count = retcount; } else { /* snprintf() doesn't understand the '%n' directive. */ if (fbp[1] != '\0') { /* Don't use the '%n' directive; instead, look at the snprintf() return value. */ fbp[1] = '\0'; continue; } else { /* Look at the snprintf() return value. */ if (retcount < 0) { /* HP-UX 10.20 snprintf() is doubly deficient: It doesn't understand the '%n' directive, *and* it returns -1 (rather than the length that would have been required) when the buffer is too small. */ size_t bigger_need = xsum (xtimes (allocated, 2), 12); ENSURE_ALLOCATION (bigger_need); continue; } else count = retcount; } } #endif /* Attempt to handle failure. */ if (count < 0) { if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); errno = EINVAL; return NULL; } #if USE_SNPRINTF /* Handle overflow of the allocated buffer. If such an overflow occurs, a C99 compliant snprintf() returns a count >= maxlen. However, a non-compliant snprintf() function returns only count = maxlen - 1. To cover both cases, test whether count >= maxlen - 1. */ if ((unsigned int) count + 1 >= maxlen) { /* If maxlen already has attained its allowed maximum, allocating more memory will not increase maxlen. Instead of looping, bail out. */ if (maxlen == INT_MAX / TCHARS_PER_DCHAR) goto overflow; else { /* Need at least count * sizeof (TCHAR_T) bytes. But allocate proportionally, to avoid looping eternally if snprintf() reports a too small count. */ size_t n = xmax (xsum (length, (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR), xtimes (allocated, 2)); ENSURE_ALLOCATION (n); continue; } } #endif #if NEED_PRINTF_UNBOUNDED_PRECISION if (prec_ourselves) { /* Handle the precision. */ TCHAR_T *prec_ptr = # if USE_SNPRINTF (TCHAR_T *) (result + length); # else tmp; # endif size_t prefix_count; size_t move; prefix_count = 0; /* Put the additional zeroes after the sign. */ if (count >= 1 && (*prec_ptr == '-' || *prec_ptr == '+' || *prec_ptr == ' ')) prefix_count = 1; /* Put the additional zeroes after the 0x prefix if (flags & FLAG_ALT) || (dp->conversion == 'p'). */ else if (count >= 2 && prec_ptr[0] == '0' && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X')) prefix_count = 2; move = count - prefix_count; if (precision > move) { /* Insert zeroes. */ size_t insert = precision - move; TCHAR_T *prec_end; # if USE_SNPRINTF size_t n = xsum (length, (count + insert + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR); length += (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; ENSURE_ALLOCATION (n); length -= (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; prec_ptr = (TCHAR_T *) (result + length); # endif prec_end = prec_ptr + count; prec_ptr += prefix_count; while (prec_end > prec_ptr) { prec_end--; prec_end[insert] = prec_end[0]; } prec_end += insert; do *--prec_end = '0'; while (prec_end > prec_ptr); count += insert; } } #endif #if !DCHAR_IS_TCHAR # if !USE_SNPRINTF if (count >= tmp_length) /* tmp_length was incorrectly calculated - fix the code above! */ abort (); # endif /* Convert from TCHAR_T[] to DCHAR_T[]. */ if (dp->conversion == 'c' || dp->conversion == 's') { /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING TYPE_WIDE_STRING. The result string is not certainly ASCII. */ const TCHAR_T *tmpsrc; DCHAR_T *tmpdst; size_t tmpdst_len; /* This code assumes that TCHAR_T is 'char'. */ typedef int TCHAR_T_verify [2 * (sizeof (TCHAR_T) == 1) - 1]; # if USE_SNPRINTF tmpsrc = (TCHAR_T *) (result + length); # else tmpsrc = tmp; # endif tmpdst = NULL; tmpdst_len = 0; if (DCHAR_CONV_FROM_ENCODING (locale_charset (), iconveh_question_mark, tmpsrc, count, NULL, &tmpdst, &tmpdst_len) < 0) { int saved_errno = errno; if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); errno = saved_errno; return NULL; } ENSURE_ALLOCATION (xsum (length, tmpdst_len)); DCHAR_CPY (result + length, tmpdst, tmpdst_len); free (tmpdst); count = tmpdst_len; } else { /* The result string is ASCII. Simple 1:1 conversion. */ # if USE_SNPRINTF /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a no-op conversion, in-place on the array starting at (result + length). */ if (sizeof (DCHAR_T) != sizeof (TCHAR_T)) # endif { const TCHAR_T *tmpsrc; DCHAR_T *tmpdst; size_t n; # if USE_SNPRINTF if (result == resultbuf) { tmpsrc = (TCHAR_T *) (result + length); /* ENSURE_ALLOCATION will not move tmpsrc (because it's part of resultbuf). */ ENSURE_ALLOCATION (xsum (length, count)); } else { /* ENSURE_ALLOCATION will move the array (because it uses realloc(). */ ENSURE_ALLOCATION (xsum (length, count)); tmpsrc = (TCHAR_T *) (result + length); } # else tmpsrc = tmp; ENSURE_ALLOCATION (xsum (length, count)); # endif tmpdst = result + length; /* Copy backwards, because of overlapping. */ tmpsrc += count; tmpdst += count; for (n = count; n > 0; n--) *--tmpdst = (unsigned char) *--tmpsrc; } } #endif #if DCHAR_IS_TCHAR && !USE_SNPRINTF /* Make room for the result. */ if (count > allocated - length) { /* Need at least count elements. But allocate proportionally. */ size_t n = xmax (xsum (length, count), xtimes (allocated, 2)); ENSURE_ALLOCATION (n); } #endif /* Here count <= allocated - length. */ /* Perform padding. */ #if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION if (pad_ourselves && has_width) { size_t w; # if ENABLE_UNISTDIO /* Outside POSIX, it's preferrable to compare the width against the number of _characters_ of the converted value. */ w = DCHAR_MBSNLEN (result + length, count); # else /* The width is compared against the number of _bytes_ of the converted value, says POSIX. */ w = count; # endif if (w < width) { size_t pad = width - w; # if USE_SNPRINTF /* Make room for the result. */ if (xsum (count, pad) > allocated - length) { /* Need at least count + pad elements. But allocate proportionally. */ size_t n = xmax (xsum3 (length, count, pad), xtimes (allocated, 2)); length += count; ENSURE_ALLOCATION (n); length -= count; } /* Here count + pad <= allocated - length. */ # endif { # if !DCHAR_IS_TCHAR || USE_SNPRINTF DCHAR_T * const rp = result + length; # else DCHAR_T * const rp = tmp; # endif DCHAR_T *p = rp + count; DCHAR_T *end = p + pad; # if NEED_PRINTF_FLAG_ZERO DCHAR_T *pad_ptr; # if !DCHAR_IS_TCHAR if (dp->conversion == 'c' || dp->conversion == 's') /* No zero-padding for string directives. */ pad_ptr = NULL; else # endif { pad_ptr = (*rp == '-' ? rp + 1 : rp); /* No zero-padding of "inf" and "nan". */ if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z') || (*pad_ptr >= 'a' && *pad_ptr <= 'z')) pad_ptr = NULL; } # endif /* The generated string now extends from rp to p, with the zero padding insertion point being at pad_ptr. */ count = count + pad; /* = end - rp */ if (flags & FLAG_LEFT) { /* Pad with spaces on the right. */ for (; pad > 0; pad--) *p++ = ' '; } # if NEED_PRINTF_FLAG_ZERO else if ((flags & FLAG_ZERO) && pad_ptr != NULL) { /* Pad with zeroes. */ DCHAR_T *q = end; while (p > pad_ptr) *--q = *--p; for (; pad > 0; pad--) *p++ = '0'; } # endif else { /* Pad with spaces on the left. */ DCHAR_T *q = end; while (p > rp) *--q = *--p; for (; pad > 0; pad--) *p++ = ' '; } } } } #endif #if DCHAR_IS_TCHAR && !USE_SNPRINTF if (count >= tmp_length) /* tmp_length was incorrectly calculated - fix the code above! */ abort (); #endif /* Here still count <= allocated - length. */ #if !DCHAR_IS_TCHAR || USE_SNPRINTF /* The snprintf() result did fit. */ #else /* Append the sprintf() result. */ memcpy (result + length, tmp, count * sizeof (DCHAR_T)); #endif #if !USE_SNPRINTF if (tmp != tmpbuf) free (tmp); #endif #if NEED_PRINTF_DIRECTIVE_F if (dp->conversion == 'F') { /* Convert the %f result to upper case for %F. */ DCHAR_T *rp = result + length; size_t rc; for (rc = count; rc > 0; rc--, rp++) if (*rp >= 'a' && *rp <= 'z') *rp = *rp - 'a' + 'A'; } #endif length += count; break; } } } } /* Add the final NUL. */ ENSURE_ALLOCATION (xsum (length, 1)); result[length] = '\0'; if (result != resultbuf && length + 1 < allocated) { /* Shrink the allocated memory if possible. */ DCHAR_T *memory; memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T)); if (memory != NULL) result = memory; } if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); *lengthp = length; /* Note that we can produce a big string of a length > INT_MAX. POSIX says that snprintf() fails with errno = EOVERFLOW in this case, but that's only because snprintf() returns an 'int'. This function does not have this limitation. */ return result; overflow: if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); errno = EOVERFLOW; return NULL; out_of_memory: if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); out_of_memory_1: CLEANUP (); errno = ENOMEM; return NULL; } } #undef TCHARS_PER_DCHAR #undef SNPRINTF #undef USE_SNPRINTF #undef DCHAR_CPY #undef PRINTF_PARSE #undef DIRECTIVES #undef DIRECTIVE #undef DCHAR_IS_TCHAR #undef TCHAR_T #undef DCHAR_T #undef FCHAR_T #undef VASNPRINTF libnih-1.0.3/intl/os2compat.c0000644000175000017500000000550711461165270012734 00000000000000/* OS/2 compatibility functions. Copyright (C) 2001-2002 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #define OS2_AWARE #ifdef HAVE_CONFIG_H #include #endif #include #include #include /* A version of getenv() that works from DLLs */ extern unsigned long DosScanEnv (const unsigned char *pszName, unsigned char **ppszValue); char * _nl_getenv (const char *name) { unsigned char *value; if (DosScanEnv (name, &value)) return NULL; else return value; } /* A fixed size buffer. */ char libintl_nl_default_dirname[MAXPATHLEN+1]; char *_nlos2_libdir = NULL; char *_nlos2_localealiaspath = NULL; char *_nlos2_localedir = NULL; static __attribute__((constructor)) void nlos2_initialize () { char *root = getenv ("UNIXROOT"); char *gnulocaledir = getenv ("GNULOCALEDIR"); _nlos2_libdir = gnulocaledir; if (!_nlos2_libdir) { if (root) { size_t sl = strlen (root); _nlos2_libdir = (char *) malloc (sl + strlen (LIBDIR) + 1); memcpy (_nlos2_libdir, root, sl); memcpy (_nlos2_libdir + sl, LIBDIR, strlen (LIBDIR) + 1); } else _nlos2_libdir = LIBDIR; } _nlos2_localealiaspath = gnulocaledir; if (!_nlos2_localealiaspath) { if (root) { size_t sl = strlen (root); _nlos2_localealiaspath = (char *) malloc (sl + strlen (LOCALE_ALIAS_PATH) + 1); memcpy (_nlos2_localealiaspath, root, sl); memcpy (_nlos2_localealiaspath + sl, LOCALE_ALIAS_PATH, strlen (LOCALE_ALIAS_PATH) + 1); } else _nlos2_localealiaspath = LOCALE_ALIAS_PATH; } _nlos2_localedir = gnulocaledir; if (!_nlos2_localedir) { if (root) { size_t sl = strlen (root); _nlos2_localedir = (char *) malloc (sl + strlen (LOCALEDIR) + 1); memcpy (_nlos2_localedir, root, sl); memcpy (_nlos2_localedir + sl, LOCALEDIR, strlen (LOCALEDIR) + 1); } else _nlos2_localedir = LOCALEDIR; } if (strlen (_nlos2_localedir) <= MAXPATHLEN) strcpy (libintl_nl_default_dirname, _nlos2_localedir); } libnih-1.0.3/intl/ChangeLog0000644000175000017500000000010711461165267012430 000000000000002007-11-07 GNU * Version 0.17 released. libnih-1.0.3/intl/printf-parse.h0000644000175000017500000000421311461165270013435 00000000000000/* Parse printf format string. Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _PRINTF_PARSE_H #define _PRINTF_PARSE_H #include "printf-args.h" /* Flags */ #define FLAG_GROUP 1 /* ' flag */ #define FLAG_LEFT 2 /* - flag */ #define FLAG_SHOWSIGN 4 /* + flag */ #define FLAG_SPACE 8 /* space flag */ #define FLAG_ALT 16 /* # flag */ #define FLAG_ZERO 32 /* arg_index value indicating that no argument is consumed. */ #define ARG_NONE (~(size_t)0) /* A parsed directive. */ typedef struct { const char* dir_start; const char* dir_end; int flags; const char* width_start; const char* width_end; size_t width_arg_index; const char* precision_start; const char* precision_end; size_t precision_arg_index; char conversion; /* d i o u x X f e E g G c s p n U % but not C S */ size_t arg_index; } char_directive; /* A parsed format string. */ typedef struct { size_t count; char_directive *dir; size_t max_width_length; size_t max_precision_length; } char_directives; /* Parses the format string. Fills in the number N of directives, and fills in directives[0], ..., directives[N-1], and sets directives[N].dir_start to the end of the format string. Also fills in the arg_type fields of the arguments and the needed count of arguments. */ #ifdef STATIC STATIC #else extern #endif int printf_parse (const char *format, char_directives *d, arguments *a); #endif /* _PRINTF_PARSE_H */ libnih-1.0.3/intl/dgettext.c0000644000175000017500000000337111461165267012660 00000000000000/* Implementation of the dgettext(3) function. Copyright (C) 1995-1997, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include "gettextP.h" #include #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* @@ end of prolog @@ */ /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define DGETTEXT __dgettext # define DCGETTEXT INTUSE(__dcgettext) #else # define DGETTEXT libintl_dgettext # define DCGETTEXT libintl_dcgettext #endif /* Look up MSGID in the DOMAINNAME message catalog of the current LC_MESSAGES locale. */ char * DGETTEXT (const char *domainname, const char *msgid) { return DCGETTEXT (domainname, msgid, LC_MESSAGES); } #ifdef _LIBC /* Alias for function name in GNU C Library. */ weak_alias (__dgettext, dgettext); #endif libnih-1.0.3/intl/printf-parse.c0000644000175000017500000003306011461165270013432 00000000000000/* Formatted output to strings. Copyright (C) 1999-2000, 2002-2003, 2006-2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* This file can be parametrized with the following macros: CHAR_T The element type of the format string. CHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters in the format string are ASCII. DIRECTIVE Structure denoting a format directive. Depends on CHAR_T. DIRECTIVES Structure denoting the set of format directives of a format string. Depends on CHAR_T. PRINTF_PARSE Function that parses a format string. Depends on CHAR_T. STATIC Set to 'static' to declare the function static. ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. */ #ifndef PRINTF_PARSE # include #endif /* Specification. */ #ifndef PRINTF_PARSE # include "printf-parse.h" #endif /* Default parameters. */ #ifndef PRINTF_PARSE # define PRINTF_PARSE printf_parse # define CHAR_T char # define DIRECTIVE char_directive # define DIRECTIVES char_directives #endif /* Get size_t, NULL. */ #include /* Get intmax_t. */ #if defined IN_LIBINTL || defined IN_LIBASPRINTF # if HAVE_STDINT_H_WITH_UINTMAX # include # endif # if HAVE_INTTYPES_H_WITH_UINTMAX # include # endif #else # include #endif /* malloc(), realloc(), free(). */ #include /* errno. */ #include /* Checked size_t computations. */ #include "xsize.h" #if CHAR_T_ONLY_ASCII /* c_isascii(). */ # include "c-ctype.h" #endif #ifdef STATIC STATIC #endif int PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) { const CHAR_T *cp = format; /* pointer into format */ size_t arg_posn = 0; /* number of regular arguments consumed */ size_t d_allocated; /* allocated elements of d->dir */ size_t a_allocated; /* allocated elements of a->arg */ size_t max_width_length = 0; size_t max_precision_length = 0; d->count = 0; d_allocated = 1; d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE)); if (d->dir == NULL) /* Out of memory. */ goto out_of_memory_1; a->count = 0; a_allocated = 0; a->arg = NULL; #define REGISTER_ARG(_index_,_type_) \ { \ size_t n = (_index_); \ if (n >= a_allocated) \ { \ size_t memory_size; \ argument *memory; \ \ a_allocated = xtimes (a_allocated, 2); \ if (a_allocated <= n) \ a_allocated = xsum (n, 1); \ memory_size = xtimes (a_allocated, sizeof (argument)); \ if (size_overflow_p (memory_size)) \ /* Overflow, would lead to out of memory. */ \ goto out_of_memory; \ memory = (argument *) (a->arg \ ? realloc (a->arg, memory_size) \ : malloc (memory_size)); \ if (memory == NULL) \ /* Out of memory. */ \ goto out_of_memory; \ a->arg = memory; \ } \ while (a->count <= n) \ a->arg[a->count++].type = TYPE_NONE; \ if (a->arg[n].type == TYPE_NONE) \ a->arg[n].type = (_type_); \ else if (a->arg[n].type != (_type_)) \ /* Ambiguous type for positional argument. */ \ goto error; \ } while (*cp != '\0') { CHAR_T c = *cp++; if (c == '%') { size_t arg_index = ARG_NONE; DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */ /* Initialize the next directive. */ dp->dir_start = cp - 1; dp->flags = 0; dp->width_start = NULL; dp->width_end = NULL; dp->width_arg_index = ARG_NONE; dp->precision_start = NULL; dp->precision_end = NULL; dp->precision_arg_index = ARG_NONE; dp->arg_index = ARG_NONE; /* Test for positional argument. */ if (*cp >= '0' && *cp <= '9') { const CHAR_T *np; for (np = cp; *np >= '0' && *np <= '9'; np++) ; if (*np == '$') { size_t n = 0; for (np = cp; *np >= '0' && *np <= '9'; np++) n = xsum (xtimes (n, 10), *np - '0'); if (n == 0) /* Positional argument 0. */ goto error; if (size_overflow_p (n)) /* n too large, would lead to out of memory later. */ goto error; arg_index = n - 1; cp = np + 1; } } /* Read the flags. */ for (;;) { if (*cp == '\'') { dp->flags |= FLAG_GROUP; cp++; } else if (*cp == '-') { dp->flags |= FLAG_LEFT; cp++; } else if (*cp == '+') { dp->flags |= FLAG_SHOWSIGN; cp++; } else if (*cp == ' ') { dp->flags |= FLAG_SPACE; cp++; } else if (*cp == '#') { dp->flags |= FLAG_ALT; cp++; } else if (*cp == '0') { dp->flags |= FLAG_ZERO; cp++; } else break; } /* Parse the field width. */ if (*cp == '*') { dp->width_start = cp; cp++; dp->width_end = cp; if (max_width_length < 1) max_width_length = 1; /* Test for positional argument. */ if (*cp >= '0' && *cp <= '9') { const CHAR_T *np; for (np = cp; *np >= '0' && *np <= '9'; np++) ; if (*np == '$') { size_t n = 0; for (np = cp; *np >= '0' && *np <= '9'; np++) n = xsum (xtimes (n, 10), *np - '0'); if (n == 0) /* Positional argument 0. */ goto error; if (size_overflow_p (n)) /* n too large, would lead to out of memory later. */ goto error; dp->width_arg_index = n - 1; cp = np + 1; } } if (dp->width_arg_index == ARG_NONE) { dp->width_arg_index = arg_posn++; if (dp->width_arg_index == ARG_NONE) /* arg_posn wrapped around. */ goto error; } REGISTER_ARG (dp->width_arg_index, TYPE_INT); } else if (*cp >= '0' && *cp <= '9') { size_t width_length; dp->width_start = cp; for (; *cp >= '0' && *cp <= '9'; cp++) ; dp->width_end = cp; width_length = dp->width_end - dp->width_start; if (max_width_length < width_length) max_width_length = width_length; } /* Parse the precision. */ if (*cp == '.') { cp++; if (*cp == '*') { dp->precision_start = cp - 1; cp++; dp->precision_end = cp; if (max_precision_length < 2) max_precision_length = 2; /* Test for positional argument. */ if (*cp >= '0' && *cp <= '9') { const CHAR_T *np; for (np = cp; *np >= '0' && *np <= '9'; np++) ; if (*np == '$') { size_t n = 0; for (np = cp; *np >= '0' && *np <= '9'; np++) n = xsum (xtimes (n, 10), *np - '0'); if (n == 0) /* Positional argument 0. */ goto error; if (size_overflow_p (n)) /* n too large, would lead to out of memory later. */ goto error; dp->precision_arg_index = n - 1; cp = np + 1; } } if (dp->precision_arg_index == ARG_NONE) { dp->precision_arg_index = arg_posn++; if (dp->precision_arg_index == ARG_NONE) /* arg_posn wrapped around. */ goto error; } REGISTER_ARG (dp->precision_arg_index, TYPE_INT); } else { size_t precision_length; dp->precision_start = cp - 1; for (; *cp >= '0' && *cp <= '9'; cp++) ; dp->precision_end = cp; precision_length = dp->precision_end - dp->precision_start; if (max_precision_length < precision_length) max_precision_length = precision_length; } } { arg_type type; /* Parse argument type/size specifiers. */ { int flags = 0; for (;;) { if (*cp == 'h') { flags |= (1 << (flags & 1)); cp++; } else if (*cp == 'L') { flags |= 4; cp++; } else if (*cp == 'l') { flags += 8; cp++; } else if (*cp == 'j') { if (sizeof (intmax_t) > sizeof (long)) { /* intmax_t = long long */ flags += 16; } else if (sizeof (intmax_t) > sizeof (int)) { /* intmax_t = long */ flags += 8; } cp++; } else if (*cp == 'z' || *cp == 'Z') { /* 'z' is standardized in ISO C 99, but glibc uses 'Z' because the warning facility in gcc-2.95.2 understands only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ if (sizeof (size_t) > sizeof (long)) { /* size_t = long long */ flags += 16; } else if (sizeof (size_t) > sizeof (int)) { /* size_t = long */ flags += 8; } cp++; } else if (*cp == 't') { if (sizeof (ptrdiff_t) > sizeof (long)) { /* ptrdiff_t = long long */ flags += 16; } else if (sizeof (ptrdiff_t) > sizeof (int)) { /* ptrdiff_t = long */ flags += 8; } cp++; } else break; } /* Read the conversion character. */ c = *cp++; switch (c) { case 'd': case 'i': #if HAVE_LONG_LONG_INT /* If 'long long' exists and is larger than 'long': */ if (flags >= 16 || (flags & 4)) type = TYPE_LONGLONGINT; else #endif /* If 'long long' exists and is the same as 'long', we parse "lld" into TYPE_LONGINT. */ if (flags >= 8) type = TYPE_LONGINT; else if (flags & 2) type = TYPE_SCHAR; else if (flags & 1) type = TYPE_SHORT; else type = TYPE_INT; break; case 'o': case 'u': case 'x': case 'X': #if HAVE_LONG_LONG_INT /* If 'long long' exists and is larger than 'long': */ if (flags >= 16 || (flags & 4)) type = TYPE_ULONGLONGINT; else #endif /* If 'unsigned long long' exists and is the same as 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ if (flags >= 8) type = TYPE_ULONGINT; else if (flags & 2) type = TYPE_UCHAR; else if (flags & 1) type = TYPE_USHORT; else type = TYPE_UINT; break; case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': case 'a': case 'A': if (flags >= 16 || (flags & 4)) type = TYPE_LONGDOUBLE; else type = TYPE_DOUBLE; break; case 'c': if (flags >= 8) #if HAVE_WINT_T type = TYPE_WIDE_CHAR; #else goto error; #endif else type = TYPE_CHAR; break; #if HAVE_WINT_T case 'C': type = TYPE_WIDE_CHAR; c = 'c'; break; #endif case 's': if (flags >= 8) #if HAVE_WCHAR_T type = TYPE_WIDE_STRING; #else goto error; #endif else type = TYPE_STRING; break; #if HAVE_WCHAR_T case 'S': type = TYPE_WIDE_STRING; c = 's'; break; #endif case 'p': type = TYPE_POINTER; break; case 'n': #if HAVE_LONG_LONG_INT /* If 'long long' exists and is larger than 'long': */ if (flags >= 16 || (flags & 4)) type = TYPE_COUNT_LONGLONGINT_POINTER; else #endif /* If 'long long' exists and is the same as 'long', we parse "lln" into TYPE_COUNT_LONGINT_POINTER. */ if (flags >= 8) type = TYPE_COUNT_LONGINT_POINTER; else if (flags & 2) type = TYPE_COUNT_SCHAR_POINTER; else if (flags & 1) type = TYPE_COUNT_SHORT_POINTER; else type = TYPE_COUNT_INT_POINTER; break; #if ENABLE_UNISTDIO /* The unistdio extensions. */ case 'U': if (flags >= 16) type = TYPE_U32_STRING; else if (flags >= 8) type = TYPE_U16_STRING; else type = TYPE_U8_STRING; break; #endif case '%': type = TYPE_NONE; break; default: /* Unknown conversion character. */ goto error; } } if (type != TYPE_NONE) { dp->arg_index = arg_index; if (dp->arg_index == ARG_NONE) { dp->arg_index = arg_posn++; if (dp->arg_index == ARG_NONE) /* arg_posn wrapped around. */ goto error; } REGISTER_ARG (dp->arg_index, type); } dp->conversion = c; dp->dir_end = cp; } d->count++; if (d->count >= d_allocated) { size_t memory_size; DIRECTIVE *memory; d_allocated = xtimes (d_allocated, 2); memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); if (size_overflow_p (memory_size)) /* Overflow, would lead to out of memory. */ goto out_of_memory; memory = (DIRECTIVE *) realloc (d->dir, memory_size); if (memory == NULL) /* Out of memory. */ goto out_of_memory; d->dir = memory; } } #if CHAR_T_ONLY_ASCII else if (!c_isascii (c)) { /* Non-ASCII character. Not supported. */ goto error; } #endif } d->dir[d->count].dir_start = cp; d->max_width_length = max_width_length; d->max_precision_length = max_precision_length; return 0; error: if (a->arg) free (a->arg); if (d->dir) free (d->dir); errno = EINVAL; return -1; out_of_memory: if (a->arg) free (a->arg); if (d->dir) free (d->dir); out_of_memory_1: errno = ENOMEM; return -1; } #undef PRINTF_PARSE #undef DIRECTIVES #undef DIRECTIVE #undef CHAR_T_ONLY_ASCII #undef CHAR_T libnih-1.0.3/intl/gettextP.h0000644000175000017500000002221411461165267012636 00000000000000/* Header describing internals of libintl library. Copyright (C) 1995-1999, 2000-2007 Free Software Foundation, Inc. Written by Ulrich Drepper , 1995. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _GETTEXTP_H #define _GETTEXTP_H #include /* Get size_t. */ #ifdef _LIBC # include "../iconv/gconv_int.h" #else # if HAVE_ICONV # include # endif #endif /* Handle multi-threaded applications. */ #ifdef _LIBC # include # define gl_rwlock_define __libc_rwlock_define #else # include "lock.h" #endif #ifdef _LIBC extern char *__gettext (const char *__msgid); extern char *__dgettext (const char *__domainname, const char *__msgid); extern char *__dcgettext (const char *__domainname, const char *__msgid, int __category); extern char *__ngettext (const char *__msgid1, const char *__msgid2, unsigned long int __n); extern char *__dngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int n); extern char *__dcngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n, int __category); extern char *__dcigettext (const char *__domainname, const char *__msgid1, const char *__msgid2, int __plural, unsigned long int __n, int __category); extern char *__textdomain (const char *__domainname); extern char *__bindtextdomain (const char *__domainname, const char *__dirname); extern char *__bind_textdomain_codeset (const char *__domainname, const char *__codeset); extern void _nl_finddomain_subfreeres (void) attribute_hidden; extern void _nl_unload_domain (struct loaded_domain *__domain) internal_function attribute_hidden; #else /* Declare the exported libintl_* functions, in a way that allows us to call them under their real name. */ # undef _INTL_REDIRECT_INLINE # undef _INTL_REDIRECT_MACROS # define _INTL_REDIRECT_MACROS # include "libgnuintl.h" # ifdef IN_LIBGLOCALE extern char *gl_dcigettext (const char *__domainname, const char *__msgid1, const char *__msgid2, int __plural, unsigned long int __n, int __category, const char *__localename, const char *__encoding); # else extern char *libintl_dcigettext (const char *__domainname, const char *__msgid1, const char *__msgid2, int __plural, unsigned long int __n, int __category); # endif #endif #include "loadinfo.h" #include "gmo.h" /* Get nls_uint32. */ /* @@ end of prolog @@ */ #ifndef internal_function # define internal_function #endif #ifndef attribute_hidden # define attribute_hidden #endif /* Tell the compiler when a conditional or integer expression is almost always true or almost always false. */ #ifndef HAVE_BUILTIN_EXPECT # define __builtin_expect(expr, val) (expr) #endif #ifndef W # define W(flag, data) ((flag) ? SWAP (data) : (data)) #endif #ifdef _LIBC # include # define SWAP(i) bswap_32 (i) #else static inline nls_uint32 # ifdef __cplusplus SWAP (nls_uint32 i) # else SWAP (i) nls_uint32 i; # endif { return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24); } #endif /* In-memory representation of system dependent string. */ struct sysdep_string_desc { /* Length of addressed string, including the trailing NUL. */ size_t length; /* Pointer to addressed string. */ const char *pointer; }; /* Cache of translated strings after charset conversion. Note: The strings are converted to the target encoding only on an as-needed basis. */ struct converted_domain { /* The target encoding name. */ const char *encoding; /* The descriptor for conversion from the message catalog's encoding to this target encoding. */ #ifdef _LIBC __gconv_t conv; #else # if HAVE_ICONV iconv_t conv; # endif #endif /* The table of translated strings after charset conversion. */ char **conv_tab; }; /* The representation of an opened message catalog. */ struct loaded_domain { /* Pointer to memory containing the .mo file. */ const char *data; /* 1 if the memory is mmap()ed, 0 if the memory is malloc()ed. */ int use_mmap; /* Size of mmap()ed memory. */ size_t mmap_size; /* 1 if the .mo file uses a different endianness than this machine. */ int must_swap; /* Pointer to additional malloc()ed memory. */ void *malloced; /* Number of static strings pairs. */ nls_uint32 nstrings; /* Pointer to descriptors of original strings in the file. */ const struct string_desc *orig_tab; /* Pointer to descriptors of translated strings in the file. */ const struct string_desc *trans_tab; /* Number of system dependent strings pairs. */ nls_uint32 n_sysdep_strings; /* Pointer to descriptors of original sysdep strings. */ const struct sysdep_string_desc *orig_sysdep_tab; /* Pointer to descriptors of translated sysdep strings. */ const struct sysdep_string_desc *trans_sysdep_tab; /* Size of hash table. */ nls_uint32 hash_size; /* Pointer to hash table. */ const nls_uint32 *hash_tab; /* 1 if the hash table uses a different endianness than this machine. */ int must_swap_hash_tab; /* Cache of charset conversions of the translated strings. */ struct converted_domain *conversions; size_t nconversions; gl_rwlock_define (, conversions_lock) const struct expression *plural; unsigned long int nplurals; }; /* We want to allocate a string at the end of the struct. But ISO C doesn't allow zero sized arrays. */ #ifdef __GNUC__ # define ZERO 0 #else # define ZERO 1 #endif /* A set of settings bound to a message domain. Used to store settings from bindtextdomain() and bind_textdomain_codeset(). */ struct binding { struct binding *next; char *dirname; char *codeset; char domainname[ZERO]; }; /* A counter which is incremented each time some previous translations become invalid. This variable is part of the external ABI of the GNU libintl. */ #ifdef IN_LIBGLOCALE # include extern LIBGLOCALE_DLL_EXPORTED int _nl_msg_cat_cntr; #else extern LIBINTL_DLL_EXPORTED int _nl_msg_cat_cntr; #endif #ifndef _LIBC extern const char *_nl_language_preferences_default (void); # define gl_locale_name_canonicalize _nl_locale_name_canonicalize extern void _nl_locale_name_canonicalize (char *name); # define gl_locale_name_posix _nl_locale_name_posix extern const char *_nl_locale_name_posix (int category, const char *categoryname); # define gl_locale_name_default _nl_locale_name_default extern const char *_nl_locale_name_default (void); # define gl_locale_name _nl_locale_name extern const char *_nl_locale_name (int category, const char *categoryname); #endif struct loaded_l10nfile *_nl_find_domain (const char *__dirname, char *__locale, const char *__domainname, struct binding *__domainbinding) internal_function; void _nl_load_domain (struct loaded_l10nfile *__domain, struct binding *__domainbinding) internal_function; #ifdef IN_LIBGLOCALE char *_nl_find_msg (struct loaded_l10nfile *domain_file, struct binding *domainbinding, const char *encoding, const char *msgid, size_t *lengthp) internal_function; #else char *_nl_find_msg (struct loaded_l10nfile *domain_file, struct binding *domainbinding, const char *msgid, int convert, size_t *lengthp) internal_function; #endif /* The internal variables in the standalone libintl.a must have different names than the internal variables in GNU libc, otherwise programs using libintl.a cannot be linked statically. */ #if !defined _LIBC # define _nl_default_dirname libintl_nl_default_dirname # define _nl_domain_bindings libintl_nl_domain_bindings #endif /* Contains the default location of the message catalogs. */ extern const char _nl_default_dirname[]; #ifdef _LIBC libc_hidden_proto (_nl_default_dirname) #endif /* List with bindings of specific domains. */ extern struct binding *_nl_domain_bindings; /* The internal variables in the standalone libintl.a must have different names than the internal variables in GNU libc, otherwise programs using libintl.a cannot be linked statically. */ #if !defined _LIBC # define _nl_default_default_domain libintl_nl_default_default_domain # define _nl_current_default_domain libintl_nl_current_default_domain #endif /* Name of the default text domain. */ extern const char _nl_default_default_domain[] attribute_hidden; /* Default text domain in which entries for gettext(3) are to be found. */ extern const char *_nl_current_default_domain attribute_hidden; /* @@ begin of epilog @@ */ #endif /* gettextP.h */ libnih-1.0.3/intl/version.c0000644000175000017500000000173111461165270012505 00000000000000/* libintl library version. Copyright (C) 2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include "libgnuintl.h" /* Version number: (major<<16) + (minor<<8) + subminor */ int libintl_version = LIBINTL_VERSION; libnih-1.0.3/intl/relocatable.c0000644000175000017500000003353411461165270013303 00000000000000/* Provide relocatable packages. Copyright (C) 2003-2006 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Tell glibc's to provide a prototype for getline(). This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #include /* Specification. */ #include "relocatable.h" #if ENABLE_RELOCATABLE #include #include #include #include #ifdef NO_XMALLOC # define xmalloc malloc #else # include "xalloc.h" #endif #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ # define WIN32_LEAN_AND_MEAN # include #endif #if DEPENDS_ON_LIBCHARSET # include #endif #if DEPENDS_ON_LIBICONV && HAVE_ICONV # include #endif #if DEPENDS_ON_LIBINTL && ENABLE_NLS # include #endif /* Faked cheap 'bool'. */ #undef bool #undef false #undef true #define bool int #define false 0 #define true 1 /* Pathname support. ISSLASH(C) tests whether C is a directory separator character. IS_PATH_WITH_DIR(P) tests whether P contains a directory specification. */ #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ /* Win32, Cygwin, OS/2, DOS */ # define ISSLASH(C) ((C) == '/' || (C) == '\\') # define HAS_DEVICE(P) \ ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \ && (P)[1] == ':') # define IS_PATH_WITH_DIR(P) \ (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P)) # define FILE_SYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0) #else /* Unix */ # define ISSLASH(C) ((C) == '/') # define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL) # define FILE_SYSTEM_PREFIX_LEN(P) 0 #endif /* Original installation prefix. */ static char *orig_prefix; static size_t orig_prefix_len; /* Current installation prefix. */ static char *curr_prefix; static size_t curr_prefix_len; /* These prefixes do not end in a slash. Anything that will be concatenated to them must start with a slash. */ /* Sets the original and the current installation prefix of this module. Relocation simply replaces a pathname starting with the original prefix by the corresponding pathname with the current prefix instead. Both prefixes should be directory names without trailing slash (i.e. use "" instead of "/"). */ static void set_this_relocation_prefix (const char *orig_prefix_arg, const char *curr_prefix_arg) { if (orig_prefix_arg != NULL && curr_prefix_arg != NULL /* Optimization: if orig_prefix and curr_prefix are equal, the relocation is a nop. */ && strcmp (orig_prefix_arg, curr_prefix_arg) != 0) { /* Duplicate the argument strings. */ char *memory; orig_prefix_len = strlen (orig_prefix_arg); curr_prefix_len = strlen (curr_prefix_arg); memory = (char *) xmalloc (orig_prefix_len + 1 + curr_prefix_len + 1); #ifdef NO_XMALLOC if (memory != NULL) #endif { memcpy (memory, orig_prefix_arg, orig_prefix_len + 1); orig_prefix = memory; memory += orig_prefix_len + 1; memcpy (memory, curr_prefix_arg, curr_prefix_len + 1); curr_prefix = memory; return; } } orig_prefix = NULL; curr_prefix = NULL; /* Don't worry about wasted memory here - this function is usually only called once. */ } /* Sets the original and the current installation prefix of the package. Relocation simply replaces a pathname starting with the original prefix by the corresponding pathname with the current prefix instead. Both prefixes should be directory names without trailing slash (i.e. use "" instead of "/"). */ void set_relocation_prefix (const char *orig_prefix_arg, const char *curr_prefix_arg) { set_this_relocation_prefix (orig_prefix_arg, curr_prefix_arg); /* Now notify all dependent libraries. */ #if DEPENDS_ON_LIBCHARSET libcharset_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg); #endif #if DEPENDS_ON_LIBICONV && HAVE_ICONV && _LIBICONV_VERSION >= 0x0109 libiconv_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg); #endif #if DEPENDS_ON_LIBINTL && ENABLE_NLS && defined libintl_set_relocation_prefix libintl_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg); #endif } #if !defined IN_LIBRARY || (defined PIC && defined INSTALLDIR) /* Convenience function: Computes the current installation prefix, based on the original installation prefix, the original installation directory of a particular file, and the current pathname of this file. Returns NULL upon failure. */ #ifdef IN_LIBRARY #define compute_curr_prefix local_compute_curr_prefix static #endif const char * compute_curr_prefix (const char *orig_installprefix, const char *orig_installdir, const char *curr_pathname) { const char *curr_installdir; const char *rel_installdir; if (curr_pathname == NULL) return NULL; /* Determine the relative installation directory, relative to the prefix. This is simply the difference between orig_installprefix and orig_installdir. */ if (strncmp (orig_installprefix, orig_installdir, strlen (orig_installprefix)) != 0) /* Shouldn't happen - nothing should be installed outside $(prefix). */ return NULL; rel_installdir = orig_installdir + strlen (orig_installprefix); /* Determine the current installation directory. */ { const char *p_base = curr_pathname + FILE_SYSTEM_PREFIX_LEN (curr_pathname); const char *p = curr_pathname + strlen (curr_pathname); char *q; while (p > p_base) { p--; if (ISSLASH (*p)) break; } q = (char *) xmalloc (p - curr_pathname + 1); #ifdef NO_XMALLOC if (q == NULL) return NULL; #endif memcpy (q, curr_pathname, p - curr_pathname); q[p - curr_pathname] = '\0'; curr_installdir = q; } /* Compute the current installation prefix by removing the trailing rel_installdir from it. */ { const char *rp = rel_installdir + strlen (rel_installdir); const char *cp = curr_installdir + strlen (curr_installdir); const char *cp_base = curr_installdir + FILE_SYSTEM_PREFIX_LEN (curr_installdir); while (rp > rel_installdir && cp > cp_base) { bool same = false; const char *rpi = rp; const char *cpi = cp; while (rpi > rel_installdir && cpi > cp_base) { rpi--; cpi--; if (ISSLASH (*rpi) || ISSLASH (*cpi)) { if (ISSLASH (*rpi) && ISSLASH (*cpi)) same = true; break; } /* Do case-insensitive comparison if the filesystem is always or often case-insensitive. It's better to accept the comparison if the difference is only in case, rather than to fail. */ #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ /* Win32, Cygwin, OS/2, DOS - case insignificant filesystem */ if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi) != (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi)) break; #else if (*rpi != *cpi) break; #endif } if (!same) break; /* The last pathname component was the same. opi and cpi now point to the slash before it. */ rp = rpi; cp = cpi; } if (rp > rel_installdir) /* Unexpected: The curr_installdir does not end with rel_installdir. */ return NULL; { size_t curr_prefix_len = cp - curr_installdir; char *curr_prefix; curr_prefix = (char *) xmalloc (curr_prefix_len + 1); #ifdef NO_XMALLOC if (curr_prefix == NULL) return NULL; #endif memcpy (curr_prefix, curr_installdir, curr_prefix_len); curr_prefix[curr_prefix_len] = '\0'; return curr_prefix; } } } #endif /* !IN_LIBRARY || PIC */ #if defined PIC && defined INSTALLDIR /* Full pathname of shared library, or NULL. */ static char *shared_library_fullname; #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ /* Determine the full pathname of the shared library when it is loaded. */ BOOL WINAPI DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved) { (void) reserved; if (event == DLL_PROCESS_ATTACH) { /* The DLL is being loaded into an application's address range. */ static char location[MAX_PATH]; if (!GetModuleFileName (module_handle, location, sizeof (location))) /* Shouldn't happen. */ return FALSE; if (!IS_PATH_WITH_DIR (location)) /* Shouldn't happen. */ return FALSE; { #if defined __CYGWIN__ /* On Cygwin, we need to convert paths coming from Win32 system calls to the Unix-like slashified notation. */ static char location_as_posix_path[2 * MAX_PATH]; /* There's no error return defined for cygwin_conv_to_posix_path. See cygwin-api/func-cygwin-conv-to-posix-path.html. Does it overflow the buffer of expected size MAX_PATH or does it truncate the path? I don't know. Let's catch both. */ cygwin_conv_to_posix_path (location, location_as_posix_path); location_as_posix_path[MAX_PATH - 1] = '\0'; if (strlen (location_as_posix_path) >= MAX_PATH - 1) /* A sign of buffer overflow or path truncation. */ return FALSE; shared_library_fullname = strdup (location_as_posix_path); #else shared_library_fullname = strdup (location); #endif } } return TRUE; } #else /* Unix except Cygwin */ static void find_shared_library_fullname () { #if defined __linux__ && __GLIBC__ >= 2 /* Linux has /proc/self/maps. glibc 2 has the getline() function. */ FILE *fp; /* Open the current process' maps file. It describes one VMA per line. */ fp = fopen ("/proc/self/maps", "r"); if (fp) { unsigned long address = (unsigned long) &find_shared_library_fullname; for (;;) { unsigned long start, end; int c; if (fscanf (fp, "%lx-%lx", &start, &end) != 2) break; if (address >= start && address <= end - 1) { /* Found it. Now see if this line contains a filename. */ while (c = getc (fp), c != EOF && c != '\n' && c != '/') continue; if (c == '/') { size_t size; int len; ungetc (c, fp); shared_library_fullname = NULL; size = 0; len = getline (&shared_library_fullname, &size, fp); if (len >= 0) { /* Success: filled shared_library_fullname. */ if (len > 0 && shared_library_fullname[len - 1] == '\n') shared_library_fullname[len - 1] = '\0'; } } break; } while (c = getc (fp), c != EOF && c != '\n') continue; } fclose (fp); } #endif } #endif /* (WIN32 or Cygwin) / (Unix except Cygwin) */ /* Return the full pathname of the current shared library. Return NULL if unknown. Guaranteed to work only on Linux, Cygwin and Woe32. */ static char * get_shared_library_fullname () { #if !(defined _WIN32 || defined __WIN32__ || defined __CYGWIN__) static bool tried_find_shared_library_fullname; if (!tried_find_shared_library_fullname) { find_shared_library_fullname (); tried_find_shared_library_fullname = true; } #endif return shared_library_fullname; } #endif /* PIC */ /* Returns the pathname, relocated according to the current installation directory. */ const char * relocate (const char *pathname) { #if defined PIC && defined INSTALLDIR static int initialized; /* Initialization code for a shared library. */ if (!initialized) { /* At this point, orig_prefix and curr_prefix likely have already been set through the main program's set_program_name_and_installdir function. This is sufficient in the case that the library has initially been installed in the same orig_prefix. But we can do better, to also cover the cases that 1. it has been installed in a different prefix before being moved to orig_prefix and (later) to curr_prefix, 2. unlike the program, it has not moved away from orig_prefix. */ const char *orig_installprefix = INSTALLPREFIX; const char *orig_installdir = INSTALLDIR; const char *curr_prefix_better; curr_prefix_better = compute_curr_prefix (orig_installprefix, orig_installdir, get_shared_library_fullname ()); if (curr_prefix_better == NULL) curr_prefix_better = curr_prefix; set_relocation_prefix (orig_installprefix, curr_prefix_better); initialized = 1; } #endif /* Note: It is not necessary to perform case insensitive comparison here, even for DOS-like filesystems, because the pathname argument was typically created from the same Makefile variable as orig_prefix came from. */ if (orig_prefix != NULL && curr_prefix != NULL && strncmp (pathname, orig_prefix, orig_prefix_len) == 0) { if (pathname[orig_prefix_len] == '\0') /* pathname equals orig_prefix. */ return curr_prefix; if (ISSLASH (pathname[orig_prefix_len])) { /* pathname starts with orig_prefix. */ const char *pathname_tail = &pathname[orig_prefix_len]; char *result = (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1); #ifdef NO_XMALLOC if (result != NULL) #endif { memcpy (result, curr_prefix, curr_prefix_len); strcpy (result + curr_prefix_len, pathname_tail); return result; } } } /* Nothing to relocate. */ return pathname; } #endif libnih-1.0.3/intl/ref-del.sin0000644000175000017500000000203011461165270012676 00000000000000# Remove this package from a list of references stored in a text file. # # Copyright (C) 2000 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. # # Written by Bruno Haible . # /^# Packages using this file: / { s/# Packages using this file:// s/ @PACKAGE@ / / s/^/# Packages using this file:/ } libnih-1.0.3/intl/vasnwprintf.h0000644000175000017500000000330611461165270013406 00000000000000/* vswprintf with automatic memory allocation. Copyright (C) 2002-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _VASNWPRINTF_H #define _VASNWPRINTF_H /* Get va_list. */ #include /* Get wchar_t, size_t. */ #include #ifdef __cplusplus extern "C" { #endif /* Write formatted output to a string dynamically allocated with malloc(). You can pass a preallocated buffer for the result in RESULTBUF and its size in *LENGTHP; otherwise you pass RESULTBUF = NULL. If successful, return the address of the string (this may be = RESULTBUF if no dynamic memory allocation was necessary) and set *LENGTHP to the number of resulting bytes, excluding the trailing NUL. Upon error, set errno and return NULL. */ extern wchar_t * asnwprintf (wchar_t *resultbuf, size_t *lengthp, const wchar_t *format, ...); extern wchar_t * vasnwprintf (wchar_t *resultbuf, size_t *lengthp, const wchar_t *format, va_list args); #ifdef __cplusplus } #endif #endif /* _VASNWPRINTF_H */ libnih-1.0.3/intl/explodename.c0000644000175000017500000000654611461165267013340 00000000000000/* Copyright (C) 1995-1998, 2000-2001, 2003, 2005, 2007 Free Software Foundation, Inc. Contributed by Ulrich Drepper , 1995. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include "loadinfo.h" /* On some strange systems still no definition of NULL is found. Sigh! */ #ifndef NULL # if defined __STDC__ && __STDC__ # define NULL ((void *) 0) # else # define NULL 0 # endif #endif /* @@ end of prolog @@ */ /* Split a locale name NAME into a leading language part and all the rest. Return a pointer to the first character after the language, i.e. to the first byte of the rest. */ static char *_nl_find_language (const char *name); static char * _nl_find_language (const char *name) { while (name[0] != '\0' && name[0] != '_' && name[0] != '@' && name[0] != '.') ++name; return (char *) name; } int _nl_explode_name (char *name, const char **language, const char **modifier, const char **territory, const char **codeset, const char **normalized_codeset) { char *cp; int mask; *modifier = NULL; *territory = NULL; *codeset = NULL; *normalized_codeset = NULL; /* Now we determine the single parts of the locale name. First look for the language. Termination symbols are `_', '.', and `@'. */ mask = 0; *language = cp = name; cp = _nl_find_language (*language); if (*language == cp) /* This does not make sense: language has to be specified. Use this entry as it is without exploding. Perhaps it is an alias. */ cp = strchr (*language, '\0'); else { if (cp[0] == '_') { /* Next is the territory. */ cp[0] = '\0'; *territory = ++cp; while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@') ++cp; mask |= XPG_TERRITORY; } if (cp[0] == '.') { /* Next is the codeset. */ cp[0] = '\0'; *codeset = ++cp; while (cp[0] != '\0' && cp[0] != '@') ++cp; mask |= XPG_CODESET; if (*codeset != cp && (*codeset)[0] != '\0') { *normalized_codeset = _nl_normalize_codeset (*codeset, cp - *codeset); if (*normalized_codeset == NULL) return -1; else if (strcmp (*codeset, *normalized_codeset) == 0) free ((char *) *normalized_codeset); else mask |= XPG_NORM_CODESET; } } } if (cp[0] == '@') { /* Next is the modifier. */ cp[0] = '\0'; *modifier = ++cp; if (cp[0] != '\0') mask |= XPG_MODIFIER; } if (*territory != NULL && (*territory)[0] == '\0') mask &= ~XPG_TERRITORY; if (*codeset != NULL && (*codeset)[0] == '\0') mask &= ~XPG_CODESET; return mask; } libnih-1.0.3/intl/localcharset.h0000644000175000017500000000256311461165267013503 00000000000000/* Determine a canonical name for the current locale's character encoding. Copyright (C) 2000-2003 Free Software Foundation, Inc. This file is part of the GNU CHARSET Library. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _LOCALCHARSET_H #define _LOCALCHARSET_H #ifdef __cplusplus extern "C" { #endif /* Determine the current locale's character encoding, and canonicalize it into one of the canonical names listed in config.charset. The result must not be freed; it is statically allocated. If the canonical name cannot be determined, the result is a non-canonical name. */ extern const char * locale_charset (void); #ifdef __cplusplus } #endif #endif /* _LOCALCHARSET_H */ libnih-1.0.3/intl/plural.c0000644000175000017500000014260311504742362012324 00000000000000 /* A Bison parser, made by GNU Bison 2.4.1. */ /* Skeleton implementation for Bison's Yacc-like parsers in C Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work under terms of your choice, so long as that work isn't itself a parser generator using the skeleton or a modified version thereof as a parser skeleton. Alternatively, if you modify or redistribute the parser skeleton itself, you may (at your option) remove this special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. There are some unavoidable exceptions within include files to define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ /* Identify Bison output. */ #define YYBISON 1 /* Bison version. */ #define YYBISON_VERSION "2.4.1" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" /* Pure parsers. */ #define YYPURE 1 /* Push parsers. */ #define YYPUSH 0 /* Pull parsers. */ #define YYPULL 1 /* Using locations. */ #define YYLSP_NEEDED 0 /* Substitute the variable and function names. */ #define yyparse __gettextparse #define yylex __gettextlex #define yyerror __gettexterror #define yylval __gettextlval #define yychar __gettextchar #define yydebug __gettextdebug #define yynerrs __gettextnerrs /* Copy the first part of user declarations. */ /* Line 189 of yacc.c */ #line 1 "plural.y" /* Expression parsing for plural form selection. Copyright (C) 2000-2001, 2003, 2005-2006 Free Software Foundation, Inc. Written by Ulrich Drepper , 2000. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* For bison < 2.0, the bison generated parser uses alloca. AIX 3 forces us to put this declaration at the beginning of the file. The declaration in bison's skeleton file comes too late. This must come before because may include arbitrary system headers. This can go away once the AM_INTL_SUBDIR macro requires bison >= 2.0. */ #if defined _AIX && !defined __GNUC__ #pragma alloca #endif #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include "plural-exp.h" /* The main function generated by the parser is called __gettextparse, but we want it to be called PLURAL_PARSE. */ #ifndef _LIBC # define __gettextparse PLURAL_PARSE #endif #define YYLEX_PARAM &((struct parse_args *) arg)->cp #define YYPARSE_PARAM arg /* Line 189 of yacc.c */ #line 130 "plural.c" /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG 0 #endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE # undef YYERROR_VERBOSE # define YYERROR_VERBOSE 1 #else # define YYERROR_VERBOSE 0 #endif /* Enabling the token table. */ #ifndef YYTOKEN_TABLE # define YYTOKEN_TABLE 0 #endif /* Tokens. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE /* Put the tokens into the symbol table, so that GDB and other debuggers know about them. */ enum yytokentype { EQUOP2 = 258, CMPOP2 = 259, ADDOP2 = 260, MULOP2 = 261, NUMBER = 262 }; #endif /* Tokens. */ #define EQUOP2 258 #define CMPOP2 259 #define ADDOP2 260 #define MULOP2 261 #define NUMBER 262 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { /* Line 214 of yacc.c */ #line 51 "plural.y" unsigned long int num; enum expression_operator op; struct expression *exp; /* Line 214 of yacc.c */ #line 188 "plural.c" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 #endif /* Copy the second part of user declarations. */ /* Line 264 of yacc.c */ #line 57 "plural.y" /* Prototypes for local functions. */ static int yylex (YYSTYPE *lval, const char **pexp); static void yyerror (const char *str); /* Allocation of expressions. */ static struct expression * new_exp (int nargs, enum expression_operator op, struct expression * const *args) { int i; struct expression *newp; /* If any of the argument could not be malloc'ed, just return NULL. */ for (i = nargs - 1; i >= 0; i--) if (args[i] == NULL) goto fail; /* Allocate a new expression. */ newp = (struct expression *) malloc (sizeof (*newp)); if (newp != NULL) { newp->nargs = nargs; newp->operation = op; for (i = nargs - 1; i >= 0; i--) newp->val.args[i] = args[i]; return newp; } fail: for (i = nargs - 1; i >= 0; i--) FREE_EXPRESSION (args[i]); return NULL; } static inline struct expression * new_exp_0 (enum expression_operator op) { return new_exp (0, op, NULL); } static inline struct expression * new_exp_1 (enum expression_operator op, struct expression *right) { struct expression *args[1]; args[0] = right; return new_exp (1, op, args); } static struct expression * new_exp_2 (enum expression_operator op, struct expression *left, struct expression *right) { struct expression *args[2]; args[0] = left; args[1] = right; return new_exp (2, op, args); } static inline struct expression * new_exp_3 (enum expression_operator op, struct expression *bexp, struct expression *tbranch, struct expression *fbranch) { struct expression *args[3]; args[0] = bexp; args[1] = tbranch; args[2] = fbranch; return new_exp (3, op, args); } /* Line 264 of yacc.c */ #line 278 "plural.c" #ifdef short # undef short #endif #ifdef YYTYPE_UINT8 typedef YYTYPE_UINT8 yytype_uint8; #else typedef unsigned char yytype_uint8; #endif #ifdef YYTYPE_INT8 typedef YYTYPE_INT8 yytype_int8; #elif (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) typedef signed char yytype_int8; #else typedef short int yytype_int8; #endif #ifdef YYTYPE_UINT16 typedef YYTYPE_UINT16 yytype_uint16; #else typedef unsigned short int yytype_uint16; #endif #ifdef YYTYPE_INT16 typedef YYTYPE_INT16 yytype_int16; #else typedef short int yytype_int16; #endif #ifndef YYSIZE_T # ifdef __SIZE_TYPE__ # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else # define YYSIZE_T unsigned int # endif #endif #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ # if YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ # define YY_(msgid) dgettext ("bison-runtime", msgid) # endif # endif # ifndef YY_ # define YY_(msgid) msgid # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ # define YYUSE(e) ((void) (e)) #else # define YYUSE(e) /* empty */ #endif /* Identity function, used to suppress warnings about constant conditions. */ #ifndef lint # define YYID(n) (n) #else #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static int YYID (int yyi) #else static int YYID (yyi) int yyi; #endif { return yyi; } #endif #if ! defined yyoverflow || YYERROR_VERBOSE /* The parser invokes alloca or malloc; define the necessary symbols. */ # ifdef YYSTACK_USE_ALLOCA # if YYSTACK_USE_ALLOCA # ifdef __GNUC__ # define YYSTACK_ALLOC __builtin_alloca # elif defined __BUILTIN_VA_ARG_INCR # include /* INFRINGES ON USER NAME SPACE */ # elif defined _AIX # define YYSTACK_ALLOC __alloca # elif defined _MSC_VER # include /* INFRINGES ON USER NAME SPACE */ # define alloca _alloca # else # define YYSTACK_ALLOC alloca # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ # ifndef _STDLIB_H # define _STDLIB_H 1 # endif # endif # endif # endif # endif # ifdef YYSTACK_ALLOC /* Pacify GCC's `empty if-body' warning. */ # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) # ifndef YYSTACK_ALLOC_MAXIMUM /* The OS might guarantee only one guard page at the bottom of the stack, and a page size can be as small as 4096 bytes. So we cannot safely invoke alloca (N) if N exceeds 4096. Use a slightly smaller number to allow for a few compiler-allocated temporary stack slots. */ # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ # endif # else # define YYSTACK_ALLOC YYMALLOC # define YYSTACK_FREE YYFREE # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif # if (defined __cplusplus && ! defined _STDLIB_H \ && ! ((defined YYMALLOC || defined malloc) \ && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ # ifndef _STDLIB_H # define _STDLIB_H 1 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ #if (! defined yyoverflow \ && (! defined __cplusplus \ || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { yytype_int16 yyss_alloc; YYSTYPE yyvs_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) /* Copy COUNT objects from FROM to TO. The source and destination do not overlap. */ # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ # define YYCOPY(To, From, Count) \ __builtin_memcpy (To, From, (Count) * sizeof (*(From))) # else # define YYCOPY(To, From, Count) \ do \ { \ YYSIZE_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (To)[yyi] = (From)[yyi]; \ } \ while (YYID (0)) # endif # endif /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ do \ { \ YYSIZE_T yynewbytes; \ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ Stack = &yyptr->Stack_alloc; \ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ yyptr += yynewbytes / sizeof (*yyptr); \ } \ while (YYID (0)) #endif /* YYFINAL -- State number of the termination state. */ #define YYFINAL 9 /* YYLAST -- Last index in YYTABLE. */ #define YYLAST 54 /* YYNTOKENS -- Number of terminals. */ #define YYNTOKENS 16 /* YYNNTS -- Number of nonterminals. */ #define YYNNTS 3 /* YYNRULES -- Number of rules. */ #define YYNRULES 13 /* YYNRULES -- Number of states. */ #define YYNSTATES 27 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 #define YYMAXUTOK 262 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ static const yytype_uint8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 10, 2, 2, 2, 2, 5, 2, 14, 15, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 12, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 13, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 6, 7, 8, 9, 11 }; #if YYDEBUG /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in YYRHS. */ static const yytype_uint8 yyprhs[] = { 0, 0, 3, 5, 11, 15, 19, 23, 27, 31, 35, 38, 40, 42 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yytype_int8 yyrhs[] = { 17, 0, -1, 18, -1, 18, 3, 18, 12, 18, -1, 18, 4, 18, -1, 18, 5, 18, -1, 18, 6, 18, -1, 18, 7, 18, -1, 18, 8, 18, -1, 18, 9, 18, -1, 10, 18, -1, 13, -1, 11, -1, 14, 18, 15, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { 0, 154, 154, 162, 166, 170, 174, 178, 182, 186, 190, 194, 198, 203 }; #endif #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { "$end", "error", "$undefined", "'?'", "'|'", "'&'", "EQUOP2", "CMPOP2", "ADDOP2", "MULOP2", "'!'", "NUMBER", "':'", "'n'", "'('", "')'", "$accept", "start", "exp", 0 }; #endif # ifdef YYPRINT /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to token YYLEX-NUM. */ static const yytype_uint16 yytoknum[] = { 0, 256, 257, 63, 124, 38, 258, 259, 260, 261, 33, 262, 58, 110, 40, 41 }; # endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const yytype_uint8 yyr1[] = { 0, 16, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const yytype_uint8 yyr2[] = { 0, 2, 1, 5, 3, 3, 3, 3, 3, 3, 2, 1, 1, 3 }; /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state STATE-NUM when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const yytype_uint8 yydefact[] = { 0, 0, 12, 11, 0, 0, 2, 10, 0, 1, 0, 0, 0, 0, 0, 0, 0, 13, 0, 4, 5, 6, 7, 8, 9, 0, 3 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int8 yydefgoto[] = { -1, 5, 6 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ #define YYPACT_NINF -10 static const yytype_int8 yypact[] = { -9, -9, -10, -10, -9, 8, 36, -10, 13, -10, -9, -9, -9, -9, -9, -9, -9, -10, 26, 41, 45, 18, -2, 14, -10, -9, 36 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { -10, -10, -1 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which number is the opposite. If zero, do what YYDEFACT says. If YYTABLE_NINF, syntax error. */ #define YYTABLE_NINF -1 static const yytype_uint8 yytable[] = { 7, 1, 2, 8, 3, 4, 15, 16, 9, 18, 19, 20, 21, 22, 23, 24, 10, 11, 12, 13, 14, 15, 16, 16, 26, 14, 15, 16, 17, 10, 11, 12, 13, 14, 15, 16, 0, 0, 25, 10, 11, 12, 13, 14, 15, 16, 12, 13, 14, 15, 16, 13, 14, 15, 16 }; static const yytype_int8 yycheck[] = { 1, 10, 11, 4, 13, 14, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 3, 4, 5, 6, 7, 8, 9, 9, 25, 7, 8, 9, 15, 3, 4, 5, 6, 7, 8, 9, -1, -1, 12, 3, 4, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 6, 7, 8, 9 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const yytype_uint8 yystos[] = { 0, 10, 11, 13, 14, 17, 18, 18, 18, 0, 3, 4, 5, 6, 7, 8, 9, 15, 18, 18, 18, 18, 18, 18, 18, 12, 18 }; #define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) #define YYEMPTY (-2) #define YYEOF 0 #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab #define YYERROR goto yyerrorlab /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. Once GCC version 2 has supplanted version 1, this can go. */ #define YYFAIL goto yyerrlab #define YYRECOVERING() (!!yyerrstatus) #define YYBACKUP(Token, Value) \ do \ if (yychar == YYEMPTY && yylen == 1) \ { \ yychar = (Token); \ yylval = (Value); \ yytoken = YYTRANSLATE (yychar); \ YYPOPSTACK (1); \ goto yybackup; \ } \ else \ { \ yyerror (YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) #define YYTERROR 1 #define YYERRCODE 256 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. If N is 0, then set CURRENT to the empty location which ends the previous symbol: RHS[0] (always defined). */ #define YYRHSLOC(Rhs, K) ((Rhs)[K]) #ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(Current, Rhs, N) \ do \ if (YYID (N)) \ { \ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ } \ else \ { \ (Current).first_line = (Current).last_line = \ YYRHSLOC (Rhs, 0).last_line; \ (Current).first_column = (Current).last_column = \ YYRHSLOC (Rhs, 0).last_column; \ } \ while (YYID (0)) #endif /* YY_LOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know we won't break user code: when these are the locations we know. */ #ifndef YY_LOCATION_PRINT # if YYLTYPE_IS_TRIVIAL # define YY_LOCATION_PRINT(File, Loc) \ fprintf (File, "%d.%d-%d.%d", \ (Loc).first_line, (Loc).first_column, \ (Loc).last_line, (Loc).last_column) # else # define YY_LOCATION_PRINT(File, Loc) ((void) 0) # endif #endif /* YYLEX -- calling `yylex' with the right arguments. */ #ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, YYLEX_PARAM) #else # define YYLEX yylex (&yylval) #endif /* Enable debugging if requested. */ #if YYDEBUG # ifndef YYFPRINTF # include /* INFRINGES ON USER NAME SPACE */ # define YYFPRINTF fprintf # endif # define YYDPRINTF(Args) \ do { \ if (yydebug) \ YYFPRINTF Args; \ } while (YYID (0)) # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ Type, Value); \ YYFPRINTF (stderr, "\n"); \ } \ } while (YYID (0)) /*--------------------------------. | Print this symbol on YYOUTPUT. | `--------------------------------*/ /*ARGSUSED*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) #else static void yy_symbol_value_print (yyoutput, yytype, yyvaluep) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; #endif { if (!yyvaluep) return; # ifdef YYPRINT if (yytype < YYNTOKENS) YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); # else YYUSE (yyoutput); # endif switch (yytype) { default: break; } } /*--------------------------------. | Print this symbol on YYOUTPUT. | `--------------------------------*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) #else static void yy_symbol_print (yyoutput, yytype, yyvaluep) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; #endif { if (yytype < YYNTOKENS) YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); else YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); yy_symbol_value_print (yyoutput, yytype, yyvaluep); YYFPRINTF (yyoutput, ")"); } /*------------------------------------------------------------------. | yy_stack_print -- Print the state stack from its BOTTOM up to its | | TOP (included). | `------------------------------------------------------------------*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) #else static void yy_stack_print (yybottom, yytop) yytype_int16 *yybottom; yytype_int16 *yytop; #endif { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) { int yybot = *yybottom; YYFPRINTF (stderr, " %d", yybot); } YYFPRINTF (stderr, "\n"); } # define YY_STACK_PRINT(Bottom, Top) \ do { \ if (yydebug) \ yy_stack_print ((Bottom), (Top)); \ } while (YYID (0)) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yy_reduce_print (YYSTYPE *yyvsp, int yyrule) #else static void yy_reduce_print (yyvsp, yyrule) YYSTYPE *yyvsp; int yyrule; #endif { int yynrhs = yyr2[yyrule]; int yyi; unsigned long int yylno = yyrline[yyrule]; YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], &(yyvsp[(yyi + 1) - (yynrhs)]) ); YYFPRINTF (stderr, "\n"); } } # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ yy_reduce_print (yyvsp, Rule); \ } while (YYID (0)) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ # define YYDPRINTF(Args) # define YY_SYMBOL_PRINT(Title, Type, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH # define YYINITDEPTH 200 #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only if the built-in stack extension method is used). Do not make this value too large; the results are undefined if YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) evaluated with infinite-precision integer arithmetic. */ #ifndef YYMAXDEPTH # define YYMAXDEPTH 10000 #endif #if YYERROR_VERBOSE # ifndef yystrlen # if defined __GLIBC__ && defined _STRING_H # define yystrlen strlen # else /* Return the length of YYSTR. */ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static YYSIZE_T yystrlen (const char *yystr) #else static YYSIZE_T yystrlen (yystr) const char *yystr; #endif { YYSIZE_T yylen; for (yylen = 0; yystr[yylen]; yylen++) continue; return yylen; } # endif # endif # ifndef yystpcpy # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE # define yystpcpy stpcpy # else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static char * yystpcpy (char *yydest, const char *yysrc) #else static char * yystpcpy (yydest, yysrc) char *yydest; const char *yysrc; #endif { char *yyd = yydest; const char *yys = yysrc; while ((*yyd++ = *yys++) != '\0') continue; return yyd - 1; } # endif # endif # ifndef yytnamerr /* Copy to YYRES the contents of YYSTR after stripping away unnecessary quotes and backslashes, so that it's suitable for yyerror. The heuristic is that double-quoting is unnecessary unless the string contains an apostrophe, a comma, or backslash (other than backslash-backslash). YYSTR is taken from yytname. If YYRES is null, do not copy; instead, return the length of what the result would have been. */ static YYSIZE_T yytnamerr (char *yyres, const char *yystr) { if (*yystr == '"') { YYSIZE_T yyn = 0; char const *yyp = yystr; for (;;) switch (*++yyp) { case '\'': case ',': goto do_not_strip_quotes; case '\\': if (*++yyp != '\\') goto do_not_strip_quotes; /* Fall through. */ default: if (yyres) yyres[yyn] = *yyp; yyn++; break; case '"': if (yyres) yyres[yyn] = '\0'; return yyn; } do_not_strip_quotes: ; } if (! yyres) return yystrlen (yystr); return yystpcpy (yyres, yystr) - yyres; } # endif /* Copy into YYRESULT an error message about the unexpected token YYCHAR while in state YYSTATE. Return the number of bytes copied, including the terminating null byte. If YYRESULT is null, do not copy anything; just return the number of bytes that would be copied. As a special case, return 0 if an ordinary "syntax error" message will do. Return YYSIZE_MAXIMUM if overflow occurs during size calculation. */ static YYSIZE_T yysyntax_error (char *yyresult, int yystate, int yychar) { int yyn = yypact[yystate]; if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) return 0; else { int yytype = YYTRANSLATE (yychar); YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); YYSIZE_T yysize = yysize0; YYSIZE_T yysize1; int yysize_overflow = 0; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; int yyx; # if 0 /* This is so xgettext sees the translatable formats that are constructed on the fly. */ YY_("syntax error, unexpected %s"); YY_("syntax error, unexpected %s, expecting %s"); YY_("syntax error, unexpected %s, expecting %s or %s"); YY_("syntax error, unexpected %s, expecting %s or %s or %s"); YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); # endif char *yyfmt; char const *yyf; static char const yyunexpected[] = "syntax error, unexpected %s"; static char const yyexpecting[] = ", expecting %s"; static char const yyor[] = " or %s"; char yyformat[sizeof yyunexpected + sizeof yyexpecting - 1 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) * (sizeof yyor - 1))]; char const *yyprefix = yyexpecting; /* Start YYX at -YYN if negative to avoid negative indexes in YYCHECK. */ int yyxbegin = yyn < 0 ? -yyn : 0; /* Stay within bounds of both yycheck and yytname. */ int yychecklim = YYLAST - yyn + 1; int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; int yycount = 1; yyarg[0] = yytname[yytype]; yyfmt = yystpcpy (yyformat, yyunexpected); for (yyx = yyxbegin; yyx < yyxend; ++yyx) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) { if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) { yycount = 1; yysize = yysize0; yyformat[sizeof yyunexpected - 1] = '\0'; break; } yyarg[yycount++] = yytname[yyx]; yysize1 = yysize + yytnamerr (0, yytname[yyx]); yysize_overflow |= (yysize1 < yysize); yysize = yysize1; yyfmt = yystpcpy (yyfmt, yyprefix); yyprefix = yyor; } yyf = YY_(yyformat); yysize1 = yysize + yystrlen (yyf); yysize_overflow |= (yysize1 < yysize); yysize = yysize1; if (yysize_overflow) return YYSIZE_MAXIMUM; if (yyresult) { /* Avoid sprintf, as that infringes on the user's name space. Don't have undefined behavior even if the translation produced a string with the wrong number of "%s"s. */ char *yyp = yyresult; int yyi = 0; while ((*yyp = *yyf) != '\0') { if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) { yyp += yytnamerr (yyp, yyarg[yyi++]); yyf += 2; } else { yyp++; yyf++; } } } return yysize; } } #endif /* YYERROR_VERBOSE */ /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ /*ARGSUSED*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) #else static void yydestruct (yymsg, yytype, yyvaluep) const char *yymsg; int yytype; YYSTYPE *yyvaluep; #endif { YYUSE (yyvaluep); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); switch (yytype) { default: break; } } /* Prevent warnings from -Wmissing-prototypes. */ #ifdef YYPARSE_PARAM #if defined __STDC__ || defined __cplusplus int yyparse (void *YYPARSE_PARAM); #else int yyparse (); #endif #else /* ! YYPARSE_PARAM */ #if defined __STDC__ || defined __cplusplus int yyparse (void); #else int yyparse (); #endif #endif /* ! YYPARSE_PARAM */ /*-------------------------. | yyparse or yypush_parse. | `-------------------------*/ #ifdef YYPARSE_PARAM #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) int yyparse (void *YYPARSE_PARAM) #else int yyparse (YYPARSE_PARAM) void *YYPARSE_PARAM; #endif #else /* ! YYPARSE_PARAM */ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) int yyparse (void) #else int yyparse () #endif #endif { /* The lookahead symbol. */ int yychar; /* The semantic value of the lookahead symbol. */ YYSTYPE yylval; /* Number of syntax errors so far. */ int yynerrs; int yystate; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; /* The stacks and their tools: `yyss': related to states. `yyvs': related to semantic values. Refer to the stacks thru separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ yytype_int16 yyssa[YYINITDEPTH]; yytype_int16 *yyss; yytype_int16 *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; YYSTYPE *yyvs; YYSTYPE *yyvsp; YYSIZE_T yystacksize; int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ int yytoken; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; #if YYERROR_VERBOSE /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; char *yymsg = yymsgbuf; YYSIZE_T yymsg_alloc = sizeof yymsgbuf; #endif #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ int yylen = 0; yytoken = 0; yyss = yyssa; yyvs = yyvsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ /* Initialize stack pointers. Waste one element of value and location stack so that they stay on the same level as the state stack. The wasted elements are never initialized. */ yyssp = yyss; yyvsp = yyvs; goto yysetstate; /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; yysetstate: *yyssp = yystate; if (yyss + yystacksize - 1 <= yyssp) { /* Get the current used size of the three stacks, in elements. */ YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ YYSTYPE *yyvs1 = yyvs; yytype_int16 *yyss1 = yyss; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow (YY_("memory exhausted"), &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE goto yyexhaustedlab; # else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { yytype_int16 *yyss1 = yyss; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs); # undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } # endif #endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; YYDPRINTF ((stderr, "Stack size increased to %lu\n", (unsigned long int) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); if (yystate == YYFINAL) YYACCEPT; goto yybackup; /*-----------. | yybackup. | `-----------*/ yybackup: /* Do appropriate processing given the current state. Read a lookahead token if we need one and don't already have one. */ /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; if (yyn == YYPACT_NINF) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; } if (yychar <= YYEOF) { yychar = yytoken = YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } else { yytoken = YYTRANSLATE (yychar); YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } /* If the proper action on seeing token YYTOKEN is to reduce or to detect an error, take that action. */ yyn += yytoken; if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) goto yydefault; yyn = yytable[yyn]; if (yyn <= 0) { if (yyn == 0 || yyn == YYTABLE_NINF) goto yyerrlab; yyn = -yyn; goto yyreduce; } /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); /* Discard the shifted token. */ yychar = YYEMPTY; yystate = yyn; *++yyvsp = yylval; goto yynewstate; /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: yyn = yydefact[yystate]; if (yyn == 0) goto yyerrlab; goto yyreduce; /*-----------------------------. | yyreduce -- Do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: `$$ = $1'. Otherwise, the following line sets YYVAL to garbage. This behavior is undocumented and Bison users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ yyval = yyvsp[1-yylen]; YY_REDUCE_PRINT (yyn); switch (yyn) { case 2: /* Line 1455 of yacc.c */ #line 155 "plural.y" { if ((yyvsp[(1) - (1)].exp) == NULL) YYABORT; ((struct parse_args *) arg)->res = (yyvsp[(1) - (1)].exp); } break; case 3: /* Line 1455 of yacc.c */ #line 163 "plural.y" { (yyval.exp) = new_exp_3 (qmop, (yyvsp[(1) - (5)].exp), (yyvsp[(3) - (5)].exp), (yyvsp[(5) - (5)].exp)); } break; case 4: /* Line 1455 of yacc.c */ #line 167 "plural.y" { (yyval.exp) = new_exp_2 (lor, (yyvsp[(1) - (3)].exp), (yyvsp[(3) - (3)].exp)); } break; case 5: /* Line 1455 of yacc.c */ #line 171 "plural.y" { (yyval.exp) = new_exp_2 (land, (yyvsp[(1) - (3)].exp), (yyvsp[(3) - (3)].exp)); } break; case 6: /* Line 1455 of yacc.c */ #line 175 "plural.y" { (yyval.exp) = new_exp_2 ((yyvsp[(2) - (3)].op), (yyvsp[(1) - (3)].exp), (yyvsp[(3) - (3)].exp)); } break; case 7: /* Line 1455 of yacc.c */ #line 179 "plural.y" { (yyval.exp) = new_exp_2 ((yyvsp[(2) - (3)].op), (yyvsp[(1) - (3)].exp), (yyvsp[(3) - (3)].exp)); } break; case 8: /* Line 1455 of yacc.c */ #line 183 "plural.y" { (yyval.exp) = new_exp_2 ((yyvsp[(2) - (3)].op), (yyvsp[(1) - (3)].exp), (yyvsp[(3) - (3)].exp)); } break; case 9: /* Line 1455 of yacc.c */ #line 187 "plural.y" { (yyval.exp) = new_exp_2 ((yyvsp[(2) - (3)].op), (yyvsp[(1) - (3)].exp), (yyvsp[(3) - (3)].exp)); } break; case 10: /* Line 1455 of yacc.c */ #line 191 "plural.y" { (yyval.exp) = new_exp_1 (lnot, (yyvsp[(2) - (2)].exp)); } break; case 11: /* Line 1455 of yacc.c */ #line 195 "plural.y" { (yyval.exp) = new_exp_0 (var); } break; case 12: /* Line 1455 of yacc.c */ #line 199 "plural.y" { if (((yyval.exp) = new_exp_0 (num)) != NULL) (yyval.exp)->val.num = (yyvsp[(1) - (1)].num); } break; case 13: /* Line 1455 of yacc.c */ #line 204 "plural.y" { (yyval.exp) = (yyvsp[(2) - (3)].exp); } break; /* Line 1455 of yacc.c */ #line 1592 "plural.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; /* Now `shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ yyn = yyr1[yyn]; yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) yystate = yytable[yystate]; else yystate = yydefgoto[yyn - YYNTOKENS]; goto yynewstate; /*------------------------------------. | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; #if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); #else { YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) { YYSIZE_T yyalloc = 2 * yysize; if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) yyalloc = YYSTACK_ALLOC_MAXIMUM; if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); yymsg = (char *) YYSTACK_ALLOC (yyalloc); if (yymsg) yymsg_alloc = yyalloc; else { yymsg = yymsgbuf; yymsg_alloc = sizeof yymsgbuf; } } if (0 < yysize && yysize <= yymsg_alloc) { (void) yysyntax_error (yymsg, yystate, yychar); yyerror (yymsg); } else { yyerror (YY_("syntax error")); if (yysize != 0) goto yyexhaustedlab; } } #endif } if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an error, discard it. */ if (yychar <= YYEOF) { /* Return failure if at end of input. */ if (yychar == YYEOF) YYABORT; } else { yydestruct ("Error: discarding", yytoken, &yylval); yychar = YYEMPTY; } } /* Else will try to reuse lookahead token after shifting the error token. */ goto yyerrlab1; /*---------------------------------------------------. | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: /* Pacify compilers like GCC when the user code never invokes YYERROR and the label yyerrorlab therefore never appears in user code. */ if (/*CONSTCOND*/ 0) goto yyerrorlab; /* Do not reclaim the symbols of the rule which action triggered this YYERROR. */ YYPOPSTACK (yylen); yylen = 0; YY_STACK_PRINT (yyss, yyssp); yystate = *yyssp; goto yyerrlab1; /*-------------------------------------------------------------. | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) { yyn = yypact[yystate]; if (yyn != YYPACT_NINF) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) { yyn = yytable[yyn]; if (0 < yyn) break; } } /* Pop the current state because it cannot handle the error token. */ if (yyssp == yyss) YYABORT; yydestruct ("Error: popping", yystos[yystate], yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } *++yyvsp = yylval; /* Shift the error token. */ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; /*-------------------------------------. | yyacceptlab -- YYACCEPT comes here. | `-------------------------------------*/ yyacceptlab: yyresult = 0; goto yyreturn; /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: yyresult = 1; goto yyreturn; #if !defined(yyoverflow) || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif yyreturn: if (yychar != YYEMPTY) yydestruct ("Cleanup: discarding lookahead", yytoken, &yylval); /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); YY_STACK_PRINT (yyss, yyssp); while (yyssp != yyss) { yydestruct ("Cleanup: popping", yystos[*yyssp], yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif #if YYERROR_VERBOSE if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); #endif /* Make sure YYID is used. */ return YYID (yyresult); } /* Line 1675 of yacc.c */ #line 209 "plural.y" void internal_function FREE_EXPRESSION (struct expression *exp) { if (exp == NULL) return; /* Handle the recursive case. */ switch (exp->nargs) { case 3: FREE_EXPRESSION (exp->val.args[2]); /* FALLTHROUGH */ case 2: FREE_EXPRESSION (exp->val.args[1]); /* FALLTHROUGH */ case 1: FREE_EXPRESSION (exp->val.args[0]); /* FALLTHROUGH */ default: break; } free (exp); } static int yylex (YYSTYPE *lval, const char **pexp) { const char *exp = *pexp; int result; while (1) { if (exp[0] == '\0') { *pexp = exp; return YYEOF; } if (exp[0] != ' ' && exp[0] != '\t') break; ++exp; } result = *exp++; switch (result) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { unsigned long int n = result - '0'; while (exp[0] >= '0' && exp[0] <= '9') { n *= 10; n += exp[0] - '0'; ++exp; } lval->num = n; result = NUMBER; } break; case '=': if (exp[0] == '=') { ++exp; lval->op = equal; result = EQUOP2; } else result = YYERRCODE; break; case '!': if (exp[0] == '=') { ++exp; lval->op = not_equal; result = EQUOP2; } break; case '&': case '|': if (exp[0] == result) ++exp; else result = YYERRCODE; break; case '<': if (exp[0] == '=') { ++exp; lval->op = less_or_equal; } else lval->op = less_than; result = CMPOP2; break; case '>': if (exp[0] == '=') { ++exp; lval->op = greater_or_equal; } else lval->op = greater_than; result = CMPOP2; break; case '*': lval->op = mult; result = MULOP2; break; case '/': lval->op = divide; result = MULOP2; break; case '%': lval->op = module; result = MULOP2; break; case '+': lval->op = plus; result = ADDOP2; break; case '-': lval->op = minus; result = ADDOP2; break; case 'n': case '?': case ':': case '(': case ')': /* Nothing, just return the character. */ break; case ';': case '\n': case '\0': /* Be safe and let the user call this function again. */ --exp; result = YYEOF; break; default: result = YYERRCODE; #if YYDEBUG != 0 --exp; #endif break; } *pexp = exp; return result; } static void yyerror (const char *str) { /* Do nothing. We don't print error messages here. */ } libnih-1.0.3/intl/gmo.h0000644000175000017500000001151211461165267011613 00000000000000/* Description of GNU message catalog format: general file layout. Copyright (C) 1995, 1997, 2000-2002, 2004, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _GETTEXT_H #define _GETTEXT_H 1 #include /* @@ end of prolog @@ */ /* The magic number of the GNU message catalog format. */ #define _MAGIC 0x950412de #define _MAGIC_SWAPPED 0xde120495 /* Revision number of the currently used .mo (binary) file format. */ #define MO_REVISION_NUMBER 0 #define MO_REVISION_NUMBER_WITH_SYSDEP_I 1 /* The following contortions are an attempt to use the C preprocessor to determine an unsigned integral type that is 32 bits wide. An alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but as of version autoconf-2.13, the AC_CHECK_SIZEOF macro doesn't work when cross-compiling. */ #if __STDC__ # define UINT_MAX_32_BITS 4294967295U #else # define UINT_MAX_32_BITS 0xFFFFFFFF #endif /* If UINT_MAX isn't defined, assume it's a 32-bit type. This should be valid for all systems GNU cares about because that doesn't include 16-bit systems, and only modern systems (that certainly have ) have 64+-bit integral types. */ #ifndef UINT_MAX # define UINT_MAX UINT_MAX_32_BITS #endif #if UINT_MAX == UINT_MAX_32_BITS typedef unsigned nls_uint32; #else # if USHRT_MAX == UINT_MAX_32_BITS typedef unsigned short nls_uint32; # else # if ULONG_MAX == UINT_MAX_32_BITS typedef unsigned long nls_uint32; # else /* The following line is intended to throw an error. Using #error is not portable enough. */ "Cannot determine unsigned 32-bit data type." # endif # endif #endif /* Header for binary .mo file format. */ struct mo_file_header { /* The magic number. */ nls_uint32 magic; /* The revision number of the file format. */ nls_uint32 revision; /* The following are only used in .mo files with major revision 0 or 1. */ /* The number of strings pairs. */ nls_uint32 nstrings; /* Offset of table with start offsets of original strings. */ nls_uint32 orig_tab_offset; /* Offset of table with start offsets of translated strings. */ nls_uint32 trans_tab_offset; /* Size of hash table. */ nls_uint32 hash_tab_size; /* Offset of first hash table entry. */ nls_uint32 hash_tab_offset; /* The following are only used in .mo files with minor revision >= 1. */ /* The number of system dependent segments. */ nls_uint32 n_sysdep_segments; /* Offset of table describing system dependent segments. */ nls_uint32 sysdep_segments_offset; /* The number of system dependent strings pairs. */ nls_uint32 n_sysdep_strings; /* Offset of table with start offsets of original sysdep strings. */ nls_uint32 orig_sysdep_tab_offset; /* Offset of table with start offsets of translated sysdep strings. */ nls_uint32 trans_sysdep_tab_offset; }; /* Descriptor for static string contained in the binary .mo file. */ struct string_desc { /* Length of addressed string, not including the trailing NUL. */ nls_uint32 length; /* Offset of string in file. */ nls_uint32 offset; }; /* The following are only used in .mo files with minor revision >= 1. */ /* Descriptor for system dependent string segment. */ struct sysdep_segment { /* Length of addressed string, including the trailing NUL. */ nls_uint32 length; /* Offset of string in file. */ nls_uint32 offset; }; /* Pair of a static and a system dependent segment, in struct sysdep_string. */ struct segment_pair { /* Size of static segment. */ nls_uint32 segsize; /* Reference to system dependent string segment, or ~0 at the end. */ nls_uint32 sysdepref; }; /* Descriptor for system dependent string. */ struct sysdep_string { /* Offset of static string segments in file. */ nls_uint32 offset; /* Alternating sequence of static and system dependent segments. The last segment is a static segment, including the trailing NUL. */ struct segment_pair segments[1]; }; /* Marker for the end of the segments[] array. This has the value 0xFFFFFFFF, regardless whether 'int' is 16 bit, 32 bit, or 64 bit. */ #define SEGMENTS_END ((nls_uint32) ~0) /* @@ begin of epilog @@ */ #endif /* gettext.h */ libnih-1.0.3/intl/log.c0000644000175000017500000000623111461165267011607 00000000000000/* Log file output. Copyright (C) 2003, 2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Bruno Haible . */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include /* Handle multi-threaded applications. */ #ifdef _LIBC # include #else # include "lock.h" #endif /* Print an ASCII string with quotes and escape sequences where needed. */ static void print_escaped (FILE *stream, const char *str) { putc ('"', stream); for (; *str != '\0'; str++) if (*str == '\n') { fputs ("\\n\"", stream); if (str[1] == '\0') return; fputs ("\n\"", stream); } else { if (*str == '"' || *str == '\\') putc ('\\', stream); putc (*str, stream); } putc ('"', stream); } static char *last_logfilename = NULL; static FILE *last_logfile = NULL; __libc_lock_define_initialized (static, lock) static inline void _nl_log_untranslated_locked (const char *logfilename, const char *domainname, const char *msgid1, const char *msgid2, int plural) { FILE *logfile; /* Can we reuse the last opened logfile? */ if (last_logfilename == NULL || strcmp (logfilename, last_logfilename) != 0) { /* Close the last used logfile. */ if (last_logfilename != NULL) { if (last_logfile != NULL) { fclose (last_logfile); last_logfile = NULL; } free (last_logfilename); last_logfilename = NULL; } /* Open the logfile. */ last_logfilename = (char *) malloc (strlen (logfilename) + 1); if (last_logfilename == NULL) return; strcpy (last_logfilename, logfilename); last_logfile = fopen (logfilename, "a"); if (last_logfile == NULL) return; } logfile = last_logfile; fprintf (logfile, "domain "); print_escaped (logfile, domainname); fprintf (logfile, "\nmsgid "); print_escaped (logfile, msgid1); if (plural) { fprintf (logfile, "\nmsgid_plural "); print_escaped (logfile, msgid2); fprintf (logfile, "\nmsgstr[0] \"\"\n"); } else fprintf (logfile, "\nmsgstr \"\"\n"); putc ('\n', logfile); } /* Add to the log file an entry denoting a failed translation. */ void _nl_log_untranslated (const char *logfilename, const char *domainname, const char *msgid1, const char *msgid2, int plural) { __libc_lock_lock (lock); _nl_log_untranslated_locked (logfilename, domainname, msgid1, msgid2, plural); __libc_lock_unlock (lock); } libnih-1.0.3/intl/finddomain.c0000644000175000017500000001367311461165267013146 00000000000000/* Handle list of needed message catalogs Copyright (C) 1995-1999, 2000-2001, 2003-2007 Free Software Foundation, Inc. Written by Ulrich Drepper , 1995. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include #if defined HAVE_UNISTD_H || defined _LIBC # include #endif #include "gettextP.h" #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* Handle multi-threaded applications. */ #ifdef _LIBC # include # define gl_rwlock_define_initialized __libc_rwlock_define_initialized # define gl_rwlock_rdlock __libc_rwlock_rdlock # define gl_rwlock_wrlock __libc_rwlock_wrlock # define gl_rwlock_unlock __libc_rwlock_unlock #else # include "lock.h" #endif /* @@ end of prolog @@ */ /* List of already loaded domains. */ static struct loaded_l10nfile *_nl_loaded_domains; /* Return a data structure describing the message catalog described by the DOMAINNAME and CATEGORY parameters with respect to the currently established bindings. */ struct loaded_l10nfile * internal_function _nl_find_domain (const char *dirname, char *locale, const char *domainname, struct binding *domainbinding) { struct loaded_l10nfile *retval; const char *language; const char *modifier; const char *territory; const char *codeset; const char *normalized_codeset; const char *alias_value; int mask; /* LOCALE can consist of up to four recognized parts for the XPG syntax: language[_territory][.codeset][@modifier] Beside the first part all of them are allowed to be missing. If the full specified locale is not found, the less specific one are looked for. The various parts will be stripped off according to the following order: (1) codeset (2) normalized codeset (3) territory (4) modifier */ /* We need to protect modifying the _NL_LOADED_DOMAINS data. */ gl_rwlock_define_initialized (static, lock); gl_rwlock_rdlock (lock); /* If we have already tested for this locale entry there has to be one data set in the list of loaded domains. */ retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname, strlen (dirname) + 1, 0, locale, NULL, NULL, NULL, NULL, domainname, 0); gl_rwlock_unlock (lock); if (retval != NULL) { /* We know something about this locale. */ int cnt; if (retval->decided <= 0) _nl_load_domain (retval, domainbinding); if (retval->data != NULL) return retval; for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) { if (retval->successor[cnt]->decided <= 0) _nl_load_domain (retval->successor[cnt], domainbinding); if (retval->successor[cnt]->data != NULL) break; } return retval; /* NOTREACHED */ } /* See whether the locale value is an alias. If yes its value *overwrites* the alias name. No test for the original value is done. */ alias_value = _nl_expand_alias (locale); if (alias_value != NULL) { #if defined _LIBC || defined HAVE_STRDUP locale = strdup (alias_value); if (locale == NULL) return NULL; #else size_t len = strlen (alias_value) + 1; locale = (char *) malloc (len); if (locale == NULL) return NULL; memcpy (locale, alias_value, len); #endif } /* Now we determine the single parts of the locale name. First look for the language. Termination symbols are `_', '.', and `@'. */ mask = _nl_explode_name (locale, &language, &modifier, &territory, &codeset, &normalized_codeset); if (mask == -1) /* This means we are out of core. */ return NULL; /* We need to protect modifying the _NL_LOADED_DOMAINS data. */ gl_rwlock_wrlock (lock); /* Create all possible locale entries which might be interested in generalization. */ retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname, strlen (dirname) + 1, mask, language, territory, codeset, normalized_codeset, modifier, domainname, 1); gl_rwlock_unlock (lock); if (retval == NULL) /* This means we are out of core. */ goto out; if (retval->decided <= 0) _nl_load_domain (retval, domainbinding); if (retval->data == NULL) { int cnt; for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) { if (retval->successor[cnt]->decided <= 0) _nl_load_domain (retval->successor[cnt], domainbinding); if (retval->successor[cnt]->data != NULL) break; } } /* The room for an alias was dynamically allocated. Free it now. */ if (alias_value != NULL) free (locale); out: /* The space for normalized_codeset is dynamically allocated. Free it. */ if (mask & XPG_NORM_CODESET) free ((void *) normalized_codeset); return retval; } #ifdef _LIBC /* This is called from iconv/gconv_db.c's free_mem, as locales must be freed before freeing gconv steps arrays. */ void __libc_freeres_fn_section _nl_finddomain_subfreeres () { struct loaded_l10nfile *runp = _nl_loaded_domains; while (runp != NULL) { struct loaded_l10nfile *here = runp; if (runp->data != NULL) _nl_unload_domain ((struct loaded_domain *) runp->data); runp = runp->next; free ((char *) here->filename); free (here); } } #endif libnih-1.0.3/intl/tsearch.c0000644000175000017500000004462011461165270012455 00000000000000/* Copyright (C) 1995, 1996, 1997, 2000, 2006 Free Software Foundation, Inc. Contributed by Bernd Schmidt , 1997. NOTE: The canonical source of this file is maintained with the GNU C Library. Bugs can be reported to bug-glibc@gnu.org. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Tree search for red/black trees. The algorithm for adding nodes is taken from one of the many "Algorithms" books by Robert Sedgewick, although the implementation differs. The algorithm for deleting nodes can probably be found in a book named "Introduction to Algorithms" by Cormen/Leiserson/Rivest. At least that's the book that my professor took most algorithms from during the "Data Structures" course... Totally public domain. */ /* Red/black trees are binary trees in which the edges are colored either red or black. They have the following properties: 1. The number of black edges on every path from the root to a leaf is constant. 2. No two red edges are adjacent. Therefore there is an upper bound on the length of every path, it's O(log n) where n is the number of nodes in the tree. No path can be longer than 1+2*P where P is the length of the shortest path in the tree. Useful for the implementation: 3. If one of the children of a node is NULL, then the other one is red (if it exists). In the implementation, not the edges are colored, but the nodes. The color interpreted as the color of the edge leading to this node. The color is meaningless for the root node, but we color the root node black for convenience. All added nodes are red initially. Adding to a red/black tree is rather easy. The right place is searched with a usual binary tree search. Additionally, whenever a node N is reached that has two red successors, the successors are colored black and the node itself colored red. This moves red edges up the tree where they pose less of a problem once we get to really insert the new node. Changing N's color to red may violate rule 2, however, so rotations may become necessary to restore the invariants. Adding a new red leaf may violate the same rule, so afterwards an additional check is run and the tree possibly rotated. Deleting is hairy. There are mainly two nodes involved: the node to be deleted (n1), and another node that is to be unchained from the tree (n2). If n1 has a successor (the node with a smallest key that is larger than n1), then the successor becomes n2 and its contents are copied into n1, otherwise n1 becomes n2. Unchaining a node may violate rule 1: if n2 is black, one subtree is missing one black edge afterwards. The algorithm must try to move this error upwards towards the root, so that the subtree that does not have enough black edges becomes the whole tree. Once that happens, the error has disappeared. It may not be necessary to go all the way up, since it is possible that rotations and recoloring can fix the error before that. Although the deletion algorithm must walk upwards through the tree, we do not store parent pointers in the nodes. Instead, delete allocates a small array of parent pointers and fills it while descending the tree. Since we know that the length of a path is O(log n), where n is the number of nodes, this is likely to use less memory. */ /* Tree rotations look like this: A C / \ / \ B C A G / \ / \ --> / \ D E F G B F / \ D E In this case, A has been rotated left. This preserves the ordering of the binary tree. */ #include /* Specification. */ #ifdef IN_LIBINTL # include "tsearch.h" #else # include #endif #include typedef int (*__compar_fn_t) (const void *, const void *); typedef void (*__action_fn_t) (const void *, VISIT, int); #ifndef weak_alias # define __tsearch tsearch # define __tfind tfind # define __tdelete tdelete # define __twalk twalk #endif #ifndef internal_function /* Inside GNU libc we mark some function in a special way. In other environments simply ignore the marking. */ # define internal_function #endif typedef struct node_t { /* Callers expect this to be the first element in the structure - do not move! */ const void *key; struct node_t *left; struct node_t *right; unsigned int red:1; } *node; typedef const struct node_t *const_node; #undef DEBUGGING #ifdef DEBUGGING /* Routines to check tree invariants. */ #include #define CHECK_TREE(a) check_tree(a) static void check_tree_recurse (node p, int d_sofar, int d_total) { if (p == NULL) { assert (d_sofar == d_total); return; } check_tree_recurse (p->left, d_sofar + (p->left && !p->left->red), d_total); check_tree_recurse (p->right, d_sofar + (p->right && !p->right->red), d_total); if (p->left) assert (!(p->left->red && p->red)); if (p->right) assert (!(p->right->red && p->red)); } static void check_tree (node root) { int cnt = 0; node p; if (root == NULL) return; root->red = 0; for(p = root->left; p; p = p->left) cnt += !p->red; check_tree_recurse (root, 0, cnt); } #else #define CHECK_TREE(a) #endif /* Possibly "split" a node with two red successors, and/or fix up two red edges in a row. ROOTP is a pointer to the lowest node we visited, PARENTP and GPARENTP pointers to its parent/grandparent. P_R and GP_R contain the comparison values that determined which way was taken in the tree to reach ROOTP. MODE is 1 if we need not do the split, but must check for two red edges between GPARENTP and ROOTP. */ static void maybe_split_for_insert (node *rootp, node *parentp, node *gparentp, int p_r, int gp_r, int mode) { node root = *rootp; node *rp, *lp; rp = &(*rootp)->right; lp = &(*rootp)->left; /* See if we have to split this node (both successors red). */ if (mode == 1 || ((*rp) != NULL && (*lp) != NULL && (*rp)->red && (*lp)->red)) { /* This node becomes red, its successors black. */ root->red = 1; if (*rp) (*rp)->red = 0; if (*lp) (*lp)->red = 0; /* If the parent of this node is also red, we have to do rotations. */ if (parentp != NULL && (*parentp)->red) { node gp = *gparentp; node p = *parentp; /* There are two main cases: 1. The edge types (left or right) of the two red edges differ. 2. Both red edges are of the same type. There exist two symmetries of each case, so there is a total of 4 cases. */ if ((p_r > 0) != (gp_r > 0)) { /* Put the child at the top of the tree, with its parent and grandparent as successors. */ p->red = 1; gp->red = 1; root->red = 0; if (p_r < 0) { /* Child is left of parent. */ p->left = *rp; *rp = p; gp->right = *lp; *lp = gp; } else { /* Child is right of parent. */ p->right = *lp; *lp = p; gp->left = *rp; *rp = gp; } *gparentp = root; } else { *gparentp = *parentp; /* Parent becomes the top of the tree, grandparent and child are its successors. */ p->red = 0; gp->red = 1; if (p_r < 0) { /* Left edges. */ gp->left = p->right; p->right = gp; } else { /* Right edges. */ gp->right = p->left; p->left = gp; } } } } } /* Find or insert datum into search tree. KEY is the key to be located, ROOTP is the address of tree root, COMPAR the ordering function. */ void * __tsearch (const void *key, void **vrootp, __compar_fn_t compar) { node q; node *parentp = NULL, *gparentp = NULL; node *rootp = (node *) vrootp; node *nextp; int r = 0, p_r = 0, gp_r = 0; /* No they might not, Mr Compiler. */ if (rootp == NULL) return NULL; /* This saves some additional tests below. */ if (*rootp != NULL) (*rootp)->red = 0; CHECK_TREE (*rootp); nextp = rootp; while (*nextp != NULL) { node root = *rootp; r = (*compar) (key, root->key); if (r == 0) return root; maybe_split_for_insert (rootp, parentp, gparentp, p_r, gp_r, 0); /* If that did any rotations, parentp and gparentp are now garbage. That doesn't matter, because the values they contain are never used again in that case. */ nextp = r < 0 ? &root->left : &root->right; if (*nextp == NULL) break; gparentp = parentp; parentp = rootp; rootp = nextp; gp_r = p_r; p_r = r; } q = (struct node_t *) malloc (sizeof (struct node_t)); if (q != NULL) { *nextp = q; /* link new node to old */ q->key = key; /* initialize new node */ q->red = 1; q->left = q->right = NULL; if (nextp != rootp) /* There may be two red edges in a row now, which we must avoid by rotating the tree. */ maybe_split_for_insert (nextp, rootp, parentp, r, p_r, 1); } return q; } #ifdef weak_alias weak_alias (__tsearch, tsearch) #endif /* Find datum in search tree. KEY is the key to be located, ROOTP is the address of tree root, COMPAR the ordering function. */ void * __tfind (key, vrootp, compar) const void *key; void *const *vrootp; __compar_fn_t compar; { node *rootp = (node *) vrootp; if (rootp == NULL) return NULL; CHECK_TREE (*rootp); while (*rootp != NULL) { node root = *rootp; int r; r = (*compar) (key, root->key); if (r == 0) return root; rootp = r < 0 ? &root->left : &root->right; } return NULL; } #ifdef weak_alias weak_alias (__tfind, tfind) #endif /* Delete node with given key. KEY is the key to be deleted, ROOTP is the address of the root of tree, COMPAR the comparison function. */ void * __tdelete (const void *key, void **vrootp, __compar_fn_t compar) { node p, q, r, retval; int cmp; node *rootp = (node *) vrootp; node root, unchained; /* Stack of nodes so we remember the parents without recursion. It's _very_ unlikely that there are paths longer than 40 nodes. The tree would need to have around 250.000 nodes. */ int stacksize = 100; int sp = 0; node *nodestack[100]; if (rootp == NULL) return NULL; p = *rootp; if (p == NULL) return NULL; CHECK_TREE (p); while ((cmp = (*compar) (key, (*rootp)->key)) != 0) { if (sp == stacksize) abort (); nodestack[sp++] = rootp; p = *rootp; rootp = ((cmp < 0) ? &(*rootp)->left : &(*rootp)->right); if (*rootp == NULL) return NULL; } /* This is bogus if the node to be deleted is the root... this routine really should return an integer with 0 for success, -1 for failure and errno = ESRCH or something. */ retval = p; /* We don't unchain the node we want to delete. Instead, we overwrite it with its successor and unchain the successor. If there is no successor, we really unchain the node to be deleted. */ root = *rootp; r = root->right; q = root->left; if (q == NULL || r == NULL) unchained = root; else { node *parent = rootp, *up = &root->right; for (;;) { if (sp == stacksize) abort (); nodestack[sp++] = parent; parent = up; if ((*up)->left == NULL) break; up = &(*up)->left; } unchained = *up; } /* We know that either the left or right successor of UNCHAINED is NULL. R becomes the other one, it is chained into the parent of UNCHAINED. */ r = unchained->left; if (r == NULL) r = unchained->right; if (sp == 0) *rootp = r; else { q = *nodestack[sp-1]; if (unchained == q->right) q->right = r; else q->left = r; } if (unchained != root) root->key = unchained->key; if (!unchained->red) { /* Now we lost a black edge, which means that the number of black edges on every path is no longer constant. We must balance the tree. */ /* NODESTACK now contains all parents of R. R is likely to be NULL in the first iteration. */ /* NULL nodes are considered black throughout - this is necessary for correctness. */ while (sp > 0 && (r == NULL || !r->red)) { node *pp = nodestack[sp - 1]; p = *pp; /* Two symmetric cases. */ if (r == p->left) { /* Q is R's brother, P is R's parent. The subtree with root R has one black edge less than the subtree with root Q. */ q = p->right; if (q->red) { /* If Q is red, we know that P is black. We rotate P left so that Q becomes the top node in the tree, with P below it. P is colored red, Q is colored black. This action does not change the black edge count for any leaf in the tree, but we will be able to recognize one of the following situations, which all require that Q is black. */ q->red = 0; p->red = 1; /* Left rotate p. */ p->right = q->left; q->left = p; *pp = q; /* Make sure pp is right if the case below tries to use it. */ nodestack[sp++] = pp = &q->left; q = p->right; } /* We know that Q can't be NULL here. We also know that Q is black. */ if ((q->left == NULL || !q->left->red) && (q->right == NULL || !q->right->red)) { /* Q has two black successors. We can simply color Q red. The whole subtree with root P is now missing one black edge. Note that this action can temporarily make the tree invalid (if P is red). But we will exit the loop in that case and set P black, which both makes the tree valid and also makes the black edge count come out right. If P is black, we are at least one step closer to the root and we'll try again the next iteration. */ q->red = 1; r = p; } else { /* Q is black, one of Q's successors is red. We can repair the tree with one operation and will exit the loop afterwards. */ if (q->right == NULL || !q->right->red) { /* The left one is red. We perform the same action as in maybe_split_for_insert where two red edges are adjacent but point in different directions: Q's left successor (let's call it Q2) becomes the top of the subtree we are looking at, its parent (Q) and grandparent (P) become its successors. The former successors of Q2 are placed below P and Q. P becomes black, and Q2 gets the color that P had. This changes the black edge count only for node R and its successors. */ node q2 = q->left; q2->red = p->red; p->right = q2->left; q->left = q2->right; q2->right = q; q2->left = p; *pp = q2; p->red = 0; } else { /* It's the right one. Rotate P left. P becomes black, and Q gets the color that P had. Q's right successor also becomes black. This changes the black edge count only for node R and its successors. */ q->red = p->red; p->red = 0; q->right->red = 0; /* left rotate p */ p->right = q->left; q->left = p; *pp = q; } /* We're done. */ sp = 1; r = NULL; } } else { /* Comments: see above. */ q = p->left; if (q->red) { q->red = 0; p->red = 1; p->left = q->right; q->right = p; *pp = q; nodestack[sp++] = pp = &q->right; q = p->left; } if ((q->right == NULL || !q->right->red) && (q->left == NULL || !q->left->red)) { q->red = 1; r = p; } else { if (q->left == NULL || !q->left->red) { node q2 = q->right; q2->red = p->red; p->left = q2->right; q->right = q2->left; q2->left = q; q2->right = p; *pp = q2; p->red = 0; } else { q->red = p->red; p->red = 0; q->left->red = 0; p->left = q->right; q->right = p; *pp = q; } sp = 1; r = NULL; } } --sp; } if (r != NULL) r->red = 0; } free (unchained); return retval; } #ifdef weak_alias weak_alias (__tdelete, tdelete) #endif /* Walk the nodes of a tree. ROOT is the root of the tree to be walked, ACTION the function to be called at each node. LEVEL is the level of ROOT in the whole tree. */ static void internal_function trecurse (const void *vroot, __action_fn_t action, int level) { const_node root = (const_node) vroot; if (root->left == NULL && root->right == NULL) (*action) (root, leaf, level); else { (*action) (root, preorder, level); if (root->left != NULL) trecurse (root->left, action, level + 1); (*action) (root, postorder, level); if (root->right != NULL) trecurse (root->right, action, level + 1); (*action) (root, endorder, level); } } /* Walk the nodes of a tree. ROOT is the root of the tree to be walked, ACTION the function to be called at each node. */ void __twalk (const void *vroot, __action_fn_t action) { const_node root = (const_node) vroot; CHECK_TREE (root); if (root != NULL && action != NULL) trecurse (root, action, 0); } #ifdef weak_alias weak_alias (__twalk, twalk) #endif #ifdef _LIBC /* The standardized functions miss an important functionality: the tree cannot be removed easily. We provide a function to do this. */ static void internal_function tdestroy_recurse (node root, __free_fn_t freefct) { if (root->left != NULL) tdestroy_recurse (root->left, freefct); if (root->right != NULL) tdestroy_recurse (root->right, freefct); (*freefct) ((void *) root->key); /* Free the node itself. */ free (root); } void __tdestroy (void *vroot, __free_fn_t freefct) { node root = (node) vroot; CHECK_TREE (root); if (root != NULL) tdestroy_recurse (root, freefct); } weak_alias (__tdestroy, tdestroy) #endif /* _LIBC */ libnih-1.0.3/intl/lock.c0000644000175000017500000005413011461165267011757 00000000000000/* Locking in multithreaded situations. Copyright (C) 2005-2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Bruno Haible , 2005. Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h, gthr-win32.h. */ #include #include "lock.h" /* ========================================================================= */ #if USE_POSIX_THREADS /* Use the POSIX threads library. */ # if PTHREAD_IN_USE_DETECTION_HARD /* The function to be executed by a dummy thread. */ static void * dummy_thread_func (void *arg) { return arg; } int glthread_in_use (void) { static int tested; static int result; /* 1: linked with -lpthread, 0: only with libc */ if (!tested) { pthread_t thread; if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0) /* Thread creation failed. */ result = 0; else { /* Thread creation works. */ void *retval; if (pthread_join (thread, &retval) != 0) abort (); result = 1; } tested = 1; } return result; } # endif /* -------------------------- gl_lock_t datatype -------------------------- */ /* ------------------------- gl_rwlock_t datatype ------------------------- */ # if HAVE_PTHREAD_RWLOCK # if !defined PTHREAD_RWLOCK_INITIALIZER void glthread_rwlock_init (gl_rwlock_t *lock) { if (pthread_rwlock_init (&lock->rwlock, NULL) != 0) abort (); lock->initialized = 1; } void glthread_rwlock_rdlock (gl_rwlock_t *lock) { if (!lock->initialized) { if (pthread_mutex_lock (&lock->guard) != 0) abort (); if (!lock->initialized) glthread_rwlock_init (lock); if (pthread_mutex_unlock (&lock->guard) != 0) abort (); } if (pthread_rwlock_rdlock (&lock->rwlock) != 0) abort (); } void glthread_rwlock_wrlock (gl_rwlock_t *lock) { if (!lock->initialized) { if (pthread_mutex_lock (&lock->guard) != 0) abort (); if (!lock->initialized) glthread_rwlock_init (lock); if (pthread_mutex_unlock (&lock->guard) != 0) abort (); } if (pthread_rwlock_wrlock (&lock->rwlock) != 0) abort (); } void glthread_rwlock_unlock (gl_rwlock_t *lock) { if (!lock->initialized) abort (); if (pthread_rwlock_unlock (&lock->rwlock) != 0) abort (); } void glthread_rwlock_destroy (gl_rwlock_t *lock) { if (!lock->initialized) abort (); if (pthread_rwlock_destroy (&lock->rwlock) != 0) abort (); lock->initialized = 0; } # endif # else void glthread_rwlock_init (gl_rwlock_t *lock) { if (pthread_mutex_init (&lock->lock, NULL) != 0) abort (); if (pthread_cond_init (&lock->waiting_readers, NULL) != 0) abort (); if (pthread_cond_init (&lock->waiting_writers, NULL) != 0) abort (); lock->waiting_writers_count = 0; lock->runcount = 0; } void glthread_rwlock_rdlock (gl_rwlock_t *lock) { if (pthread_mutex_lock (&lock->lock) != 0) abort (); /* Test whether only readers are currently running, and whether the runcount field will not overflow. */ /* POSIX says: "It is implementation-defined whether the calling thread acquires the lock when a writer does not hold the lock and there are writers blocked on the lock." Let's say, no: give the writers a higher priority. */ while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) { /* This thread has to wait for a while. Enqueue it among the waiting_readers. */ if (pthread_cond_wait (&lock->waiting_readers, &lock->lock) != 0) abort (); } lock->runcount++; if (pthread_mutex_unlock (&lock->lock) != 0) abort (); } void glthread_rwlock_wrlock (gl_rwlock_t *lock) { if (pthread_mutex_lock (&lock->lock) != 0) abort (); /* Test whether no readers or writers are currently running. */ while (!(lock->runcount == 0)) { /* This thread has to wait for a while. Enqueue it among the waiting_writers. */ lock->waiting_writers_count++; if (pthread_cond_wait (&lock->waiting_writers, &lock->lock) != 0) abort (); lock->waiting_writers_count--; } lock->runcount--; /* runcount becomes -1 */ if (pthread_mutex_unlock (&lock->lock) != 0) abort (); } void glthread_rwlock_unlock (gl_rwlock_t *lock) { if (pthread_mutex_lock (&lock->lock) != 0) abort (); if (lock->runcount < 0) { /* Drop a writer lock. */ if (!(lock->runcount == -1)) abort (); lock->runcount = 0; } else { /* Drop a reader lock. */ if (!(lock->runcount > 0)) abort (); lock->runcount--; } if (lock->runcount == 0) { /* POSIX recommends that "write locks shall take precedence over read locks", to avoid "writer starvation". */ if (lock->waiting_writers_count > 0) { /* Wake up one of the waiting writers. */ if (pthread_cond_signal (&lock->waiting_writers) != 0) abort (); } else { /* Wake up all waiting readers. */ if (pthread_cond_broadcast (&lock->waiting_readers) != 0) abort (); } } if (pthread_mutex_unlock (&lock->lock) != 0) abort (); } void glthread_rwlock_destroy (gl_rwlock_t *lock) { if (pthread_mutex_destroy (&lock->lock) != 0) abort (); if (pthread_cond_destroy (&lock->waiting_readers) != 0) abort (); if (pthread_cond_destroy (&lock->waiting_writers) != 0) abort (); } # endif /* --------------------- gl_recursive_lock_t datatype --------------------- */ # if HAVE_PTHREAD_MUTEX_RECURSIVE # if !(defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) void glthread_recursive_lock_init (gl_recursive_lock_t *lock) { pthread_mutexattr_t attributes; if (pthread_mutexattr_init (&attributes) != 0) abort (); if (pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE) != 0) abort (); if (pthread_mutex_init (&lock->recmutex, &attributes) != 0) abort (); if (pthread_mutexattr_destroy (&attributes) != 0) abort (); lock->initialized = 1; } void glthread_recursive_lock_lock (gl_recursive_lock_t *lock) { if (!lock->initialized) { if (pthread_mutex_lock (&lock->guard) != 0) abort (); if (!lock->initialized) glthread_recursive_lock_init (lock); if (pthread_mutex_unlock (&lock->guard) != 0) abort (); } if (pthread_mutex_lock (&lock->recmutex) != 0) abort (); } void glthread_recursive_lock_unlock (gl_recursive_lock_t *lock) { if (!lock->initialized) abort (); if (pthread_mutex_unlock (&lock->recmutex) != 0) abort (); } void glthread_recursive_lock_destroy (gl_recursive_lock_t *lock) { if (!lock->initialized) abort (); if (pthread_mutex_destroy (&lock->recmutex) != 0) abort (); lock->initialized = 0; } # endif # else void glthread_recursive_lock_init (gl_recursive_lock_t *lock) { if (pthread_mutex_init (&lock->mutex, NULL) != 0) abort (); lock->owner = (pthread_t) 0; lock->depth = 0; } void glthread_recursive_lock_lock (gl_recursive_lock_t *lock) { pthread_t self = pthread_self (); if (lock->owner != self) { if (pthread_mutex_lock (&lock->mutex) != 0) abort (); lock->owner = self; } if (++(lock->depth) == 0) /* wraparound? */ abort (); } void glthread_recursive_lock_unlock (gl_recursive_lock_t *lock) { if (lock->owner != pthread_self ()) abort (); if (lock->depth == 0) abort (); if (--(lock->depth) == 0) { lock->owner = (pthread_t) 0; if (pthread_mutex_unlock (&lock->mutex) != 0) abort (); } } void glthread_recursive_lock_destroy (gl_recursive_lock_t *lock) { if (lock->owner != (pthread_t) 0) abort (); if (pthread_mutex_destroy (&lock->mutex) != 0) abort (); } # endif /* -------------------------- gl_once_t datatype -------------------------- */ static const pthread_once_t fresh_once = PTHREAD_ONCE_INIT; int glthread_once_singlethreaded (pthread_once_t *once_control) { /* We don't know whether pthread_once_t is an integer type, a floating-point type, a pointer type, or a structure type. */ char *firstbyte = (char *)once_control; if (*firstbyte == *(const char *)&fresh_once) { /* First time use of once_control. Invert the first byte. */ *firstbyte = ~ *(const char *)&fresh_once; return 1; } else return 0; } #endif /* ========================================================================= */ #if USE_PTH_THREADS /* Use the GNU Pth threads library. */ /* -------------------------- gl_lock_t datatype -------------------------- */ /* ------------------------- gl_rwlock_t datatype ------------------------- */ /* --------------------- gl_recursive_lock_t datatype --------------------- */ /* -------------------------- gl_once_t datatype -------------------------- */ void glthread_once_call (void *arg) { void (**gl_once_temp_addr) (void) = (void (**) (void)) arg; void (*initfunction) (void) = *gl_once_temp_addr; initfunction (); } int glthread_once_singlethreaded (pth_once_t *once_control) { /* We know that pth_once_t is an integer type. */ if (*once_control == PTH_ONCE_INIT) { /* First time use of once_control. Invert the marker. */ *once_control = ~ PTH_ONCE_INIT; return 1; } else return 0; } #endif /* ========================================================================= */ #if USE_SOLARIS_THREADS /* Use the old Solaris threads library. */ /* -------------------------- gl_lock_t datatype -------------------------- */ /* ------------------------- gl_rwlock_t datatype ------------------------- */ /* --------------------- gl_recursive_lock_t datatype --------------------- */ void glthread_recursive_lock_init (gl_recursive_lock_t *lock) { if (mutex_init (&lock->mutex, USYNC_THREAD, NULL) != 0) abort (); lock->owner = (thread_t) 0; lock->depth = 0; } void glthread_recursive_lock_lock (gl_recursive_lock_t *lock) { thread_t self = thr_self (); if (lock->owner != self) { if (mutex_lock (&lock->mutex) != 0) abort (); lock->owner = self; } if (++(lock->depth) == 0) /* wraparound? */ abort (); } void glthread_recursive_lock_unlock (gl_recursive_lock_t *lock) { if (lock->owner != thr_self ()) abort (); if (lock->depth == 0) abort (); if (--(lock->depth) == 0) { lock->owner = (thread_t) 0; if (mutex_unlock (&lock->mutex) != 0) abort (); } } void glthread_recursive_lock_destroy (gl_recursive_lock_t *lock) { if (lock->owner != (thread_t) 0) abort (); if (mutex_destroy (&lock->mutex) != 0) abort (); } /* -------------------------- gl_once_t datatype -------------------------- */ void glthread_once (gl_once_t *once_control, void (*initfunction) (void)) { if (!once_control->inited) { /* Use the mutex to guarantee that if another thread is already calling the initfunction, this thread waits until it's finished. */ if (mutex_lock (&once_control->mutex) != 0) abort (); if (!once_control->inited) { once_control->inited = 1; initfunction (); } if (mutex_unlock (&once_control->mutex) != 0) abort (); } } int glthread_once_singlethreaded (gl_once_t *once_control) { /* We know that gl_once_t contains an integer type. */ if (!once_control->inited) { /* First time use of once_control. Invert the marker. */ once_control->inited = ~ 0; return 1; } else return 0; } #endif /* ========================================================================= */ #if USE_WIN32_THREADS /* -------------------------- gl_lock_t datatype -------------------------- */ void glthread_lock_init (gl_lock_t *lock) { InitializeCriticalSection (&lock->lock); lock->guard.done = 1; } void glthread_lock_lock (gl_lock_t *lock) { if (!lock->guard.done) { if (InterlockedIncrement (&lock->guard.started) == 0) /* This thread is the first one to need this lock. Initialize it. */ glthread_lock_init (lock); else /* Yield the CPU while waiting for another thread to finish initializing this lock. */ while (!lock->guard.done) Sleep (0); } EnterCriticalSection (&lock->lock); } void glthread_lock_unlock (gl_lock_t *lock) { if (!lock->guard.done) abort (); LeaveCriticalSection (&lock->lock); } void glthread_lock_destroy (gl_lock_t *lock) { if (!lock->guard.done) abort (); DeleteCriticalSection (&lock->lock); lock->guard.done = 0; } /* ------------------------- gl_rwlock_t datatype ------------------------- */ static inline void gl_waitqueue_init (gl_waitqueue_t *wq) { wq->array = NULL; wq->count = 0; wq->alloc = 0; wq->offset = 0; } /* Enqueues the current thread, represented by an event, in a wait queue. Returns INVALID_HANDLE_VALUE if an allocation failure occurs. */ static HANDLE gl_waitqueue_add (gl_waitqueue_t *wq) { HANDLE event; unsigned int index; if (wq->count == wq->alloc) { unsigned int new_alloc = 2 * wq->alloc + 1; HANDLE *new_array = (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE)); if (new_array == NULL) /* No more memory. */ return INVALID_HANDLE_VALUE; /* Now is a good opportunity to rotate the array so that its contents starts at offset 0. */ if (wq->offset > 0) { unsigned int old_count = wq->count; unsigned int old_alloc = wq->alloc; unsigned int old_offset = wq->offset; unsigned int i; if (old_offset + old_count > old_alloc) { unsigned int limit = old_offset + old_count - old_alloc; for (i = 0; i < limit; i++) new_array[old_alloc + i] = new_array[i]; } for (i = 0; i < old_count; i++) new_array[i] = new_array[old_offset + i]; wq->offset = 0; } wq->array = new_array; wq->alloc = new_alloc; } event = CreateEvent (NULL, TRUE, FALSE, NULL); if (event == INVALID_HANDLE_VALUE) /* No way to allocate an event. */ return INVALID_HANDLE_VALUE; index = wq->offset + wq->count; if (index >= wq->alloc) index -= wq->alloc; wq->array[index] = event; wq->count++; return event; } /* Notifies the first thread from a wait queue and dequeues it. */ static inline void gl_waitqueue_notify_first (gl_waitqueue_t *wq) { SetEvent (wq->array[wq->offset + 0]); wq->offset++; wq->count--; if (wq->count == 0 || wq->offset == wq->alloc) wq->offset = 0; } /* Notifies all threads from a wait queue and dequeues them all. */ static inline void gl_waitqueue_notify_all (gl_waitqueue_t *wq) { unsigned int i; for (i = 0; i < wq->count; i++) { unsigned int index = wq->offset + i; if (index >= wq->alloc) index -= wq->alloc; SetEvent (wq->array[index]); } wq->count = 0; wq->offset = 0; } void glthread_rwlock_init (gl_rwlock_t *lock) { InitializeCriticalSection (&lock->lock); gl_waitqueue_init (&lock->waiting_readers); gl_waitqueue_init (&lock->waiting_writers); lock->runcount = 0; lock->guard.done = 1; } void glthread_rwlock_rdlock (gl_rwlock_t *lock) { if (!lock->guard.done) { if (InterlockedIncrement (&lock->guard.started) == 0) /* This thread is the first one to need this lock. Initialize it. */ glthread_rwlock_init (lock); else /* Yield the CPU while waiting for another thread to finish initializing this lock. */ while (!lock->guard.done) Sleep (0); } EnterCriticalSection (&lock->lock); /* Test whether only readers are currently running, and whether the runcount field will not overflow. */ if (!(lock->runcount + 1 > 0)) { /* This thread has to wait for a while. Enqueue it among the waiting_readers. */ HANDLE event = gl_waitqueue_add (&lock->waiting_readers); if (event != INVALID_HANDLE_VALUE) { DWORD result; LeaveCriticalSection (&lock->lock); /* Wait until another thread signals this event. */ result = WaitForSingleObject (event, INFINITE); if (result == WAIT_FAILED || result == WAIT_TIMEOUT) abort (); CloseHandle (event); /* The thread which signalled the event already did the bookkeeping: removed us from the waiting_readers, incremented lock->runcount. */ if (!(lock->runcount > 0)) abort (); return; } else { /* Allocation failure. Weird. */ do { LeaveCriticalSection (&lock->lock); Sleep (1); EnterCriticalSection (&lock->lock); } while (!(lock->runcount + 1 > 0)); } } lock->runcount++; LeaveCriticalSection (&lock->lock); } void glthread_rwlock_wrlock (gl_rwlock_t *lock) { if (!lock->guard.done) { if (InterlockedIncrement (&lock->guard.started) == 0) /* This thread is the first one to need this lock. Initialize it. */ glthread_rwlock_init (lock); else /* Yield the CPU while waiting for another thread to finish initializing this lock. */ while (!lock->guard.done) Sleep (0); } EnterCriticalSection (&lock->lock); /* Test whether no readers or writers are currently running. */ if (!(lock->runcount == 0)) { /* This thread has to wait for a while. Enqueue it among the waiting_writers. */ HANDLE event = gl_waitqueue_add (&lock->waiting_writers); if (event != INVALID_HANDLE_VALUE) { DWORD result; LeaveCriticalSection (&lock->lock); /* Wait until another thread signals this event. */ result = WaitForSingleObject (event, INFINITE); if (result == WAIT_FAILED || result == WAIT_TIMEOUT) abort (); CloseHandle (event); /* The thread which signalled the event already did the bookkeeping: removed us from the waiting_writers, set lock->runcount = -1. */ if (!(lock->runcount == -1)) abort (); return; } else { /* Allocation failure. Weird. */ do { LeaveCriticalSection (&lock->lock); Sleep (1); EnterCriticalSection (&lock->lock); } while (!(lock->runcount == 0)); } } lock->runcount--; /* runcount becomes -1 */ LeaveCriticalSection (&lock->lock); } void glthread_rwlock_unlock (gl_rwlock_t *lock) { if (!lock->guard.done) abort (); EnterCriticalSection (&lock->lock); if (lock->runcount < 0) { /* Drop a writer lock. */ if (!(lock->runcount == -1)) abort (); lock->runcount = 0; } else { /* Drop a reader lock. */ if (!(lock->runcount > 0)) abort (); lock->runcount--; } if (lock->runcount == 0) { /* POSIX recommends that "write locks shall take precedence over read locks", to avoid "writer starvation". */ if (lock->waiting_writers.count > 0) { /* Wake up one of the waiting writers. */ lock->runcount--; gl_waitqueue_notify_first (&lock->waiting_writers); } else { /* Wake up all waiting readers. */ lock->runcount += lock->waiting_readers.count; gl_waitqueue_notify_all (&lock->waiting_readers); } } LeaveCriticalSection (&lock->lock); } void glthread_rwlock_destroy (gl_rwlock_t *lock) { if (!lock->guard.done) abort (); if (lock->runcount != 0) abort (); DeleteCriticalSection (&lock->lock); if (lock->waiting_readers.array != NULL) free (lock->waiting_readers.array); if (lock->waiting_writers.array != NULL) free (lock->waiting_writers.array); lock->guard.done = 0; } /* --------------------- gl_recursive_lock_t datatype --------------------- */ void glthread_recursive_lock_init (gl_recursive_lock_t *lock) { lock->owner = 0; lock->depth = 0; InitializeCriticalSection (&lock->lock); lock->guard.done = 1; } void glthread_recursive_lock_lock (gl_recursive_lock_t *lock) { if (!lock->guard.done) { if (InterlockedIncrement (&lock->guard.started) == 0) /* This thread is the first one to need this lock. Initialize it. */ glthread_recursive_lock_init (lock); else /* Yield the CPU while waiting for another thread to finish initializing this lock. */ while (!lock->guard.done) Sleep (0); } { DWORD self = GetCurrentThreadId (); if (lock->owner != self) { EnterCriticalSection (&lock->lock); lock->owner = self; } if (++(lock->depth) == 0) /* wraparound? */ abort (); } } void glthread_recursive_lock_unlock (gl_recursive_lock_t *lock) { if (lock->owner != GetCurrentThreadId ()) abort (); if (lock->depth == 0) abort (); if (--(lock->depth) == 0) { lock->owner = 0; LeaveCriticalSection (&lock->lock); } } void glthread_recursive_lock_destroy (gl_recursive_lock_t *lock) { if (lock->owner != 0) abort (); DeleteCriticalSection (&lock->lock); lock->guard.done = 0; } /* -------------------------- gl_once_t datatype -------------------------- */ void glthread_once (gl_once_t *once_control, void (*initfunction) (void)) { if (once_control->inited <= 0) { if (InterlockedIncrement (&once_control->started) == 0) { /* This thread is the first one to come to this once_control. */ InitializeCriticalSection (&once_control->lock); EnterCriticalSection (&once_control->lock); once_control->inited = 0; initfunction (); once_control->inited = 1; LeaveCriticalSection (&once_control->lock); } else { /* Undo last operation. */ InterlockedDecrement (&once_control->started); /* Some other thread has already started the initialization. Yield the CPU while waiting for the other thread to finish initializing and taking the lock. */ while (once_control->inited < 0) Sleep (0); if (once_control->inited <= 0) { /* Take the lock. This blocks until the other thread has finished calling the initfunction. */ EnterCriticalSection (&once_control->lock); LeaveCriticalSection (&once_control->lock); if (!(once_control->inited > 0)) abort (); } } } } #endif /* ========================================================================= */ libnih-1.0.3/intl/os2compat.h0000644000175000017500000000302611461165270012733 00000000000000/* OS/2 compatibility defines. This file is intended to be included from config.h Copyright (C) 2001-2002 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* When included from os2compat.h we need all the original definitions */ #ifndef OS2_AWARE #undef LIBDIR #define LIBDIR _nlos2_libdir extern char *_nlos2_libdir; #undef LOCALEDIR #define LOCALEDIR _nlos2_localedir extern char *_nlos2_localedir; #undef LOCALE_ALIAS_PATH #define LOCALE_ALIAS_PATH _nlos2_localealiaspath extern char *_nlos2_localealiaspath; #endif #undef HAVE_STRCASECMP #define HAVE_STRCASECMP 1 #define strcasecmp stricmp #define strncasecmp strnicmp /* We have our own getenv() which works even if library is compiled as DLL */ #define getenv _nl_getenv /* Older versions of gettext used -1 as the value of LC_MESSAGES */ #define LC_MESSAGES_COMPAT (-1) libnih-1.0.3/intl/l10nflist.c0000644000175000017500000002557211461165267012653 00000000000000/* Copyright (C) 1995-1999, 2000-2006 Free Software Foundation, Inc. Contributed by Ulrich Drepper , 1995. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Tell glibc's to provide a prototype for stpcpy(). This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #ifdef HAVE_CONFIG_H # include #endif #include #if defined _LIBC || defined HAVE_ARGZ_H # include #endif #include #include #include #include "loadinfo.h" /* On some strange systems still no definition of NULL is found. Sigh! */ #ifndef NULL # if defined __STDC__ && __STDC__ # define NULL ((void *) 0) # else # define NULL 0 # endif #endif /* @@ end of prolog @@ */ #ifdef _LIBC /* Rename the non ANSI C functions. This is required by the standard because some ANSI C functions will require linking with this object file and the name space must not be polluted. */ # ifndef stpcpy # define stpcpy(dest, src) __stpcpy(dest, src) # endif #else # ifndef HAVE_STPCPY static char *stpcpy (char *dest, const char *src); # endif #endif /* Pathname support. ISSLASH(C) tests whether C is a directory separator character. IS_ABSOLUTE_PATH(P) tests whether P is an absolute path. If it is not, it may be concatenated to a directory pathname. */ #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ /* Win32, Cygwin, OS/2, DOS */ # define ISSLASH(C) ((C) == '/' || (C) == '\\') # define HAS_DEVICE(P) \ ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \ && (P)[1] == ':') # define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P)) #else /* Unix */ # define ISSLASH(C) ((C) == '/') # define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0]) #endif /* Define function which are usually not available. */ #ifdef _LIBC # define __argz_count(argz, len) INTUSE(__argz_count) (argz, len) #elif defined HAVE_ARGZ_COUNT # undef __argz_count # define __argz_count argz_count #else /* Returns the number of strings in ARGZ. */ static size_t argz_count__ (const char *argz, size_t len) { size_t count = 0; while (len > 0) { size_t part_len = strlen (argz); argz += part_len + 1; len -= part_len + 1; count++; } return count; } # undef __argz_count # define __argz_count(argz, len) argz_count__ (argz, len) #endif /* !_LIBC && !HAVE_ARGZ_COUNT */ #ifdef _LIBC # define __argz_stringify(argz, len, sep) \ INTUSE(__argz_stringify) (argz, len, sep) #elif defined HAVE_ARGZ_STRINGIFY # undef __argz_stringify # define __argz_stringify argz_stringify #else /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's except the last into the character SEP. */ static void argz_stringify__ (char *argz, size_t len, int sep) { while (len > 0) { size_t part_len = strlen (argz); argz += part_len; len -= part_len + 1; if (len > 0) *argz++ = sep; } } # undef __argz_stringify # define __argz_stringify(argz, len, sep) argz_stringify__ (argz, len, sep) #endif /* !_LIBC && !HAVE_ARGZ_STRINGIFY */ #ifdef _LIBC #elif defined HAVE_ARGZ_NEXT # undef __argz_next # define __argz_next argz_next #else static char * argz_next__ (char *argz, size_t argz_len, const char *entry) { if (entry) { if (entry < argz + argz_len) entry = strchr (entry, '\0') + 1; return entry >= argz + argz_len ? NULL : (char *) entry; } else if (argz_len > 0) return argz; else return 0; } # undef __argz_next # define __argz_next(argz, len, entry) argz_next__ (argz, len, entry) #endif /* !_LIBC && !HAVE_ARGZ_NEXT */ /* Return number of bits set in X. */ static inline int pop (int x) { /* We assume that no more than 16 bits are used. */ x = ((x & ~0x5555) >> 1) + (x & 0x5555); x = ((x & ~0x3333) >> 2) + (x & 0x3333); x = ((x >> 4) + x) & 0x0f0f; x = ((x >> 8) + x) & 0xff; return x; } struct loaded_l10nfile * _nl_make_l10nflist (struct loaded_l10nfile **l10nfile_list, const char *dirlist, size_t dirlist_len, int mask, const char *language, const char *territory, const char *codeset, const char *normalized_codeset, const char *modifier, const char *filename, int do_allocate) { char *abs_filename; struct loaded_l10nfile **lastp; struct loaded_l10nfile *retval; char *cp; size_t dirlist_count; size_t entries; int cnt; /* If LANGUAGE contains an absolute directory specification, we ignore DIRLIST. */ if (IS_ABSOLUTE_PATH (language)) dirlist_len = 0; /* Allocate room for the full file name. */ abs_filename = (char *) malloc (dirlist_len + strlen (language) + ((mask & XPG_TERRITORY) != 0 ? strlen (territory) + 1 : 0) + ((mask & XPG_CODESET) != 0 ? strlen (codeset) + 1 : 0) + ((mask & XPG_NORM_CODESET) != 0 ? strlen (normalized_codeset) + 1 : 0) + ((mask & XPG_MODIFIER) != 0 ? strlen (modifier) + 1 : 0) + 1 + strlen (filename) + 1); if (abs_filename == NULL) return NULL; /* Construct file name. */ cp = abs_filename; if (dirlist_len > 0) { memcpy (cp, dirlist, dirlist_len); __argz_stringify (cp, dirlist_len, PATH_SEPARATOR); cp += dirlist_len; cp[-1] = '/'; } cp = stpcpy (cp, language); if ((mask & XPG_TERRITORY) != 0) { *cp++ = '_'; cp = stpcpy (cp, territory); } if ((mask & XPG_CODESET) != 0) { *cp++ = '.'; cp = stpcpy (cp, codeset); } if ((mask & XPG_NORM_CODESET) != 0) { *cp++ = '.'; cp = stpcpy (cp, normalized_codeset); } if ((mask & XPG_MODIFIER) != 0) { *cp++ = '@'; cp = stpcpy (cp, modifier); } *cp++ = '/'; stpcpy (cp, filename); /* Look in list of already loaded domains whether it is already available. */ lastp = l10nfile_list; for (retval = *l10nfile_list; retval != NULL; retval = retval->next) if (retval->filename != NULL) { int compare = strcmp (retval->filename, abs_filename); if (compare == 0) /* We found it! */ break; if (compare < 0) { /* It's not in the list. */ retval = NULL; break; } lastp = &retval->next; } if (retval != NULL || do_allocate == 0) { free (abs_filename); return retval; } dirlist_count = (dirlist_len > 0 ? __argz_count (dirlist, dirlist_len) : 1); /* Allocate a new loaded_l10nfile. */ retval = (struct loaded_l10nfile *) malloc (sizeof (*retval) + (((dirlist_count << pop (mask)) + (dirlist_count > 1 ? 1 : 0)) * sizeof (struct loaded_l10nfile *))); if (retval == NULL) { free (abs_filename); return NULL; } retval->filename = abs_filename; /* We set retval->data to NULL here; it is filled in later. Setting retval->decided to 1 here means that retval does not correspond to a real file (dirlist_count > 1) or is not worth looking up (if an unnormalized codeset was specified). */ retval->decided = (dirlist_count > 1 || ((mask & XPG_CODESET) != 0 && (mask & XPG_NORM_CODESET) != 0)); retval->data = NULL; retval->next = *lastp; *lastp = retval; entries = 0; /* Recurse to fill the inheritance list of RETVAL. If the DIRLIST is a real list (i.e. DIRLIST_COUNT > 1), the RETVAL entry does not correspond to a real file; retval->filename contains colons. In this case we loop across all elements of DIRLIST and across all bit patterns dominated by MASK. If the DIRLIST is a single directory or entirely redundant (i.e. DIRLIST_COUNT == 1), we loop across all bit patterns dominated by MASK, excluding MASK itself. In either case, we loop down from MASK to 0. This has the effect that the extra bits in the locale name are dropped in this order: first the modifier, then the territory, then the codeset, then the normalized_codeset. */ for (cnt = dirlist_count > 1 ? mask : mask - 1; cnt >= 0; --cnt) if ((cnt & ~mask) == 0 && !((cnt & XPG_CODESET) != 0 && (cnt & XPG_NORM_CODESET) != 0)) { if (dirlist_count > 1) { /* Iterate over all elements of the DIRLIST. */ char *dir = NULL; while ((dir = __argz_next ((char *) dirlist, dirlist_len, dir)) != NULL) retval->successor[entries++] = _nl_make_l10nflist (l10nfile_list, dir, strlen (dir) + 1, cnt, language, territory, codeset, normalized_codeset, modifier, filename, 1); } else retval->successor[entries++] = _nl_make_l10nflist (l10nfile_list, dirlist, dirlist_len, cnt, language, territory, codeset, normalized_codeset, modifier, filename, 1); } retval->successor[entries] = NULL; return retval; } /* Normalize codeset name. There is no standard for the codeset names. Normalization allows the user to use any of the common names. The return value is dynamically allocated and has to be freed by the caller. */ const char * _nl_normalize_codeset (const char *codeset, size_t name_len) { int len = 0; int only_digit = 1; char *retval; char *wp; size_t cnt; for (cnt = 0; cnt < name_len; ++cnt) if (isalnum ((unsigned char) codeset[cnt])) { ++len; if (isalpha ((unsigned char) codeset[cnt])) only_digit = 0; } retval = (char *) malloc ((only_digit ? 3 : 0) + len + 1); if (retval != NULL) { if (only_digit) wp = stpcpy (retval, "iso"); else wp = retval; for (cnt = 0; cnt < name_len; ++cnt) if (isalpha ((unsigned char) codeset[cnt])) *wp++ = tolower ((unsigned char) codeset[cnt]); else if (isdigit ((unsigned char) codeset[cnt])) *wp++ = codeset[cnt]; *wp = '\0'; } return (const char *) retval; } /* @@ begin of epilog @@ */ /* We don't want libintl.a to depend on any other library. So we avoid the non-standard function stpcpy. In GNU C Library this function is available, though. Also allow the symbol HAVE_STPCPY to be defined. */ #if !_LIBC && !HAVE_STPCPY static char * stpcpy (char *dest, const char *src) { while ((*dest++ = *src++) != '\0') /* Do nothing. */ ; return dest - 1; } #endif libnih-1.0.3/intl/textdomain.c0000644000175000017500000000746611461165270013207 00000000000000/* Implementation of the textdomain(3) function. Copyright (C) 1995-1998, 2000-2003, 2005-2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include "gettextP.h" #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* Handle multi-threaded applications. */ #ifdef _LIBC # include # define gl_rwlock_define __libc_rwlock_define # define gl_rwlock_wrlock __libc_rwlock_wrlock # define gl_rwlock_unlock __libc_rwlock_unlock #else # include "lock.h" #endif /* @@ end of prolog @@ */ /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define TEXTDOMAIN __textdomain # ifndef strdup # define strdup(str) __strdup (str) # endif #else # define TEXTDOMAIN libintl_textdomain #endif /* Lock variable to protect the global data in the gettext implementation. */ gl_rwlock_define (extern, _nl_state_lock attribute_hidden) /* Set the current default message catalog to DOMAINNAME. If DOMAINNAME is null, return the current default. If DOMAINNAME is "", reset to the default of "messages". */ char * TEXTDOMAIN (const char *domainname) { char *new_domain; char *old_domain; /* A NULL pointer requests the current setting. */ if (domainname == NULL) return (char *) _nl_current_default_domain; gl_rwlock_wrlock (_nl_state_lock); old_domain = (char *) _nl_current_default_domain; /* If domain name is the null string set to default domain "messages". */ if (domainname[0] == '\0' || strcmp (domainname, _nl_default_default_domain) == 0) { _nl_current_default_domain = _nl_default_default_domain; new_domain = (char *) _nl_current_default_domain; } else if (strcmp (domainname, old_domain) == 0) /* This can happen and people will use it to signal that some environment variable changed. */ new_domain = old_domain; else { /* If the following malloc fails `_nl_current_default_domain' will be NULL. This value will be returned and so signals we are out of core. */ #if defined _LIBC || defined HAVE_STRDUP new_domain = strdup (domainname); #else size_t len = strlen (domainname) + 1; new_domain = (char *) malloc (len); if (new_domain != NULL) memcpy (new_domain, domainname, len); #endif if (new_domain != NULL) _nl_current_default_domain = new_domain; } /* We use this possibility to signal a change of the loaded catalogs since this is most likely the case and there is no other easy we to do it. Do it only when the call was successful. */ if (new_domain != NULL) { ++_nl_msg_cat_cntr; if (old_domain != new_domain && old_domain != _nl_default_default_domain) free (old_domain); } gl_rwlock_unlock (_nl_state_lock); return new_domain; } #ifdef _LIBC /* Alias for function name in GNU C Library. */ weak_alias (__textdomain, textdomain); #endif libnih-1.0.3/intl/printf.c0000644000175000017500000002217311461165270012325 00000000000000/* Formatted output to strings, using POSIX/XSI format strings with positions. Copyright (C) 2003, 2006-2007 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #ifdef __GNUC__ # define alloca __builtin_alloca # define HAVE_ALLOCA 1 #else # ifdef _MSC_VER # include # define alloca _alloca # else # if defined HAVE_ALLOCA_H || defined _LIBC # include # else # ifdef _AIX #pragma alloca # else # ifndef alloca char *alloca (); # endif # endif # endif # endif #endif #include #if !HAVE_POSIX_PRINTF #include #include #include #include /* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ #ifndef EOVERFLOW # define EOVERFLOW E2BIG #endif /* When building a DLL, we must export some functions. Note that because the functions are only defined for binary backward compatibility, we don't need to use __declspec(dllimport) in any case. */ #if defined _MSC_VER && BUILDING_DLL # define DLL_EXPORTED __declspec(dllexport) #else # define DLL_EXPORTED #endif #define STATIC static /* This needs to be consistent with libgnuintl.h.in. */ #if defined __NetBSD__ || defined __BEOS__ || defined __CYGWIN__ || defined __MINGW32__ /* Don't break __attribute__((format(printf,M,N))). This redefinition is only possible because the libc in NetBSD, Cygwin, mingw does not have a function __printf__. */ # define libintl_printf __printf__ #endif /* Define auxiliary functions declared in "printf-args.h". */ #include "printf-args.c" /* Define auxiliary functions declared in "printf-parse.h". */ #include "printf-parse.c" /* Define functions declared in "vasnprintf.h". */ #define vasnprintf libintl_vasnprintf #include "vasnprintf.c" #if 0 /* not needed */ #define asnprintf libintl_asnprintf #include "asnprintf.c" #endif DLL_EXPORTED int libintl_vfprintf (FILE *stream, const char *format, va_list args) { if (strchr (format, '$') == NULL) return vfprintf (stream, format, args); else { size_t length; char *result = libintl_vasnprintf (NULL, &length, format, args); int retval = -1; if (result != NULL) { size_t written = fwrite (result, 1, length, stream); free (result); if (written == length) { if (length > INT_MAX) errno = EOVERFLOW; else retval = length; } } return retval; } } DLL_EXPORTED int libintl_fprintf (FILE *stream, const char *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vfprintf (stream, format, args); va_end (args); return retval; } DLL_EXPORTED int libintl_vprintf (const char *format, va_list args) { return libintl_vfprintf (stdout, format, args); } DLL_EXPORTED int libintl_printf (const char *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vprintf (format, args); va_end (args); return retval; } DLL_EXPORTED int libintl_vsprintf (char *resultbuf, const char *format, va_list args) { if (strchr (format, '$') == NULL) return vsprintf (resultbuf, format, args); else { size_t length = (size_t) ~0 / (4 * sizeof (char)); char *result = libintl_vasnprintf (resultbuf, &length, format, args); if (result != resultbuf) { free (result); return -1; } if (length > INT_MAX) { errno = EOVERFLOW; return -1; } else return length; } } DLL_EXPORTED int libintl_sprintf (char *resultbuf, const char *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vsprintf (resultbuf, format, args); va_end (args); return retval; } #if HAVE_SNPRINTF # if HAVE_DECL__SNPRINTF /* Windows. */ # define system_vsnprintf _vsnprintf # else /* Unix. */ # define system_vsnprintf vsnprintf # endif DLL_EXPORTED int libintl_vsnprintf (char *resultbuf, size_t length, const char *format, va_list args) { if (strchr (format, '$') == NULL) return system_vsnprintf (resultbuf, length, format, args); else { size_t maxlength = length; char *result = libintl_vasnprintf (resultbuf, &length, format, args); if (result != resultbuf) { if (maxlength > 0) { size_t pruned_length = (length < maxlength ? length : maxlength - 1); memcpy (resultbuf, result, pruned_length); resultbuf[pruned_length] = '\0'; } free (result); } if (length > INT_MAX) { errno = EOVERFLOW; return -1; } else return length; } } DLL_EXPORTED int libintl_snprintf (char *resultbuf, size_t length, const char *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vsnprintf (resultbuf, length, format, args); va_end (args); return retval; } #endif #if HAVE_ASPRINTF DLL_EXPORTED int libintl_vasprintf (char **resultp, const char *format, va_list args) { size_t length; char *result = libintl_vasnprintf (NULL, &length, format, args); if (result == NULL) return -1; if (length > INT_MAX) { free (result); errno = EOVERFLOW; return -1; } *resultp = result; return length; } DLL_EXPORTED int libintl_asprintf (char **resultp, const char *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vasprintf (resultp, format, args); va_end (args); return retval; } #endif #if HAVE_FWPRINTF #include #define WIDE_CHAR_VERSION 1 #include "wprintf-parse.h" /* Define auxiliary functions declared in "wprintf-parse.h". */ #define CHAR_T wchar_t #define DIRECTIVE wchar_t_directive #define DIRECTIVES wchar_t_directives #define PRINTF_PARSE wprintf_parse #include "printf-parse.c" /* Define functions declared in "vasnprintf.h". */ #define vasnwprintf libintl_vasnwprintf #include "vasnprintf.c" #if 0 /* not needed */ #define asnwprintf libintl_asnwprintf #include "asnprintf.c" #endif # if HAVE_DECL__SNWPRINTF /* Windows. */ # define system_vswprintf _vsnwprintf # else /* Unix. */ # define system_vswprintf vswprintf # endif DLL_EXPORTED int libintl_vfwprintf (FILE *stream, const wchar_t *format, va_list args) { if (wcschr (format, '$') == NULL) return vfwprintf (stream, format, args); else { size_t length; wchar_t *result = libintl_vasnwprintf (NULL, &length, format, args); int retval = -1; if (result != NULL) { size_t i; for (i = 0; i < length; i++) if (fputwc (result[i], stream) == WEOF) break; free (result); if (i == length) { if (length > INT_MAX) errno = EOVERFLOW; else retval = length; } } return retval; } } DLL_EXPORTED int libintl_fwprintf (FILE *stream, const wchar_t *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vfwprintf (stream, format, args); va_end (args); return retval; } DLL_EXPORTED int libintl_vwprintf (const wchar_t *format, va_list args) { return libintl_vfwprintf (stdout, format, args); } DLL_EXPORTED int libintl_wprintf (const wchar_t *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vwprintf (format, args); va_end (args); return retval; } DLL_EXPORTED int libintl_vswprintf (wchar_t *resultbuf, size_t length, const wchar_t *format, va_list args) { if (wcschr (format, '$') == NULL) return system_vswprintf (resultbuf, length, format, args); else { size_t maxlength = length; wchar_t *result = libintl_vasnwprintf (resultbuf, &length, format, args); if (result != resultbuf) { if (maxlength > 0) { size_t pruned_length = (length < maxlength ? length : maxlength - 1); memcpy (resultbuf, result, pruned_length * sizeof (wchar_t)); resultbuf[pruned_length] = 0; } free (result); /* Unlike vsnprintf, which has to return the number of character that would have been produced if the resultbuf had been sufficiently large, the vswprintf function has to return a negative value if the resultbuf was not sufficiently large. */ if (length >= maxlength) return -1; } if (length > INT_MAX) { errno = EOVERFLOW; return -1; } else return length; } } DLL_EXPORTED int libintl_swprintf (wchar_t *resultbuf, size_t length, const wchar_t *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vswprintf (resultbuf, length, format, args); va_end (args); return retval; } #endif #endif libnih-1.0.3/intl/xsize.h0000644000175000017500000000672611461165270012200 00000000000000/* xsize.h -- Checked size_t computations. Copyright (C) 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _XSIZE_H #define _XSIZE_H /* Get size_t. */ #include /* Get SIZE_MAX. */ #include #if HAVE_STDINT_H # include #endif /* The size of memory objects is often computed through expressions of type size_t. Example: void* p = malloc (header_size + n * element_size). These computations can lead to overflow. When this happens, malloc() returns a piece of memory that is way too small, and the program then crashes while attempting to fill the memory. To avoid this, the functions and macros in this file check for overflow. The convention is that SIZE_MAX represents overflow. malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc implementation that uses mmap --, it's recommended to use size_overflow_p() or size_in_bounds_p() before invoking malloc(). The example thus becomes: size_t size = xsum (header_size, xtimes (n, element_size)); void *p = (size_in_bounds_p (size) ? malloc (size) : NULL); */ /* Convert an arbitrary value >= 0 to type size_t. */ #define xcast_size_t(N) \ ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX) /* Sum of two sizes, with overflow check. */ static inline size_t #if __GNUC__ >= 3 __attribute__ ((__pure__)) #endif xsum (size_t size1, size_t size2) { size_t sum = size1 + size2; return (sum >= size1 ? sum : SIZE_MAX); } /* Sum of three sizes, with overflow check. */ static inline size_t #if __GNUC__ >= 3 __attribute__ ((__pure__)) #endif xsum3 (size_t size1, size_t size2, size_t size3) { return xsum (xsum (size1, size2), size3); } /* Sum of four sizes, with overflow check. */ static inline size_t #if __GNUC__ >= 3 __attribute__ ((__pure__)) #endif xsum4 (size_t size1, size_t size2, size_t size3, size_t size4) { return xsum (xsum (xsum (size1, size2), size3), size4); } /* Maximum of two sizes, with overflow check. */ static inline size_t #if __GNUC__ >= 3 __attribute__ ((__pure__)) #endif xmax (size_t size1, size_t size2) { /* No explicit check is needed here, because for any n: max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX. */ return (size1 >= size2 ? size1 : size2); } /* Multiplication of a count with an element size, with overflow check. The count must be >= 0 and the element size must be > 0. This is a macro, not an inline function, so that it works correctly even when N is of a wider tupe and N > SIZE_MAX. */ #define xtimes(N, ELSIZE) \ ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX) /* Check for overflow. */ #define size_overflow_p(SIZE) \ ((SIZE) == SIZE_MAX) /* Check against overflow. */ #define size_in_bounds_p(SIZE) \ ((SIZE) != SIZE_MAX) #endif /* _XSIZE_H */ libnih-1.0.3/intl/config.charset0000755000175000017500000004702611461165267013514 00000000000000#! /bin/sh # Output a system dependent table of character encoding aliases. # # Copyright (C) 2000-2004, 2006 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. # # The table consists of lines of the form # ALIAS CANONICAL # # ALIAS is the (system dependent) result of "nl_langinfo (CODESET)". # ALIAS is compared in a case sensitive way. # # CANONICAL is the GNU canonical name for this character encoding. # It must be an encoding supported by libiconv. Support by GNU libc is # also desirable. CANONICAL is case insensitive. Usually an upper case # MIME charset name is preferred. # The current list of GNU canonical charset names is as follows. # # name MIME? used by which systems # ASCII, ANSI_X3.4-1968 glibc solaris freebsd netbsd darwin # ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd netbsd darwin # ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd netbsd darwin # ISO-8859-3 Y glibc solaris # ISO-8859-4 Y osf solaris freebsd netbsd darwin # ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd netbsd darwin # ISO-8859-6 Y glibc aix hpux solaris # ISO-8859-7 Y glibc aix hpux irix osf solaris netbsd darwin # ISO-8859-8 Y glibc aix hpux osf solaris # ISO-8859-9 Y glibc aix hpux irix osf solaris darwin # ISO-8859-13 glibc netbsd darwin # ISO-8859-14 glibc # ISO-8859-15 glibc aix osf solaris freebsd darwin # KOI8-R Y glibc solaris freebsd netbsd darwin # KOI8-U Y glibc freebsd netbsd darwin # KOI8-T glibc # CP437 dos # CP775 dos # CP850 aix osf dos # CP852 dos # CP855 dos # CP856 aix # CP857 dos # CP861 dos # CP862 dos # CP864 dos # CP865 dos # CP866 freebsd netbsd darwin dos # CP869 dos # CP874 woe32 dos # CP922 aix # CP932 aix woe32 dos # CP943 aix # CP949 osf woe32 dos # CP950 woe32 dos # CP1046 aix # CP1124 aix # CP1125 dos # CP1129 aix # CP1250 woe32 # CP1251 glibc solaris netbsd darwin woe32 # CP1252 aix woe32 # CP1253 woe32 # CP1254 woe32 # CP1255 glibc woe32 # CP1256 woe32 # CP1257 woe32 # GB2312 Y glibc aix hpux irix solaris freebsd netbsd darwin # EUC-JP Y glibc aix hpux irix osf solaris freebsd netbsd darwin # EUC-KR Y glibc aix hpux irix osf solaris freebsd netbsd darwin # EUC-TW glibc aix hpux irix osf solaris netbsd # BIG5 Y glibc aix hpux osf solaris freebsd netbsd darwin # BIG5-HKSCS glibc solaris # GBK glibc aix osf solaris woe32 dos # GB18030 glibc solaris netbsd # SHIFT_JIS Y hpux osf solaris freebsd netbsd darwin # JOHAB glibc solaris woe32 # TIS-620 glibc aix hpux osf solaris # VISCII Y glibc # TCVN5712-1 glibc # GEORGIAN-PS glibc # HP-ROMAN8 hpux # HP-ARABIC8 hpux # HP-GREEK8 hpux # HP-HEBREW8 hpux # HP-TURKISH8 hpux # HP-KANA8 hpux # DEC-KANJI osf # DEC-HANYU osf # UTF-8 Y glibc aix hpux osf solaris netbsd darwin # # Note: Names which are not marked as being a MIME name should not be used in # Internet protocols for information interchange (mail, news, etc.). # # Note: ASCII and ANSI_X3.4-1968 are synonymous canonical names. Applications # must understand both names and treat them as equivalent. # # The first argument passed to this file is the canonical host specification, # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM # or # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM host="$1" os=`echo "$host" | sed -e 's/^[^-]*-[^-]*-\(.*\)$/\1/'` echo "# This file contains a table of character encoding aliases," echo "# suitable for operating system '${os}'." echo "# It was automatically generated from config.charset." # List of references, updated during installation: echo "# Packages using this file: " case "$os" in linux-gnulibc1*) # Linux libc5 doesn't have nl_langinfo(CODESET); therefore # localcharset.c falls back to using the full locale name # from the environment variables. echo "C ASCII" echo "POSIX ASCII" for l in af af_ZA ca ca_ES da da_DK de de_AT de_BE de_CH de_DE de_LU \ en en_AU en_BW en_CA en_DK en_GB en_IE en_NZ en_US en_ZA \ en_ZW es es_AR es_BO es_CL es_CO es_DO es_EC es_ES es_GT \ es_HN es_MX es_PA es_PE es_PY es_SV es_US es_UY es_VE et \ et_EE eu eu_ES fi fi_FI fo fo_FO fr fr_BE fr_CA fr_CH fr_FR \ fr_LU ga ga_IE gl gl_ES id id_ID in in_ID is is_IS it it_CH \ it_IT kl kl_GL nl nl_BE nl_NL no no_NO pt pt_BR pt_PT sv \ sv_FI sv_SE; do echo "$l ISO-8859-1" echo "$l.iso-8859-1 ISO-8859-1" echo "$l.iso-8859-15 ISO-8859-15" echo "$l.iso-8859-15@euro ISO-8859-15" echo "$l@euro ISO-8859-15" echo "$l.cp-437 CP437" echo "$l.cp-850 CP850" echo "$l.cp-1252 CP1252" echo "$l.cp-1252@euro CP1252" #echo "$l.atari-st ATARI-ST" # not a commonly used encoding echo "$l.utf-8 UTF-8" echo "$l.utf-8@euro UTF-8" done for l in cs cs_CZ hr hr_HR hu hu_HU pl pl_PL ro ro_RO sk sk_SK sl \ sl_SI sr sr_CS sr_YU; do echo "$l ISO-8859-2" echo "$l.iso-8859-2 ISO-8859-2" echo "$l.cp-852 CP852" echo "$l.cp-1250 CP1250" echo "$l.utf-8 UTF-8" done for l in mk mk_MK ru ru_RU; do echo "$l ISO-8859-5" echo "$l.iso-8859-5 ISO-8859-5" echo "$l.koi8-r KOI8-R" echo "$l.cp-866 CP866" echo "$l.cp-1251 CP1251" echo "$l.utf-8 UTF-8" done for l in ar ar_SA; do echo "$l ISO-8859-6" echo "$l.iso-8859-6 ISO-8859-6" echo "$l.cp-864 CP864" #echo "$l.cp-868 CP868" # not a commonly used encoding echo "$l.cp-1256 CP1256" echo "$l.utf-8 UTF-8" done for l in el el_GR gr gr_GR; do echo "$l ISO-8859-7" echo "$l.iso-8859-7 ISO-8859-7" echo "$l.cp-869 CP869" echo "$l.cp-1253 CP1253" echo "$l.cp-1253@euro CP1253" echo "$l.utf-8 UTF-8" echo "$l.utf-8@euro UTF-8" done for l in he he_IL iw iw_IL; do echo "$l ISO-8859-8" echo "$l.iso-8859-8 ISO-8859-8" echo "$l.cp-862 CP862" echo "$l.cp-1255 CP1255" echo "$l.utf-8 UTF-8" done for l in tr tr_TR; do echo "$l ISO-8859-9" echo "$l.iso-8859-9 ISO-8859-9" echo "$l.cp-857 CP857" echo "$l.cp-1254 CP1254" echo "$l.utf-8 UTF-8" done for l in lt lt_LT lv lv_LV; do #echo "$l BALTIC" # not a commonly used encoding, wrong encoding name echo "$l ISO-8859-13" done for l in ru_UA uk uk_UA; do echo "$l KOI8-U" done for l in zh zh_CN; do #echo "$l GB_2312-80" # not a commonly used encoding, wrong encoding name echo "$l GB2312" done for l in ja ja_JP ja_JP.EUC; do echo "$l EUC-JP" done for l in ko ko_KR; do echo "$l EUC-KR" done for l in th th_TH; do echo "$l TIS-620" done for l in fa fa_IR; do #echo "$l ISIRI-3342" # a broken encoding echo "$l.utf-8 UTF-8" done ;; linux* | *-gnu*) # With glibc-2.1 or newer, we don't need any canonicalization, # because glibc has iconv and both glibc and libiconv support all # GNU canonical names directly. Therefore, the Makefile does not # need to install the alias file at all. # The following applies only to glibc-2.0.x and older libcs. echo "ISO_646.IRV:1983 ASCII" ;; aix*) echo "ISO8859-1 ISO-8859-1" echo "ISO8859-2 ISO-8859-2" echo "ISO8859-5 ISO-8859-5" echo "ISO8859-6 ISO-8859-6" echo "ISO8859-7 ISO-8859-7" echo "ISO8859-8 ISO-8859-8" echo "ISO8859-9 ISO-8859-9" echo "ISO8859-15 ISO-8859-15" echo "IBM-850 CP850" echo "IBM-856 CP856" echo "IBM-921 ISO-8859-13" echo "IBM-922 CP922" echo "IBM-932 CP932" echo "IBM-943 CP943" echo "IBM-1046 CP1046" echo "IBM-1124 CP1124" echo "IBM-1129 CP1129" echo "IBM-1252 CP1252" echo "IBM-eucCN GB2312" echo "IBM-eucJP EUC-JP" echo "IBM-eucKR EUC-KR" echo "IBM-eucTW EUC-TW" echo "big5 BIG5" echo "GBK GBK" echo "TIS-620 TIS-620" echo "UTF-8 UTF-8" ;; hpux*) echo "iso88591 ISO-8859-1" echo "iso88592 ISO-8859-2" echo "iso88595 ISO-8859-5" echo "iso88596 ISO-8859-6" echo "iso88597 ISO-8859-7" echo "iso88598 ISO-8859-8" echo "iso88599 ISO-8859-9" echo "iso885915 ISO-8859-15" echo "roman8 HP-ROMAN8" echo "arabic8 HP-ARABIC8" echo "greek8 HP-GREEK8" echo "hebrew8 HP-HEBREW8" echo "turkish8 HP-TURKISH8" echo "kana8 HP-KANA8" echo "tis620 TIS-620" echo "big5 BIG5" echo "eucJP EUC-JP" echo "eucKR EUC-KR" echo "eucTW EUC-TW" echo "hp15CN GB2312" #echo "ccdc ?" # what is this? echo "SJIS SHIFT_JIS" echo "utf8 UTF-8" ;; irix*) echo "ISO8859-1 ISO-8859-1" echo "ISO8859-2 ISO-8859-2" echo "ISO8859-5 ISO-8859-5" echo "ISO8859-7 ISO-8859-7" echo "ISO8859-9 ISO-8859-9" echo "eucCN GB2312" echo "eucJP EUC-JP" echo "eucKR EUC-KR" echo "eucTW EUC-TW" ;; osf*) echo "ISO8859-1 ISO-8859-1" echo "ISO8859-2 ISO-8859-2" echo "ISO8859-4 ISO-8859-4" echo "ISO8859-5 ISO-8859-5" echo "ISO8859-7 ISO-8859-7" echo "ISO8859-8 ISO-8859-8" echo "ISO8859-9 ISO-8859-9" echo "ISO8859-15 ISO-8859-15" echo "cp850 CP850" echo "big5 BIG5" echo "dechanyu DEC-HANYU" echo "dechanzi GB2312" echo "deckanji DEC-KANJI" echo "deckorean EUC-KR" echo "eucJP EUC-JP" echo "eucKR EUC-KR" echo "eucTW EUC-TW" echo "GBK GBK" echo "KSC5601 CP949" echo "sdeckanji EUC-JP" echo "SJIS SHIFT_JIS" echo "TACTIS TIS-620" echo "UTF-8 UTF-8" ;; solaris*) echo "646 ASCII" echo "ISO8859-1 ISO-8859-1" echo "ISO8859-2 ISO-8859-2" echo "ISO8859-3 ISO-8859-3" echo "ISO8859-4 ISO-8859-4" echo "ISO8859-5 ISO-8859-5" echo "ISO8859-6 ISO-8859-6" echo "ISO8859-7 ISO-8859-7" echo "ISO8859-8 ISO-8859-8" echo "ISO8859-9 ISO-8859-9" echo "ISO8859-15 ISO-8859-15" echo "koi8-r KOI8-R" echo "ansi-1251 CP1251" echo "BIG5 BIG5" echo "Big5-HKSCS BIG5-HKSCS" echo "gb2312 GB2312" echo "GBK GBK" echo "GB18030 GB18030" echo "cns11643 EUC-TW" echo "5601 EUC-KR" echo "ko_KR.johap92 JOHAB" echo "eucJP EUC-JP" echo "PCK SHIFT_JIS" echo "TIS620.2533 TIS-620" #echo "sun_eu_greek ?" # what is this? echo "UTF-8 UTF-8" ;; freebsd* | os2*) # FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore # localcharset.c falls back to using the full locale name # from the environment variables. # Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just # reuse FreeBSD's locale data for OS/2. echo "C ASCII" echo "US-ASCII ASCII" for l in la_LN lt_LN; do echo "$l.ASCII ASCII" done for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \ fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT la_LN \ lt_LN nl_BE nl_NL no_NO pt_PT sv_SE; do echo "$l.ISO_8859-1 ISO-8859-1" echo "$l.DIS_8859-15 ISO-8859-15" done for l in cs_CZ hr_HR hu_HU la_LN lt_LN pl_PL sl_SI; do echo "$l.ISO_8859-2 ISO-8859-2" done for l in la_LN lt_LT; do echo "$l.ISO_8859-4 ISO-8859-4" done for l in ru_RU ru_SU; do echo "$l.KOI8-R KOI8-R" echo "$l.ISO_8859-5 ISO-8859-5" echo "$l.CP866 CP866" done echo "uk_UA.KOI8-U KOI8-U" echo "zh_TW.BIG5 BIG5" echo "zh_TW.Big5 BIG5" echo "zh_CN.EUC GB2312" echo "ja_JP.EUC EUC-JP" echo "ja_JP.SJIS SHIFT_JIS" echo "ja_JP.Shift_JIS SHIFT_JIS" echo "ko_KR.EUC EUC-KR" ;; netbsd*) echo "646 ASCII" echo "ISO8859-1 ISO-8859-1" echo "ISO8859-2 ISO-8859-2" echo "ISO8859-4 ISO-8859-4" echo "ISO8859-5 ISO-8859-5" echo "ISO8859-7 ISO-8859-7" echo "ISO8859-13 ISO-8859-13" echo "ISO8859-15 ISO-8859-15" echo "eucCN GB2312" echo "eucJP EUC-JP" echo "eucKR EUC-KR" echo "eucTW EUC-TW" echo "BIG5 BIG5" echo "SJIS SHIFT_JIS" ;; darwin[56]*) # Darwin 6.8 doesn't have nl_langinfo(CODESET); therefore # localcharset.c falls back to using the full locale name # from the environment variables. echo "C ASCII" for l in en_AU en_CA en_GB en_US la_LN; do echo "$l.US-ASCII ASCII" done for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \ fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT nl_BE \ nl_NL no_NO pt_PT sv_SE; do echo "$l ISO-8859-1" echo "$l.ISO8859-1 ISO-8859-1" echo "$l.ISO8859-15 ISO-8859-15" done for l in la_LN; do echo "$l.ISO8859-1 ISO-8859-1" echo "$l.ISO8859-15 ISO-8859-15" done for l in cs_CZ hr_HR hu_HU la_LN pl_PL sl_SI; do echo "$l.ISO8859-2 ISO-8859-2" done for l in la_LN lt_LT; do echo "$l.ISO8859-4 ISO-8859-4" done for l in ru_RU; do echo "$l.KOI8-R KOI8-R" echo "$l.ISO8859-5 ISO-8859-5" echo "$l.CP866 CP866" done for l in bg_BG; do echo "$l.CP1251 CP1251" done echo "uk_UA.KOI8-U KOI8-U" echo "zh_TW.BIG5 BIG5" echo "zh_TW.Big5 BIG5" echo "zh_CN.EUC GB2312" echo "ja_JP.EUC EUC-JP" echo "ja_JP.SJIS SHIFT_JIS" echo "ko_KR.EUC EUC-KR" ;; darwin*) # Darwin 7.5 has nl_langinfo(CODESET), but it is useless: # - It returns the empty string when LANG is set to a locale of the # form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8 # LC_CTYPE file. # - The environment variables LANG, LC_CTYPE, LC_ALL are not set by # the system; nl_langinfo(CODESET) returns "US-ASCII" in this case. # - The documentation says: # "... all code that calls BSD system routines should ensure # that the const *char parameters of these routines are in UTF-8 # encoding. All BSD system functions expect their string # parameters to be in UTF-8 encoding and nothing else." # It also says # "An additional caveat is that string parameters for files, # paths, and other file-system entities must be in canonical # UTF-8. In a canonical UTF-8 Unicode string, all decomposable # characters are decomposed ..." # but this is not true: You can pass non-decomposed UTF-8 strings # to file system functions, and it is the OS which will convert # them to decomposed UTF-8 before accessing the file system. # - The Apple Terminal application displays UTF-8 by default. # - However, other applications are free to use different encodings: # - xterm uses ISO-8859-1 by default. # - TextEdit uses MacRoman by default. # We prefer UTF-8 over decomposed UTF-8-MAC because one should # minimize the use of decomposed Unicode. Unfortunately, through the # Darwin file system, decomposed UTF-8 strings are leaked into user # space nevertheless. echo "* UTF-8" ;; beos*) # BeOS has a single locale, and it has UTF-8 encoding. echo "* UTF-8" ;; msdosdjgpp*) # DJGPP 2.03 doesn't have nl_langinfo(CODESET); therefore # localcharset.c falls back to using the full locale name # from the environment variables. echo "#" echo "# The encodings given here may not all be correct." echo "# If you find that the encoding given for your language and" echo "# country is not the one your DOS machine actually uses, just" echo "# correct it in this file, and send a mail to" echo "# Juan Manuel Guerrero " echo "# and Bruno Haible ." echo "#" echo "C ASCII" # ISO-8859-1 languages echo "ca CP850" echo "ca_ES CP850" echo "da CP865" # not CP850 ?? echo "da_DK CP865" # not CP850 ?? echo "de CP850" echo "de_AT CP850" echo "de_CH CP850" echo "de_DE CP850" echo "en CP850" echo "en_AU CP850" # not CP437 ?? echo "en_CA CP850" echo "en_GB CP850" echo "en_NZ CP437" echo "en_US CP437" echo "en_ZA CP850" # not CP437 ?? echo "es CP850" echo "es_AR CP850" echo "es_BO CP850" echo "es_CL CP850" echo "es_CO CP850" echo "es_CR CP850" echo "es_CU CP850" echo "es_DO CP850" echo "es_EC CP850" echo "es_ES CP850" echo "es_GT CP850" echo "es_HN CP850" echo "es_MX CP850" echo "es_NI CP850" echo "es_PA CP850" echo "es_PY CP850" echo "es_PE CP850" echo "es_SV CP850" echo "es_UY CP850" echo "es_VE CP850" echo "et CP850" echo "et_EE CP850" echo "eu CP850" echo "eu_ES CP850" echo "fi CP850" echo "fi_FI CP850" echo "fr CP850" echo "fr_BE CP850" echo "fr_CA CP850" echo "fr_CH CP850" echo "fr_FR CP850" echo "ga CP850" echo "ga_IE CP850" echo "gd CP850" echo "gd_GB CP850" echo "gl CP850" echo "gl_ES CP850" echo "id CP850" # not CP437 ?? echo "id_ID CP850" # not CP437 ?? echo "is CP861" # not CP850 ?? echo "is_IS CP861" # not CP850 ?? echo "it CP850" echo "it_CH CP850" echo "it_IT CP850" echo "lt CP775" echo "lt_LT CP775" echo "lv CP775" echo "lv_LV CP775" echo "nb CP865" # not CP850 ?? echo "nb_NO CP865" # not CP850 ?? echo "nl CP850" echo "nl_BE CP850" echo "nl_NL CP850" echo "nn CP865" # not CP850 ?? echo "nn_NO CP865" # not CP850 ?? echo "no CP865" # not CP850 ?? echo "no_NO CP865" # not CP850 ?? echo "pt CP850" echo "pt_BR CP850" echo "pt_PT CP850" echo "sv CP850" echo "sv_SE CP850" # ISO-8859-2 languages echo "cs CP852" echo "cs_CZ CP852" echo "hr CP852" echo "hr_HR CP852" echo "hu CP852" echo "hu_HU CP852" echo "pl CP852" echo "pl_PL CP852" echo "ro CP852" echo "ro_RO CP852" echo "sk CP852" echo "sk_SK CP852" echo "sl CP852" echo "sl_SI CP852" echo "sq CP852" echo "sq_AL CP852" echo "sr CP852" # CP852 or CP866 or CP855 ?? echo "sr_CS CP852" # CP852 or CP866 or CP855 ?? echo "sr_YU CP852" # CP852 or CP866 or CP855 ?? # ISO-8859-3 languages echo "mt CP850" echo "mt_MT CP850" # ISO-8859-5 languages echo "be CP866" echo "be_BE CP866" echo "bg CP866" # not CP855 ?? echo "bg_BG CP866" # not CP855 ?? echo "mk CP866" # not CP855 ?? echo "mk_MK CP866" # not CP855 ?? echo "ru CP866" echo "ru_RU CP866" echo "uk CP1125" echo "uk_UA CP1125" # ISO-8859-6 languages echo "ar CP864" echo "ar_AE CP864" echo "ar_DZ CP864" echo "ar_EG CP864" echo "ar_IQ CP864" echo "ar_IR CP864" echo "ar_JO CP864" echo "ar_KW CP864" echo "ar_MA CP864" echo "ar_OM CP864" echo "ar_QA CP864" echo "ar_SA CP864" echo "ar_SY CP864" # ISO-8859-7 languages echo "el CP869" echo "el_GR CP869" # ISO-8859-8 languages echo "he CP862" echo "he_IL CP862" # ISO-8859-9 languages echo "tr CP857" echo "tr_TR CP857" # Japanese echo "ja CP932" echo "ja_JP CP932" # Chinese echo "zh_CN GBK" echo "zh_TW CP950" # not CP938 ?? # Korean echo "kr CP949" # not CP934 ?? echo "kr_KR CP949" # not CP934 ?? # Thai echo "th CP874" echo "th_TH CP874" # Other echo "eo CP850" echo "eo_EO CP850" ;; esac libnih-1.0.3/intl/ngettext.c0000644000175000017500000000367411461165267012700 00000000000000/* Implementation of ngettext(3) function. Copyright (C) 1995, 1997, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #ifdef _LIBC # define __need_NULL # include #else # include /* Just for NULL. */ #endif #include "gettextP.h" #ifdef _LIBC # include #else # include "libgnuintl.h" #endif #include /* @@ end of prolog @@ */ /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define NGETTEXT __ngettext # define DCNGETTEXT __dcngettext #else # define NGETTEXT libintl_ngettext # define DCNGETTEXT libintl_dcngettext #endif /* Look up MSGID in the current default message catalog for the current LC_MESSAGES locale. If not found, returns MSGID itself (the default text). */ char * NGETTEXT (const char *msgid1, const char *msgid2, unsigned long int n) { return DCNGETTEXT (NULL, msgid1, msgid2, n, LC_MESSAGES); } #ifdef _LIBC /* Alias for function name in GNU C Library. */ weak_alias (__ngettext, ngettext); #endif libnih-1.0.3/intl/intl-exports.c0000644000175000017500000000273311461165267013501 00000000000000/* List of exported symbols of libintl on Cygwin. Copyright (C) 2006 Free Software Foundation, Inc. Written by Bruno Haible , 2006. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* IMP(x) is a symbol that contains the address of x. */ #define IMP(x) _imp__##x /* Ensure that the variable x is exported from the library, and that a pseudo-variable IMP(x) is available. */ #define VARIABLE(x) \ /* Export x without redefining x. This code was found by compiling a \ snippet: \ extern __declspec(dllexport) int x; int x = 42; */ \ asm (".section .drectve\n"); \ asm (".ascii \" -export:" #x ",data\"\n"); \ asm (".data\n"); \ /* Allocate a pseudo-variable IMP(x). */ \ extern int x; \ void * IMP(x) = &x; VARIABLE(libintl_version) libnih-1.0.3/intl/dcigettext.c0000644000175000017500000013334511461165267013201 00000000000000/* Implementation of the internal dcigettext function. Copyright (C) 1995-1999, 2000-2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Tell glibc's to provide a prototype for mempcpy(). This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #ifdef HAVE_CONFIG_H # include #endif /* NL_LOCALE_NAME does not work in glibc-2.4. Ignore it. */ #undef HAVE_NL_LOCALE_NAME #include #ifdef __GNUC__ # define alloca __builtin_alloca # define HAVE_ALLOCA 1 #else # ifdef _MSC_VER # include # define alloca _alloca # else # if defined HAVE_ALLOCA_H || defined _LIBC # include # else # ifdef _AIX #pragma alloca # else # ifndef alloca char *alloca (); # endif # endif # endif # endif #endif #include #ifndef errno extern int errno; #endif #ifndef __set_errno # define __set_errno(val) errno = (val) #endif #include #include #include #if defined HAVE_UNISTD_H || defined _LIBC # include #endif #include #ifdef _LIBC /* Guess whether integer division by zero raises signal SIGFPE. Set to 1 only if you know for sure. In case of doubt, set to 0. */ # if defined __alpha__ || defined __arm__ || defined __i386__ \ || defined __m68k__ || defined __s390__ # define INTDIV0_RAISES_SIGFPE 1 # else # define INTDIV0_RAISES_SIGFPE 0 # endif #endif #if !INTDIV0_RAISES_SIGFPE # include #endif #if defined HAVE_SYS_PARAM_H || defined _LIBC # include #endif #if !defined _LIBC # if HAVE_NL_LOCALE_NAME # include # endif # include "localcharset.h" #endif #include "gettextP.h" #include "plural-exp.h" #ifdef _LIBC # include #else # ifdef IN_LIBGLOCALE # include # endif # include "libgnuintl.h" #endif #include "hash-string.h" /* Handle multi-threaded applications. */ #ifdef _LIBC # include # define gl_rwlock_define_initialized __libc_rwlock_define_initialized # define gl_rwlock_rdlock __libc_rwlock_rdlock # define gl_rwlock_wrlock __libc_rwlock_wrlock # define gl_rwlock_unlock __libc_rwlock_unlock #else # include "lock.h" #endif /* Alignment of types. */ #if defined __GNUC__ && __GNUC__ >= 2 # define alignof(TYPE) __alignof__ (TYPE) #else # define alignof(TYPE) \ ((int) &((struct { char dummy1; TYPE dummy2; } *) 0)->dummy2) #endif /* Some compilers, like SunOS4 cc, don't have offsetof in . */ #ifndef offsetof # define offsetof(type,ident) ((size_t)&(((type*)0)->ident)) #endif /* @@ end of prolog @@ */ #ifdef _LIBC /* Rename the non ANSI C functions. This is required by the standard because some ANSI C functions will require linking with this object file and the name space must not be polluted. */ # define getcwd __getcwd # ifndef stpcpy # define stpcpy __stpcpy # endif # define tfind __tfind #else # if !defined HAVE_GETCWD char *getwd (); # define getcwd(buf, max) getwd (buf) # else # if VMS # define getcwd(buf, max) (getcwd) (buf, max, 0) # else char *getcwd (); # endif # endif # ifndef HAVE_STPCPY static char *stpcpy (char *dest, const char *src); # endif # ifndef HAVE_MEMPCPY static void *mempcpy (void *dest, const void *src, size_t n); # endif #endif /* Use a replacement if the system does not provide the `tsearch' function family. */ #if HAVE_TSEARCH || defined _LIBC # include #else # define tsearch libintl_tsearch # define tfind libintl_tfind # define tdelete libintl_tdelete # define twalk libintl_twalk # include "tsearch.h" #endif #ifdef _LIBC # define tsearch __tsearch #endif /* Amount to increase buffer size by in each try. */ #define PATH_INCR 32 /* The following is from pathmax.h. */ /* Non-POSIX BSD systems might have gcc's limits.h, which doesn't define PATH_MAX but might cause redefinition warnings when sys/param.h is later included (as on MORE/BSD 4.3). */ #if defined _POSIX_VERSION || (defined HAVE_LIMITS_H && !defined __GNUC__) # include #endif #ifndef _POSIX_PATH_MAX # define _POSIX_PATH_MAX 255 #endif #if !defined PATH_MAX && defined _PC_PATH_MAX # define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 : pathconf ("/", _PC_PATH_MAX)) #endif /* Don't include sys/param.h if it already has been. */ #if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN # include #endif #if !defined PATH_MAX && defined MAXPATHLEN # define PATH_MAX MAXPATHLEN #endif #ifndef PATH_MAX # define PATH_MAX _POSIX_PATH_MAX #endif /* Pathname support. ISSLASH(C) tests whether C is a directory separator character. IS_ABSOLUTE_PATH(P) tests whether P is an absolute path. If it is not, it may be concatenated to a directory pathname. IS_PATH_WITH_DIR(P) tests whether P contains a directory specification. */ #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ /* Win32, Cygwin, OS/2, DOS */ # define ISSLASH(C) ((C) == '/' || (C) == '\\') # define HAS_DEVICE(P) \ ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \ && (P)[1] == ':') # define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P)) # define IS_PATH_WITH_DIR(P) \ (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P)) #else /* Unix */ # define ISSLASH(C) ((C) == '/') # define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0]) # define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL) #endif /* Whether to support different locales in different threads. */ #if defined _LIBC || HAVE_NL_LOCALE_NAME || (HAVE_STRUCT___LOCALE_STRUCT___NAMES && defined USE_IN_GETTEXT_TESTS) || defined IN_LIBGLOCALE # define HAVE_PER_THREAD_LOCALE #endif /* This is the type used for the search tree where known translations are stored. */ struct known_translation_t { /* Domain in which to search. */ const char *domainname; /* The category. */ int category; #ifdef HAVE_PER_THREAD_LOCALE /* Name of the relevant locale category, or "" for the global locale. */ const char *localename; #endif #ifdef IN_LIBGLOCALE /* The character encoding. */ const char *encoding; #endif /* State of the catalog counter at the point the string was found. */ int counter; /* Catalog where the string was found. */ struct loaded_l10nfile *domain; /* And finally the translation. */ const char *translation; size_t translation_length; /* Pointer to the string in question. */ char msgid[ZERO]; }; gl_rwlock_define_initialized (static, tree_lock) /* Root of the search tree with known translations. */ static void *root; /* Function to compare two entries in the table of known translations. */ static int transcmp (const void *p1, const void *p2) { const struct known_translation_t *s1; const struct known_translation_t *s2; int result; s1 = (const struct known_translation_t *) p1; s2 = (const struct known_translation_t *) p2; result = strcmp (s1->msgid, s2->msgid); if (result == 0) { result = strcmp (s1->domainname, s2->domainname); if (result == 0) { #ifdef HAVE_PER_THREAD_LOCALE result = strcmp (s1->localename, s2->localename); if (result == 0) #endif { #ifdef IN_LIBGLOCALE result = strcmp (s1->encoding, s2->encoding); if (result == 0) #endif /* We compare the category last (though this is the cheapest operation) since it is hopefully always the same (namely LC_MESSAGES). */ result = s1->category - s2->category; } } } return result; } /* Name of the default domain used for gettext(3) prior any call to textdomain(3). The default value for this is "messages". */ const char _nl_default_default_domain[] attribute_hidden = "messages"; #ifndef IN_LIBGLOCALE /* Value used as the default domain for gettext(3). */ const char *_nl_current_default_domain attribute_hidden = _nl_default_default_domain; #endif /* Contains the default location of the message catalogs. */ #if defined __EMX__ extern const char _nl_default_dirname[]; #else # ifdef _LIBC extern const char _nl_default_dirname[]; libc_hidden_proto (_nl_default_dirname) # endif const char _nl_default_dirname[] = LOCALEDIR; # ifdef _LIBC libc_hidden_data_def (_nl_default_dirname) # endif #endif #ifndef IN_LIBGLOCALE /* List with bindings of specific domains created by bindtextdomain() calls. */ struct binding *_nl_domain_bindings; #endif /* Prototypes for local functions. */ static char *plural_lookup (struct loaded_l10nfile *domain, unsigned long int n, const char *translation, size_t translation_len) internal_function; #ifdef IN_LIBGLOCALE static const char *guess_category_value (int category, const char *categoryname, const char *localename) internal_function; #else static const char *guess_category_value (int category, const char *categoryname) internal_function; #endif #ifdef _LIBC # include "../locale/localeinfo.h" # define category_to_name(category) \ _nl_category_names.str + _nl_category_name_idxs[category] #else static const char *category_to_name (int category) internal_function; #endif #if (defined _LIBC || HAVE_ICONV) && !defined IN_LIBGLOCALE static const char *get_output_charset (struct binding *domainbinding) internal_function; #endif /* For those loosing systems which don't have `alloca' we have to add some additional code emulating it. */ #ifdef HAVE_ALLOCA /* Nothing has to be done. */ # define freea(p) /* nothing */ # define ADD_BLOCK(list, address) /* nothing */ # define FREE_BLOCKS(list) /* nothing */ #else struct block_list { void *address; struct block_list *next; }; # define ADD_BLOCK(list, addr) \ do { \ struct block_list *newp = (struct block_list *) malloc (sizeof (*newp)); \ /* If we cannot get a free block we cannot add the new element to \ the list. */ \ if (newp != NULL) { \ newp->address = (addr); \ newp->next = (list); \ (list) = newp; \ } \ } while (0) # define FREE_BLOCKS(list) \ do { \ while (list != NULL) { \ struct block_list *old = list; \ list = list->next; \ free (old->address); \ free (old); \ } \ } while (0) # undef alloca # define alloca(size) (malloc (size)) # define freea(p) free (p) #endif /* have alloca */ #ifdef _LIBC /* List of blocks allocated for translations. */ typedef struct transmem_list { struct transmem_list *next; char data[ZERO]; } transmem_block_t; static struct transmem_list *transmem_list; #else typedef unsigned char transmem_block_t; #endif /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define DCIGETTEXT __dcigettext #else # define DCIGETTEXT libintl_dcigettext #endif /* Lock variable to protect the global data in the gettext implementation. */ gl_rwlock_define_initialized (, _nl_state_lock attribute_hidden) /* Checking whether the binaries runs SUID must be done and glibc provides easier methods therefore we make a difference here. */ #ifdef _LIBC # define ENABLE_SECURE __libc_enable_secure # define DETERMINE_SECURE #else # ifndef HAVE_GETUID # define getuid() 0 # endif # ifndef HAVE_GETGID # define getgid() 0 # endif # ifndef HAVE_GETEUID # define geteuid() getuid() # endif # ifndef HAVE_GETEGID # define getegid() getgid() # endif static int enable_secure; # define ENABLE_SECURE (enable_secure == 1) # define DETERMINE_SECURE \ if (enable_secure == 0) \ { \ if (getuid () != geteuid () || getgid () != getegid ()) \ enable_secure = 1; \ else \ enable_secure = -1; \ } #endif /* Get the function to evaluate the plural expression. */ #include "eval-plural.h" /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY locale and, if PLURAL is nonzero, search over string depending on the plural form determined by N. */ #ifdef IN_LIBGLOCALE char * gl_dcigettext (const char *domainname, const char *msgid1, const char *msgid2, int plural, unsigned long int n, int category, const char *localename, const char *encoding) #else char * DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, int plural, unsigned long int n, int category) #endif { #ifndef HAVE_ALLOCA struct block_list *block_list = NULL; #endif struct loaded_l10nfile *domain; struct binding *binding; const char *categoryname; const char *categoryvalue; const char *dirname; char *xdomainname; char *single_locale; char *retval; size_t retlen; int saved_errno; struct known_translation_t *search; struct known_translation_t **foundp = NULL; size_t msgid_len; #if defined HAVE_PER_THREAD_LOCALE && !defined IN_LIBGLOCALE const char *localename; #endif size_t domainname_len; /* If no real MSGID is given return NULL. */ if (msgid1 == NULL) return NULL; #ifdef _LIBC if (category < 0 || category >= __LC_LAST || category == LC_ALL) /* Bogus. */ return (plural == 0 ? (char *) msgid1 /* Use the Germanic plural rule. */ : n == 1 ? (char *) msgid1 : (char *) msgid2); #endif /* Preserve the `errno' value. */ saved_errno = errno; gl_rwlock_rdlock (_nl_state_lock); /* If DOMAINNAME is NULL, we are interested in the default domain. If CATEGORY is not LC_MESSAGES this might not make much sense but the definition left this undefined. */ if (domainname == NULL) domainname = _nl_current_default_domain; /* OS/2 specific: backward compatibility with older libintl versions */ #ifdef LC_MESSAGES_COMPAT if (category == LC_MESSAGES_COMPAT) category = LC_MESSAGES; #endif msgid_len = strlen (msgid1) + 1; /* Try to find the translation among those which we found at some time. */ search = (struct known_translation_t *) alloca (offsetof (struct known_translation_t, msgid) + msgid_len); memcpy (search->msgid, msgid1, msgid_len); search->domainname = domainname; search->category = category; #ifdef HAVE_PER_THREAD_LOCALE # ifndef IN_LIBGLOCALE # ifdef _LIBC localename = __current_locale_name (category); # else # if HAVE_NL_LOCALE_NAME /* NL_LOCALE_NAME is public glibc API introduced in glibc-2.4. */ localename = nl_langinfo (NL_LOCALE_NAME (category)); # else # if HAVE_STRUCT___LOCALE_STRUCT___NAMES && defined USE_IN_GETTEXT_TESTS /* The __names field is not public glibc API and must therefore not be used in code that is installed in public locations. */ { locale_t thread_locale = uselocale (NULL); if (thread_locale != LC_GLOBAL_LOCALE) localename = thread_locale->__names[category]; else localename = ""; } # endif # endif # endif # endif search->localename = localename; # ifdef IN_LIBGLOCALE search->encoding = encoding; # endif /* Since tfind/tsearch manage a balanced tree, concurrent tfind and tsearch calls can be fatal. */ gl_rwlock_rdlock (tree_lock); foundp = (struct known_translation_t **) tfind (search, &root, transcmp); gl_rwlock_unlock (tree_lock); freea (search); if (foundp != NULL && (*foundp)->counter == _nl_msg_cat_cntr) { /* Now deal with plural. */ if (plural) retval = plural_lookup ((*foundp)->domain, n, (*foundp)->translation, (*foundp)->translation_length); else retval = (char *) (*foundp)->translation; gl_rwlock_unlock (_nl_state_lock); __set_errno (saved_errno); return retval; } #endif /* See whether this is a SUID binary or not. */ DETERMINE_SECURE; /* First find matching binding. */ #ifdef IN_LIBGLOCALE /* We can use a trivial binding, since _nl_find_msg will ignore it anyway, and _nl_load_domain and _nl_find_domain just pass it through. */ binding = NULL; dirname = bindtextdomain (domainname, NULL); #else for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next) { int compare = strcmp (domainname, binding->domainname); if (compare == 0) /* We found it! */ break; if (compare < 0) { /* It is not in the list. */ binding = NULL; break; } } if (binding == NULL) dirname = _nl_default_dirname; else { dirname = binding->dirname; #endif if (!IS_ABSOLUTE_PATH (dirname)) { /* We have a relative path. Make it absolute now. */ size_t dirname_len = strlen (dirname) + 1; size_t path_max; char *resolved_dirname; char *ret; path_max = (unsigned int) PATH_MAX; path_max += 2; /* The getcwd docs say to do this. */ for (;;) { resolved_dirname = (char *) alloca (path_max + dirname_len); ADD_BLOCK (block_list, tmp_dirname); __set_errno (0); ret = getcwd (resolved_dirname, path_max); if (ret != NULL || errno != ERANGE) break; path_max += path_max / 2; path_max += PATH_INCR; } if (ret == NULL) /* We cannot get the current working directory. Don't signal an error but simply return the default string. */ goto return_untranslated; stpcpy (stpcpy (strchr (resolved_dirname, '\0'), "/"), dirname); dirname = resolved_dirname; } #ifndef IN_LIBGLOCALE } #endif /* Now determine the symbolic name of CATEGORY and its value. */ categoryname = category_to_name (category); #ifdef IN_LIBGLOCALE categoryvalue = guess_category_value (category, categoryname, localename); #else categoryvalue = guess_category_value (category, categoryname); #endif domainname_len = strlen (domainname); xdomainname = (char *) alloca (strlen (categoryname) + domainname_len + 5); ADD_BLOCK (block_list, xdomainname); stpcpy ((char *) mempcpy (stpcpy (stpcpy (xdomainname, categoryname), "/"), domainname, domainname_len), ".mo"); /* Creating working area. */ single_locale = (char *) alloca (strlen (categoryvalue) + 1); ADD_BLOCK (block_list, single_locale); /* Search for the given string. This is a loop because we perhaps got an ordered list of languages to consider for the translation. */ while (1) { /* Make CATEGORYVALUE point to the next element of the list. */ while (categoryvalue[0] != '\0' && categoryvalue[0] == ':') ++categoryvalue; if (categoryvalue[0] == '\0') { /* The whole contents of CATEGORYVALUE has been searched but no valid entry has been found. We solve this situation by implicitly appending a "C" entry, i.e. no translation will take place. */ single_locale[0] = 'C'; single_locale[1] = '\0'; } else { char *cp = single_locale; while (categoryvalue[0] != '\0' && categoryvalue[0] != ':') *cp++ = *categoryvalue++; *cp = '\0'; /* When this is a SUID binary we must not allow accessing files outside the dedicated directories. */ if (ENABLE_SECURE && IS_PATH_WITH_DIR (single_locale)) /* Ingore this entry. */ continue; } /* If the current locale value is C (or POSIX) we don't load a domain. Return the MSGID. */ if (strcmp (single_locale, "C") == 0 || strcmp (single_locale, "POSIX") == 0) break; /* Find structure describing the message catalog matching the DOMAINNAME and CATEGORY. */ domain = _nl_find_domain (dirname, single_locale, xdomainname, binding); if (domain != NULL) { #if defined IN_LIBGLOCALE retval = _nl_find_msg (domain, binding, encoding, msgid1, &retlen); #else retval = _nl_find_msg (domain, binding, msgid1, 1, &retlen); #endif if (retval == NULL) { int cnt; for (cnt = 0; domain->successor[cnt] != NULL; ++cnt) { #if defined IN_LIBGLOCALE retval = _nl_find_msg (domain->successor[cnt], binding, encoding, msgid1, &retlen); #else retval = _nl_find_msg (domain->successor[cnt], binding, msgid1, 1, &retlen); #endif if (retval != NULL) { domain = domain->successor[cnt]; break; } } } /* Returning -1 means that some resource problem exists (likely memory) and that the strings could not be converted. Return the original strings. */ if (__builtin_expect (retval == (char *) -1, 0)) break; if (retval != NULL) { /* Found the translation of MSGID1 in domain DOMAIN: starting at RETVAL, RETLEN bytes. */ FREE_BLOCKS (block_list); if (foundp == NULL) { /* Create a new entry and add it to the search tree. */ size_t size; struct known_translation_t *newp; size = offsetof (struct known_translation_t, msgid) + msgid_len + domainname_len + 1; #ifdef HAVE_PER_THREAD_LOCALE size += strlen (localename) + 1; #endif newp = (struct known_translation_t *) malloc (size); if (newp != NULL) { char *new_domainname; #ifdef HAVE_PER_THREAD_LOCALE char *new_localename; #endif new_domainname = (char *) mempcpy (newp->msgid, msgid1, msgid_len); memcpy (new_domainname, domainname, domainname_len + 1); #ifdef HAVE_PER_THREAD_LOCALE new_localename = new_domainname + domainname_len + 1; strcpy (new_localename, localename); #endif newp->domainname = new_domainname; newp->category = category; #ifdef HAVE_PER_THREAD_LOCALE newp->localename = new_localename; #endif #ifdef IN_LIBGLOCALE newp->encoding = encoding; #endif newp->counter = _nl_msg_cat_cntr; newp->domain = domain; newp->translation = retval; newp->translation_length = retlen; gl_rwlock_wrlock (tree_lock); /* Insert the entry in the search tree. */ foundp = (struct known_translation_t **) tsearch (newp, &root, transcmp); gl_rwlock_unlock (tree_lock); if (foundp == NULL || __builtin_expect (*foundp != newp, 0)) /* The insert failed. */ free (newp); } } else { /* We can update the existing entry. */ (*foundp)->counter = _nl_msg_cat_cntr; (*foundp)->domain = domain; (*foundp)->translation = retval; (*foundp)->translation_length = retlen; } __set_errno (saved_errno); /* Now deal with plural. */ if (plural) retval = plural_lookup (domain, n, retval, retlen); gl_rwlock_unlock (_nl_state_lock); return retval; } } } return_untranslated: /* Return the untranslated MSGID. */ FREE_BLOCKS (block_list); gl_rwlock_unlock (_nl_state_lock); #ifndef _LIBC if (!ENABLE_SECURE) { extern void _nl_log_untranslated (const char *logfilename, const char *domainname, const char *msgid1, const char *msgid2, int plural); const char *logfilename = getenv ("GETTEXT_LOG_UNTRANSLATED"); if (logfilename != NULL && logfilename[0] != '\0') _nl_log_untranslated (logfilename, domainname, msgid1, msgid2, plural); } #endif __set_errno (saved_errno); return (plural == 0 ? (char *) msgid1 /* Use the Germanic plural rule. */ : n == 1 ? (char *) msgid1 : (char *) msgid2); } /* Look up the translation of msgid within DOMAIN_FILE and DOMAINBINDING. Return it if found. Return NULL if not found or in case of a conversion failure (problem in the particular message catalog). Return (char *) -1 in case of a memory allocation failure during conversion (only if ENCODING != NULL resp. CONVERT == true). */ char * internal_function #ifdef IN_LIBGLOCALE _nl_find_msg (struct loaded_l10nfile *domain_file, struct binding *domainbinding, const char *encoding, const char *msgid, size_t *lengthp) #else _nl_find_msg (struct loaded_l10nfile *domain_file, struct binding *domainbinding, const char *msgid, int convert, size_t *lengthp) #endif { struct loaded_domain *domain; nls_uint32 nstrings; size_t act; char *result; size_t resultlen; if (domain_file->decided <= 0) _nl_load_domain (domain_file, domainbinding); if (domain_file->data == NULL) return NULL; domain = (struct loaded_domain *) domain_file->data; nstrings = domain->nstrings; /* Locate the MSGID and its translation. */ if (domain->hash_tab != NULL) { /* Use the hashing table. */ nls_uint32 len = strlen (msgid); nls_uint32 hash_val = __hash_string (msgid); nls_uint32 idx = hash_val % domain->hash_size; nls_uint32 incr = 1 + (hash_val % (domain->hash_size - 2)); while (1) { nls_uint32 nstr = W (domain->must_swap_hash_tab, domain->hash_tab[idx]); if (nstr == 0) /* Hash table entry is empty. */ return NULL; nstr--; /* Compare msgid with the original string at index nstr. We compare the lengths with >=, not ==, because plural entries are represented by strings with an embedded NUL. */ if (nstr < nstrings ? W (domain->must_swap, domain->orig_tab[nstr].length) >= len && (strcmp (msgid, domain->data + W (domain->must_swap, domain->orig_tab[nstr].offset)) == 0) : domain->orig_sysdep_tab[nstr - nstrings].length > len && (strcmp (msgid, domain->orig_sysdep_tab[nstr - nstrings].pointer) == 0)) { act = nstr; goto found; } if (idx >= domain->hash_size - incr) idx -= domain->hash_size - incr; else idx += incr; } /* NOTREACHED */ } else { /* Try the default method: binary search in the sorted array of messages. */ size_t top, bottom; bottom = 0; top = nstrings; while (bottom < top) { int cmp_val; act = (bottom + top) / 2; cmp_val = strcmp (msgid, (domain->data + W (domain->must_swap, domain->orig_tab[act].offset))); if (cmp_val < 0) top = act; else if (cmp_val > 0) bottom = act + 1; else goto found; } /* No translation was found. */ return NULL; } found: /* The translation was found at index ACT. If we have to convert the string to use a different character set, this is the time. */ if (act < nstrings) { result = (char *) (domain->data + W (domain->must_swap, domain->trans_tab[act].offset)); resultlen = W (domain->must_swap, domain->trans_tab[act].length) + 1; } else { result = (char *) domain->trans_sysdep_tab[act - nstrings].pointer; resultlen = domain->trans_sysdep_tab[act - nstrings].length; } #if defined _LIBC || HAVE_ICONV # ifdef IN_LIBGLOCALE if (encoding != NULL) # else if (convert) # endif { /* We are supposed to do a conversion. */ # ifndef IN_LIBGLOCALE const char *encoding = get_output_charset (domainbinding); # endif size_t nconversions; struct converted_domain *convd; size_t i; /* Protect against reallocation of the table. */ gl_rwlock_rdlock (domain->conversions_lock); /* Search whether a table with converted translations for this encoding has already been allocated. */ nconversions = domain->nconversions; convd = NULL; for (i = nconversions; i > 0; ) { i--; if (strcmp (domain->conversions[i].encoding, encoding) == 0) { convd = &domain->conversions[i]; break; } } gl_rwlock_unlock (domain->conversions_lock); if (convd == NULL) { /* We have to allocate a new conversions table. */ gl_rwlock_wrlock (domain->conversions_lock); /* Maybe in the meantime somebody added the translation. Recheck. */ for (i = nconversions; i > 0; ) { i--; if (strcmp (domain->conversions[i].encoding, encoding) == 0) { convd = &domain->conversions[i]; goto found_convd; } } { /* Allocate a table for the converted translations for this encoding. */ struct converted_domain *new_conversions = (struct converted_domain *) (domain->conversions != NULL ? realloc (domain->conversions, (nconversions + 1) * sizeof (struct converted_domain)) : malloc ((nconversions + 1) * sizeof (struct converted_domain))); if (__builtin_expect (new_conversions == NULL, 0)) { /* Nothing we can do, no more memory. We cannot use the translation because it might be encoded incorrectly. */ unlock_fail: gl_rwlock_unlock (domain->conversions_lock); return (char *) -1; } domain->conversions = new_conversions; /* Copy the 'encoding' string to permanent storage. */ encoding = strdup (encoding); if (__builtin_expect (encoding == NULL, 0)) /* Nothing we can do, no more memory. We cannot use the translation because it might be encoded incorrectly. */ goto unlock_fail; convd = &new_conversions[nconversions]; convd->encoding = encoding; /* Find out about the character set the file is encoded with. This can be found (in textual form) in the entry "". If this entry does not exist or if this does not contain the 'charset=' information, we will assume the charset matches the one the current locale and we don't have to perform any conversion. */ # ifdef _LIBC convd->conv = (__gconv_t) -1; # else # if HAVE_ICONV convd->conv = (iconv_t) -1; # endif # endif { char *nullentry; size_t nullentrylen; /* Get the header entry. This is a recursion, but it doesn't reallocate domain->conversions because we pass encoding = NULL or convert = 0, respectively. */ nullentry = # ifdef IN_LIBGLOCALE _nl_find_msg (domain_file, domainbinding, NULL, "", &nullentrylen); # else _nl_find_msg (domain_file, domainbinding, "", 0, &nullentrylen); # endif if (nullentry != NULL) { const char *charsetstr; charsetstr = strstr (nullentry, "charset="); if (charsetstr != NULL) { size_t len; char *charset; const char *outcharset; charsetstr += strlen ("charset="); len = strcspn (charsetstr, " \t\n"); charset = (char *) alloca (len + 1); # if defined _LIBC || HAVE_MEMPCPY *((char *) mempcpy (charset, charsetstr, len)) = '\0'; # else memcpy (charset, charsetstr, len); charset[len] = '\0'; # endif outcharset = encoding; # ifdef _LIBC /* We always want to use transliteration. */ outcharset = norm_add_slashes (outcharset, "TRANSLIT"); charset = norm_add_slashes (charset, ""); int r = __gconv_open (outcharset, charset, &convd->conv, GCONV_AVOID_NOCONV); if (__builtin_expect (r != __GCONV_OK, 0)) { /* If the output encoding is the same there is nothing to do. Otherwise do not use the translation at all. */ if (__builtin_expect (r != __GCONV_NULCONV, 1)) { gl_rwlock_unlock (domain->conversions_lock); free ((char *) encoding); return NULL; } convd->conv = (__gconv_t) -1; } # else # if HAVE_ICONV /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5, we want to use transliteration. */ # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \ || _LIBICONV_VERSION >= 0x0105 if (strchr (outcharset, '/') == NULL) { char *tmp; len = strlen (outcharset); tmp = (char *) alloca (len + 10 + 1); memcpy (tmp, outcharset, len); memcpy (tmp + len, "//TRANSLIT", 10 + 1); outcharset = tmp; convd->conv = iconv_open (outcharset, charset); freea (outcharset); } else # endif convd->conv = iconv_open (outcharset, charset); # endif # endif freea (charset); } } } convd->conv_tab = NULL; /* Here domain->conversions is still == new_conversions. */ domain->nconversions++; } found_convd: gl_rwlock_unlock (domain->conversions_lock); } if ( # ifdef _LIBC convd->conv != (__gconv_t) -1 # else # if HAVE_ICONV convd->conv != (iconv_t) -1 # endif # endif ) { /* We are supposed to do a conversion. First allocate an appropriate table with the same structure as the table of translations in the file, where we can put the pointers to the converted strings in. There is a slight complication with plural entries. They are represented by consecutive NUL terminated strings. We handle this case by converting RESULTLEN bytes, including NULs. */ if (convd->conv_tab == NULL && ((convd->conv_tab = (char **) calloc (nstrings + domain->n_sysdep_strings, sizeof (char *))) == NULL)) /* Mark that we didn't succeed allocating a table. */ convd->conv_tab = (char **) -1; if (__builtin_expect (convd->conv_tab == (char **) -1, 0)) /* Nothing we can do, no more memory. We cannot use the translation because it might be encoded incorrectly. */ return (char *) -1; if (convd->conv_tab[act] == NULL) { /* We haven't used this string so far, so it is not translated yet. Do this now. */ /* We use a bit more efficient memory handling. We allocate always larger blocks which get used over time. This is faster than many small allocations. */ __libc_lock_define_initialized (static, lock) # define INITIAL_BLOCK_SIZE 4080 static unsigned char *freemem; static size_t freemem_size; const unsigned char *inbuf; unsigned char *outbuf; int malloc_count; # ifndef _LIBC transmem_block_t *transmem_list = NULL; # endif __libc_lock_lock (lock); inbuf = (const unsigned char *) result; outbuf = freemem + sizeof (size_t); malloc_count = 0; while (1) { transmem_block_t *newmem; # ifdef _LIBC size_t non_reversible; int res; if (freemem_size < sizeof (size_t)) goto resize_freemem; res = __gconv (convd->conv, &inbuf, inbuf + resultlen, &outbuf, outbuf + freemem_size - sizeof (size_t), &non_reversible); if (res == __GCONV_OK || res == __GCONV_EMPTY_INPUT) break; if (res != __GCONV_FULL_OUTPUT) { /* We should not use the translation at all, it is incorrectly encoded. */ __libc_lock_unlock (lock); return NULL; } inbuf = (const unsigned char *) result; # else # if HAVE_ICONV const char *inptr = (const char *) inbuf; size_t inleft = resultlen; char *outptr = (char *) outbuf; size_t outleft; if (freemem_size < sizeof (size_t)) goto resize_freemem; outleft = freemem_size - sizeof (size_t); if (iconv (convd->conv, (ICONV_CONST char **) &inptr, &inleft, &outptr, &outleft) != (size_t) (-1)) { outbuf = (unsigned char *) outptr; break; } if (errno != E2BIG) { __libc_lock_unlock (lock); return NULL; } # endif # endif resize_freemem: /* We must allocate a new buffer or resize the old one. */ if (malloc_count > 0) { ++malloc_count; freemem_size = malloc_count * INITIAL_BLOCK_SIZE; newmem = (transmem_block_t *) realloc (transmem_list, freemem_size); # ifdef _LIBC if (newmem != NULL) transmem_list = transmem_list->next; else { struct transmem_list *old = transmem_list; transmem_list = transmem_list->next; free (old); } # endif } else { malloc_count = 1; freemem_size = INITIAL_BLOCK_SIZE; newmem = (transmem_block_t *) malloc (freemem_size); } if (__builtin_expect (newmem == NULL, 0)) { freemem = NULL; freemem_size = 0; __libc_lock_unlock (lock); return (char *) -1; } # ifdef _LIBC /* Add the block to the list of blocks we have to free at some point. */ newmem->next = transmem_list; transmem_list = newmem; freemem = (unsigned char *) newmem->data; freemem_size -= offsetof (struct transmem_list, data); # else transmem_list = newmem; freemem = newmem; # endif outbuf = freemem + sizeof (size_t); } /* We have now in our buffer a converted string. Put this into the table of conversions. */ *(size_t *) freemem = outbuf - freemem - sizeof (size_t); convd->conv_tab[act] = (char *) freemem; /* Shrink freemem, but keep it aligned. */ freemem_size -= outbuf - freemem; freemem = outbuf; freemem += freemem_size & (alignof (size_t) - 1); freemem_size = freemem_size & ~ (alignof (size_t) - 1); __libc_lock_unlock (lock); } /* Now convd->conv_tab[act] contains the translation of all the plural variants. */ result = convd->conv_tab[act] + sizeof (size_t); resultlen = *(size_t *) convd->conv_tab[act]; } } /* The result string is converted. */ #endif /* _LIBC || HAVE_ICONV */ *lengthp = resultlen; return result; } /* Look up a plural variant. */ static char * internal_function plural_lookup (struct loaded_l10nfile *domain, unsigned long int n, const char *translation, size_t translation_len) { struct loaded_domain *domaindata = (struct loaded_domain *) domain->data; unsigned long int index; const char *p; index = plural_eval (domaindata->plural, n); if (index >= domaindata->nplurals) /* This should never happen. It means the plural expression and the given maximum value do not match. */ index = 0; /* Skip INDEX strings at TRANSLATION. */ p = translation; while (index-- > 0) { #ifdef _LIBC p = __rawmemchr (p, '\0'); #else p = strchr (p, '\0'); #endif /* And skip over the NUL byte. */ p++; if (p >= translation + translation_len) /* This should never happen. It means the plural expression evaluated to a value larger than the number of variants available for MSGID1. */ return (char *) translation; } return (char *) p; } #ifndef _LIBC /* Return string representation of locale CATEGORY. */ static const char * internal_function category_to_name (int category) { const char *retval; switch (category) { #ifdef LC_COLLATE case LC_COLLATE: retval = "LC_COLLATE"; break; #endif #ifdef LC_CTYPE case LC_CTYPE: retval = "LC_CTYPE"; break; #endif #ifdef LC_MONETARY case LC_MONETARY: retval = "LC_MONETARY"; break; #endif #ifdef LC_NUMERIC case LC_NUMERIC: retval = "LC_NUMERIC"; break; #endif #ifdef LC_TIME case LC_TIME: retval = "LC_TIME"; break; #endif #ifdef LC_MESSAGES case LC_MESSAGES: retval = "LC_MESSAGES"; break; #endif #ifdef LC_RESPONSE case LC_RESPONSE: retval = "LC_RESPONSE"; break; #endif #ifdef LC_ALL case LC_ALL: /* This might not make sense but is perhaps better than any other value. */ retval = "LC_ALL"; break; #endif default: /* If you have a better idea for a default value let me know. */ retval = "LC_XXX"; } return retval; } #endif /* Guess value of current locale from value of the environment variables or system-dependent defaults. */ static const char * internal_function #ifdef IN_LIBGLOCALE guess_category_value (int category, const char *categoryname, const char *locale) #else guess_category_value (int category, const char *categoryname) #endif { const char *language; #ifndef IN_LIBGLOCALE const char *locale; # ifndef _LIBC const char *language_default; int locale_defaulted; # endif #endif /* We use the settings in the following order: 1. The value of the environment variable 'LANGUAGE'. This is a GNU extension. Its value can be a colon-separated list of locale names. 2. The value of the environment variable 'LC_ALL', 'LC_xxx', or 'LANG'. More precisely, the first among these that is set to a non-empty value. This is how POSIX specifies it. The value is a single locale name. 3. A system-dependent preference list of languages. Its value can be a colon-separated list of locale names. 4. A system-dependent default locale name. This way: - System-dependent settings can be overridden by environment variables. - If the system provides both a list of languages and a default locale, the former is used. */ #ifndef IN_LIBGLOCALE /* Fetch the locale name, through the POSIX method of looking to `LC_ALL', `LC_xxx', and `LANG'. On some systems this can be done by the `setlocale' function itself. */ # ifdef _LIBC locale = __current_locale_name (category); # else # if HAVE_STRUCT___LOCALE_STRUCT___NAMES && defined USE_IN_GETTEXT_TESTS /* The __names field is not public glibc API and must therefore not be used in code that is installed in public locations. */ locale_t thread_locale = uselocale (NULL); if (thread_locale != LC_GLOBAL_LOCALE) { locale = thread_locale->__names[category]; locale_defaulted = 0; } else # endif { locale = _nl_locale_name_posix (category, categoryname); locale_defaulted = 0; if (locale == NULL) { locale = _nl_locale_name_default (); locale_defaulted = 1; } } # endif #endif /* Ignore LANGUAGE and its system-dependent analogon if the locale is set to "C" because 1. "C" locale usually uses the ASCII encoding, and most international messages use non-ASCII characters. These characters get displayed as question marks (if using glibc's iconv()) or as invalid 8-bit characters (because other iconv()s refuse to convert most non-ASCII characters to ASCII). In any case, the output is ugly. 2. The precise output of some programs in the "C" locale is specified by POSIX and should not depend on environment variables like "LANGUAGE" or system-dependent information. We allow such programs to use gettext(). */ if (strcmp (locale, "C") == 0) return locale; /* The highest priority value is the value of the 'LANGUAGE' environment variable. */ language = getenv ("LANGUAGE"); if (language != NULL && language[0] != '\0') return language; #if !defined IN_LIBGLOCALE && !defined _LIBC /* The next priority value is the locale name, if not defaulted. */ if (locale_defaulted) { /* The next priority value is the default language preferences list. */ language_default = _nl_language_preferences_default (); if (language_default != NULL) return language_default; } /* The least priority value is the locale name, if defaulted. */ #endif return locale; } #if (defined _LIBC || HAVE_ICONV) && !defined IN_LIBGLOCALE /* Returns the output charset. */ static const char * internal_function get_output_charset (struct binding *domainbinding) { /* The output charset should normally be determined by the locale. But sometimes the locale is not used or not correctly set up, so we provide a possibility for the user to override this: the OUTPUT_CHARSET environment variable. Moreover, the value specified through bind_textdomain_codeset overrides both. */ if (domainbinding != NULL && domainbinding->codeset != NULL) return domainbinding->codeset; else { /* For speed reasons, we look at the value of OUTPUT_CHARSET only once. This is a user variable that is not supposed to change during a program run. */ static char *output_charset_cache; static int output_charset_cached; if (!output_charset_cached) { const char *value = getenv ("OUTPUT_CHARSET"); if (value != NULL && value[0] != '\0') { size_t len = strlen (value) + 1; char *value_copy = (char *) malloc (len); if (value_copy != NULL) memcpy (value_copy, value, len); output_charset_cache = value_copy; } output_charset_cached = 1; } if (output_charset_cache != NULL) return output_charset_cache; else { # ifdef _LIBC return _NL_CURRENT (LC_CTYPE, CODESET); # else # if HAVE_ICONV return locale_charset (); # endif # endif } } } #endif /* @@ begin of epilog @@ */ /* We don't want libintl.a to depend on any other library. So we avoid the non-standard function stpcpy. In GNU C Library this function is available, though. Also allow the symbol HAVE_STPCPY to be defined. */ #if !_LIBC && !HAVE_STPCPY static char * stpcpy (char *dest, const char *src) { while ((*dest++ = *src++) != '\0') /* Do nothing. */ ; return dest - 1; } #endif #if !_LIBC && !HAVE_MEMPCPY static void * mempcpy (void *dest, const void *src, size_t n) { return (void *) ((char *) memcpy (dest, src, n) + n); } #endif #if !_LIBC && !HAVE_TSEARCH # include "tsearch.c" #endif #ifdef _LIBC /* If we want to free all resources we have to do some work at program's end. */ libc_freeres_fn (free_mem) { void *old; while (_nl_domain_bindings != NULL) { struct binding *oldp = _nl_domain_bindings; _nl_domain_bindings = _nl_domain_bindings->next; if (oldp->dirname != _nl_default_dirname) /* Yes, this is a pointer comparison. */ free (oldp->dirname); free (oldp->codeset); free (oldp); } if (_nl_current_default_domain != _nl_default_default_domain) /* Yes, again a pointer comparison. */ free ((char *) _nl_current_default_domain); /* Remove the search tree with the known translations. */ __tdestroy (root, free); root = NULL; while (transmem_list != NULL) { old = transmem_list; transmem_list = transmem_list->next; free (old); } } #endif libnih-1.0.3/compile0000755000175000017500000000727111461165303011266 00000000000000#! /bin/sh # Wrapper for compilers which do not understand `-c -o'. scriptversion=2009-10-06.20; # UTC # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009 Free Software # Foundation, Inc. # Written by Tom Tromey . # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # This file is maintained in Automake, please report # bugs to or send patches to # . case $1 in '') echo "$0: No command. Try \`$0 --help' for more information." 1>&2 exit 1; ;; -h | --h*) cat <<\EOF Usage: compile [--help] [--version] PROGRAM [ARGS] Wrapper for compilers which do not understand `-c -o'. Remove `-o dest.o' from ARGS, run PROGRAM with the remaining arguments, and rename the output as expected. If you are trying to build a whole package this is not the right script to run: please start by reading the file `INSTALL'. Report bugs to . EOF exit $? ;; -v | --v*) echo "compile $scriptversion" exit $? ;; esac ofile= cfile= eat= for arg do if test -n "$eat"; then eat= else case $1 in -o) # configure might choose to run compile as `compile cc -o foo foo.c'. # So we strip `-o arg' only if arg is an object. eat=1 case $2 in *.o | *.obj) ofile=$2 ;; *) set x "$@" -o "$2" shift ;; esac ;; *.c) cfile=$1 set x "$@" "$1" shift ;; *) set x "$@" "$1" shift ;; esac fi shift done if test -z "$ofile" || test -z "$cfile"; then # If no `-o' option was seen then we might have been invoked from a # pattern rule where we don't need one. That is ok -- this is a # normal compilation that the losing compiler can handle. If no # `.c' file was seen then we are probably linking. That is also # ok. exec "$@" fi # Name of file we expect compiler to create. cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` # Create the lock directory. # Note: use `[/\\:.-]' here to ensure that we don't use the same name # that we are using for the .o file. Also, base the name on the expected # object file name, since that is what matters with a parallel build. lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d while true; do if mkdir "$lockdir" >/dev/null 2>&1; then break fi sleep 1 done # FIXME: race condition here if user kills between mkdir and trap. trap "rmdir '$lockdir'; exit 1" 1 2 15 # Run the compile. "$@" ret=$? if test -f "$cofile"; then test "$cofile" = "$ofile" || mv "$cofile" "$ofile" elif test -f "${cofile}bj"; then test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" fi rmdir "$lockdir" exit $ret # Local Variables: # mode: shell-script # sh-indentation: 2 # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: libnih-1.0.3/NEWS0000644000175000017500000003623011504742346010412 000000000000001.0.3 2010-12-23 * Support for passing file descriptors over D-Bus added to nih-dbus-tool. Due to code limitations, to avoid leaking the file descriptor in case of error it must be the last input argument to any method being implemented and within your function you are responsible for closing it on error. 1.0.2 2010-04-27 * AC_COPYRIGHT wrapper renamed to NIH_COPYRIGHT. (Bug: #519278) * Serial added to libnih.m4 to stop aclocal overwriting a local copy with an older installed copy. * NIH_WITH_LOCAL_LIBNIH macro added that can be used by external sources to add a --with-local-libnih configure argument. 1.0.1 2010-02-04 * Add missing __nih_* symbols to the linker version script, otherwise software using TEST_ALLOC_FAIL cannot be compiled (like Upstart). * The glibc __abort_msg symbol is now only linked as a weak reference, if your C library does not have the symbol, libnih will still work. 1.0.0 2009-11-28 * libnih is no longer intended to be copied into an application source tree and linked statically, but is now installed onto the system and dynamically linked normally. The nihify script has been removed accordingly. * Future 1.0.x versions will contain bug fixes, but no API or ABI changes. Future 1.x.0 versions may introduce new things to the API or ABI but will be backwards compatible with previous versions. Future x.0.0 versions will not be backwards compatible. * The NIH_INIT macro has been removed, to check for libnih or libnih-dbus you should now use pkg-config, e.g.: PKG_CHECK_MODULES([NIH], [libnih >= 1.0.0]) any other checks should be added as necessary instead of relying on that macro to do them for you. * An external pre-built nih-dbus-tool may be used instead of the built copy by passing NIH_DBUS_TOOL to configure. If you are cross-compiling, this will be automatically searched for in the PATH and a warning output if it doesn't exist and you fail to specify it. (Bug: #426740) * nih_alloc() has been fixed to work on platforms with alignment greater than 4 bytes. (Bug: #436758) * nih_alloc() no longer permits objects to have zero references, passing NULL for the parent now creates a special reference from a NULL parent. * nih_discard() removes this special reference before checking whether remaining references free the object. * nih_ref() and nih_unref() may have NULL as the parent reference and add or remove the special reference respectively. * nih_ref() does not remove the NULL reference, you must now use nih_discard() or nih_local to construct floating objects. * Since nih_ref() may be used when parent is NULL, there's no reason for an nih_unref_only() function so it has been dropped; the following code is now perfectly safe: nih_ref (obj, new_parent); nih_unref (object, old_parent); * nih_alloc_parent() has changed again, now when passed NULL it only returns TRUE if the object has the special NULL parent. * TEST_ALLOC_PARENT() has likewise changed, restoring the previous behaviour that TEST_ALLOC_PARENT(ptr, NULL) tests whether it has the NULL parent. * The TEST_ALLOC_ORPHAN() macro has been dropped, objects may no longer have no parents. * A new TEST_ALLOC_NOT_PARENT() macro has been added that is the exact inverse of TEST_ALLOC_PARENT() * These changes solve the problem where the object "obj" in the following code would be freed, even though it was intended that it be a top-level object: obj = nih_new (NULL, Obj); nih_ref (obj, tmp_obj); nih_unref (obj, tmp_obj); This comes at a cost of breaking the previous behaviour where a NULL-parented object could be considered floating and ignored once referenced. This kind of code was brittle anyway and nih_local far better solves it, e.g. replace code such as: Obj *obj; obj = nih_new (NULL, Obj); func_that_will_ref (obj); with: nih_local Obj *obj = NULL; obj = nih_new (NULL, Obj); func_that_will_ref (obj); * nih_log_message() will set the glibc __abort_msg variable to any log message of NIH_LOG_FATAL priority or greater, this means that should you call abort() core dump analysers can retrieve the message; especially useful for nih_assert(). (Bug: #429411) * nih-dbus-tool generated code has been fixed so that when a method call function is called on a disconnected connection it returns a raised DBUS_ERROR_DISCONNECTED rather than causing an assertion error. (Bug: #477116) 0.3.2 2009-08-02 * D-Bus 1.2.16 is now required. * Fixed compilation on ia64. * nih-dbus-tool(1) manpage will not be installed, since the binary is not. (Bug: #403103) 0.3.1 2009-07-09 * The licence for libnih has been changed back to version 2 of the GNU GPL. * D-Bus 1.2.15 is now required, this is the current GIT HEAD pending a 1.2.16 release. * TEST_EXPECTED_STR and TEST_EXPECTED_FILE added. These compare the contents of a string and file respectively against the contents of a given filename relative to the "expected" directory alongside the test binary, e.g.: TEST_EXPECTED_STR (code, "foo.c"); in tests/test_foo will be TRUE if the contents of the C string "code" match the contents of the file tests/expected/foo.c * NihFileFilter (the function type passed to nih_dir_walk and nih_watch_new) now has an extra is_dir argument, this is set without calling stat() * NihTimer now uses a monotonic clock, so is unaffected by changes in the system clock; this means that you'll need to use clock_gettime (CLOCK_MONOTONIC) when manually adjusting the due time rather than time (). (Bug: #389589) * NihError may now be directly embedded into other structures with the NIH_ERROR_MEMBERS macro. * NihDBusError now directly embeds the members of NihError, there is no longer an "error" member, instead you can directly access "number" and "message" members. * NihDBusProxy has gained an auto_start member, TRUE by default. If you do not want method calls to automatically start a service, you may set this to FALSE after creating the proxy. nih-dbus-tool generated method calls will respect this flag. * nih_dbus_proxy_connect() no longer has both a parent and proxy argument, it now only takes the proxy and is always a child of it. * NihDBusProxySignal no longer has connection, name or path members and instead has a proxy member from which the values can be found. * nih_dbus_proxy_new() will now begin tracking any name given, even if there is no lost_handler passed. This (and the above changes) allows signal handlers to compare the sender of a signal (which is always a unique name) against the owner of the associated proxy. * Attempting to read from a D-Bus property that is write-only, or attempting to write to a D-Bus property that is read-only will now return the DBUS_ERROR_ACCESS_DENIED error rather than DBUS_ERROR_UNKNOWN_METHOD. * An empty com.netsplit.Nih.Symbol annotation is no longer permitted for D-Bus interfaces. Instead use the new --default-interface option to nih-dbus-tool. * nih-dbus-tool now properly supports structures, including arrays of structures and arrays of dictionary entries. The default naming of the structure is derived from the method or signal name and argument or the property name; the default naming of the members is "item0".."itemN". Structure definitions appear in the generated header file. * nih-dbus-tool now generates prefix_interface_get_all() and prefix_interface_get_all_sync() methods for each interface, these get the values of all of the properties and store them in a PrefixInterfaceProperties structure defined in the header file. * A side-effect of the above is that it's no longer possible to name properties after C keywords. 0.3.0 2009-06-17 * The licence for libnih has been changed to MIT/X11. * The --enable-compiler-warnings configure option has been extended to add -Wextra, but turns off a few of the more extreme warnings * TEST_FILE_MATCH() added to allow matching of a line in a file against a wildcard string * NIH_MUST(), NIH_ZERO() and NIH_SHOULD() now expand to an expression with the value of the expression inside. This means that the code like the following is now valid: ret = NIH_SHOULD (some_function_call ()); if (ret < 0) ... This style is preferred to the previous way of doing it (set ret inside the macro call) and the code has been updated. * nih_option_parser() fixed to not eat an argument containing a lone dash. * nih_error_raise_again() renamed to nih_error_raise_error(). * Errors are no longer removed from the context when you call nih_error_get(), this means that to clear the error you must free it and it's now a bug to call nih_error_raise_error() to raise it again. * Unhandled errors now result in an assertion error, rather than a log message being emitted. This assertion will include the filename, line number and function name where the error was originally raised. The assertion may be generated on exit from the program. * nih_option_help() produces slightly different output if the bug reporting address is a URL. * GNU C Library v2.4 (or backported inotify support) is required * D-Bus object and proxy interface structure definitions have been moved to nih-dbus/dbus_interface.h, this file is still included by nih-dbus/dbus_object.h and nih-dbus/dbus_proxy.h so there may be no need to include it directly. * nih_dbus_proxy_new() has additional arguments, a lost handler function which enables tracking of the owner of the well-known name, and a data pointer. NihDBusProxy has a new owner member which contains this. * Signals may be connected using nih_dbus_proxy_connect(), this requires both a handler function and an intermediate filter function. The NihDBusSignal structure gained a filter member to specify the latter. * The D-Bus binding tool has moved into a separate nih-dbus-tool subdirectory, and rewritten from Python to C. * The D-Bus binding tool now uses annotations rather than XML namespaced attributes to adjust the output: - set com.netsplit.Nih.Method.Async to "true" instead of using nih:object="async" - com.netsplit.Nih.Symbol may be used to override C symbol name generation - org.freedesktop.DBus.Deprecated results in a deprecated attribute on external API * Function names generated by the D-Bus binding tool now include the last element of the interface name; my_method() would now be named my_interface_method(). The interface name can be ommitted by setting the com.netsplit.Nih.Symbol annotation to "" * Proxy method functions are now asynchronous by default, the synchronous version has _sync() appended to its name. * Signal function names now always include "emit" in them. * Signal filter functions are generated by the binding tool for use with nih_dbus_proxy_connect() * Get and Set access functions are now generated for properties, and in object mode are expected to be provided. * Arrays of arrays are now fully supported; if the array is an array of basic types, the function will have two arguments; a NULL-terminated array of arrays, and a second NULL-terminated array of those array lengths. This is supported to infinite depths. * D-Bus 1.2.4 is now required. * pkg-config 0.22 is now required, it probably was anyway but we now explicitly check for it. * Dependency on Python for the D-Bus binding tool has been dropped and replaced with a dependency on expat 2.0.0 * The NIH_DBUS_ERROR and NIH_DBUS_INVALID_ARGS error enums have been moved to nih-dbus/errors.h 0.2.0 2009-01-29 * nih_alloc_set_allocator() is now a macro that casts the function to the right typedef, so such casts are no longer needed * nih_alloc() now permits multiple parent references - nih_ref(ptr, parent) creates a new parent reference - nih_unref(ptr, parent) drops a reference and frees if the last - nih_unref_only(ptr, parent) drops a reference without freeing - nih_free() unconditionally frees as it always has - nih_discard() only frees if there are no references * nih_local may be added to variable definitions to have the pointer automatically discarded when it goes out of scope, unless it is referenced in the meantime: { nih_local char *str = NULL; str = nih_strdup (NULL, "some string"); pass_to_func (str); } * nih_alloc_reparent() has been dropped, it can be replaced with an nih_unref_only()/nih_ref() pair - however many uses of this are no longer necessary and it's worth taking some time to refactor the code. * nih_alloc_parent() has changed; it now accepts both an object ptr and a parent and returns TRUE if the object has that parent, if parent is NULL is returns TRUE of the object has any parent. (previously it was used to return _the_ parent). * TEST_ALLOC_PARENT() now behaves as nih_alloc_parent(), which means testing for no parent with NULL has the exact opposite behaviour use the new TEST_ALLOC_ORPHAN(ptr) macro instead. * nih_str_array_addp() now references the passed pointer, instead of reparenting it. Calling code should be modified to make sure it either calls nih_discard() or uses nih_local to be safe in case of error. * nih_strv_free() has been dropped since it did not match the behaviour of the other functions * new NIH_LIST_ITER(iter, type, member) macro to handle the case of an offset head in an iterated structure * nih_hash_pointer_new(), nih_hash_pointer_key(), nih_hash_pointer_hash() and nih_hash_pointer_cmp() have been dropped since they did strange things to pointers that probably aren't legal C. * nih_config_parse() now reads the file into memory, instead of using mmap(). The API is unchanged, however the errors may be different. * The D-Bus bindings have been moved into a separate sub-directory and split out into multiple files. You will need to update your includes as follows: - NihDBusError and nih_dbus_error_*() are in nih-dbus/dbus_error.h - nih_dbus_connect(), nih_dbus_bus(), nih_dbus_setup() and nih_dbus_server() are in nih-dbus/dbus_connection.h - NihDBusMessage and nih_dbus_message_*() are in nih-dbus/dbus_message.h - NihDBusObject, NihDBusInterface and nih_dbus_object_new() are in nih-dbus/dbus_object.h - NihDBusProxy and nih_dbus_proxy_new() are in nih-dbus/dbus_proxy.h - nih_dbus_path() is now in nih-dbus/dbus_util.h * The D-Bus test macros are now in nih-dbus/test_dbus.h * nih_dbus_message_new() now exists as a function in its own right * Asynchronous method callbacks must take a reference to the NihDBusMessage object they are passed, otherwise it will be freed * Reply functions and nih_dbus_message_error() no longer free the message passed in, this is consistent with the above change. * libtool 2.2.4 is now required * The MIN() and MAX() macros are no longer defined, instead use nih_min() and nih_max() which do not re-evaluate their parameters multiple times. * The nih_main_package_string() function has been dropped, instead just access the package_string global set by nih_main_init_full() 0.1.0 2008-10-24 * Initial public release. libnih-1.0.3/nih-dbus/0000755000175000017500000000000011504742362011476 500000000000000libnih-1.0.3/nih-dbus/dbus_pending_data.h0000644000175000017500000000751111445765555015242 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_PENDING_DATA_H #define NIH_DBUS_PENDING_DATA_H /** * NihDBusPendingData structures may be attached as the data member to a * DBusPendingCall to pass information to the notify function about the * connection the message was sent on, and the reply and error handlers * to be used. * * This is primarily used by code generated by nih-dbus-tool, which * calls nih_dbus_pending_data_new() in the method call function and * expects the structure to be passed to the notify function it sets on * the pending call. * * You may wish to use it in your own equivalent code. **/ #include #include #include /** * NihDBusReplyHandler: * @data: data pointer passed to nih_dbus_pending_data_new(), * @message: NihDBusMessage context for reply (including connection): * * A D-Bus Reply Handler is expected to handle the receipt of a validated * reply to a method call, generally they will be called with additional * arguments representing the demarshalled data from the D-Bus reply * message itself. * * @message is a context containing both the connection the reply was * received on, and the reply message itself (which may have additional * data or flags). **/ typedef void (*NihDBusReplyHandler) (void *data, NihDBusMessage *message, ...); /** * NihDBusErrorHandler: * @data: data pointer passed to nih_dbus_pending_data_new(), * @message: NihDBusMessage context for reply (including connection): * * A D-Bus Error Handler is expected to handle the receipt of an error * reply to a method call, or the receipt of an invalid reply. The * error to be handled is raised when the handler is called; for a * reply received from the server it will be NIH_DBUS_ERROR, for the * receipt of an invalid reply it will be NIH_DBUS_INVALID_ARGS. * * @message is a context containing both the connection the reply was * received on, and the reply message itself (which may have additional * data or flags). **/ typedef void (*NihDBusErrorHandler) (void *data, NihDBusMessage *message); /** * NihDBusPendingData: * @connection: D-Bus connection message message is pending on, * @handler: function to handle a valid reply, * @error_handler: function to handle errors, * @data: data to pass to @handler and @error_handler. * * This structure is used as a context for the processing of a message; the * primary reason for its existance is to be used as an nih_alloc() context * for any reply data. * * Instances are allocated automatically and passed to marshaller functions, * and freed on their return. **/ typedef struct nih_dbus_pending_data { DBusConnection * connection; NihDBusReplyHandler handler; NihDBusErrorHandler error_handler; void * data; } NihDBusPendingData; NIH_BEGIN_EXTERN NihDBusPendingData *nih_dbus_pending_data_new (const void *parent, DBusConnection *connection, NihDBusReplyHandler handler, NihDBusErrorHandler error_handler, void *data) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_PENDING_DATA_H */ libnih-1.0.3/nih-dbus/libnih-dbus.ver0000644000175000017500000000007111445765555014347 00000000000000LIBNIH_DBUS_1_0 { global: nih_dbus_*; local: *; }; libnih-1.0.3/nih-dbus/dbus_pending_data.c0000644000175000017500000000572711445765555015244 00000000000000/* libnih * * dbus_pending_data.c - D-Bus pending call attached data * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include "dbus_pending_data.h" /* Prototypes for static functions */ static int nih_dbus_pending_data_destroy (NihDBusPendingData *pending_data); /** * nih_dbus_pending_data_new: * @parent: parent object for new structure, * @connection: D-Bus connection to associate with, * @message: D-Bus message to encapulsate. * * Creates a new D-Bus pending call data object allocated using * nih_alloc(). You would then use this as the data pointer of a * DBusPendingCall to be passed to the notify function. The structure * contains a reference to the underlying D-Bus connection and details * about the handler functions and user data pointer. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned object. When all parents * of the returned object are freed, the returned object will also be * freed. * * Returns: new NihDBusPendingData structure, or NULL if insufficient memory. **/ NihDBusPendingData * nih_dbus_pending_data_new (const void * parent, DBusConnection * connection, NihDBusReplyHandler handler, NihDBusErrorHandler error_handler, void * data) { NihDBusPendingData *pending_data; nih_assert (connection != NULL); nih_assert (error_handler != NULL); pending_data = nih_new (parent, NihDBusPendingData); if (! pending_data) return NULL; pending_data->connection = connection; dbus_connection_ref (pending_data->connection); pending_data->handler = handler; pending_data->error_handler = error_handler; pending_data->data = data; nih_alloc_set_destructor (pending_data, nih_dbus_pending_data_destroy); return pending_data; } /** * nih_dbus_pending_data_destroy: * @pending_data: pending data to be destroyed. * * Unreferences the attached D-Bus connection. * * Returns: zero **/ static int nih_dbus_pending_data_destroy (NihDBusPendingData *pending_data) { nih_assert (pending_data != NULL); dbus_connection_unref (pending_data->connection); return 0; } libnih-1.0.3/nih-dbus/libnih-dbus.supp0000644000175000017500000000273511445765555014553 00000000000000# This is a valgrind suppressions file. # See nih/libnih.supp for common patterns. # These suppressions all assume that your libdbus is compiled with the # --enable-verbose-mode --enable-tests --enable-asserts options, without # compiler optimisation, and installed unstripped. # D-Bus keeps its connection slots around forever, even after a # dbus_shutdown() { dbus-data-slot-allocator-alloc Memcheck:Leak fun:realloc fun:_dbus_data_slot_allocator_alloc } { dbus-data-slot-allocator-alloc Memcheck:Leak fun:malloc fun:realloc fun:dbus_realloc fun:_dbus_data_slot_allocator_alloc } { dbus-data-slot-allocator-alloc Memcheck:Leak fun:realloc fun:dbus_realloc fun:_dbus_data_slot_allocator_alloc } { dbus-data-slot-allocator-alloc Memcheck:Leak fun:realloc obj:/lib/libdbus-1.so.* fun:nih_dbus_server } # It looks like glibc caches NSS lookup information, so it always looks # like we leak it. Missing valgrind default suppression perhaps? { nss-lookup-function Memcheck:Leak fun:malloc fun:__nss_lookup_function } { nss-lookup-function Memcheck:Leak fun:malloc fun:tsearch fun:__nss_lookup_function } { nss-database-lookup Memcheck:Leak fun:malloc fun:nss_parse_service_list fun:__nss_database_lookup } { nss-database-lookup Memcheck:Leak fun:malloc obj:/lib/libc-*.so fun:__nss_database_lookup } { nss-database-lookup Memcheck:Leak fun:malloc obj:/lib/tls/i686/cmov/libc-*.so fun:__nss_database_lookup } libnih-1.0.3/nih-dbus/dbus_object.c0000644000175000017500000007046011445765555014071 00000000000000/* libnih * * dbus_object.c - D-Bus local object implementation * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include #include #include "dbus_object.h" /* Prototypes for static functions */ static int nih_dbus_object_destroy (NihDBusObject *object); static void nih_dbus_object_unregister (DBusConnection *connection, NihDBusObject *object); static DBusHandlerResult nih_dbus_object_message (DBusConnection *connection, DBusMessage *message, NihDBusObject *object); static DBusHandlerResult nih_dbus_object_introspect (DBusConnection *connection, DBusMessage *message, NihDBusObject *object); static DBusHandlerResult nih_dbus_object_property_get (DBusConnection *connection, DBusMessage *message, NihDBusObject *object); static DBusHandlerResult nih_dbus_object_property_get_all (DBusConnection *connection, DBusMessage *message, NihDBusObject *object); static DBusHandlerResult nih_dbus_object_property_set (DBusConnection *connection, DBusMessage *message, NihDBusObject *object); /** * nih_dbus_object_vtable: * * Table of functions for handling D-Bus objects. **/ static const DBusObjectPathVTable nih_dbus_object_vtable = { (DBusObjectPathUnregisterFunction)nih_dbus_object_unregister, (DBusObjectPathMessageFunction)nih_dbus_object_message, NULL, }; /** * nih_dbus_object_new: * @parent: parent object for new object, * @connection: D-Bus connection to associate with, * @path: path of object, * @interfaces: interfaces list to attach, * @data: data pointer. * * Creates a new D-Bus object with the attached list of @interfaces which * specify the methods, signals and properties that object will export * and the C functions that will handle them. * * @interfaces should be a NULL-terminated array of pointers to * NihDBusInterface structures. Normally this is constructed using pointers * to structures defined by nih-dbus-tool which provides all the necessary * glue arrays and functions. * * The object structure is allocated using nih_alloc() and connected to * the given @connection, it can be unregistered by freeing it and it will be * automatically unregistered should @connection be disconnected. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned object. When all parents * of the returned object are freed, the returned object will also be * freed. * * Returns: new NihDBusObject structure on success, or NULL if * insufficient memory. **/ NihDBusObject * nih_dbus_object_new (const void * parent, DBusConnection * connection, const char * path, const NihDBusInterface **interfaces, void * data) { NihDBusObject *object; nih_assert (connection != NULL); nih_assert (path != NULL); nih_assert (interfaces != NULL); object = nih_new (parent, NihDBusObject); if (! object) return NULL; object->path = nih_strdup (object, path); if (! object->path) { nih_free (object); return NULL; } /* We don't reference the connection, it's only used to unregister * the object when freed directly; in addition, we get called if * the connection is freed and discard this object - and don't want * to block that happening. */ object->connection = connection; object->data = data; object->interfaces = interfaces; object->registered = FALSE; if (! dbus_connection_register_object_path (object->connection, object->path, &nih_dbus_object_vtable, object)) { nih_free (object); return NULL; } object->registered = TRUE; nih_alloc_set_destructor (object, nih_dbus_object_destroy); return object; } /** * nih_dbus_object_destroy: * @object: D-Bus object being destroyed. * * Destructor function for an NihDBusObject structure, ensures that it * is unregistered from the attached D-Bus connection and path. * * Returns: always zero. **/ static int nih_dbus_object_destroy (NihDBusObject *object) { nih_assert (object != NULL); if (object->registered) { object->registered = FALSE; dbus_connection_unregister_object_path (object->connection, object->path); } return 0; } /** * nih_dbus_object_unregister: * @connection: D-Bus connection, * @object: D-Bus object to destroy. * * Called by D-Bus to unregister the @object attached to the D-Bus connection * @connection, requires us to free the attached structure. **/ static void nih_dbus_object_unregister (DBusConnection *connection, NihDBusObject * object) { nih_assert (connection != NULL); nih_assert (object != NULL); nih_assert (object->connection == connection); if (object->registered) { object->registered = FALSE; nih_free (object); } } /** * nih_dbus_object_message: * @connection: D-Bus connection, * @message: D-Bus message received, * @object: Object that received the message. * * Called by D-Bus when a @message is received for a registered @object. We * handle messages related to introspection and properties ourselves, * otherwise the method invoked is located in the @object's interfaces array * and the handler function called to handle it. * * Returns: result of handling the message. **/ static DBusHandlerResult nih_dbus_object_message (DBusConnection *connection, DBusMessage * message, NihDBusObject * object) { const NihDBusInterface **interface; nih_assert (connection != NULL); nih_assert (message != NULL); nih_assert (object != NULL); nih_assert (object->connection == connection); /* Handle introspection internally */ if (dbus_message_is_method_call ( message, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) return nih_dbus_object_introspect (connection, message, object); /* Handle properties semi-internally */ if (dbus_message_is_method_call ( message, DBUS_INTERFACE_PROPERTIES, "Get")) return nih_dbus_object_property_get (connection, message, object); if (dbus_message_is_method_call ( message, DBUS_INTERFACE_PROPERTIES, "Set")) return nih_dbus_object_property_set (connection, message, object); if (dbus_message_is_method_call ( message, DBUS_INTERFACE_PROPERTIES, "GetAll")) return nih_dbus_object_property_get_all (connection, message, object); /* No built-in handling, locate a handler function in the defined * interfaces that can handle it. */ for (interface = object->interfaces; interface && *interface; interface++) { const NihDBusMethod *method; for (method = (*interface)->methods; method && method->name; method++) { nih_assert (method->handler != NULL); if (dbus_message_is_method_call (message, (*interface)->name, method->name)) { nih_local NihDBusMessage *msg = NULL; DBusHandlerResult result; msg = nih_dbus_message_new (NULL, connection, message); if (! msg) return DBUS_HANDLER_RESULT_NEED_MEMORY; nih_error_push_context (); result = method->handler (object, msg); nih_error_pop_context (); if (result != DBUS_HANDLER_RESULT_NOT_YET_HANDLED) return result; } } } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /** * nih_dbus_object_introspect: * @connection: D-Bus connection, * @message: D-Bus message received, * @object: Object that received the message. * * Called because the D-Bus introspection method has been invoked on @object, * we return an XML description of the object's interfaces, methods, signals * and properties based on its interfaces array. * * Returns: result of handling the message. **/ static DBusHandlerResult nih_dbus_object_introspect (DBusConnection *connection, DBusMessage * message, NihDBusObject * object) { const NihDBusInterface **interface; nih_local char * xml = NULL; char ** children = NULL; char ** child; DBusMessage * reply = NULL; int have_props = FALSE; nih_assert (connection != NULL); nih_assert (message != NULL); nih_assert (object != NULL); nih_assert (object->connection == connection); /* Make sure the message signature was what we expected */ if (! dbus_message_has_signature (message, "")) { reply = dbus_message_new_error (message, DBUS_ERROR_INVALID_ARGS, _("Invalid arguments to Introspect method")); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } xml = nih_strdup (NULL, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE); if (! xml) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Root node */ if (! nih_strcat_sprintf (&xml, NULL, "\n", object->path)) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Add each interface definition */ for (interface = object->interfaces; interface && *interface; interface++) { const NihDBusMethod * method; const NihDBusSignal * signal; const NihDBusProperty *property; if (! nih_strcat_sprintf (&xml, NULL, " \n", (*interface)->name)) return DBUS_HANDLER_RESULT_NEED_MEMORY; for (method = (*interface)->methods; method && method->name; method++) { const NihDBusArg *arg; if (! nih_strcat_sprintf (&xml, NULL, " \n", method->name)) return DBUS_HANDLER_RESULT_NEED_MEMORY; for (arg = method->args; arg && arg->type; arg++) { if (! nih_strcat_sprintf ( &xml, NULL, " name) if (! nih_strcat_sprintf ( &xml, NULL, " name=\"%s\"", arg->name)) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! nih_strcat_sprintf ( &xml, NULL, " type=\"%s\"" " direction=\"%s\"/>\n", arg->type, (arg->dir == NIH_DBUS_ARG_IN ? "in" : "out"))) return DBUS_HANDLER_RESULT_NEED_MEMORY; } if (! nih_strcat (&xml, NULL, " \n")) return DBUS_HANDLER_RESULT_NEED_MEMORY; } for (signal = (*interface)->signals; signal && signal->name; signal++) { const NihDBusArg *arg; if (! nih_strcat_sprintf (&xml, NULL, " \n", signal->name)) return DBUS_HANDLER_RESULT_NEED_MEMORY; for (arg = signal->args; arg && arg->type; arg++) { if (! nih_strcat_sprintf ( &xml, NULL, " name) if (! nih_strcat_sprintf ( &xml, NULL, " name=\"%s\"", arg->name)) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! nih_strcat_sprintf ( &xml, NULL, " type=\"%s\"/>\n", arg->type)) return DBUS_HANDLER_RESULT_NEED_MEMORY; } if (! nih_strcat (&xml, NULL, " \n")) return DBUS_HANDLER_RESULT_NEED_MEMORY; } for (property = (*interface)->properties; property && property->name; property++) { have_props = TRUE; if (! nih_strcat_sprintf ( &xml, NULL, " \n", property->name, property->type, (property->access == NIH_DBUS_READ ? "read" : (property->access == NIH_DBUS_WRITE ? "write" : "readwrite")))) return DBUS_HANDLER_RESULT_NEED_MEMORY; } if (! nih_strcat (&xml, NULL, " \n")) return DBUS_HANDLER_RESULT_NEED_MEMORY; } /* We may also support properties, but don't want to announce that * unless we really do have some. */ if (have_props) if (! nih_strcat_sprintf ( &xml, NULL, " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n", DBUS_INTERFACE_PROPERTIES)) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Obviously we support introspection */ if (! nih_strcat_sprintf (&xml, NULL, " \n" " \n" " \n" " \n" " \n", DBUS_INTERFACE_INTROSPECTABLE)) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Add node items for children */ if (! dbus_connection_list_registered (connection, object->path, &children)) return DBUS_HANDLER_RESULT_NEED_MEMORY; for (child = children; *child; child++) { if (! nih_strcat_sprintf (&xml, NULL, " \n", *child)) { dbus_free_string_array (children); return DBUS_HANDLER_RESULT_NEED_MEMORY; } } if (! nih_strcat (&xml, NULL, "\n")) { dbus_free_string_array (children); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_free_string_array (children); /* Generate and send the reply */ reply = dbus_message_new_method_return (message); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_message_append_args (reply, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } if (! dbus_connection_send (connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /** * nih_dbus_object_property_get: * @connection: D-Bus connection, * @message: D-Bus message received, * @object: Object that received the message. * * Called because the D-Bus properties Get method has been invoked on * @object We locate the property in the @object's interfaces array and * call the getter function to append a variant onto the reply we * generate. * * Returns: result of handling the message. **/ static DBusHandlerResult nih_dbus_object_property_get (DBusConnection *connection, DBusMessage * message, NihDBusObject * object) { DBusMessage * reply; DBusMessageIter iter; const char * interface_name; const char * property_name; const NihDBusInterface **interface; nih_assert (connection != NULL); nih_assert (message != NULL); nih_assert (object != NULL); nih_assert (object->connection == connection); /* Retrieve the requested interface and property names from the * method call, first making sure the message signature was what * we expected. */ if (! dbus_message_has_signature (message, (DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING))) { reply = dbus_message_new_error (message, DBUS_ERROR_INVALID_ARGS, _("Invalid arguments to Get method")); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_init (message, &iter); dbus_message_iter_get_basic (&iter, &interface_name); dbus_message_iter_next (&iter); dbus_message_iter_get_basic (&iter, &property_name); dbus_message_iter_next (&iter); /* Locate a getter function in the defined interfaces. */ for (interface = object->interfaces; interface && *interface; interface++) { const NihDBusProperty *property; for (property = (*interface)->properties; property && property->name; property++) { nih_local NihDBusMessage *msg = NULL; int ret; if (strcmp (property->name, property_name) || (strlen (interface_name) && strcmp ((*interface)->name, interface_name))) continue; if (property->getter) { msg = nih_dbus_message_new (NULL, connection, message); if (! msg) return DBUS_HANDLER_RESULT_NEED_MEMORY; reply = dbus_message_new_method_return (message); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; dbus_message_iter_init_append (reply, &iter); nih_error_push_context (); ret = property->getter (object, msg, &iter); if (ret < 0) { NihError *err; dbus_message_unref (reply); err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error ( message, dbus_err->name, dbus_err->message)); nih_free (err); nih_error_pop_context (); } else { reply = NIH_MUST (dbus_message_new_error ( message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); } } else { nih_error_pop_context (); } } else { reply = dbus_message_new_error_printf ( message, DBUS_ERROR_ACCESS_DENIED, _("The %s property is write-only"), property->name); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; } if (! dbus_connection_send (connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /** * nih_dbus_object_property_get_all: * @connection: D-Bus connection, * @message: D-Bus message received, * @object: Object that received the message. * * Called because the D-Bus properties Get method has been invoked on * @object We locate the property in the @object's interfaces array and * call the getter function to append a variant onto the reply we * generate. * * Returns: result of handling the message. **/ static DBusHandlerResult nih_dbus_object_property_get_all (DBusConnection *connection, DBusMessage * message, NihDBusObject * object) { DBusMessage * reply; DBusMessageIter iter; DBusMessageIter arrayiter; const char * interface_name; nih_local NihHash * name_hash = NULL; nih_local NihDBusMessage *msg = NULL; const NihDBusInterface ** interface; nih_assert (connection != NULL); nih_assert (message != NULL); nih_assert (object != NULL); nih_assert (object->connection == connection); /* Retrieve the requested interface name from the method call, * first making sure the message signature was what we expected. */ if (! dbus_message_has_signature (message, DBUS_TYPE_STRING_AS_STRING)) { reply = dbus_message_new_error (message, DBUS_ERROR_INVALID_ARGS, _("Invalid arguments to GetAll method")); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_init (message, &iter); dbus_message_iter_get_basic (&iter, &interface_name); dbus_message_iter_next (&iter); /* D-Bus forbids us from returning multiple properties with the * same name in the dictionary, so we actually have to build * a dictionary of the properties we've visited. */ name_hash = nih_hash_string_new (NULL, 0); if (! name_hash) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Use the same NihDBusMessage object for each of the getters we * call for efficiency */ msg = nih_dbus_message_new (NULL, connection, message); if (! msg) return DBUS_HANDLER_RESULT_NEED_MEMORY; /* Begin constructing the reply immediately as well */ reply = dbus_message_new_method_return (message); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; dbus_message_iter_init_append (reply, &iter); if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING), &arrayiter)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } /* Call each of the getter functions for the matching interface, * or all of them if it's an empty string. */ for (interface = object->interfaces; interface && *interface; interface++) { const NihDBusProperty *property; if (strlen (interface_name) && strcmp ((*interface)->name, interface_name)) continue; for (property = (*interface)->properties; property && property->name; property++) { if (property->getter && (! nih_hash_lookup (name_hash, property->name))) { NihListEntry * entry; DBusMessageIter dictiter; int ret; entry = nih_list_entry_new (name_hash); if (! entry) { dbus_message_iter_abandon_container (&iter, &arrayiter); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } entry->str = (char *)property->name; nih_hash_add (name_hash, &entry->entry); if (! dbus_message_iter_open_container ( &arrayiter, DBUS_TYPE_DICT_ENTRY, NULL, &dictiter)) { dbus_message_iter_abandon_container (&iter, &arrayiter); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } if (! dbus_message_iter_append_basic ( &dictiter, DBUS_TYPE_STRING, &(property->name))) { dbus_message_iter_abandon_container (&arrayiter, &dictiter); dbus_message_iter_abandon_container (&iter, &arrayiter); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } nih_error_push_context (); ret = property->getter (object, msg, &dictiter); if (ret < 0) { NihError *err; dbus_message_iter_abandon_container (&arrayiter, &dictiter); dbus_message_iter_abandon_container (&iter, &arrayiter); dbus_message_unref (reply); err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error ( message, dbus_err->name, dbus_err->message)); nih_free (err); nih_error_pop_context (); } else { reply = NIH_MUST (dbus_message_new_error ( message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); } goto reply; } else { nih_error_pop_context (); if (! dbus_message_iter_close_container ( &arrayiter, &dictiter)) { dbus_message_iter_abandon_container (&iter, &arrayiter); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } } } } } /* Close the array and send the reply */ if (! dbus_message_iter_close_container (&iter, &arrayiter)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } reply: if (! dbus_connection_send (connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } /** * nih_dbus_object_property_set: * @connection: D-Bus connection, * @message: D-Bus message received, * @object: Object that received the message. * * Called because the D-Bus properties Set method has been invoked on * @object We locate the property in the @object's interfaces array and * call the setter function to retrieve the variant and generate a reply. * * Returns: result of handling the message. **/ static DBusHandlerResult nih_dbus_object_property_set (DBusConnection *connection, DBusMessage * message, NihDBusObject * object) { DBusMessage * reply; DBusMessageIter iter; const char * interface_name; const char * property_name; const NihDBusInterface **interface; nih_assert (connection != NULL); nih_assert (message != NULL); nih_assert (object != NULL); nih_assert (object->connection == connection); /* Retrieve the requested interface and property names from the * method call, first making sure the message signature was what * we expected. */ if (! dbus_message_has_signature (message, (DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING))) { reply = dbus_message_new_error (message, DBUS_ERROR_INVALID_ARGS, _("Invalid arguments to Set method")); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; if (! dbus_connection_send (connection, reply, NULL)) { dbus_message_unref (reply); return DBUS_HANDLER_RESULT_NEED_MEMORY; } dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } dbus_message_iter_init (message, &iter); dbus_message_iter_get_basic (&iter, &interface_name); dbus_message_iter_next (&iter); dbus_message_iter_get_basic (&iter, &property_name); dbus_message_iter_next (&iter); /* Locate a setter function in the defined interfaces. */ for (interface = object->interfaces; interface && *interface; interface++) { const NihDBusProperty *property; for (property = (*interface)->properties; property && property->name; property++) { nih_local NihDBusMessage *msg = NULL; DBusMessage * reply; int ret; if (strcmp (property->name, property_name) || (strlen (interface_name) && strcmp ((*interface)->name, interface_name))) continue; if (property->setter) { msg = nih_dbus_message_new (NULL, connection, message); if (! msg) return DBUS_HANDLER_RESULT_NEED_MEMORY; nih_error_push_context (); ret = property->setter (object, msg, &iter); if (ret < 0) { NihError *err; err = nih_error_get (); if (err->number == ENOMEM) { nih_free (err); nih_error_pop_context (); return DBUS_HANDLER_RESULT_NEED_MEMORY; } else if (err->number == NIH_DBUS_ERROR) { NihDBusError *dbus_err = (NihDBusError *)err; reply = NIH_MUST (dbus_message_new_error ( message, dbus_err->name, dbus_err->message)); nih_free (err); nih_error_pop_context (); } else { reply = NIH_MUST (dbus_message_new_error ( message, DBUS_ERROR_FAILED, err->message)); nih_free (err); nih_error_pop_context (); } } else { nih_error_pop_context (); reply = NIH_MUST (dbus_message_new_method_return (message)); } } else { reply = dbus_message_new_error_printf ( message, DBUS_ERROR_ACCESS_DENIED, _("The %s property is read-only"), property->name); if (! reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; } NIH_MUST (dbus_connection_send (connection, reply, NULL)); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } libnih-1.0.3/nih-dbus/dbus_error.h0000644000175000017500000000624111445765555013755 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_ERROR_H #define NIH_DBUS_ERROR_H /** * Errors in libnih are raised by placing an NihError object in a local * variable that can be retrieved using nih_error_get(). Errors in libdbus * are returned on the stack by passing the address of a DBusError object * when calling functions. * * This module allows the two techniques to be bridged. * * When calling a libnih function, or writing a handler called by such * a function, you may use nih_dbus_error_raise() or * nih_dbus_error_raise_printf(). This may be retrieved by nih_error_get(), * and the handler poll function will do so and convert this into a D-Bus * error message if appropriate. * * For example: * * nih_dbus_error_raise (DBUS_ERROR_INVALID_ARGS, "Expected Int32"); * return -1; * * When calling a libdbus function you should initialise a DBusError with * dbus_error_init() and pass its address to your function call. Should * an error be returned, you can raise that so it can be retrieved by * nih_error_get() by passing the name and message members to * nih_dbus_error_raise(). * * For example: * * dbus_error_init (&dbus_err); * if (! dbus_connection_open (address, &dbus_err)) { * nih_dbus_error_raise (dbus_err.name, dbus_err.message); * dbus_error_free (&dbus_err); * * return -1; * } * * In both cases, the error variable returned by nih_error_get() is not * actually NihError but NihDBusError. This extends the original structure * to add a "name" member containing the D-Bus error name. The error * number for all such errors is NIH_DBUS_ERROR. * * The nih_dbus_message_error() function defined in nih-dbus/dbus_message.h * allows you to send either type of error as a D-Bus error message. **/ #include #include /** * NihDBusError: * @name: D-Bus name. * * This structure builds on NihError to include an additional @name field * required for transport across D-Bus. * * If you receive a NIH_DBUS_ERROR, the returned NihError structure is * actually this structure and can be cast to get the additional fields. **/ typedef struct nih_dbus_error { NIH_ERROR_MEMBERS char * name; } NihDBusError; NIH_BEGIN_EXTERN void nih_dbus_error_raise (const char *name, const char *message); void nih_dbus_error_raise_printf (const char *name, const char *format, ...) __attribute__ ((format (printf, 2, 3))); NIH_END_EXTERN #endif /* NIH_DBUS_ERROR_H */ libnih-1.0.3/nih-dbus/Makefile.am0000644000175000017500000000465611445765555013502 00000000000000## Process this file with automake to produce Makefile.in AM_CFLAGS = \ $(DBUS_CFLAGS) AM_CPPFLAGS = \ -DLOCALEDIR="\"$(localedir)\"" \ -I$(top_builddir) -I$(top_srcdir) \ -I$(top_srcdir)/intl lib_LTLIBRARIES = libnih-dbus.la libnih_dbus_la_SOURCES = \ dbus_error.c \ dbus_connection.c \ dbus_message.c \ dbus_object.c \ dbus_pending_data.c \ dbus_proxy.c \ dbus_util.c libnih_dbus_la_LDFLAGS = \ -version-info 1:0:0 if HAVE_VERSION_SCRIPT_ARG libnih_dbus_la_LDFLAGS += @VERSION_SCRIPT_ARG@=$(srcdir)/libnih-dbus.ver endif libnih_dbus_la_LIBADD = \ ../nih/libnih.la \ $(DBUS_LIBS) \ -lrt include_HEADERS = \ libnih-dbus.h nihdbusincludedir = $(includedir)/nih-dbus nihdbusinclude_HEADERS = \ dbus_error.h \ dbus_connection.h \ dbus_message.h \ dbus_interface.h \ dbus_object.h \ dbus_pending_data.h \ dbus_proxy.h \ dbus_util.h \ errors.h \ test_dbus.h pkgconfigdir = $(prefix)/lib/pkgconfig pkgconfig_DATA = libnih-dbus.pc EXTRA_DIST = libnih-dbus.ver libnih-dbus.supp libnih-dbus.pc.in TESTS = \ test_dbus_error \ test_dbus_connection \ test_dbus_message \ test_dbus_object \ test_dbus_pending_data \ test_dbus_proxy \ test_dbus_util check_PROGRAMS = $(TESTS) test_dbus_error_SOURCES = tests/test_dbus_error.c test_dbus_error_LDFLAGS = -static test_dbus_error_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_dbus_connection_SOURCES = tests/test_dbus_connection.c test_dbus_connection_LDFLAGS = -static test_dbus_connection_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_dbus_message_SOURCES = tests/test_dbus_message.c test_dbus_message_LDFLAGS = -static test_dbus_message_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_dbus_object_SOURCES = tests/test_dbus_object.c test_dbus_object_LDFLAGS = -static test_dbus_object_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_dbus_pending_data_SOURCES = tests/test_dbus_pending_data.c test_dbus_pending_data_LDFLAGS = -static test_dbus_pending_data_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_dbus_proxy_SOURCES = tests/test_dbus_proxy.c test_dbus_proxy_LDFLAGS = -static test_dbus_proxy_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_dbus_util_SOURCES = tests/test_dbus_util.c test_dbus_util_LDFLAGS = -static test_dbus_util_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) .PHONY: tests tests: $(BUILT_SOURCES) $(check_PROGRAMS) clean-local: rm -f *.gcno *.gcda maintainer-clean-local: rm -f *.gcov libnih-1.0.3/nih-dbus/dbus_connection.h0000644000175000017500000001051011445765555014755 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_CONNECTION_H #define NIH_DBUS_CONNECTION_H /** * This module provides the necessary glue to hook D-Bus connections and * servers up to the libnih main loop. * * Connections obtained from the libdbus library can be hooked up using * the nih_dbus_setup() function. Once called, data on the underlying * socket will be sent and received through NihIo and timeouts will be * maintained using NihTimer objects. Each time through the main loop * any unhandled messages will be dispatched. * * The lifetime of connections is also partially managed by the library. * Disconnection from the D-Bus server will result in a disconnect handler * function being called, and the connection automatically unreferenced * and discarded. A typically well-behaved application might set a timer * to attempt to reconnect to the bus. * * Convenient functions exist to setup connections to servers at specific * addresses and to well known bus daemons: nih_dbus_connect() and * nih_dbus_bus(). These are equivalent to calling dbus_connection_open() * or dbus_bus_get() followed by nih_dbus_setup(). * * Mostly equivalent, anyway. nih_dbus_bus() explicitly sets the bus * connection to NOT result in the application exiting on disconnection, * and instead you should cope in your disconnect handler. * * = Servers = * * This module may also be used to create D-Bus servers, which is * practically impossible to do without main loop integration. * nih_dbus_server() creates a server listening on the given address. * * A connection handler function is called when a new connection is made * to the server. This function generally registers objects or adds * filters to the connection and returns TRUE to hook it up to the main * loop with the given disconnct handler. If the function returns FALSE, * it is generally dropped. * * = Allocation = * * Note that the structures returned by nih_dbus_connect(), nih_dbus_bus() * and nih_dbus_server() are NOT allocated with nih_alloc() but instead * by the D-Bus library. **/ #include #include /** * NihDBusDisconnectHandler: * @connection: Connection that was lost. * * A D-Bus disconnect handler is a function called when the D-Bus connection * @connection is disconnected from its server. Once called, the connection * is automatically unreferenced. **/ typedef void (*NihDBusDisconnectHandler) (DBusConnection *connection); /** * NihDBusConnectHandler: * @server: Server that received new connection, * @connection: New connection. * * A D-Bus connection handler is a function called when the D-Bus @server * receives a new connection @connection. The function must return TRUE * for the connection to be accepted, otherwise it will be dropped. * * Returns: TRUE if connection accepted, FALSE otherwise. **/ typedef int (*NihDBusConnectHandler) (DBusServer *server, DBusConnection *connection); NIH_BEGIN_EXTERN DBusConnection *nih_dbus_connect (const char *address, NihDBusDisconnectHandler disconnect_handler) __attribute__ ((warn_unused_result)); DBusConnection *nih_dbus_bus (DBusBusType bus, NihDBusDisconnectHandler disconnect_handler) __attribute__ ((warn_unused_result)); int nih_dbus_setup (DBusConnection *connection, NihDBusDisconnectHandler disconnect_handler) __attribute__ ((warn_unused_result)); DBusServer * nih_dbus_server (const char *address, NihDBusConnectHandler connect_handler, NihDBusDisconnectHandler disconnect_handler) __attribute__ ((warn_unused_result)); NIH_END_EXTERN #endif /* NIH_DBUS_CONNECTION_H */ libnih-1.0.3/nih-dbus/errors.h0000644000175000017500000000223711445765555013124 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_ERRORS_H #define NIH_DBUS_ERRORS_H #include #include #include /* Allocated error numbers */ enum { NIH_DBUS_ERROR_START = NIH_ERROR_LIBNIH_DBUS_START, NIH_DBUS_ERROR, NIH_DBUS_INVALID_ARGS, }; /* Error strings for defined messages */ #define NIH_DBUS_INVALID_ARGS_STR N_("Invalid arguments received in reply") #endif /* NIH_DBUS_ERRORS_H */ libnih-1.0.3/nih-dbus/test_dbus.h0000644000175000017500000001073511445765555013606 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_TEST_DBUS_H #define NIH_TEST_DBUS_H #include #include #include #include #include #include #include #include /** * TEST_DBUS: * @_pid: variable to store pid in. * * Spawns a D-Bus bus daemon which may be used for testing purposes. You * may create connections to the daemon with either the system bus or session * bus addresses, which will both contain its address; alternatively use * TEST_DBUS_OPEN() to establish a connection. * * The pid of the daemon process is stored in @_pid. * * The daemon should be killed with TEST_DBUS_END() once you have finished * with it. **/ #define TEST_DBUS(_pid) \ do { \ int _test_fds[2]; \ assert0 (pipe (_test_fds)); \ assert ((_pid = fork ()) >= 0); \ if (_pid > 0) { \ char _test_address[128] = { 0 }; \ close (_test_fds[1]); \ assert (read (_test_fds[0], _test_address, \ sizeof (_test_address)) > 0); \ close (_test_fds[0]); \ \ while (strrchr (_test_address, '\n')) \ *(strrchr (_test_address, '\n')) = '\0'; \ \ assert0 (setenv ("DBUS_SYSTEM_BUS_ADDRESS", \ _test_address, TRUE)); \ assert0 (setenv ("DBUS_SESSION_BUS_ADDRESS", \ _test_address, TRUE)); \ } else if (_pid == 0) { \ close (_test_fds[0]); \ assert (dup2 (_test_fds[1], STDOUT_FILENO) >= 0); \ assert0 (execlp ("dbus-daemon", "test_dbus-daemon", \ "--session", "--print-address", NULL)); \ exit (255); \ } \ } while (0) /** * TEST_DBUS_OPEN: * @_conn: variable to store connection in. * * Creates a new connection to the temporary D-Bus server, ensuring that * it won't exit on disconnect and removing the NameAcquired signal from * the incoming queue. * * The connection may be closed again using TEST_DBUS_CLOSE(). **/ #define TEST_DBUS_OPEN(_conn) \ do { \ DBusMessage *_test_message; \ \ assert ((_conn = dbus_bus_get_private (DBUS_BUS_SYSTEM, NULL)) != NULL); \ dbus_connection_set_exit_on_disconnect (_conn, FALSE); \ \ while (! (_test_message = dbus_connection_pop_message (_conn))) \ dbus_connection_read_write (_conn, -1); \ \ assert (dbus_message_is_signal ( \ _test_message, DBUS_INTERFACE_DBUS, \ "NameAcquired")); \ \ dbus_message_unref (_test_message); \ } while (0) /** * TEST_DBUS_MESSAGE: * @_conn: connection, * @_message: variable to store message in. * * Waits for a single message to arrive and pops it from the incoming queue, * placing it in @_message. **/ #define TEST_DBUS_MESSAGE(_conn, _message) \ while (! (_message = dbus_connection_pop_message (_conn))) \ dbus_connection_read_write (_conn, -1); /** * TEST_DBUS_DISPATCH: * @_conn: connection. * * Reads and writes from the connection @_conn and dispatches whatever * messages were received or sent in that pulse. **/ #define TEST_DBUS_DISPATCH(_conn) \ do { \ dbus_connection_read_write (_conn, -1); \ while (dbus_connection_dispatch (_conn) != DBUS_DISPATCH_COMPLETE) \ ; \ } while (0) /** * TEST_DBUS_CLOSE: * @_conn: connection to close. * * Closes the connection opened with TEST_DBUS_OPEN(). **/ #define TEST_DBUS_CLOSE(_conn) \ do { \ dbus_connection_close (_conn); \ dbus_connection_unref (_conn); \ } while (0) /** * TEST_DBUS_END: * @_pid: pid of dbus daemon. * * Terminates a dbus daemon that has been used for testing. **/ #define TEST_DBUS_END(_pid) \ do { \ kill (_pid, SIGTERM); \ waitpid (_pid, NULL, 0); \ unsetenv ("DBUS_SESSION_BUS_ADDRESS"); \ unsetenv ("DBUS_SYSTEM_BUS_ADDRESS"); \ } while (0) #endif /* NIH_TEST_DBUS_H */ libnih-1.0.3/nih-dbus/dbus_error.c0000644000175000017500000000640611445765555013753 00000000000000/* libnih * * dbus_error.c - D-Bus error handling * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include "dbus_error.h" /** * nih_dbus_error_raise: * @name: D-Bus name for error, * @message: Human-readable error message. * * Raises an error which includes a D-Bus name so that it may be sent as * a reply to a method call, the error type is fixed to NIH_DBUS_ERROR. * * You may use this in D-Bus handlers and return a negative number to * automatically have this error returned as the method reply. It is also * useful when mixing D-Bus and libnih function calls in your own methods * to return consistent error forms, in which case pass the name and message * members of the DBusError structure before freeing it. **/ void nih_dbus_error_raise (const char *name, const char *message) { NihDBusError *err; nih_assert (name != NULL); nih_assert (message != NULL); err = NIH_MUST (nih_new (NULL, NihDBusError)); err->number = NIH_DBUS_ERROR; err->name = NIH_MUST (nih_strdup (err, name)); err->message = NIH_MUST (nih_strdup (err, message)); nih_error_raise_error ((NihError *)err); } /** * nih_dbus_error_raise_printf: * @name: D-Bus name for error, * @format: format string for human-readable message. * * Raises an error which includes a D-Bus name so that it may be sent as * a reply to a method call, the error type is fixed to NIH_DBUS_ERROR. * * The human-readable message for the error is parsed according to @format, * and allocated as a child of the error object so that it is freed. * * You may use this in D-Bus handlers and return a negative number to * automatically have this error returned as the method reply. It is also * useful when mixing D-Bus and libnih function calls in your own methods * to return consistent error forms, in which case pass the name and message * members of the DBusError structure before freeing it. **/ void nih_dbus_error_raise_printf (const char *name, const char *format, ...) { NihDBusError *err; va_list args; nih_assert (name != NULL); nih_assert (format != NULL); err = NIH_MUST (nih_new (NULL, NihDBusError)); err->number = NIH_DBUS_ERROR; err->name = NIH_MUST (nih_strdup (err, name)); va_start (args, format); err->message = NIH_MUST (nih_vsprintf (err, format, args)); va_end (args); nih_error_raise_error ((NihError *)err); } libnih-1.0.3/nih-dbus/dbus_message.h0000644000175000017500000000461511445765555014253 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_MESSAGE_H #define NIH_DBUS_MESSAGE_H /** * The NihDBusMessage structure references both an incoming D-Bus message * and the connection it was received on, and may be created with the * nih_dbus_message_new() function. * * This allows both a single pointer to be passed around to deal with a * message, and also provides an nih_alloc() context for attaching allocated * data that can be discarded when the message has been processed (often * strings used to generate the reply, for example). * * A typical function that uses this structure is nih_dbus_message_error() * which generates and sends a reply to the incoming message that is an * error return with the given name and format. **/ #include #include /** * NihDBusMessage: * @connection: D-Bus connection message was received on, * @message: message object received. * * This structure is used as a context for the processing of a message; the * primary reason for its existance is to be used as an nih_alloc() context * for any reply data. * * Instances are allocated automatically and passed to marshaller functions, * and freed on their return. **/ typedef struct nih_dbus_message { DBusConnection *connection; DBusMessage * message; } NihDBusMessage; NIH_BEGIN_EXTERN NihDBusMessage *nih_dbus_message_new (const void *parent, DBusConnection *connection, DBusMessage *message) __attribute__ ((warn_unused_result)); int nih_dbus_message_error (NihDBusMessage *msg, const char *name, const char *format, ...) __attribute__ ((warn_unused_result)); NIH_END_EXTERN #endif /* NIH_DBUS_MESSAGE_H */ libnih-1.0.3/nih-dbus/dbus_interface.h0000644000175000017500000002375111445765555014571 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_INTERFACE_H #define NIH_DBUS_INTERFACE_H #include #include #include /* Structures declared elsewhere */ typedef struct nih_dbus_object NihDBusObject; typedef struct nih_dbus_proxy NihDBusProxy; typedef struct nih_dbus_proxy_signal NihDBusProxySignal; /** * NihDBusMethodHandler: * @object: D-Bus object being handled, * @message: information about method call message to handle. * * A method handler function is called for a specific D-Bus method call * on @object, available as the @message parameter. The handler should * examine the arguments and send the method reply or an error. * * While method handlers can be written by hand, it's far more efficient * to have them generated automatically. nih-dbus-tool will generate * method handlers that call C functions of appropriate names with * ordinary arguments matching the expected types based on the message, * and that generate the reply message based on the return arguments. * * Returns: DBUS_HANDLER_RESULT_HANDLED when the message has been handled * and a reply or error sent, DBUS_HANDLER_RESULT_NOT_YET_HANDLED if the * handler has declined to handle the message or * DBUS_HANDLER_RESULT_NEED_MEMORY if insufficient memory to handle the * message. **/ typedef DBusHandlerResult (*NihDBusMethodHandler) (NihDBusObject *object, NihDBusMessage *message); /** * NihDBusSignalFilter: * @connection: D-Bus connection that received the message, * @signal: D-Bus message containing the message received, * @proxied: proxied signal connection information. * * A signal filter is hooked up to a D-Bus connection @connection and called * for all messages received on that connection, it is expected to check * that the @message matches the @proxied signal and if so, call the signal * handler function with the expected arguments. * * While signal filter functions can be written by hand, it's far more * efficient to have them generated automatically. nih-dbus-tool will * generate signal filters that call C functions of appropriate names with * ordinary arguments matching the expected types based on the message, * and that generate the reply message based on the return arguments. * * Returns: usually DBUS_HANDLER_RESULT_NOT_YET_HANDLED even if the message * has been handled to allow other signal filter functions to process the * message or DBUS_HANDLER_RESULT_NEED_MEMORY if insufficient memory to * handle the message. **/ typedef DBusHandlerResult (*NihDBusSignalFilter) (DBusConnection *connection, DBusMessage *signal, NihDBusProxySignal *proxied); /** * NihDBusPropertyGetter: * @object: D-Bus object being handled, * @message: information about property get message, * @iter: iterator to append value to. * * A property getter function is called when generating a reply to a * D-Bus properties Get or GetAll method, available as the @message * parameter. The getter should append a variant onto @iter containing * the property value. * * Unlike method handlers, the Get and GetAll methods are implemented * internally to libnih-dbus, with a reply being generated and sent as * part of that handling. It's only necessary to provide the actual * property value wrapped up in a variant. * * While property getters can be written by hand, it's far more efficient * to have them generated automatically. nih-dbus-tool will generate * property getters that call C functions of appropriate names with an * ordinary pointer argument matching the expected type that the function * can place the property value into. * * Returns: zero on success, negative value if insufficient memory. **/ typedef int (*NihDBusPropertyGetter) (NihDBusObject *object, NihDBusMessage *message, DBusMessageIter *iter); /** * NihDBusPropertySetter: * @object: D-Bus object being handled, * @message: information about property get message, * @iter: iterator to obtain value from. * * A property setter function is called when a handling the D-Bus * properties Set method, available as the @message parameter. The * setter should obtain the new value from the variant pointed to by * @iter and return either an empty reply message or an error message. * * Unlike method handlers, the Set method is implemented internally to * libnih-dbus, with a reply being generated and sent as part of that * handling. It's only necessary to take the property value from the * variant and set it. * * While property setters can be written by hand, it's far more efficient * to have them generated automatically. nih-dbus-tool will generate * property getters that call C functions of appropriate names with an * ordinary argument matching the expected type that the function * can obtain the property value from. * * Returns: zero on success, negative value on raised error. **/ typedef int (*NihDBusPropertySetter) (NihDBusObject *object, NihDBusMessage *message, DBusMessageIter *iter); /** * NihDBusArgDir: * * Whether an argument is for the method call (in) or method reply (out). **/ typedef enum nih_dbus_arg_dir { NIH_DBUS_ARG_IN, NIH_DBUS_ARG_OUT } NihDBusArgDir; /** * NihDBusArg: * @type: D-Bus type signature, * @name: name of argument, * @dir: whether argument is for method call or reply. * * This structure defines an argument to a D-Bus method or signal and is used * to provide introspection of that method. * * It's unusual to use this directly, instead methods are pre-defined as * members of const arrays by nih-dbus-tool and referenced by the interfaces * it also defines. **/ typedef struct nih_dbus_arg { const char * name; const char * type; NihDBusArgDir dir; } NihDBusArg; /** * NihDBusMethod: * @name: name of the method, * @args: NULL-terminated array of arguments, * @handler: handler function. * * This structure defines a method associated with a D-Bus interface. * * It's unusual to use this directly, instead methods are pre-defined as * members of const arrays by nih-dbus-tool and referenced by the interfaces * it also defines. * * When the method is invoked, the @handler function will be called and * is expected to reply with a method return or error message. Method * handler functions are also normally generated by nih-dbus-tool. * * @args is used to provide introspection of the method. **/ typedef struct nih_dbus_method { const char * name; const NihDBusArg * args; NihDBusMethodHandler handler; } NihDBusMethod; /** * NihDBusSignal: * @name: name of the signal, * @args: NULL-terminated array of arguments, * @filter: filter function. * * This structure defines a signal that can be emitted by a D-Bus interface * and is used to provide introspection of that signal. * * It's unusual to use this directly, instead signals are pre-defined as * const arrays by nih-dbus-tool and referenced by the interfaces it also * defines. * * The signal itself is normally emitted by a function generated by * nih-dbus-tool that accepts C arguments matching @args. The @filter * function is intended to be hooked up to the D-Bus connection to * handle the incoming signal. **/ typedef struct nih_dbus_signal { const char * name; const NihDBusArg * args; NihDBusSignalFilter filter; } NihDBusSignal; /** * NihDBusAccess: * * Access restrictions for a property. **/ typedef enum nih_dbus_access { NIH_DBUS_READ, NIH_DBUS_WRITE, NIH_DBUS_READWRITE } NihDBusAccess; /** * NihDBusProperty: * @name: name of the property, * @type: type signature of value, * @access: access restrictions, * @getter: getter function, * @setter: setter function. * * This structure defines a property associated with a D-Bus interface. * * It's unusual to use this directly, instead properties are pre-defined as * members of const arrays by nih-dbus-tool and referenced by the interfaces * it also defines. * * When the D-Bus properties Get or GetAll methods are invoked, the * @getter function will be called and is expected to add a variant to a * message being generated. When the D-Bus properties Set method is invoked, * the @setter function will be called and is expected to return an empty * reply or an error. Both getter and setter functions are also normally * generated by nih-dbus-tool. * * @access is used to provide introspection of the property. **/ typedef struct nih_dbus_property { const char * name; const char * type; NihDBusAccess access; NihDBusPropertyGetter getter; NihDBusPropertySetter setter; } NihDBusProperty; /** * NihDBusInterface: * @name: name of the interface, * @methods: NULL-terminated array of methods, * @signals: NULL-terminated array of signals, * @properties: NULL-terminated array of properties. * * This structure defines an interface that may be implemented by a D-Bus * object. It's unusual to use this in any form other than a const array * for each type of object, and even then the individual members of that * array are normally taken from macros defined by nih-dbus-tool that expand * to interfaces it defines. **/ typedef struct nih_dbus_interface { const char * name; const NihDBusMethod * methods; const NihDBusSignal * signals; const NihDBusProperty *properties; } NihDBusInterface; #endif /* NIH_DBUS_INTERFACE_H */ libnih-1.0.3/nih-dbus/Makefile.in0000644000175000017500000014112411503251220013451 00000000000000# Makefile.in generated by automake 1.11.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, # 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, # Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ @HAVE_VERSION_SCRIPT_ARG_TRUE@am__append_1 = @VERSION_SCRIPT_ARG@=$(srcdir)/libnih-dbus.ver TESTS = test_dbus_error$(EXEEXT) test_dbus_connection$(EXEEXT) \ test_dbus_message$(EXEEXT) test_dbus_object$(EXEEXT) \ test_dbus_pending_data$(EXEEXT) test_dbus_proxy$(EXEEXT) \ test_dbus_util$(EXEEXT) check_PROGRAMS = $(am__EXEEXT_1) subdir = nih-dbus DIST_COMMON = $(include_HEADERS) $(nihdbusinclude_HEADERS) \ $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ $(srcdir)/libnih-dbus.pc.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/codeset.m4 \ $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/glibc2.m4 \ $(top_srcdir)/m4/glibc21.m4 $(top_srcdir)/m4/iconv.m4 \ $(top_srcdir)/m4/intdiv0.m4 $(top_srcdir)/m4/intl.m4 \ $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/intmax.m4 \ $(top_srcdir)/m4/inttypes-pri.m4 \ $(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/lcmessage.m4 \ $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libnih.m4 \ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/lock.m4 \ $(top_srcdir)/m4/longlong.m4 $(top_srcdir)/m4/ltoptions.m4 \ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \ $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/m4/po.m4 \ $(top_srcdir)/m4/printf-posix.m4 $(top_srcdir)/m4/progtest.m4 \ $(top_srcdir)/m4/size_max.m4 $(top_srcdir)/m4/stdint_h.m4 \ $(top_srcdir)/m4/uintmax_t.m4 $(top_srcdir)/m4/visibility.m4 \ $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/m4/wint_t.m4 \ $(top_srcdir)/m4/xsize.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = libnih-dbus.pc CONFIG_CLEAN_VPATH_FILES = am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" \ "$(DESTDIR)$(includedir)" "$(DESTDIR)$(nihdbusincludedir)" LTLIBRARIES = $(lib_LTLIBRARIES) am__DEPENDENCIES_1 = libnih_dbus_la_DEPENDENCIES = ../nih/libnih.la $(am__DEPENDENCIES_1) am_libnih_dbus_la_OBJECTS = dbus_error.lo dbus_connection.lo \ dbus_message.lo dbus_object.lo dbus_pending_data.lo \ dbus_proxy.lo dbus_util.lo libnih_dbus_la_OBJECTS = $(am_libnih_dbus_la_OBJECTS) AM_V_lt = $(am__v_lt_$(V)) am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) am__v_lt_0 = --silent libnih_dbus_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(libnih_dbus_la_LDFLAGS) $(LDFLAGS) -o \ $@ am__EXEEXT_1 = test_dbus_error$(EXEEXT) test_dbus_connection$(EXEEXT) \ test_dbus_message$(EXEEXT) test_dbus_object$(EXEEXT) \ test_dbus_pending_data$(EXEEXT) test_dbus_proxy$(EXEEXT) \ test_dbus_util$(EXEEXT) am_test_dbus_connection_OBJECTS = test_dbus_connection.$(OBJEXT) test_dbus_connection_OBJECTS = $(am_test_dbus_connection_OBJECTS) test_dbus_connection_DEPENDENCIES = libnih-dbus.la ../nih/libnih.la \ $(am__DEPENDENCIES_1) test_dbus_connection_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(test_dbus_connection_LDFLAGS) \ $(LDFLAGS) -o $@ am_test_dbus_error_OBJECTS = test_dbus_error.$(OBJEXT) test_dbus_error_OBJECTS = $(am_test_dbus_error_OBJECTS) test_dbus_error_DEPENDENCIES = libnih-dbus.la ../nih/libnih.la \ $(am__DEPENDENCIES_1) test_dbus_error_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(test_dbus_error_LDFLAGS) $(LDFLAGS) \ -o $@ am_test_dbus_message_OBJECTS = test_dbus_message.$(OBJEXT) test_dbus_message_OBJECTS = $(am_test_dbus_message_OBJECTS) test_dbus_message_DEPENDENCIES = libnih-dbus.la ../nih/libnih.la \ $(am__DEPENDENCIES_1) test_dbus_message_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(test_dbus_message_LDFLAGS) $(LDFLAGS) \ -o $@ am_test_dbus_object_OBJECTS = test_dbus_object.$(OBJEXT) test_dbus_object_OBJECTS = $(am_test_dbus_object_OBJECTS) test_dbus_object_DEPENDENCIES = libnih-dbus.la ../nih/libnih.la \ $(am__DEPENDENCIES_1) test_dbus_object_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(test_dbus_object_LDFLAGS) $(LDFLAGS) \ -o $@ am_test_dbus_pending_data_OBJECTS = test_dbus_pending_data.$(OBJEXT) test_dbus_pending_data_OBJECTS = $(am_test_dbus_pending_data_OBJECTS) test_dbus_pending_data_DEPENDENCIES = libnih-dbus.la ../nih/libnih.la \ $(am__DEPENDENCIES_1) test_dbus_pending_data_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(test_dbus_pending_data_LDFLAGS) \ $(LDFLAGS) -o $@ am_test_dbus_proxy_OBJECTS = test_dbus_proxy.$(OBJEXT) test_dbus_proxy_OBJECTS = $(am_test_dbus_proxy_OBJECTS) test_dbus_proxy_DEPENDENCIES = libnih-dbus.la ../nih/libnih.la \ $(am__DEPENDENCIES_1) test_dbus_proxy_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(test_dbus_proxy_LDFLAGS) $(LDFLAGS) \ -o $@ am_test_dbus_util_OBJECTS = test_dbus_util.$(OBJEXT) test_dbus_util_OBJECTS = $(am_test_dbus_util_OBJECTS) test_dbus_util_DEPENDENCIES = libnih-dbus.la ../nih/libnih.la \ $(am__DEPENDENCIES_1) test_dbus_util_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(test_dbus_util_LDFLAGS) $(LDFLAGS) -o \ $@ DEFAULT_INCLUDES = depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ $(AM_CFLAGS) $(CFLAGS) AM_V_CC = $(am__v_CC_$(V)) am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) am__v_CC_0 = @echo " CC " $@; AM_V_at = $(am__v_at_$(V)) am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) am__v_at_0 = @ CCLD = $(CC) LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_CCLD = $(am__v_CCLD_$(V)) am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) am__v_CCLD_0 = @echo " CCLD " $@; AM_V_GEN = $(am__v_GEN_$(V)) am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) am__v_GEN_0 = @echo " GEN " $@; SOURCES = $(libnih_dbus_la_SOURCES) $(test_dbus_connection_SOURCES) \ $(test_dbus_error_SOURCES) $(test_dbus_message_SOURCES) \ $(test_dbus_object_SOURCES) $(test_dbus_pending_data_SOURCES) \ $(test_dbus_proxy_SOURCES) $(test_dbus_util_SOURCES) DIST_SOURCES = $(libnih_dbus_la_SOURCES) \ $(test_dbus_connection_SOURCES) $(test_dbus_error_SOURCES) \ $(test_dbus_message_SOURCES) $(test_dbus_object_SOURCES) \ $(test_dbus_pending_data_SOURCES) $(test_dbus_proxy_SOURCES) \ $(test_dbus_util_SOURCES) DATA = $(pkgconfig_DATA) HEADERS = $(include_HEADERS) $(nihdbusinclude_HEADERS) ETAGS = etags CTAGS = ctags # If stdout is a non-dumb tty, use colors. If test -t is not supported, # then this fails; a conservative approach. Of course do not redirect # stdout here, just stderr. am__tty_colors = \ red=; grn=; lgn=; blu=; std=; \ test "X$(AM_COLOR_TESTS)" != Xno \ && test "X$$TERM" != Xdumb \ && { test "X$(AM_COLOR_TESTS)" = Xalways || test -t 1 2>/dev/null; } \ && { \ red=''; \ grn=''; \ lgn=''; \ blu=''; \ std=''; \ } DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ ALLOCA = @ALLOCA@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@ CATOBJEXT = @CATOBJEXT@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CFLAG_VISIBILITY = @CFLAG_VISIBILITY@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DATADIRNAME = @DATADIRNAME@ DBUS_CFLAGS = @DBUS_CFLAGS@ DBUS_LIBS = @DBUS_LIBS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ EXPAT_LIBS = @EXPAT_LIBS@ FGREP = @FGREP@ GENCAT = @GENCAT@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ GLIBC2 = @GLIBC2@ GLIBC21 = @GLIBC21@ GMSGFMT = @GMSGFMT@ GMSGFMT_015 = @GMSGFMT_015@ GREP = @GREP@ HAVE_ASPRINTF = @HAVE_ASPRINTF@ HAVE_POSIX_PRINTF = @HAVE_POSIX_PRINTF@ HAVE_SNPRINTF = @HAVE_SNPRINTF@ HAVE_VISIBILITY = @HAVE_VISIBILITY@ HAVE_WPRINTF = @HAVE_WPRINTF@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INSTOBJEXT = @INSTOBJEXT@ INTLBISON = @INTLBISON@ INTLLIBS = @INTLLIBS@ INTLOBJS = @INTLOBJS@ INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@ INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBMULTITHREAD = @LIBMULTITHREAD@ LIBOBJS = @LIBOBJS@ LIBPTH = @LIBPTH@ LIBPTH_PREFIX = @LIBPTH_PREFIX@ LIBS = @LIBS@ LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBC = @LTLIBC@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ LTLIBMULTITHREAD = @LTLIBMULTITHREAD@ LTLIBOBJS = @LTLIBOBJS@ LTLIBPTH = @LTLIBPTH@ LTLIBTHREAD = @LTLIBTHREAD@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ NIH_DBUS_TOOL = @NIH_DBUS_TOOL@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_COPYRIGHT = @PACKAGE_COPYRIGHT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ POSUB = @POSUB@ PRI_MACROS_BROKEN = @PRI_MACROS_BROKEN@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@ USE_NLS = @USE_NLS@ VERSION = @VERSION@ VERSION_SCRIPT_ARG = @VERSION_SCRIPT_ARG@ WINDRES = @WINDRES@ WOE32 = @WOE32@ WOE32DLL = @WOE32DLL@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AM_CFLAGS = \ $(DBUS_CFLAGS) AM_CPPFLAGS = \ -DLOCALEDIR="\"$(localedir)\"" \ -I$(top_builddir) -I$(top_srcdir) \ -I$(top_srcdir)/intl lib_LTLIBRARIES = libnih-dbus.la libnih_dbus_la_SOURCES = \ dbus_error.c \ dbus_connection.c \ dbus_message.c \ dbus_object.c \ dbus_pending_data.c \ dbus_proxy.c \ dbus_util.c libnih_dbus_la_LDFLAGS = -version-info 1:0:0 $(am__append_1) libnih_dbus_la_LIBADD = \ ../nih/libnih.la \ $(DBUS_LIBS) \ -lrt include_HEADERS = \ libnih-dbus.h nihdbusincludedir = $(includedir)/nih-dbus nihdbusinclude_HEADERS = \ dbus_error.h \ dbus_connection.h \ dbus_message.h \ dbus_interface.h \ dbus_object.h \ dbus_pending_data.h \ dbus_proxy.h \ dbus_util.h \ errors.h \ test_dbus.h pkgconfigdir = $(prefix)/lib/pkgconfig pkgconfig_DATA = libnih-dbus.pc EXTRA_DIST = libnih-dbus.ver libnih-dbus.supp libnih-dbus.pc.in test_dbus_error_SOURCES = tests/test_dbus_error.c test_dbus_error_LDFLAGS = -static test_dbus_error_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_dbus_connection_SOURCES = tests/test_dbus_connection.c test_dbus_connection_LDFLAGS = -static test_dbus_connection_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_dbus_message_SOURCES = tests/test_dbus_message.c test_dbus_message_LDFLAGS = -static test_dbus_message_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_dbus_object_SOURCES = tests/test_dbus_object.c test_dbus_object_LDFLAGS = -static test_dbus_object_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_dbus_pending_data_SOURCES = tests/test_dbus_pending_data.c test_dbus_pending_data_LDFLAGS = -static test_dbus_pending_data_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_dbus_proxy_SOURCES = tests/test_dbus_proxy.c test_dbus_proxy_LDFLAGS = -static test_dbus_proxy_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) test_dbus_util_SOURCES = tests/test_dbus_util.c test_dbus_util_LDFLAGS = -static test_dbus_util_LDADD = libnih-dbus.la ../nih/libnih.la $(DBUS_LIBS) all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu nih-dbus/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu nih-dbus/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): libnih-dbus.pc: $(top_builddir)/config.status $(srcdir)/libnih-dbus.pc.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ install-libLTLIBRARIES: $(lib_LTLIBRARIES) @$(NORMAL_INSTALL) test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ list2=; for p in $$list; do \ if test -f $$p; then \ list2="$$list2 $$p"; \ else :; fi; \ done; \ test -z "$$list2" || { \ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ } uninstall-libLTLIBRARIES: @$(NORMAL_UNINSTALL) @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ for p in $$list; do \ $(am__strip_dir) \ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ done clean-libLTLIBRARIES: -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ test "$$dir" != "$$p" || dir=.; \ echo "rm -f \"$${dir}/so_locations\""; \ rm -f "$${dir}/so_locations"; \ done libnih-dbus.la: $(libnih_dbus_la_OBJECTS) $(libnih_dbus_la_DEPENDENCIES) $(AM_V_CCLD)$(libnih_dbus_la_LINK) -rpath $(libdir) $(libnih_dbus_la_OBJECTS) $(libnih_dbus_la_LIBADD) $(LIBS) clean-checkPROGRAMS: @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \ echo " rm -f" $$list; \ rm -f $$list || exit $$?; \ test -n "$(EXEEXT)" || exit 0; \ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list test_dbus_connection$(EXEEXT): $(test_dbus_connection_OBJECTS) $(test_dbus_connection_DEPENDENCIES) @rm -f test_dbus_connection$(EXEEXT) $(AM_V_CCLD)$(test_dbus_connection_LINK) $(test_dbus_connection_OBJECTS) $(test_dbus_connection_LDADD) $(LIBS) test_dbus_error$(EXEEXT): $(test_dbus_error_OBJECTS) $(test_dbus_error_DEPENDENCIES) @rm -f test_dbus_error$(EXEEXT) $(AM_V_CCLD)$(test_dbus_error_LINK) $(test_dbus_error_OBJECTS) $(test_dbus_error_LDADD) $(LIBS) test_dbus_message$(EXEEXT): $(test_dbus_message_OBJECTS) $(test_dbus_message_DEPENDENCIES) @rm -f test_dbus_message$(EXEEXT) $(AM_V_CCLD)$(test_dbus_message_LINK) $(test_dbus_message_OBJECTS) $(test_dbus_message_LDADD) $(LIBS) test_dbus_object$(EXEEXT): $(test_dbus_object_OBJECTS) $(test_dbus_object_DEPENDENCIES) @rm -f test_dbus_object$(EXEEXT) $(AM_V_CCLD)$(test_dbus_object_LINK) $(test_dbus_object_OBJECTS) $(test_dbus_object_LDADD) $(LIBS) test_dbus_pending_data$(EXEEXT): $(test_dbus_pending_data_OBJECTS) $(test_dbus_pending_data_DEPENDENCIES) @rm -f test_dbus_pending_data$(EXEEXT) $(AM_V_CCLD)$(test_dbus_pending_data_LINK) $(test_dbus_pending_data_OBJECTS) $(test_dbus_pending_data_LDADD) $(LIBS) test_dbus_proxy$(EXEEXT): $(test_dbus_proxy_OBJECTS) $(test_dbus_proxy_DEPENDENCIES) @rm -f test_dbus_proxy$(EXEEXT) $(AM_V_CCLD)$(test_dbus_proxy_LINK) $(test_dbus_proxy_OBJECTS) $(test_dbus_proxy_LDADD) $(LIBS) test_dbus_util$(EXEEXT): $(test_dbus_util_OBJECTS) $(test_dbus_util_DEPENDENCIES) @rm -f test_dbus_util$(EXEEXT) $(AM_V_CCLD)$(test_dbus_util_LINK) $(test_dbus_util_OBJECTS) $(test_dbus_util_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbus_connection.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbus_error.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbus_message.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbus_object.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbus_pending_data.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbus_proxy.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbus_util.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_dbus_connection.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_dbus_error.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_dbus_message.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_dbus_object.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_dbus_pending_data.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_dbus_proxy.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_dbus_util.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< test_dbus_connection.o: tests/test_dbus_connection.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_connection.o -MD -MP -MF $(DEPDIR)/test_dbus_connection.Tpo -c -o test_dbus_connection.o `test -f 'tests/test_dbus_connection.c' || echo '$(srcdir)/'`tests/test_dbus_connection.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_connection.Tpo $(DEPDIR)/test_dbus_connection.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_connection.c' object='test_dbus_connection.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_connection.o `test -f 'tests/test_dbus_connection.c' || echo '$(srcdir)/'`tests/test_dbus_connection.c test_dbus_connection.obj: tests/test_dbus_connection.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_connection.obj -MD -MP -MF $(DEPDIR)/test_dbus_connection.Tpo -c -o test_dbus_connection.obj `if test -f 'tests/test_dbus_connection.c'; then $(CYGPATH_W) 'tests/test_dbus_connection.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_connection.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_connection.Tpo $(DEPDIR)/test_dbus_connection.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_connection.c' object='test_dbus_connection.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_connection.obj `if test -f 'tests/test_dbus_connection.c'; then $(CYGPATH_W) 'tests/test_dbus_connection.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_connection.c'; fi` test_dbus_error.o: tests/test_dbus_error.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_error.o -MD -MP -MF $(DEPDIR)/test_dbus_error.Tpo -c -o test_dbus_error.o `test -f 'tests/test_dbus_error.c' || echo '$(srcdir)/'`tests/test_dbus_error.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_error.Tpo $(DEPDIR)/test_dbus_error.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_error.c' object='test_dbus_error.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_error.o `test -f 'tests/test_dbus_error.c' || echo '$(srcdir)/'`tests/test_dbus_error.c test_dbus_error.obj: tests/test_dbus_error.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_error.obj -MD -MP -MF $(DEPDIR)/test_dbus_error.Tpo -c -o test_dbus_error.obj `if test -f 'tests/test_dbus_error.c'; then $(CYGPATH_W) 'tests/test_dbus_error.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_error.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_error.Tpo $(DEPDIR)/test_dbus_error.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_error.c' object='test_dbus_error.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_error.obj `if test -f 'tests/test_dbus_error.c'; then $(CYGPATH_W) 'tests/test_dbus_error.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_error.c'; fi` test_dbus_message.o: tests/test_dbus_message.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_message.o -MD -MP -MF $(DEPDIR)/test_dbus_message.Tpo -c -o test_dbus_message.o `test -f 'tests/test_dbus_message.c' || echo '$(srcdir)/'`tests/test_dbus_message.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_message.Tpo $(DEPDIR)/test_dbus_message.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_message.c' object='test_dbus_message.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_message.o `test -f 'tests/test_dbus_message.c' || echo '$(srcdir)/'`tests/test_dbus_message.c test_dbus_message.obj: tests/test_dbus_message.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_message.obj -MD -MP -MF $(DEPDIR)/test_dbus_message.Tpo -c -o test_dbus_message.obj `if test -f 'tests/test_dbus_message.c'; then $(CYGPATH_W) 'tests/test_dbus_message.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_message.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_message.Tpo $(DEPDIR)/test_dbus_message.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_message.c' object='test_dbus_message.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_message.obj `if test -f 'tests/test_dbus_message.c'; then $(CYGPATH_W) 'tests/test_dbus_message.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_message.c'; fi` test_dbus_object.o: tests/test_dbus_object.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_object.o -MD -MP -MF $(DEPDIR)/test_dbus_object.Tpo -c -o test_dbus_object.o `test -f 'tests/test_dbus_object.c' || echo '$(srcdir)/'`tests/test_dbus_object.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_object.Tpo $(DEPDIR)/test_dbus_object.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_object.c' object='test_dbus_object.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_object.o `test -f 'tests/test_dbus_object.c' || echo '$(srcdir)/'`tests/test_dbus_object.c test_dbus_object.obj: tests/test_dbus_object.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_object.obj -MD -MP -MF $(DEPDIR)/test_dbus_object.Tpo -c -o test_dbus_object.obj `if test -f 'tests/test_dbus_object.c'; then $(CYGPATH_W) 'tests/test_dbus_object.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_object.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_object.Tpo $(DEPDIR)/test_dbus_object.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_object.c' object='test_dbus_object.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_object.obj `if test -f 'tests/test_dbus_object.c'; then $(CYGPATH_W) 'tests/test_dbus_object.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_object.c'; fi` test_dbus_pending_data.o: tests/test_dbus_pending_data.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_pending_data.o -MD -MP -MF $(DEPDIR)/test_dbus_pending_data.Tpo -c -o test_dbus_pending_data.o `test -f 'tests/test_dbus_pending_data.c' || echo '$(srcdir)/'`tests/test_dbus_pending_data.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_pending_data.Tpo $(DEPDIR)/test_dbus_pending_data.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_pending_data.c' object='test_dbus_pending_data.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_pending_data.o `test -f 'tests/test_dbus_pending_data.c' || echo '$(srcdir)/'`tests/test_dbus_pending_data.c test_dbus_pending_data.obj: tests/test_dbus_pending_data.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_pending_data.obj -MD -MP -MF $(DEPDIR)/test_dbus_pending_data.Tpo -c -o test_dbus_pending_data.obj `if test -f 'tests/test_dbus_pending_data.c'; then $(CYGPATH_W) 'tests/test_dbus_pending_data.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_pending_data.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_pending_data.Tpo $(DEPDIR)/test_dbus_pending_data.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_pending_data.c' object='test_dbus_pending_data.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_pending_data.obj `if test -f 'tests/test_dbus_pending_data.c'; then $(CYGPATH_W) 'tests/test_dbus_pending_data.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_pending_data.c'; fi` test_dbus_proxy.o: tests/test_dbus_proxy.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_proxy.o -MD -MP -MF $(DEPDIR)/test_dbus_proxy.Tpo -c -o test_dbus_proxy.o `test -f 'tests/test_dbus_proxy.c' || echo '$(srcdir)/'`tests/test_dbus_proxy.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_proxy.Tpo $(DEPDIR)/test_dbus_proxy.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_proxy.c' object='test_dbus_proxy.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_proxy.o `test -f 'tests/test_dbus_proxy.c' || echo '$(srcdir)/'`tests/test_dbus_proxy.c test_dbus_proxy.obj: tests/test_dbus_proxy.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_proxy.obj -MD -MP -MF $(DEPDIR)/test_dbus_proxy.Tpo -c -o test_dbus_proxy.obj `if test -f 'tests/test_dbus_proxy.c'; then $(CYGPATH_W) 'tests/test_dbus_proxy.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_proxy.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_proxy.Tpo $(DEPDIR)/test_dbus_proxy.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_proxy.c' object='test_dbus_proxy.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_proxy.obj `if test -f 'tests/test_dbus_proxy.c'; then $(CYGPATH_W) 'tests/test_dbus_proxy.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_proxy.c'; fi` test_dbus_util.o: tests/test_dbus_util.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_util.o -MD -MP -MF $(DEPDIR)/test_dbus_util.Tpo -c -o test_dbus_util.o `test -f 'tests/test_dbus_util.c' || echo '$(srcdir)/'`tests/test_dbus_util.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_util.Tpo $(DEPDIR)/test_dbus_util.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_util.c' object='test_dbus_util.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_util.o `test -f 'tests/test_dbus_util.c' || echo '$(srcdir)/'`tests/test_dbus_util.c test_dbus_util.obj: tests/test_dbus_util.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_dbus_util.obj -MD -MP -MF $(DEPDIR)/test_dbus_util.Tpo -c -o test_dbus_util.obj `if test -f 'tests/test_dbus_util.c'; then $(CYGPATH_W) 'tests/test_dbus_util.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_util.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_dbus_util.Tpo $(DEPDIR)/test_dbus_util.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='tests/test_dbus_util.c' object='test_dbus_util.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_dbus_util.obj `if test -f 'tests/test_dbus_util.c'; then $(CYGPATH_W) 'tests/test_dbus_util.c'; else $(CYGPATH_W) '$(srcdir)/tests/test_dbus_util.c'; fi` mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-pkgconfigDATA: $(pkgconfig_DATA) @$(NORMAL_INSTALL) test -z "$(pkgconfigdir)" || $(MKDIR_P) "$(DESTDIR)$(pkgconfigdir)" @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgconfigdir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgconfigdir)" || exit $$?; \ done uninstall-pkgconfigDATA: @$(NORMAL_UNINSTALL) @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ test -n "$$files" || exit 0; \ echo " ( cd '$(DESTDIR)$(pkgconfigdir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(pkgconfigdir)" && rm -f $$files install-includeHEADERS: $(include_HEADERS) @$(NORMAL_INSTALL) test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)" @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \ $(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \ done uninstall-includeHEADERS: @$(NORMAL_UNINSTALL) @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ test -n "$$files" || exit 0; \ echo " ( cd '$(DESTDIR)$(includedir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(includedir)" && rm -f $$files install-nihdbusincludeHEADERS: $(nihdbusinclude_HEADERS) @$(NORMAL_INSTALL) test -z "$(nihdbusincludedir)" || $(MKDIR_P) "$(DESTDIR)$(nihdbusincludedir)" @list='$(nihdbusinclude_HEADERS)'; test -n "$(nihdbusincludedir)" || list=; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(nihdbusincludedir)'"; \ $(INSTALL_HEADER) $$files "$(DESTDIR)$(nihdbusincludedir)" || exit $$?; \ done uninstall-nihdbusincludeHEADERS: @$(NORMAL_UNINSTALL) @list='$(nihdbusinclude_HEADERS)'; test -n "$(nihdbusincludedir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ test -n "$$files" || exit 0; \ echo " ( cd '$(DESTDIR)$(nihdbusincludedir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(nihdbusincludedir)" && rm -f $$files ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) set x; \ here=`pwd`; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags check-TESTS: $(TESTS) @failed=0; all=0; xfail=0; xpass=0; skip=0; \ srcdir=$(srcdir); export srcdir; \ list=' $(TESTS) '; \ $(am__tty_colors); \ if test -n "$$list"; then \ for tst in $$list; do \ if test -f ./$$tst; then dir=./; \ elif test -f $$tst; then dir=; \ else dir="$(srcdir)/"; fi; \ if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ all=`expr $$all + 1`; \ case " $(XFAIL_TESTS) " in \ *[\ \ ]$$tst[\ \ ]*) \ xpass=`expr $$xpass + 1`; \ failed=`expr $$failed + 1`; \ col=$$red; res=XPASS; \ ;; \ *) \ col=$$grn; res=PASS; \ ;; \ esac; \ elif test $$? -ne 77; then \ all=`expr $$all + 1`; \ case " $(XFAIL_TESTS) " in \ *[\ \ ]$$tst[\ \ ]*) \ xfail=`expr $$xfail + 1`; \ col=$$lgn; res=XFAIL; \ ;; \ *) \ failed=`expr $$failed + 1`; \ col=$$red; res=FAIL; \ ;; \ esac; \ else \ skip=`expr $$skip + 1`; \ col=$$blu; res=SKIP; \ fi; \ echo "$${col}$$res$${std}: $$tst"; \ done; \ if test "$$all" -eq 1; then \ tests="test"; \ All=""; \ else \ tests="tests"; \ All="All "; \ fi; \ if test "$$failed" -eq 0; then \ if test "$$xfail" -eq 0; then \ banner="$$All$$all $$tests passed"; \ else \ if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ fi; \ else \ if test "$$xpass" -eq 0; then \ banner="$$failed of $$all $$tests failed"; \ else \ if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ fi; \ fi; \ dashes="$$banner"; \ skipped=""; \ if test "$$skip" -ne 0; then \ if test "$$skip" -eq 1; then \ skipped="($$skip test was not run)"; \ else \ skipped="($$skip tests were not run)"; \ fi; \ test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ dashes="$$skipped"; \ fi; \ report=""; \ if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ report="Please report to $(PACKAGE_BUGREPORT)"; \ test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ dashes="$$report"; \ fi; \ dashes=`echo "$$dashes" | sed s/./=/g`; \ if test "$$failed" -eq 0; then \ echo "$$grn$$dashes"; \ else \ echo "$$red$$dashes"; \ fi; \ echo "$$banner"; \ test -z "$$skipped" || echo "$$skipped"; \ test -z "$$report" || echo "$$report"; \ echo "$$dashes$$std"; \ test "$$failed" -eq 0; \ else :; fi distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: check-am all-am: Makefile $(LTLIBRARIES) $(DATA) $(HEADERS) installdirs: for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(includedir)" "$(DESTDIR)$(nihdbusincludedir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ `test -z '$(STRIP)' || \ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install mostlyclean-generic: clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-am clean-am: clean-checkPROGRAMS clean-generic clean-libLTLIBRARIES \ clean-libtool clean-local mostlyclean-am distclean: distclean-am -rm -rf ./$(DEPDIR) -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-includeHEADERS install-nihdbusincludeHEADERS \ install-pkgconfigDATA install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-libLTLIBRARIES install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -rf ./$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic \ maintainer-clean-local mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES \ uninstall-nihdbusincludeHEADERS uninstall-pkgconfigDATA .MAKE: check-am install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \ clean-checkPROGRAMS clean-generic clean-libLTLIBRARIES \ clean-libtool clean-local ctags distclean distclean-compile \ distclean-generic distclean-libtool distclean-tags distdir dvi \ dvi-am html html-am info info-am install install-am \ install-data install-data-am install-dvi install-dvi-am \ install-exec install-exec-am install-html install-html-am \ install-includeHEADERS install-info install-info-am \ install-libLTLIBRARIES install-man \ install-nihdbusincludeHEADERS install-pdf install-pdf-am \ install-pkgconfigDATA install-ps install-ps-am install-strip \ installcheck installcheck-am installdirs maintainer-clean \ maintainer-clean-generic maintainer-clean-local mostlyclean \ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ pdf pdf-am ps ps-am tags uninstall uninstall-am \ uninstall-includeHEADERS uninstall-libLTLIBRARIES \ uninstall-nihdbusincludeHEADERS uninstall-pkgconfigDATA .PHONY: tests tests: $(BUILT_SOURCES) $(check_PROGRAMS) clean-local: rm -f *.gcno *.gcda maintainer-clean-local: rm -f *.gcov # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: libnih-1.0.3/nih-dbus/dbus_util.h0000644000175000017500000000201111445765555013570 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_UTIL_H #define NIH_DBUS_UTIL_H #include NIH_BEGIN_EXTERN char *nih_dbus_path (const void *parent, const char *root, ...) __attribute__ ((sentinel, warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_UTIL_H */ libnih-1.0.3/nih-dbus/dbus_message.c0000644000175000017500000001013511445765555014240 00000000000000/* libnih * * dbus_message.c - D-Bus message handling * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include "dbus_message.h" /* Prototypes for static functions */ static int nih_dbus_message_destroy (NihDBusMessage *msg); /** * nih_dbus_message_new: * @parent: parent object for new message, * @connection: D-Bus connection to associate with, * @message: D-Bus message to encapulsate. * * Creates a new D-Bus message object allocated using nih_alloc(). This * encapsulates both an underlying D-Bus connection and message received * on it, referencing both. * * Objects of this structure are passed to method implementation functions * so the original message information may be extracted; if the function * is asynchronous, you should take a reference to this structure and pass * it when sending the reply or an error. * * When the message is freed, the references to the connection and message * will be dropped, which may disconnect the connection. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned object. When all parents * of the returned object are freed, the returned object will also be * freed. * * Returns: new NihDBusMessage structure, or NULL if insufficient memory. **/ NihDBusMessage * nih_dbus_message_new (const void * parent, DBusConnection *connection, DBusMessage * message) { NihDBusMessage *msg; nih_assert (connection != NULL); nih_assert (message != NULL); msg = nih_new (parent, NihDBusMessage); if (! msg) return NULL; msg->connection = connection; dbus_connection_ref (msg->connection); msg->message = message; dbus_message_ref (msg->message); nih_alloc_set_destructor (msg, nih_dbus_message_destroy); return msg; } /** * nih_dbus_message_destroy: * @msg: message to be destroyed. * * Unreferences the attached D-Bus message and connection. * * Returns: zero **/ static int nih_dbus_message_destroy (NihDBusMessage *msg) { nih_assert (msg != NULL); dbus_message_unref (msg->message); dbus_connection_unref (msg->connection); return 0; } /** * nih_dbus_message_error: * @msg: message to reply to, * @name: name of D-Bus error to reply with, * @format: format string for human-readable message. * * Replies to an asynchronous D-Bus message @msg with the D-Bus error * @name with a human-readable message parsed according to @format. * * Returns: zero on success, negative value on insufficient memory. **/ int nih_dbus_message_error (NihDBusMessage *msg, const char * name, const char * format, ...) { DBusMessage * message; va_list args; nih_local char *str = NULL; nih_assert (msg != NULL); nih_assert (name != NULL); nih_assert (format != NULL); /* Create the message string */ va_start (args, format); str = nih_vsprintf (NULL, format, args); va_end (args); if (! str) return -1; /* And the reply */ message = dbus_message_new_error (msg->message, name, str); if (! message) return -1; /* Send the error back to the connection the original message * was received from. */ if (! dbus_connection_send (msg->connection, message, NULL)) { dbus_message_unref (message); return -1; } dbus_message_unref (message); return 0; } libnih-1.0.3/nih-dbus/tests/0000755000175000017500000000000011504742362012640 500000000000000libnih-1.0.3/nih-dbus/tests/test_dbus_proxy.c0000644000175000017500000006517611445765555016215 00000000000000/* libnih * * test_dbus_proxy.c - test suite for nih-dbus/dbus_proxy.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include static int my_lost_handler_called = FALSE; static void my_lost_handler (void * data, NihDBusProxy *proxy) { my_lost_handler_called++; TEST_NE_P (proxy, NULL); TEST_EQ_P (data, proxy->connection); } static void my_freeing_lost_handler (void * data, NihDBusProxy *proxy) { my_lost_handler_called++; TEST_NE_P (proxy, NULL); TEST_EQ_P (data, proxy->connection); nih_free (proxy); } void test_new (void) { pid_t dbus_pid; DBusConnection *conn; DBusConnection *other_conn; NihDBusProxy * proxy; NihError * err; TEST_FUNCTION ("nih_dbus_proxy_new"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (conn); /* Check that we can create a simple proxy for a remote object on * a peer-to-peer connection, and have a proxy object returned with * the right detailed filled in. */ TEST_FEATURE ("with peer-to-peer object"); TEST_ALLOC_FAIL { proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih", NULL, NULL); if (test_alloc_failed) { TEST_EQ_P (proxy, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_ALLOC_SIZE (proxy, sizeof (NihDBusProxy)); TEST_EQ_P (proxy->connection, conn); TEST_EQ_P (proxy->name, NULL); TEST_EQ_P (proxy->owner, NULL); TEST_ALLOC_PARENT (proxy->path, proxy); TEST_EQ_STR (proxy->path, "/com/netsplit/Nih"); TEST_TRUE (proxy->auto_start); TEST_EQ_P (proxy->lost_handler, NULL); TEST_EQ_P (proxy->data, NULL); nih_free (proxy); } /* Check that we can pass a well-known name which looks up * whether the name is on the bus, and sets up a match for it. * If the name does not exist on the bus, NULL should be set for * the owner. */ TEST_FEATURE ("with unconnected well-known name"); TEST_ALLOC_FAIL { proxy = nih_dbus_proxy_new (NULL, conn, "com.netsplit.Nih", "/com/netsplit/Nih", NULL, NULL); if (test_alloc_failed) { TEST_EQ_P (proxy, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_ALLOC_SIZE (proxy, sizeof (NihDBusProxy)); TEST_EQ_P (proxy->connection, conn); TEST_ALLOC_PARENT (proxy->name, proxy); TEST_EQ_STR (proxy->name, "com.netsplit.Nih"); TEST_EQ_P (proxy->owner, NULL); TEST_ALLOC_PARENT (proxy->path, proxy); TEST_EQ_STR (proxy->path, "/com/netsplit/Nih"); TEST_TRUE (proxy->auto_start); TEST_EQ_P (proxy->lost_handler, NULL); TEST_EQ_P (proxy->data, NULL); /* Constructs the rule when we free */ TEST_ALLOC_SAFE { nih_free (proxy); } } /* Check that we can pass a well-known name when the name * does exist on the bus, and that the unique name of the owner * is stored in the owner member. */ TEST_FEATURE ("with connected well-known name"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (other_conn); assert (dbus_bus_request_name (other_conn, "com.netsplit.Nih", 0, NULL) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); proxy = nih_dbus_proxy_new (NULL, conn, "com.netsplit.Nih", "/com/netsplit/Nih", NULL, NULL); if (test_alloc_failed) { TEST_EQ_P (proxy, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_DBUS_CLOSE (other_conn); continue; } TEST_ALLOC_SIZE (proxy, sizeof (NihDBusProxy)); TEST_EQ_P (proxy->connection, conn); TEST_ALLOC_PARENT (proxy->name, proxy); TEST_EQ_STR (proxy->name, "com.netsplit.Nih"); TEST_ALLOC_PARENT (proxy->owner, proxy); TEST_EQ_STR (proxy->owner, dbus_bus_get_unique_name (other_conn)); TEST_ALLOC_PARENT (proxy->path, proxy); TEST_EQ_STR (proxy->path, "/com/netsplit/Nih"); TEST_TRUE (proxy->auto_start); TEST_EQ_P (proxy->lost_handler, NULL); TEST_EQ_P (proxy->data, NULL); /* Constructs the rule when we free */ TEST_ALLOC_SAFE { nih_free (proxy); } TEST_DBUS_CLOSE (other_conn); } /* Check that we can pass a unique name, and that it is copied * into the owner member. */ TEST_FEATURE ("with unique name"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (other_conn); proxy = nih_dbus_proxy_new (NULL, conn, dbus_bus_get_unique_name (other_conn), "/com/netsplit/Nih", NULL, NULL); if (test_alloc_failed) { TEST_EQ_P (proxy, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); TEST_DBUS_CLOSE (other_conn); continue; } TEST_ALLOC_SIZE (proxy, sizeof (NihDBusProxy)); TEST_EQ_P (proxy->connection, conn); TEST_ALLOC_PARENT (proxy->name, proxy); TEST_EQ_STR (proxy->name, dbus_bus_get_unique_name (other_conn)); TEST_ALLOC_PARENT (proxy->owner, proxy); TEST_EQ_STR (proxy->owner, dbus_bus_get_unique_name (other_conn)); TEST_ALLOC_PARENT (proxy->path, proxy); TEST_EQ_STR (proxy->path, "/com/netsplit/Nih"); TEST_TRUE (proxy->auto_start); TEST_EQ_P (proxy->lost_handler, NULL); TEST_EQ_P (proxy->data, NULL); /* Constructs the rule when we free */ TEST_ALLOC_SAFE { nih_free (proxy); } TEST_DBUS_CLOSE (other_conn); } /* Check that we can pass a lost handler function and data pointer, * which get stored in the structure for later use. */ TEST_FEATURE ("with lost_handler"); TEST_ALLOC_FAIL { proxy = nih_dbus_proxy_new (NULL, conn, "com.netsplit.Nih", "/com/netsplit/Nih", my_lost_handler, conn); if (test_alloc_failed) { TEST_EQ_P (proxy, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); continue; } TEST_ALLOC_SIZE (proxy, sizeof (NihDBusProxy)); TEST_EQ_P (proxy->connection, conn); TEST_ALLOC_PARENT (proxy->name, proxy); TEST_EQ_STR (proxy->name, "com.netsplit.Nih"); TEST_EQ_P (proxy->owner, NULL); TEST_ALLOC_PARENT (proxy->path, proxy); TEST_EQ_STR (proxy->path, "/com/netsplit/Nih"); TEST_TRUE (proxy->auto_start); TEST_EQ_P (proxy->lost_handler, my_lost_handler); TEST_EQ_P (proxy->data, conn); /* Constructs the rule when we free */ TEST_ALLOC_SAFE { nih_free (proxy); } } TEST_DBUS_CLOSE (conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_name_owner_changed (void) { pid_t dbus_pid; DBusConnection *conn; DBusConnection *first_conn; DBusConnection *second_conn; NihDBusProxy * proxy = NULL; char * last_owner; TEST_FUNCTION ("nih_dbus_proxy_name_owner_changed"); TEST_DBUS (dbus_pid); /* Check that when we start off with an unconnected name, and it * joins the bus, the owner field is automatically updated based * on the information in the NameOwnerChanged signal that it's * asked to receive. */ TEST_FEATURE ("with initially unconnected name"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (conn); my_lost_handler_called = FALSE; TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, conn, "com.netsplit.Nih", "/com/netsplit/Nih", my_lost_handler, conn); } TEST_EQ_P (proxy->owner, NULL); TEST_DBUS_OPEN (first_conn); assert (dbus_bus_request_name (first_conn, "com.netsplit.Nih", 0, NULL) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); TEST_DBUS_DISPATCH (conn); TEST_ALLOC_PARENT (proxy->owner, proxy); TEST_EQ_STR (proxy->owner, dbus_bus_get_unique_name (first_conn)); TEST_FALSE (my_lost_handler_called); /* Constructs the rule when we free */ TEST_ALLOC_SAFE { nih_free (proxy); } TEST_DBUS_CLOSE (first_conn); TEST_DBUS_CLOSE (conn); } /* Check that when we start off with an unconnected name, and it * changes its name after having joined the bus, the owner field * is updated again. */ TEST_FEATURE ("with change of initially unconnected name"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (conn); my_lost_handler_called = FALSE; TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, conn, "com.netsplit.Nih", "/com/netsplit/Nih", my_lost_handler, conn); } TEST_EQ_P (proxy->owner, NULL); TEST_DBUS_OPEN (first_conn); assert (dbus_bus_request_name (first_conn, "com.netsplit.Nih", DBUS_NAME_FLAG_ALLOW_REPLACEMENT, NULL) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); TEST_DBUS_DISPATCH (conn); TEST_ALLOC_PARENT (proxy->owner, proxy); TEST_EQ_STR (proxy->owner, dbus_bus_get_unique_name (first_conn)); last_owner = proxy->owner; TEST_FREE_TAG (last_owner); TEST_FALSE (my_lost_handler_called); TEST_DBUS_OPEN (second_conn); assert (dbus_bus_request_name (second_conn, "com.netsplit.Nih", DBUS_NAME_FLAG_REPLACE_EXISTING, NULL) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); TEST_DBUS_DISPATCH (conn); TEST_ALLOC_PARENT (proxy->owner, proxy); TEST_EQ_STR (proxy->owner, dbus_bus_get_unique_name (second_conn)); TEST_FREE (last_owner); TEST_FALSE (my_lost_handler_called); /* Constructs the rule when we free */ TEST_ALLOC_SAFE { nih_free (proxy); } TEST_DBUS_CLOSE (first_conn); TEST_DBUS_CLOSE (second_conn); TEST_DBUS_CLOSE (conn); } /* Check that when we start off with an connected name, and it * changes its name, the owner field is updated. */ TEST_FEATURE ("with change of initially connected name"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (conn); my_lost_handler_called = FALSE; TEST_DBUS_OPEN (first_conn); assert (dbus_bus_request_name (first_conn, "com.netsplit.Nih", DBUS_NAME_FLAG_ALLOW_REPLACEMENT, NULL) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, conn, "com.netsplit.Nih", "/com/netsplit/Nih", my_lost_handler, conn); } TEST_ALLOC_PARENT (proxy->owner, proxy); TEST_EQ_STR (proxy->owner, dbus_bus_get_unique_name (first_conn)); last_owner = proxy->owner; TEST_FREE_TAG (last_owner); TEST_DBUS_OPEN (second_conn); assert (dbus_bus_request_name (second_conn, "com.netsplit.Nih", DBUS_NAME_FLAG_REPLACE_EXISTING, NULL) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); TEST_DBUS_DISPATCH (conn); TEST_ALLOC_PARENT (proxy->owner, proxy); TEST_EQ_STR (proxy->owner, dbus_bus_get_unique_name (second_conn)); TEST_FREE (last_owner); TEST_FALSE (my_lost_handler_called); /* Constructs the rule when we free */ TEST_ALLOC_SAFE { nih_free (proxy); } TEST_DBUS_CLOSE (first_conn); TEST_DBUS_CLOSE (second_conn); TEST_DBUS_CLOSE (conn); } /* Check that when an initially connected name leaves the bus, * the lost handler is called and the owner field reset to NULL. */ TEST_FEATURE ("with loss of initially unconnected name"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (conn); my_lost_handler_called = FALSE; TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, conn, "com.netsplit.Nih", "/com/netsplit/Nih", my_lost_handler, conn); } TEST_EQ_P (proxy->owner, NULL); TEST_DBUS_OPEN (first_conn); assert (dbus_bus_request_name (first_conn, "com.netsplit.Nih", 0, NULL) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); TEST_DBUS_DISPATCH (conn); TEST_ALLOC_PARENT (proxy->owner, proxy); TEST_EQ_STR (proxy->owner, dbus_bus_get_unique_name (first_conn)); last_owner = proxy->owner; TEST_FREE_TAG (last_owner); TEST_FALSE (my_lost_handler_called); TEST_DBUS_CLOSE (first_conn); TEST_DBUS_DISPATCH (conn); TEST_EQ_P (proxy->owner, NULL); TEST_FREE (last_owner); TEST_TRUE (my_lost_handler_called); /* Constructs the rule when we free */ TEST_ALLOC_SAFE { nih_free (proxy); } TEST_DBUS_CLOSE (conn); } /* Check that when an initially connected name leaves the bus, * the lost handler is called and the owner field reset to NULL. */ TEST_FEATURE ("with loss of initially connected name"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (conn); my_lost_handler_called = FALSE; TEST_DBUS_OPEN (first_conn); assert (dbus_bus_request_name (first_conn, "com.netsplit.Nih", 0, NULL) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, conn, "com.netsplit.Nih", "/com/netsplit/Nih", my_lost_handler, conn); } TEST_ALLOC_PARENT (proxy->owner, proxy); TEST_EQ_STR (proxy->owner, dbus_bus_get_unique_name (first_conn)); last_owner = proxy->owner; TEST_FREE_TAG (last_owner); TEST_DBUS_CLOSE (first_conn); TEST_DBUS_DISPATCH (conn); TEST_EQ_P (proxy->owner, NULL); TEST_FREE (last_owner); TEST_TRUE (my_lost_handler_called); /* Constructs the rule when we free */ TEST_ALLOC_SAFE { nih_free (proxy); } TEST_DBUS_CLOSE (conn); } /* Check that when a unique name leaves the bus, the lost handler * is still called and the owner field rest to NULL. */ TEST_FEATURE ("with loss of unique name"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (conn); my_lost_handler_called = FALSE; TEST_DBUS_OPEN (first_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, conn, dbus_bus_get_unique_name (first_conn), "/com/netsplit/Nih", my_lost_handler, conn); } TEST_ALLOC_PARENT (proxy->owner, proxy); TEST_EQ_STR (proxy->owner, dbus_bus_get_unique_name (first_conn)); last_owner = proxy->owner; TEST_FREE_TAG (last_owner); TEST_DBUS_CLOSE (first_conn); TEST_DBUS_DISPATCH (conn); TEST_EQ_P (proxy->owner, NULL); TEST_FREE (last_owner); TEST_TRUE (my_lost_handler_called); /* Constructs the rule when we free */ TEST_ALLOC_SAFE { nih_free (proxy); } TEST_DBUS_CLOSE (conn); } /* Check that if the lost handler doesn't free the structure and * it comes back on the bus after having left, the owner field * is updated with the new name. */ TEST_FEATURE ("with return of lost name"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (conn); my_lost_handler_called = FALSE; TEST_DBUS_OPEN (first_conn); assert (dbus_bus_request_name (first_conn, "com.netsplit.Nih", 0, NULL) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, conn, "com.netsplit.Nih", "/com/netsplit/Nih", my_lost_handler, conn); } TEST_ALLOC_PARENT (proxy->owner, proxy); TEST_EQ_STR (proxy->owner, dbus_bus_get_unique_name (first_conn)); last_owner = proxy->owner; TEST_FREE_TAG (last_owner); TEST_DBUS_CLOSE (first_conn); TEST_DBUS_DISPATCH (conn); TEST_EQ_P (proxy->owner, NULL); TEST_FREE (last_owner); TEST_TRUE (my_lost_handler_called); my_lost_handler_called = FALSE; TEST_DBUS_OPEN (second_conn); assert (dbus_bus_request_name (second_conn, "com.netsplit.Nih", 0, NULL) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); TEST_DBUS_DISPATCH (conn); TEST_ALLOC_PARENT (proxy->owner, proxy); TEST_EQ_STR (proxy->owner, dbus_bus_get_unique_name (second_conn)); /* Constructs the rule when we free */ TEST_ALLOC_SAFE { nih_free (proxy); } TEST_DBUS_CLOSE (second_conn); TEST_DBUS_CLOSE (conn); } /* Check that the lost handler may free the proxy structure. */ TEST_FEATURE ("with free of proxy structure by handler"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (conn); my_lost_handler_called = FALSE; TEST_DBUS_OPEN (first_conn); assert (dbus_bus_request_name (first_conn, "com.netsplit.Nih", 0, NULL) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, conn, "com.netsplit.Nih", "/com/netsplit/Nih", my_freeing_lost_handler, conn); } TEST_ALLOC_PARENT (proxy->owner, proxy); TEST_EQ_STR (proxy->owner, dbus_bus_get_unique_name (first_conn)); TEST_FREE_TAG (proxy); TEST_DBUS_CLOSE (first_conn); TEST_DBUS_DISPATCH (conn); TEST_FREE (proxy); TEST_TRUE (my_lost_handler_called); TEST_DBUS_CLOSE (conn); } TEST_DBUS_END (dbus_pid); dbus_shutdown (); } static int my_signal_filter_called = FALSE; static DBusConnection * last_conn = NULL; static DBusMessage * last_message = NULL; static NihDBusProxySignal *last_proxied = NULL; static DBusHandlerResult my_signal_filter (DBusConnection * conn, DBusMessage * message, NihDBusProxySignal *proxied) { my_signal_filter_called++; TEST_NE_P (conn, NULL); last_conn = conn; TEST_NE_P (message, NULL); last_message = message; dbus_message_ref (message); TEST_NE_P (proxied, NULL); last_proxied = proxied; return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } static void my_signal_handler (void * data, NihDBusMessage *message, ...) { } const NihDBusSignal my_interface_signals[] = { { "MySignal", NULL, my_signal_filter }, { NULL } }; const NihDBusInterface my_interface = { "com.netsplit.Nih", NULL, my_interface_signals, NULL }; void test_connect (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; NihDBusProxy * proxy = NULL; NihDBusProxySignal *proxied; NihError * err; DBusMessage * signal; dbus_uint32_t serial; DBusError dbus_error; TEST_FUNCTION ("nih_dbus_proxy_connect"); TEST_DBUS (dbus_pid); /* Check that we can connect a signal to a bus connection, with the * remote end identified by a unique name and having a proxied signal * structure returned to us. If a matching signal is then emitted by * the server-side, the filter function is called with the expected * arguments. */ TEST_FEATURE ("with bus connection by unique name"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, NULL); } proxied = nih_dbus_proxy_connect (proxy, &my_interface, "MySignal", my_signal_handler, NULL); if (test_alloc_failed) { TEST_EQ_P (proxied, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); continue; } TEST_ALLOC_SIZE (proxied, sizeof (NihDBusProxySignal)); TEST_EQ_P (proxied->proxy, proxy); TEST_EQ_P (proxied->interface, &my_interface); TEST_EQ_P (proxied->signal, &my_interface_signals[0]); TEST_EQ_P (proxied->handler, my_signal_handler); TEST_EQ_P (proxied->data, NULL); TEST_ALLOC_PARENT (proxied, proxy); my_signal_filter_called = FALSE; last_conn = NULL; last_message = NULL; last_proxied = NULL; signal = dbus_message_new_signal ("/com/netsplit/Nih", "com.netsplit.Nih", "MySignal"); dbus_connection_send (server_conn, signal, &serial); dbus_connection_flush (server_conn); dbus_message_unref (signal); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (my_signal_filter_called); TEST_EQ_P (last_conn, client_conn); TEST_NE_P (last_message, NULL); TEST_EQ (dbus_message_get_serial (last_message), serial); TEST_TRUE (dbus_message_is_signal (last_message, "com.netsplit.Nih", "MySignal")); TEST_EQ_STR (dbus_message_get_path (last_message), "/com/netsplit/Nih"); TEST_EQ_P (last_proxied, proxied); dbus_message_unref (last_message); TEST_ALLOC_SAFE { nih_free (proxied); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); } /* Check that we can connect a signal to a bus connection, with the * remote end identified by a well-known name and having a proxied * signal structure returned to us. If a matching signal is then emitted * by the server-side, the filter function is called with the expected * arguments. */ TEST_FEATURE ("with bus connection by well known name"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); assert (dbus_bus_request_name (server_conn, "com.netsplit.Nih", 0, NULL) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, "com.netsplit.Nih", "/com/netsplit/Nih", NULL, NULL); } proxied = nih_dbus_proxy_connect (proxy, &my_interface, "MySignal", my_signal_handler, NULL); if (test_alloc_failed) { TEST_EQ_P (proxied, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); continue; } TEST_ALLOC_SIZE (proxied, sizeof (NihDBusProxySignal)); TEST_EQ_P (proxied->proxy, proxy); TEST_EQ_P (proxied->interface, &my_interface); TEST_EQ_P (proxied->signal, &my_interface_signals[0]); TEST_EQ_P (proxied->handler, my_signal_handler); TEST_EQ_P (proxied->data, NULL); TEST_ALLOC_PARENT (proxied, proxy); my_signal_filter_called = FALSE; last_conn = NULL; last_message = NULL; last_proxied = NULL; signal = dbus_message_new_signal ("/com/netsplit/Nih", "com.netsplit.Nih", "MySignal"); dbus_connection_send (server_conn, signal, &serial); dbus_connection_flush (server_conn); dbus_message_unref (signal); TEST_DBUS_DISPATCH (client_conn); TEST_TRUE (my_signal_filter_called); TEST_EQ_P (last_conn, client_conn); TEST_NE_P (last_message, NULL); TEST_EQ (dbus_message_get_serial (last_message), serial); TEST_TRUE (dbus_message_is_signal (last_message, "com.netsplit.Nih", "MySignal")); TEST_EQ_STR (dbus_message_get_path (last_message), "/com/netsplit/Nih"); TEST_EQ_P (last_proxied, proxied); dbus_message_unref (last_message); TEST_ALLOC_SAFE { nih_free (proxied); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); } /* Check that we can also connect a signal to a peer-to-peer * connection that does not have a name. If a matching signal * is then emitted by the other side, the filter function is * called with the expected arguments. We cheat for this and * just make the client accept all signals rather than using a * real peer-to-peer. */ TEST_FEATURE ("with peer-to-peer connection"); TEST_ALLOC_FAIL { TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, NULL, "/com/netsplit/Nih", NULL, NULL); } proxied = nih_dbus_proxy_connect (proxy, &my_interface, "MySignal", my_signal_handler, NULL); if (test_alloc_failed) { TEST_EQ_P (proxied, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); nih_free (proxy); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); continue; } TEST_ALLOC_SIZE (proxied, sizeof (NihDBusProxySignal)); TEST_EQ_P (proxied->proxy, proxy); TEST_EQ_P (proxied->interface, &my_interface); TEST_EQ_P (proxied->signal, &my_interface_signals[0]); TEST_EQ_P (proxied->handler, my_signal_handler); TEST_EQ_P (proxied->data, NULL); TEST_ALLOC_PARENT (proxied, proxy); my_signal_filter_called = FALSE; last_conn = NULL; last_message = NULL; last_proxied = NULL; dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); dbus_error_free (&dbus_error); signal = dbus_message_new_signal ("/com/netsplit/Nih", "com.netsplit.Nih", "MySignal"); dbus_connection_send (server_conn, signal, &serial); dbus_connection_flush (server_conn); dbus_message_unref (signal); TEST_DBUS_DISPATCH (client_conn); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); dbus_error_free (&dbus_error); TEST_TRUE (my_signal_filter_called); TEST_EQ_P (last_conn, client_conn); TEST_NE_P (last_message, NULL); TEST_EQ (dbus_message_get_serial (last_message), serial); TEST_TRUE (dbus_message_is_signal (last_message, "com.netsplit.Nih", "MySignal")); TEST_EQ_STR (dbus_message_get_path (last_message), "/com/netsplit/Nih"); TEST_EQ_P (last_proxied, proxied); dbus_message_unref (last_message); TEST_ALLOC_SAFE { nih_free (proxied); nih_free (proxy); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); } TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_signal_destroy (void) { pid_t dbus_pid; DBusConnection * client_conn; DBusConnection * server_conn; NihDBusProxy * proxy = NULL; NihDBusProxySignal *proxied = NULL; DBusMessage * signal; DBusError dbus_error; /* Check that when an NihDBusProxySignal structure is destroyed, * a signal no longer results in the filter function being called. */ TEST_FUNCTION ("nih_dbus_proxy_signal_destroy"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (client_conn); TEST_DBUS_OPEN (server_conn); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { proxy = nih_dbus_proxy_new (NULL, client_conn, NULL, "/com/netsplit/Nih", NULL, NULL); proxied = nih_dbus_proxy_connect (proxy, &my_interface, "MySignal", my_signal_handler, NULL); } my_signal_filter_called = FALSE; last_conn = NULL; last_message = NULL; last_proxied = NULL; dbus_error_init (&dbus_error); dbus_bus_add_match (client_conn, "type='signal'", &dbus_error); dbus_error_free (&dbus_error); signal = dbus_message_new_signal ("/com/netsplit/Nih", "com.netsplit.Nih", "MySignal"); dbus_connection_send (server_conn, signal, NULL); dbus_connection_flush (server_conn); dbus_message_unref (signal); /* Free the proxied signal */ nih_free (proxied); TEST_DBUS_DISPATCH (client_conn); dbus_error_init (&dbus_error); dbus_bus_remove_match (client_conn, "type='signal'", &dbus_error); dbus_error_free (&dbus_error); TEST_FALSE (my_signal_filter_called); TEST_ALLOC_SAFE { nih_free (proxy); } } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } int main (int argc, char *argv[]) { nih_error_init (); test_new (); test_name_owner_changed (); test_connect (); test_signal_destroy (); return 0; } libnih-1.0.3/nih-dbus/tests/test_dbus_connection.c0000644000175000017500000011221711445765555017160 00000000000000/* libnih * * test_dbus_connection.c - test suite for nih-dbus/dbus_connection.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static DBusConnection *client_connection = NULL; static void my_new_connection (DBusServer * server, DBusConnection *connection, void * data) { dbus_connection_ref (connection); if (client_connection) { dbus_connection_close (client_connection); dbus_connection_unref (client_connection); } client_connection = connection; } static int disconnected = FALSE; static DBusConnection *last_disconnection = NULL; static void my_disconnect_handler (DBusConnection *connection) { disconnected = TRUE; last_disconnection = connection; nih_main_loop_exit (0); } static void my_new_connection_drop (DBusServer * server, DBusConnection *connection, void * data) { } static int my_message_received = FALSE; static DBusHandlerResult my_message_received_function (DBusConnection *connection, DBusMessage * message, void * data) { my_message_received++; return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } static void my_new_connection_fake (DBusServer * server, DBusConnection *connection, void * data) { DBusMessage *signal; my_new_connection (server, connection, data); signal = dbus_message_new_signal (DBUS_PATH_LOCAL "x", DBUS_INTERFACE_LOCAL "x", "Disconnected"); dbus_connection_send (client_connection, signal, NULL); dbus_connection_flush (client_connection); dbus_message_unref (signal); } static DBusHandlerResult my_message_received_break_function (DBusConnection *connection, DBusMessage * message, void * data) { my_message_received++; nih_main_loop_exit (0); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } static DBusHandlerResult my_message_handle_function (DBusConnection *connection, DBusMessage * message, void * data) { DBusMessage *reply; reply = dbus_message_new_method_return (message); dbus_connection_send (connection, reply, NULL); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; } static int my_method_connect_handler (DBusServer * server, DBusConnection *connection) { if (client_connection) { dbus_connection_close (client_connection); dbus_connection_unref (client_connection); } client_connection = connection; dbus_connection_add_filter (client_connection, my_message_handle_function, NULL, NULL); return TRUE; } static void my_notify_function (DBusPendingCall *pending_call, void * data) { nih_main_loop_exit (0); } void test_connect (void) { pid_t dbus_pid = 0; int wait_fd; DBusServer * server; DBusConnection * conn = NULL; DBusConnection * last_conn; NihIoWatch * io_watch = NULL; NihMainLoopFunc *loop_func = NULL; NihError * err; int fd; int status; DBusMessage * method_call = NULL; DBusPendingCall *pending_call = NULL; DBusMessage * reply; int ret; TEST_FUNCTION ("nih_dbus_connect"); /* Check that we can create a new connection to a listening dbus * server, the returned object should be hooked up to the main loop * and the server should receive the connection. */ TEST_FEATURE ("with listening server"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { TEST_CHILD_WAIT (dbus_pid, wait_fd) { NihSignal *sh; nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (sh = nih_signal_add_handler (NULL, SIGTERM, nih_main_term_signal, NULL)); server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", NULL, NULL); assert (server != NULL); dbus_server_set_new_connection_function (server, my_new_connection, NULL, NULL); client_connection = NULL; TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); if (client_connection) { dbus_connection_close (client_connection); dbus_connection_unref (client_connection); } dbus_server_disconnect (server); dbus_server_unref (server); dbus_shutdown (); nih_free (sh); exit (0); } } conn = nih_dbus_connect ("unix:abstract=/com/netsplit/nih/test_dbus", NULL); if (test_alloc_failed) { TEST_EQ_P (conn, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); kill (dbus_pid, SIGTERM); waitpid (dbus_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); dbus_shutdown (); continue; } TEST_NE_P (conn, NULL); TEST_TRUE (dbus_connection_get_is_connected (conn)); /* Should be a single I/O watch */ TEST_LIST_NOT_EMPTY (nih_io_watches); io_watch = (NihIoWatch *)nih_io_watches->next; dbus_connection_get_unix_fd (conn, &fd); TEST_EQ (io_watch->fd, fd); TEST_NE_P (io_watch->data, NULL); TEST_EQ_P (io_watch->entry.next, nih_io_watches); /* Should be a single main loop function. */ TEST_LIST_NOT_EMPTY (nih_main_loop_functions); loop_func = (NihMainLoopFunc *)nih_main_loop_functions->next; TEST_EQ_P (loop_func->data, conn); TEST_EQ_P (loop_func->entry.next, nih_main_loop_functions); dbus_connection_unref (conn); kill (dbus_pid, SIGTERM); waitpid (dbus_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); dbus_shutdown (); } /* Check that if the server disconnects, our disconnect handler is * called and the connection is automatically unreferenced, freeing * the loop function. Any other filter function we've placed on * the connection should also be run. */ TEST_FEATURE ("with disconnection from server"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { TEST_CHILD_WAIT (dbus_pid, wait_fd) { NihSignal *sh; nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (sh = nih_signal_add_handler (NULL, SIGTERM, nih_main_term_signal, NULL)); server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", NULL, NULL); assert (server != NULL); dbus_server_set_new_connection_function (server, my_new_connection, NULL, NULL); client_connection = NULL; TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); if (client_connection) { dbus_connection_close (client_connection); dbus_connection_unref (client_connection); } dbus_server_disconnect (server); dbus_server_unref (server); dbus_shutdown (); nih_free (sh); exit (0); } conn = nih_dbus_connect ("unix:abstract=/com/netsplit/nih/test_dbus", my_disconnect_handler); assert (conn != NULL); assert (dbus_connection_get_is_connected (conn)); assert (! NIH_LIST_EMPTY (nih_io_watches)); io_watch = (NihIoWatch *)nih_io_watches->next; dbus_connection_get_unix_fd (conn, &fd); assert (io_watch->fd == fd); assert (! NIH_LIST_EMPTY (nih_main_loop_functions)); loop_func = (NihMainLoopFunc *)nih_main_loop_functions->next; assert (loop_func->data == conn); } disconnected = FALSE; last_disconnection = NULL; my_message_received = FALSE; dbus_connection_add_filter (conn, my_message_received_function, NULL, NULL); TEST_FREE_TAG (io_watch); TEST_FREE_TAG (loop_func); kill (dbus_pid, SIGTERM); waitpid (dbus_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); nih_main_loop (); TEST_TRUE (disconnected); TEST_EQ_P (last_disconnection, conn); TEST_TRUE (my_message_received); TEST_FREE (io_watch); TEST_FREE (loop_func); dbus_shutdown (); } /* Check that a fake Disconnected signal does not trigger automatic * disconnection but does call our other filter function. We can * only test a wrong path and interface because otherwise D-Bus * disconnects us for sending naughty data. */ TEST_FEATURE ("with disconnection signal from wrong path"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { TEST_CHILD_WAIT (dbus_pid, wait_fd) { NihSignal *sh; nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (sh = nih_signal_add_handler (NULL, SIGTERM, nih_main_term_signal, NULL)); server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", NULL, NULL); assert (server != NULL); dbus_server_set_new_connection_function (server, my_new_connection_fake, NULL, NULL); client_connection = NULL; TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); if (client_connection) { dbus_connection_close (client_connection); dbus_connection_unref (client_connection); } dbus_server_disconnect (server); dbus_server_unref (server); dbus_shutdown (); nih_free (sh); exit (0); } conn = nih_dbus_connect ("unix:abstract=/com/netsplit/nih/test_dbus", my_disconnect_handler); assert (conn != NULL); assert (dbus_connection_get_is_connected (conn)); assert (! NIH_LIST_EMPTY (nih_io_watches)); io_watch = (NihIoWatch *)nih_io_watches->next; dbus_connection_get_unix_fd (conn, &fd); assert (io_watch->fd == fd); assert (! NIH_LIST_EMPTY (nih_main_loop_functions)); loop_func = (NihMainLoopFunc *)nih_main_loop_functions->next; assert (loop_func->data == conn); } disconnected = FALSE; last_disconnection = NULL; my_message_received = FALSE; dbus_connection_add_filter (conn, my_message_received_break_function, NULL, NULL); TEST_FREE_TAG (io_watch); TEST_FREE_TAG (loop_func); nih_main_loop (); TEST_FALSE (disconnected); TEST_TRUE (my_message_received); TEST_NOT_FREE (io_watch); TEST_NOT_FREE (loop_func); dbus_connection_unref (conn); kill (dbus_pid, SIGTERM); waitpid (dbus_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); dbus_shutdown (); } /* Check that by using a GUID we can reuse connections to the same * server, the second call to connect just returns the same * connection as the first. */ TEST_FEATURE ("with multiple shared connections"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { TEST_CHILD_WAIT (dbus_pid, wait_fd) { NihSignal *sh; nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (sh = nih_signal_add_handler (NULL, SIGTERM, nih_main_term_signal, NULL)); server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", NULL, NULL); assert (server != NULL); dbus_server_set_new_connection_function (server, my_new_connection, NULL, NULL); client_connection = NULL; TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); if (client_connection) { dbus_connection_close (client_connection); dbus_connection_unref (client_connection); } dbus_server_disconnect (server); dbus_server_unref (server); dbus_shutdown (); nih_free (sh); exit (0); } conn = nih_dbus_connect ("unix:abstract=/com/netsplit/nih/test_dbus,guid=deadbeef", my_disconnect_handler); assert (conn != NULL); assert (dbus_connection_get_is_connected (conn)); assert (! NIH_LIST_EMPTY (nih_io_watches)); io_watch = (NihIoWatch *)nih_io_watches->next; dbus_connection_get_unix_fd (conn, &fd); assert (io_watch->fd == fd); assert (! NIH_LIST_EMPTY (nih_main_loop_functions)); loop_func = (NihMainLoopFunc *)nih_main_loop_functions->next; assert (loop_func->data == conn); } TEST_FREE_TAG (io_watch); TEST_FREE_TAG (loop_func); last_conn = conn; /* Make another connection */ conn = nih_dbus_connect ("unix:abstract=/com/netsplit/nih/test_dbus,guid=deadbeef", my_disconnect_handler); if (test_alloc_failed && (conn == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); } else { TEST_EQ_P (conn, last_conn); } /* Still should be a single I/O watch */ TEST_NOT_FREE (io_watch); TEST_LIST_NOT_EMPTY (nih_io_watches); TEST_EQ_P ((NihIoWatch *)nih_io_watches->next, io_watch); TEST_EQ_P (io_watch->entry.next, nih_io_watches); /* Still should be a single main loop function */ TEST_NOT_FREE (loop_func); TEST_LIST_NOT_EMPTY (nih_main_loop_functions); TEST_EQ_P ((NihMainLoopFunc *)nih_main_loop_functions->next, loop_func); TEST_EQ_P (loop_func->entry.next, nih_main_loop_functions); /* Disconnection should free both references */ disconnected = FALSE; last_disconnection = NULL; kill (dbus_pid, SIGTERM); waitpid (dbus_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); nih_main_loop (); TEST_TRUE (disconnected); TEST_EQ_P (last_disconnection, last_conn); TEST_FREE (io_watch); TEST_FREE (loop_func); dbus_shutdown (); } /* Check that we can create a new connection to a listening dbus * server, it should return a hooked up object but if the server * immediately drops it, should get disconnected. */ TEST_FEATURE ("with server that drops our connection"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { TEST_CHILD_WAIT (dbus_pid, wait_fd) { NihSignal *sh; nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (sh = nih_signal_add_handler (NULL, SIGTERM, nih_main_term_signal, NULL)); server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", NULL, NULL); assert (server != NULL); dbus_server_set_new_connection_function (server, my_new_connection_drop, NULL, NULL); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); dbus_server_disconnect (server); dbus_server_unref (server); dbus_shutdown (); nih_free (sh); exit (0); } conn = nih_dbus_connect ("unix:abstract=/com/netsplit/nih/test_dbus", my_disconnect_handler); assert (conn != NULL); assert (dbus_connection_get_is_connected (conn)); assert (! NIH_LIST_EMPTY (nih_io_watches)); io_watch = (NihIoWatch *)nih_io_watches->next; dbus_connection_get_unix_fd (conn, &fd); assert (io_watch->fd == fd); assert (! NIH_LIST_EMPTY (nih_main_loop_functions)); loop_func = (NihMainLoopFunc *)nih_main_loop_functions->next; assert (loop_func->data == conn); } TEST_FREE_TAG (io_watch); TEST_FREE_TAG (loop_func); disconnected = FALSE; last_disconnection = NULL; nih_main_loop (); TEST_TRUE (disconnected); TEST_EQ_P (last_disconnection, conn); TEST_FREE (io_watch); TEST_FREE (loop_func); kill (dbus_pid, SIGTERM); waitpid (dbus_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); dbus_shutdown (); } /* Check that if we create a new connection to a non-listening * address, no object is returned. */ TEST_FEATURE ("with non-listening server"); TEST_ALLOC_FAIL { conn = nih_dbus_connect ("unix:abstract=/com/netsplit/nih/test_dbus", NULL); TEST_EQ_P (conn, NULL); err = nih_error_get (); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); TEST_EQ_STR (((NihDBusError *)err)->name, DBUS_ERROR_NO_SERVER); nih_free (err); dbus_shutdown (); } /* Check that we can make a method call on the connection to the * server and that we can receive its reply, all from the main * loop. */ TEST_FEATURE ("with method call and reply"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { TEST_CHILD_WAIT (dbus_pid, wait_fd) { NihSignal *sh; nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (sh = nih_signal_add_handler (NULL, SIGTERM, nih_main_term_signal, NULL)); server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", my_method_connect_handler, NULL); assert (server != NULL); client_connection = NULL; TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); if (client_connection) { dbus_connection_close (client_connection); dbus_connection_unref (client_connection); } dbus_server_disconnect (server); dbus_server_unref (server); dbus_shutdown (); nih_free (sh); exit (0); } } conn = nih_dbus_connect ("unix:abstract=/com/netsplit/nih/test_dbus", NULL); if (test_alloc_failed && (conn == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); kill (dbus_pid, SIGTERM); waitpid (dbus_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); dbus_shutdown (); continue; } TEST_NE_P (conn, NULL); TEST_TRUE (dbus_connection_get_is_connected (conn)); method_call = dbus_message_new_method_call ( "com.netsplit.Nih.Test", "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "TestMethod"); pending_call = NULL; ret = dbus_connection_send_with_reply (conn, method_call, &pending_call, 30000); if (test_alloc_failed && (ret == FALSE)) { dbus_message_unref (method_call); assert (! pending_call); dbus_connection_unref (conn); kill (dbus_pid, SIGTERM); waitpid (dbus_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); dbus_shutdown (); continue; } dbus_message_unref (method_call); assert (pending_call != NULL); dbus_pending_call_set_notify (pending_call, my_notify_function, NULL, NULL); nih_main_loop (); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_NE_P (reply, NULL); dbus_pending_call_unref (pending_call); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); dbus_message_unref (reply); dbus_connection_unref (conn); kill (dbus_pid, SIGTERM); waitpid (dbus_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); dbus_shutdown (); } /* Check that we can make a method call on the connection to the * server and that it can timeout, all from the main loop. */ TEST_FEATURE ("with method call and timeout"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { TEST_CHILD_WAIT (dbus_pid, wait_fd) { NihSignal *sh; nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (sh = nih_signal_add_handler (NULL, SIGTERM, nih_main_term_signal, NULL)); server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", NULL, NULL); assert (server != NULL); dbus_server_set_new_connection_function (server, my_new_connection, NULL, NULL); client_connection = NULL; TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); if (client_connection) { dbus_connection_close (client_connection); dbus_connection_unref (client_connection); } dbus_server_disconnect (server); dbus_server_unref (server); dbus_shutdown (); nih_free (sh); exit (0); } } conn = nih_dbus_connect ("unix:abstract=/com/netsplit/nih/test_dbus", NULL); if (test_alloc_failed && (conn == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); kill (dbus_pid, SIGTERM); waitpid (dbus_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); dbus_shutdown (); continue; } TEST_NE_P (conn, NULL); TEST_TRUE (dbus_connection_get_is_connected (conn)); method_call = dbus_message_new_method_call ( "com.netsplit.Nih.Test", "/com/netsplit/Nih/Test", "com.netsplit.Nih.Test", "TestMethod"); pending_call = NULL; ret = dbus_connection_send_with_reply (conn, method_call, &pending_call, 100); if (test_alloc_failed && (ret == FALSE)) { dbus_message_unref (method_call); assert (! pending_call); dbus_connection_unref (conn); kill (dbus_pid, SIGTERM); waitpid (dbus_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); dbus_shutdown (); continue; } dbus_message_unref (method_call); assert (pending_call != NULL); dbus_pending_call_set_notify (pending_call, my_notify_function, NULL, NULL); nih_main_loop (); TEST_TRUE (dbus_pending_call_get_completed (pending_call)); reply = dbus_pending_call_steal_reply (pending_call); TEST_NE_P (reply, NULL); dbus_pending_call_unref (pending_call); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_ERROR); TEST_EQ_STR (dbus_message_get_error_name (reply), DBUS_ERROR_NO_REPLY); dbus_message_unref (reply); dbus_connection_unref (conn); kill (dbus_pid, SIGTERM); waitpid (dbus_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); dbus_shutdown (); } } void test_bus (void) { DBusServer * server; DBusConnection * conn; DBusConnection * last_conn; NihIoWatch * io_watch = NULL; NihMainLoopFunc *loop_func = NULL; NihError * err; pid_t pid1; pid_t pid2; int fd; int wait_fd; int status; TEST_FUNCTION ("nih_dbus_bus"); conn = dbus_bus_get_private (DBUS_BUS_SESSION, NULL); if (! conn) { printf ("SKIP: session bus not available\n"); goto system_bus; } dbus_connection_close (conn); dbus_connection_unref (conn); dbus_shutdown (); /* Check that we can create a connection to the D-Bus session bus, * the returned object should be hooked up to the main loop. */ TEST_FEATURE ("with session bus"); TEST_ALLOC_FAIL { conn = nih_dbus_bus (DBUS_BUS_SESSION, my_disconnect_handler); if (test_alloc_failed) { TEST_EQ_P (conn, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); dbus_shutdown (); continue; } TEST_NE_P (conn, NULL); TEST_TRUE (dbus_connection_get_is_connected (conn)); /* Should be a single I/O watch */ TEST_LIST_NOT_EMPTY (nih_io_watches); io_watch = (NihIoWatch *)nih_io_watches->next; dbus_connection_get_unix_fd (conn, &fd); TEST_EQ (io_watch->fd, fd); TEST_NE_P (io_watch->data, NULL); TEST_EQ_P (io_watch->entry.next, nih_io_watches); /* Should be a single main loop function. */ TEST_LIST_NOT_EMPTY (nih_main_loop_functions); loop_func = (NihMainLoopFunc *)nih_main_loop_functions->next; TEST_EQ_P (loop_func->data, conn); TEST_EQ_P (loop_func->entry.next, nih_main_loop_functions); dbus_connection_unref (conn); dbus_shutdown (); } system_bus: conn = dbus_bus_get_private (DBUS_BUS_SYSTEM, NULL); if (! conn) { printf ("SKIP: system bus not available\n"); return; } dbus_connection_close (conn); dbus_connection_unref (conn); dbus_shutdown (); /* Check that we can create a connection to the D-Bus system bus, * the returned object should be hooked up to the main loop. */ TEST_FEATURE ("with system bus"); TEST_ALLOC_FAIL { conn = nih_dbus_bus (DBUS_BUS_SYSTEM, my_disconnect_handler); if (test_alloc_failed) { TEST_EQ_P (conn, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); dbus_shutdown (); continue; } TEST_NE_P (conn, NULL); TEST_TRUE (dbus_connection_get_is_connected (conn)); /* Should be a single I/O watch */ TEST_LIST_NOT_EMPTY (nih_io_watches); io_watch = (NihIoWatch *)nih_io_watches->next; dbus_connection_get_unix_fd (conn, &fd); TEST_EQ (io_watch->fd, fd); TEST_NE_P (io_watch->data, NULL); TEST_EQ_P (io_watch->entry.next, nih_io_watches); /* Should be a single main loop function. */ TEST_LIST_NOT_EMPTY (nih_main_loop_functions); loop_func = (NihMainLoopFunc *)nih_main_loop_functions->next; TEST_EQ_P (loop_func->data, conn); TEST_EQ_P (loop_func->entry.next, nih_main_loop_functions); dbus_connection_unref (conn); dbus_shutdown (); } /* Check that we can share connections to a bus. */ TEST_FEATURE ("with shared bus connection"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { conn = nih_dbus_bus (DBUS_BUS_SYSTEM, my_disconnect_handler); assert (conn != NULL); assert (dbus_connection_get_is_connected (conn)); assert (! NIH_LIST_EMPTY (nih_io_watches)); io_watch = (NihIoWatch *)nih_io_watches->next; dbus_connection_get_unix_fd (conn, &fd); assert (io_watch->fd == fd); assert (! NIH_LIST_EMPTY (nih_main_loop_functions)); loop_func = (NihMainLoopFunc *)nih_main_loop_functions->next; assert (loop_func->data == conn); } TEST_FREE_TAG (io_watch); TEST_FREE_TAG (loop_func); last_conn = conn; /* Make another connection */ conn = nih_dbus_bus (DBUS_BUS_SYSTEM, my_disconnect_handler); if (test_alloc_failed && (conn == NULL)) { err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); } else { TEST_EQ_P (conn, last_conn); } /* Still should be a single I/O watch */ TEST_NOT_FREE (io_watch); TEST_LIST_NOT_EMPTY (nih_io_watches); TEST_EQ_P ((NihIoWatch *)nih_io_watches->next, io_watch); TEST_EQ_P (io_watch->entry.next, nih_io_watches); /* Still should be a single main loop function */ TEST_NOT_FREE (loop_func); TEST_LIST_NOT_EMPTY (nih_main_loop_functions); TEST_EQ_P ((NihMainLoopFunc *)nih_main_loop_functions->next, loop_func); TEST_EQ_P (loop_func->entry.next, nih_main_loop_functions); dbus_connection_unref (conn); dbus_connection_unref (last_conn); dbus_shutdown (); } /* Check that if the bus disconnects before registration, NULL * is returned along with an error. Stock dbus tends to bail out * with an exit code, so we watch very carefully for that ;-) */ TEST_FEATURE ("with disconnection before registration"); TEST_CHILD (pid1) { TEST_CHILD_WAIT (pid2, wait_fd) { NihSignal *sh; nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (sh = nih_signal_add_handler (NULL, SIGTERM, nih_main_term_signal, NULL)); server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", NULL, NULL); assert (server != NULL); dbus_server_set_new_connection_function (server, my_new_connection_drop, NULL, NULL); TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); dbus_server_disconnect (server); dbus_server_unref (server); dbus_shutdown (); nih_free (sh); exit (0); } setenv ("DBUS_SYSTEM_BUS_ADDRESS", "unix:abstract=/com/netsplit/nih/test_dbus", TRUE); conn = nih_dbus_bus (DBUS_BUS_SYSTEM, my_disconnect_handler); TEST_EQ_P (conn, NULL); err = nih_error_get (); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); TEST_EQ_STR (((NihDBusError *)err)->name, DBUS_ERROR_NO_REPLY); nih_free (err); dbus_shutdown (); unsetenv ("DBUS_SYSTEM_BUS_ADDRESS"); kill (pid2, SIGTERM); waitpid (pid2, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); exit (123); } assert (waitpid (pid1, &status, 0) == pid1); if ((! WIFEXITED (status)) || (WEXITSTATUS (status) != 123)) TEST_FAILED ("unexpected exit(), unpatched D-Bus?"); /* Check that if the bus is not available, NULL is returned and * an error. */ TEST_FEATURE ("with no bus"); setenv ("DBUS_SYSTEM_BUS_ADDRESS", "unix:abstract=/com/netsplit/nih/test_foo", TRUE); conn = nih_dbus_bus (DBUS_BUS_SYSTEM, my_disconnect_handler); TEST_EQ_P (conn, NULL); err = nih_error_get (); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); TEST_EQ_STR (((NihDBusError *)err)->name, DBUS_ERROR_NO_SERVER); nih_free (err); dbus_shutdown (); unsetenv ("DBUS_SYSTEM_BUS_ADDRESS"); } void test_setup (void) { pid_t dbus_pid; int wait_fd; DBusServer * server; DBusConnection * conn = NULL; NihIoWatch * io_watch = NULL; NihMainLoopFunc *loop_func = NULL; int ret; int fd; int status; TEST_FUNCTION ("nih_dbus_setup"); TEST_CHILD_WAIT (dbus_pid, wait_fd) { NihSignal *sh; nih_signal_set_handler (SIGTERM, nih_signal_handler); assert (sh = nih_signal_add_handler (NULL, SIGTERM, nih_main_term_signal, NULL)); server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", NULL, NULL); assert (server != NULL); dbus_server_set_new_connection_function (server, my_new_connection, NULL, NULL); client_connection = NULL; TEST_CHILD_RELEASE (wait_fd); nih_main_loop (); if (client_connection) { dbus_connection_close (client_connection); dbus_connection_unref (client_connection); } dbus_server_disconnect (server); dbus_server_unref (server); dbus_shutdown (); nih_free (sh); exit (0); } /* Check that we can setup a new connection for use with the * nih main loop. */ TEST_FEATURE ("with new connection"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { conn = dbus_connection_open_private ("unix:abstract=/com/netsplit/nih/test_dbus", NULL); assert (conn != NULL); assert (dbus_connection_get_is_connected (conn)); } dbus_connection_set_exit_on_disconnect (conn, FALSE); ret = nih_dbus_setup (conn, NULL); if (test_alloc_failed) { TEST_LT (ret, 0); dbus_connection_close (conn); dbus_connection_unref (conn); dbus_shutdown (); continue; } TEST_EQ (ret, 0); /* Should be a single I/O watch */ TEST_LIST_NOT_EMPTY (nih_io_watches); io_watch = (NihIoWatch *)nih_io_watches->next; dbus_connection_get_unix_fd (conn, &fd); TEST_EQ (io_watch->fd, fd); TEST_NE_P (io_watch->data, NULL); TEST_EQ_P (io_watch->entry.next, nih_io_watches); /* Should be a single main loop function. */ TEST_LIST_NOT_EMPTY (nih_main_loop_functions); loop_func = (NihMainLoopFunc *)nih_main_loop_functions->next; TEST_EQ_P (loop_func->data, conn); TEST_EQ_P (loop_func->entry.next, nih_main_loop_functions); dbus_connection_close (conn); dbus_connection_unref (conn); dbus_shutdown (); } /* Check that if we try and set the same connection up again, * nothing changes. */ TEST_FEATURE ("with existing connection"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { conn = dbus_connection_open_private ("unix:abstract=/com/netsplit/nih/test_dbus", NULL); assert (conn != NULL); assert (dbus_connection_get_is_connected (conn)); dbus_connection_set_exit_on_disconnect (conn, FALSE); ret = nih_dbus_setup (conn, NULL); assert (ret == 0); assert (! NIH_LIST_EMPTY (nih_io_watches)); io_watch = (NihIoWatch *)nih_io_watches->next; dbus_connection_get_unix_fd (conn, &fd); assert (io_watch->fd == fd); assert (! NIH_LIST_EMPTY (nih_main_loop_functions)); loop_func = (NihMainLoopFunc *)nih_main_loop_functions->next; assert (loop_func->data == conn); } TEST_FREE_TAG (io_watch); TEST_FREE_TAG (loop_func); ret = nih_dbus_setup (conn, NULL); if (test_alloc_failed) { TEST_LT (ret, 0); } else { TEST_EQ (ret, 0); } /* Still should be a single I/O watch */ TEST_NOT_FREE (io_watch); TEST_LIST_NOT_EMPTY (nih_io_watches); TEST_EQ_P ((NihIoWatch *)nih_io_watches->next, io_watch); TEST_EQ_P (io_watch->entry.next, nih_io_watches); /* Still should be a single main loop function */ TEST_NOT_FREE (loop_func); TEST_LIST_NOT_EMPTY (nih_main_loop_functions); TEST_EQ_P ((NihMainLoopFunc *)nih_main_loop_functions->next, loop_func); TEST_EQ_P (loop_func->entry.next, nih_main_loop_functions); dbus_connection_close (conn); dbus_connection_unref (conn); dbus_shutdown (); } kill (dbus_pid, SIGTERM); waitpid (dbus_pid, &status, 0); TEST_TRUE (WIFEXITED (status)); TEST_EQ (WEXITSTATUS (status), 0); } static int connected = FALSE; static int drop_connection = FALSE; static DBusConnection *last_connection = NULL; static int my_connect_handler (DBusServer * server, DBusConnection *connection) { connected = TRUE; if (! drop_connection) last_connection = connection; nih_main_loop_exit (0); return drop_connection ? FALSE : TRUE; } void test_server (void) { DBusServer * other_server = NULL; DBusServer * server = NULL; DBusConnection *conn = NULL; DBusConnection *server_conn = NULL; NihIoWatch * io_watch; NihError * err; TEST_FUNCTION ("nih_dbus_server"); /* Check that we can create a new D-Bus server instance and that * it is hooked up to the main loop with an IoWatch. */ TEST_FEATURE ("with new server"); TEST_ALLOC_FAIL { server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", NULL, NULL); if (test_alloc_failed) { TEST_EQ_P (server, NULL); err = nih_error_get (); TEST_EQ (err->number, ENOMEM); nih_free (err); dbus_shutdown (); continue; } TEST_NE_P (server, NULL); TEST_LIST_NOT_EMPTY (nih_io_watches); io_watch = (NihIoWatch *)nih_io_watches->next; TEST_EQ_P (io_watch->entry.next, nih_io_watches); dbus_server_disconnect (server); dbus_server_unref (server); dbus_shutdown (); } /* Check that a connection to that server results in the connect * handler being called, and that if that returns TRUE, the * connection remains open. */ TEST_FEATURE ("with connection to server"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", my_connect_handler, NULL); assert (server != NULL); } conn = dbus_connection_open_private ("unix:abstract=/com/netsplit/nih/test_dbus", NULL); TEST_NE_P (conn, NULL); connected = FALSE; last_connection = NULL; drop_connection = FALSE; nih_main_loop (); TEST_TRUE (dbus_connection_get_is_connected (conn)); TEST_TRUE (connected); TEST_NE_P (last_connection, NULL); server_conn = last_connection; dbus_connection_close (conn); dbus_connection_unref (conn); dbus_connection_close (server_conn); dbus_connection_unref (server_conn); dbus_server_disconnect (server); dbus_server_unref (server); dbus_shutdown (); } /* Check that if the client disconnects, the server connection * disconnect handler is called and unreferenced. */ TEST_FEATURE ("with disconnect by client"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", my_connect_handler, my_disconnect_handler); assert (server != NULL); conn = dbus_connection_open_private ("unix:abstract=/com/netsplit/nih/test_dbus", NULL); assert (conn != NULL); connected = FALSE; last_connection = NULL; nih_main_loop (); assert (connected); server_conn = last_connection; } disconnected = FALSE; last_disconnection = NULL; dbus_connection_close (conn); dbus_connection_unref (conn); nih_main_loop (); TEST_TRUE (disconnected); TEST_EQ_P (last_disconnection, server_conn); dbus_server_disconnect (server); dbus_server_unref (server); dbus_shutdown (); } /* Check that if the connect handler returns FALSE, the connection * is abandoned and the client disconnected. */ TEST_FEATURE ("with decline by connect handler"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", my_connect_handler, my_disconnect_handler); assert (server != NULL); } conn = dbus_connection_open_private ("unix:abstract=/com/netsplit/nih/test_dbus", NULL); TEST_NE_P (conn, NULL); connected = FALSE; last_connection = NULL; drop_connection = TRUE; disconnected = FALSE; last_disconnection = NULL; nih_main_loop (); TEST_TRUE (connected); while (dbus_connection_read_write_dispatch (conn, -1)) ; TEST_FALSE (dbus_connection_get_is_connected (conn)); /* Disconnect handler should not be called */ TEST_FALSE (disconnected); TEST_EQ_P (last_disconnection, NULL); dbus_connection_unref (conn); dbus_server_disconnect (server); dbus_server_unref (server); dbus_shutdown (); } /* Check that creating a server on an address which is already in * use returns no object and the error. */ TEST_FEATURE ("with address in use"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { other_server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", NULL, NULL); assert (other_server != NULL); } server = nih_dbus_server ("unix:abstract=/com/netsplit/nih/test_dbus", NULL, NULL); TEST_EQ_P (server, NULL); err = nih_error_get (); TEST_EQ (err->number, NIH_DBUS_ERROR); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); TEST_EQ_STR (((NihDBusError *)err)->name, DBUS_ERROR_ADDRESS_IN_USE); nih_free (err); dbus_server_disconnect (other_server); dbus_server_unref (other_server); dbus_shutdown (); } } int main (int argc, char *argv[]) { nih_timer_init (); nih_signal_init (); nih_child_init (); nih_io_init (); nih_main_loop_init (); nih_error_init (); test_connect (); test_bus (); test_setup (); test_server (); return 0; } libnih-1.0.3/nih-dbus/tests/test_dbus_message.c0000644000175000017500000001011211445765555016434 00000000000000/* libnih * * test_dbus_message.c - test suite for nih-dbus/dbus_message.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void test_message_new (void) { NihDBusMessage *msg; pid_t dbus_pid; DBusConnection *conn; DBusMessage * message; /* Check that we can create a new DBus message structure, and that * it references the connection and message. */ TEST_FUNCTION ("nih_dbus_message_new"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (conn); message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL); TEST_ALLOC_FAIL { msg = nih_dbus_message_new (NULL, conn, message); if (test_alloc_failed) { TEST_EQ_P (msg, NULL); continue; } TEST_ALLOC_SIZE (msg, sizeof (NihDBusMessage)); TEST_EQ_P (msg->connection, conn); TEST_EQ_P (msg->message, message); nih_free (msg); } dbus_message_unref (message); TEST_DBUS_CLOSE (conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_message_error (void) { pid_t dbus_pid; DBusConnection *server_conn; DBusConnection *client_conn; DBusMessage * method_call; DBusMessage * reply; dbus_uint32_t serial; NihDBusMessage *message = NULL; int ret; DBusError error; /* Check that an error returned outside the handler with the * nih_dbus_message_error() function is returned to the sender * with the right details. */ TEST_FUNCTION ("nih_dbus_message_error"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); TEST_ALLOC_FAIL { method_call = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "com.netsplit.Nih.Glue", "ReturnError"); dbus_connection_send (client_conn, method_call, &serial); dbus_connection_flush (client_conn); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (server_conn, method_call); assert (dbus_message_get_serial (method_call) == serial); TEST_ALLOC_SAFE { message = nih_new (NULL, NihDBusMessage); message->connection = client_conn; message->message = method_call; } ret = nih_dbus_message_error (message, "com.netsplit.Nih.Test.MyError", "this is a %s %d", "test", 1234); if (test_alloc_failed) { TEST_LT (ret, 0); nih_free (message); dbus_message_unref (method_call); continue; } TEST_EQ (ret, 0); nih_free (message); dbus_message_unref (method_call); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_ERROR); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&error); dbus_set_error_from_message (&error, reply); TEST_EQ_STR (error.name, "com.netsplit.Nih.Test.MyError"); TEST_EQ_STR (error.message, "this is a test 1234"); dbus_error_free (&error); dbus_message_unref (reply); } TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } int main (int argc, char *argv[]) { test_message_new (); test_message_error (); return 0; } libnih-1.0.3/nih-dbus/tests/test_dbus_error.c0000644000175000017500000000471211445765555016152 00000000000000/* libnih * * test_dbus_error.c - test suite for nih-dbus/dbus_error.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include void test_error_raise (void) { NihError * err; NihDBusError *dbus_err; /* Make sure that an NIH_DBUS_ERROR is raised with the name and * message we give. */ TEST_FUNCTION ("nih_dbus_error_raise"); TEST_ALLOC_FAIL { nih_dbus_error_raise ("foo", "bar"); err = nih_error_get (); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); TEST_EQ (err->number, NIH_DBUS_ERROR); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "foo"); TEST_ALLOC_PARENT (dbus_err->name, dbus_err); TEST_EQ_STR (dbus_err->message, "bar"); TEST_ALLOC_PARENT (dbus_err->message, dbus_err); nih_free (dbus_err); } } void test_error_raise_printf (void) { NihError * err; NihDBusError *dbus_err; /* Make sure that an NIH_DBUS_ERROR is raised with the name and * formatted message we give. */ TEST_FUNCTION ("nih_dbus_error_raise_printf"); TEST_ALLOC_FAIL { nih_dbus_error_raise_printf ("foo", "hello %d this is a %s", 123, "test"); err = nih_error_get (); TEST_ALLOC_SIZE (err, sizeof (NihDBusError)); TEST_EQ (err->number, NIH_DBUS_ERROR); dbus_err = (NihDBusError *)err; TEST_EQ_STR (dbus_err->name, "foo"); TEST_ALLOC_PARENT (dbus_err->name, dbus_err); TEST_EQ_STR (dbus_err->message, "hello 123 this is a test"); TEST_ALLOC_PARENT (dbus_err->message, dbus_err); nih_free (dbus_err); } } int main (int argc, char *argv[]) { nih_error_init (); test_error_raise (); test_error_raise_printf (); return 0; } libnih-1.0.3/nih-dbus/tests/test_dbus_util.c0000644000175000017500000000715011445765555015775 00000000000000/* libnih * * test_dbus_util.c - test suite for nih-dbus/dbus_util.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include void test_path (void) { char *path; TEST_FUNCTION ("nih_dbus_path"); /* Check that a root path with no additional elements is simply * returned duplicated, the root should not be escaped. */ TEST_FEATURE ("with root only"); TEST_ALLOC_FAIL { path = nih_dbus_path (NULL, "/com/netsplit/Nih", NULL); if (test_alloc_failed) { TEST_EQ_P (path, NULL); continue; } TEST_EQ_STR (path, "/com/netsplit/Nih"); nih_free (path); } /* Check that a root path with a single additional element has that * appended separated by a slash. */ TEST_FEATURE ("with single additional element"); TEST_ALLOC_FAIL { path = nih_dbus_path (NULL, "/com/netsplit/Nih", "test", NULL); if (test_alloc_failed) { TEST_EQ_P (path, NULL); continue; } TEST_EQ_STR (path, "/com/netsplit/Nih/test"); nih_free (path); } /* Check that a root path with multiple additional elements have them * appended separated by slashes. */ TEST_FEATURE ("with multiple additional elements"); TEST_ALLOC_FAIL { path = nih_dbus_path (NULL, "/com/netsplit/Nih", "test", "frodo", NULL); if (test_alloc_failed) { TEST_EQ_P (path, NULL); continue; } TEST_EQ_STR (path, "/com/netsplit/Nih/test/frodo"); nih_free (path); } /* Check that if one of the additional elements requires escaping, * it is appended in the escaped form. */ TEST_FEATURE ("with element requiring escaping"); TEST_ALLOC_FAIL { path = nih_dbus_path (NULL, "/com/netsplit/Nih", "test", "foo/bar.baz", "frodo", NULL); if (test_alloc_failed) { TEST_EQ_P (path, NULL); continue; } TEST_EQ_STR (path, ("/com/netsplit/Nih" "/test/foo_2fbar_2ebaz/frodo")); nih_free (path); } /* Check that when multiple elements require escaping, they are * all escaped; also check that an underscore requires escaping to * ensure path uniqueness. */ TEST_FEATURE ("with multiple elements requiring escaping"); TEST_ALLOC_FAIL { path = nih_dbus_path (NULL, "/com/netsplit/Nih", "test_thing", "foo/bar.baz", "frodo", NULL); if (test_alloc_failed) { TEST_EQ_P (path, NULL); continue; } TEST_EQ_STR (path, ("/com/netsplit/Nih" "/test_5fthing/foo_2fbar_2ebaz/frodo")); nih_free (path); } /* Check that if one of the additional elements is empty, it * is replaced with an underscore. */ TEST_FEATURE ("with empty element"); TEST_ALLOC_FAIL { path = nih_dbus_path (NULL, "/com/netsplit/Nih", "", NULL); if (test_alloc_failed) { TEST_EQ_P (path, NULL); continue; } TEST_EQ_STR (path, "/com/netsplit/Nih/_"); nih_free (path); } } int main (int argc, char *argv[]) { test_path (); return 0; } libnih-1.0.3/nih-dbus/tests/test_dbus_pending_data.c0000644000175000017500000000575511445765555017446 00000000000000/* libnih * * test_dbus_pending_data.c - test suite for nih-dbus/dbus_pending_data.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include void my_reply_handler (void * data, NihDBusMessage *message, const char * arg1, int32_t arg2) { } void my_error_handler (void * data, NihDBusMessage *message) { } void test_new (void) { NihDBusPendingData *pending_data; pid_t dbus_pid; DBusConnection * conn; TEST_FUNCTION ("nih_dbus_pending_data_new"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (conn); /* Check that we can create a new NihDBusPendingData structure, * with all the details filled in correctly, and that it references * the connection. */ TEST_FEATURE ("with handler"); TEST_ALLOC_FAIL { pending_data = nih_dbus_pending_data_new (NULL, conn, (NihDBusReplyHandler)my_reply_handler, my_error_handler, &conn); if (test_alloc_failed) { TEST_EQ_P (pending_data, NULL); continue; } TEST_ALLOC_SIZE (pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (pending_data->connection, conn); TEST_EQ_P (pending_data->handler, (NihDBusReplyHandler)my_reply_handler); TEST_EQ_P (pending_data->error_handler, my_error_handler); TEST_EQ_P (pending_data->data, &conn); nih_free (pending_data); } /* Check that the handler argument is optional and NULL may be * specified for it. */ TEST_FEATURE ("with no handler"); TEST_ALLOC_FAIL { pending_data = nih_dbus_pending_data_new (NULL, conn, NULL, my_error_handler, &conn); if (test_alloc_failed) { TEST_EQ_P (pending_data, NULL); continue; } TEST_ALLOC_SIZE (pending_data, sizeof (NihDBusPendingData)); TEST_EQ_P (pending_data->connection, conn); TEST_EQ_P (pending_data->handler, NULL); TEST_EQ_P (pending_data->error_handler, my_error_handler); TEST_EQ_P (pending_data->data, &conn); nih_free (pending_data); } TEST_DBUS_CLOSE (conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } int main (int argc, char *argv[]) { test_new (); return 0; } libnih-1.0.3/nih-dbus/tests/test_dbus_object.c0000644000175000017500000030274211445765555016273 00000000000000/* libnih * * test_dbus_object.c - test suite for nih-dbus/dbus_object.c * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #include #include #include #include #include #include #include static int foo_called = FALSE; static NihDBusObject * last_object = NULL; static NihDBusMessage *last_message = NULL; static DBusConnection *last_message_conn = NULL; static DBusHandlerResult foo_handler (NihDBusObject * object, NihDBusMessage *message) { foo_called = TRUE; last_object = object; last_message = message; last_message_conn = message->connection; TEST_FREE_TAG (message); return DBUS_HANDLER_RESULT_HANDLED; } static int bar_decline = FALSE; static int bar_called = FALSE; static DBusHandlerResult bar_handler (NihDBusObject * object, NihDBusMessage *message) { bar_called = TRUE; last_object = object; last_message = message; last_message_conn = message->connection; if (bar_decline) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; TEST_FREE_TAG (message); return DBUS_HANDLER_RESULT_HANDLED; } static const char *colour; static int colour_get_called = FALSE; static int colour_set_called = FALSE; static int colour_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter subiter; colour_get_called = TRUE; last_object = object; last_message = message; last_message_conn = message->connection; TEST_FREE_TAG (message); if (! strcmp (colour, "secret")) { nih_dbus_error_raise (DBUS_ERROR_ACCESS_DENIED, "Access denied"); return -1; } else if (! strcmp (colour, "chicken")) { nih_error_raise (EBADF, strerror (EBADF)); return -1; } if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter)) { nih_error_raise_no_memory (); return -1; } if (! dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &colour)) { nih_error_raise_no_memory (); return -1; } if (! dbus_message_iter_close_container (iter, &subiter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int colour_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter subiter; const char * value; nih_local char *dup = NULL; colour_set_called = TRUE; last_object = object; last_message = message; last_message_conn = message->connection; TEST_FREE_TAG (message); TEST_EQ (dbus_message_iter_get_arg_type (iter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &value); if (! strcmp (value, "pig")) { nih_dbus_error_raise ("com.netsplit.Nih.NotAColour", "pig is not a colour"); return -1; } else if (! strlen (value)) { nih_error_raise (EBADF, strerror (EBADF)); return -1; } else { TEST_EQ_STR (value, "red"); dup = nih_strdup (NULL, value); if (! dup) { nih_error_raise_no_memory (); return -1; } } return 0; } static int size_get_called = FALSE; static int size_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter subiter; dbus_uint32_t uint32_value; size_get_called = TRUE; last_object = object; last_message = message; last_message_conn = message->connection; TEST_FREE_TAG (message); if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &subiter)) { nih_error_raise_no_memory (); return -1; } uint32_value = 34; if (! dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value)) { nih_error_raise_no_memory (); return -1; } if (! dbus_message_iter_close_container (iter, &subiter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int other_get_called = FALSE; static int other_get (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { DBusMessageIter subiter; dbus_uint32_t uint32_value; other_get_called = TRUE; last_object = object; last_message = message; last_message_conn = message->connection; TEST_FREE_TAG (message); if (! dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &subiter)) { nih_error_raise_no_memory (); return -1; } uint32_value = 186; if (! dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value)) { nih_error_raise_no_memory (); return -1; } if (! dbus_message_iter_close_container (iter, &subiter)) { nih_error_raise_no_memory (); return -1; } return 0; } static int poke_set_called = FALSE; static int poke_set (NihDBusObject * object, NihDBusMessage * message, DBusMessageIter *iter) { poke_set_called = TRUE; last_object = object; last_message = message; last_message_conn = message->connection; TEST_FREE_TAG (message); return 0; } static const NihDBusArg foo_args[] = { { "str", "s", NIH_DBUS_ARG_IN }, { "len", "u", NIH_DBUS_ARG_IN }, { "count", "u", NIH_DBUS_ARG_OUT }, { NULL } }; static const NihDBusArg bar_args[] = { { NULL, "d", NIH_DBUS_ARG_IN }, { NULL } }; static const NihDBusArg baz_args[] = { { NULL } }; static const NihDBusArg signal_args[] = { { "msg", "s", NIH_DBUS_ARG_IN }, { NULL } }; static const NihDBusMethod interface_a_methods[] = { { "Foo", foo_args, foo_handler }, { "Bar", bar_args, bar_handler }, { NULL } }; static const NihDBusSignal interface_a_signals[] = { { "Alert", signal_args }, { "Panic", signal_args }, { NULL } }; static const NihDBusMethod interface_b_methods[] = { { "Bar", bar_args, foo_handler }, { "Baz", baz_args, foo_handler }, { NULL } }; static const NihDBusProperty interface_b_props[] = { { "Colour", "s", NIH_DBUS_READWRITE, colour_get, colour_set }, { "Size", "u", NIH_DBUS_READ, size_get, NULL }, { "Poke", "d", NIH_DBUS_WRITE, NULL, poke_set }, { NULL } }; static const NihDBusProperty interface_c_props[] = { { "Colour", "u", NIH_DBUS_READWRITE, other_get, poke_set }, { "Height", "u", NIH_DBUS_READ, other_get, NULL }, { NULL } }; static const NihDBusInterface interface_a = { "Nih.TestA", interface_a_methods, interface_a_signals, NULL }; static const NihDBusInterface interface_b = { "Nih.TestB", interface_b_methods, NULL, interface_b_props }; static const NihDBusInterface interface_c = { "Nih.TestC", NULL, NULL, interface_c_props }; static const NihDBusInterface *no_interfaces[] = { NULL }; static const NihDBusInterface *one_interface[] = { &interface_a, NULL }; static const NihDBusInterface *prop_interface[] = { &interface_b, NULL }; static const NihDBusInterface *all_interfaces[] = { &interface_a, &interface_b, &interface_c, NULL }; void test_object_new (void) { pid_t dbus_pid; DBusConnection *conn; NihDBusObject * object; /* Check that we can register a new object, having the filled in * structure returned for us with the object registered against * the connection at the right path. */ TEST_FUNCTION ("nih_dbus_object_new"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (conn); TEST_ALLOC_FAIL { void *data; object = nih_dbus_object_new (NULL, conn, "/com/netsplit/Nih", all_interfaces, &object); if (test_alloc_failed) { TEST_EQ_P (object, NULL); continue; } TEST_ALLOC_SIZE (object, sizeof (NihDBusObject)); TEST_ALLOC_PARENT (object->path, object); TEST_EQ_STR (object->path, "/com/netsplit/Nih"); TEST_EQ_P (object->connection, conn); TEST_EQ_P (object->data, &object); TEST_EQ_P (object->interfaces, all_interfaces); TEST_EQ (object->registered, TRUE); TEST_TRUE (dbus_connection_get_object_path_data ( conn, "/com/netsplit/Nih", &data)); TEST_EQ_P (data, object); nih_free (object); } TEST_DBUS_CLOSE (conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_object_destroy (void) { pid_t dbus_pid; DBusConnection *conn; NihDBusObject * object; void * data; /* Check that a registered D-Bus object is unregistered from the * bus when it is destroyed. */ TEST_FUNCTION ("nih_dbus_object_destroy"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (conn); dbus_connection_set_exit_on_disconnect (conn, FALSE); object = nih_dbus_object_new (NULL, conn, "/com/netsplit/Nih", all_interfaces, &object); assert (object != NULL); assert (dbus_connection_get_object_path_data ( conn, "/com/netsplit/Nih", &data)); assert (data == object); nih_free (object); TEST_TRUE (dbus_connection_get_object_path_data ( conn, "/com/netsplit/Nih", &data)); TEST_EQ_P (data, NULL); TEST_DBUS_CLOSE (conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_object_unregister (void) { pid_t dbus_pid; DBusConnection *conn; NihDBusObject * object; /* Check that when a D-Bus connection is destroyed, any registered * D-Bus objects go as well. */ TEST_FUNCTION ("nih_dbus_object_unregister"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (conn); dbus_connection_set_exit_on_disconnect (conn, FALSE); object = nih_dbus_object_new (NULL, conn, "/com/netsplit/Nih", all_interfaces, &object); assert (object != NULL); TEST_FREE_TAG (object); TEST_DBUS_CLOSE (conn); TEST_FREE (object); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_object_message (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihDBusObject * object; DBusMessage * message; dbus_uint32_t serial; DBusMessage * reply; TEST_FUNCTION ("nih_dbus_object_message"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that the handler for a known method is called with the * object passed in along with a message structure containing * both the message and connection (which will be freed before * returning. */ TEST_FEATURE ("with registered method"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", one_interface, &server_conn); TEST_ALLOC_FAIL { foo_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "Nih.TestA", "Foo"); assert (message != NULL); assert (dbus_connection_send (client_conn, message, NULL)); dbus_connection_flush (client_conn); dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (foo_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); } nih_free (object); /* Check that the first of two handlers for a method without a * specified interface is called. */ TEST_FEATURE ("with method registered to multiple interfaces"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { bar_decline = FALSE; foo_called = FALSE; bar_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, "Bar"); assert (message != NULL); assert (dbus_connection_send (client_conn, message, NULL)); dbus_connection_flush (client_conn); dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (foo_called); TEST_TRUE (bar_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); } nih_free (object); /* Check that if the first of two handlers for a method without * a specified interface declines to handle, we move onto the * second one. */ TEST_FEATURE ("with first handler declining and second available"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { bar_decline = TRUE; foo_called = FALSE; bar_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, "Bar"); assert (message != NULL); assert (dbus_connection_send (client_conn, message, NULL)); dbus_connection_flush (client_conn); dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (bar_called); TEST_TRUE (foo_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); bar_decline = FALSE; } nih_free (object); /* Check that an unknown method on a known interface results in * an error being returned to the caller. */ TEST_FEATURE ("with unknown method on known interface"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { foo_called = FALSE; bar_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "Nih.TestB", "Wibble"); assert (message != NULL); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_FALSE (foo_called); TEST_FALSE (bar_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_UNKNOWN_METHOD)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that an unknown method on an unknown interface results in * an error being returned to the caller. */ TEST_FEATURE ("with unknown method on unknown interface"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { foo_called = FALSE; bar_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "Nih.TestC", "Wibble"); assert (message != NULL); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_FALSE (foo_called); TEST_FALSE (bar_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_UNKNOWN_METHOD)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that an unknown method with no specified interface results in * an error being returned to the caller. */ TEST_FEATURE ("with unknown method with no interface"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { foo_called = FALSE; bar_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", NULL, "Wibble"); assert (message != NULL); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_FALSE (foo_called); TEST_FALSE (bar_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_UNKNOWN_METHOD)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that a method call when no interfaces are specified results * in an error being returned to the caller. */ TEST_FEATURE ("with method call and no interfaces"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", no_interfaces, &server_conn); TEST_ALLOC_FAIL { foo_called = FALSE; bar_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", "Nih.TestA", "Foo"); assert (message != NULL); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_FALSE (foo_called); TEST_FALSE (bar_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_UNKNOWN_METHOD)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_object_introspect (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihDBusObject * object; NihDBusObject * child1; NihDBusObject * child2; DBusMessage * message; dbus_uint32_t serial; DBusMessage * reply; const char * xml; DBusMessageIter iter; TEST_FUNCTION ("nih_dbus_object_introspect"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that the Introspect message is handled internally with * an accurate portrayal of the interfaces and their properties * returned. */ TEST_FEATURE ("with fully-fledged object"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_INTROSPECTABLE, "Introspect"); assert (message != NULL); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "s")); TEST_TRUE (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID)); TEST_EQ_STRN (xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE); xml += strlen (DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE); TEST_EQ_STRN (xml, "\n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, "\n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STR (xml, ""); dbus_message_unref (reply); } nih_free (object); /* Check that the Introspect message does not include the * Properties interfaces in the output if none of the interfaces * implement properties. */ TEST_FEATURE ("with no properties"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", one_interface, &server_conn); TEST_ALLOC_FAIL { message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_INTROSPECTABLE, "Introspect"); assert (message != NULL); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "s")); TEST_TRUE (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID)); TEST_EQ_STRN (xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE); xml += strlen (DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE); TEST_EQ_STRN (xml, "\n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, "\n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STR (xml, ""); dbus_message_unref (reply); } nih_free (object); /* Check that the Introspect message works when there are no * interfaces. */ TEST_FEATURE ("with no interfaces"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", no_interfaces, &server_conn); TEST_ALLOC_FAIL { message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_INTROSPECTABLE, "Introspect"); assert (message != NULL); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "s")); TEST_TRUE (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID)); TEST_EQ_STRN (xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE); xml += strlen (DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE); TEST_EQ_STRN (xml, "\n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, "\n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STR (xml, ""); dbus_message_unref (reply); } nih_free (object); /* Check that the Introspect message contains node entries for * children, but doesn't bother to flesh them out. */ TEST_FEATURE ("with children nodes"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", no_interfaces, &server_conn); child1 = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Frodo", one_interface, &server_conn); child2 = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih/Bilbo", all_interfaces, &server_conn); TEST_ALLOC_FAIL { message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_INTROSPECTABLE, "Introspect"); assert (message != NULL); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "s")); TEST_TRUE (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &xml, DBUS_TYPE_INVALID)); TEST_EQ_STRN (xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE); xml += strlen (DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE); TEST_EQ_STRN (xml, "\n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, " \n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STRN (xml, "\n"); xml = strchr (xml, '\n') + 1; TEST_EQ_STR (xml, ""); dbus_message_unref (reply); } nih_free (child2); nih_free (child1); nih_free (object); /* Check that we receive an Invalid Args error when we pass too * many arguments. */ TEST_FEATURE ("with too many arguments"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_INTROSPECTABLE, "Introspect"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); xml = "\n"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &xml)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_object_property_get (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihDBusObject * object; DBusMessage * message; DBusMessageIter iter; DBusMessageIter subiter; const char * interface_name; const char * property_name; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; uint32_t uint32_value; DBusError dbus_error; TEST_FUNCTION ("nih_dbus_object_property_get"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can get the value of a read/write property, with the * actual reply handled internally but the variant appended to * the message. */ TEST_FEATURE ("with read/write property"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", prop_interface, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; colour = "blue"; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (colour_get_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "v")); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "blue"); dbus_message_unref (reply); } nih_free (object); /* Check that we can get the value of a read-only property, with the * actual reply handled internally but the variant appended to * the message. */ TEST_FEATURE ("with read-only property"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", prop_interface, &server_conn); TEST_ALLOC_FAIL { size_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Size"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (size_get_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "v")); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UINT32); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 34); dbus_message_unref (reply); } nih_free (object); /* Check that we can't get the value of a write-only property, and * that an "access denied" error message is returned instead. */ TEST_FEATURE ("with write-only property"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", prop_interface, &server_conn); TEST_ALLOC_FAIL { last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Poke"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_ACCESS_DENIED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that the first of two properties with the same name * but on different interfaces is used when the property interface * is not given. */ TEST_FEATURE ("with property registered to multiple interfaces"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour = "blue"; colour_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = ""; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (colour_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "v")); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "blue"); dbus_message_unref (reply); } nih_free (object); /* Check that attempting to get an unknown property on a known * interface results in an error reply. */ TEST_FEATURE ("with unknown property on known interface"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Height"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_UNKNOWN_METHOD)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that a property on an unknown interface always results in * an error reply. */ TEST_FEATURE ("with unknown property on unknown interface"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.FooBar"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_UNKNOWN_METHOD)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that an unknown property when no interface was specified * results in an error reply. */ TEST_FEATURE ("with unknown property with no interface"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = ""; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Width"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_UNKNOWN_METHOD)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that an error reply is always received when no interfaces * were defined. */ TEST_FEATURE ("with no interfaces"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", no_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = ""; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Width"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_UNKNOWN_METHOD)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that a property get handler may raise a D-Bus error, and * that it is returned by the Get method. */ TEST_FEATURE ("with D-Bus error from handler"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", prop_interface, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; colour = "secret"; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (colour_get_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_ACCESS_DENIED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that a property get handler may raise a generic error, which * should be returned as a general failed message. */ TEST_FEATURE ("with generic error from handler"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", prop_interface, &server_conn); TEST_ALLOC_FAIL { colour = "chicken"; colour_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (colour_get_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, strerror (EBADF)); dbus_error_free (&dbus_error); dbus_message_unref (reply); } nih_free (object); /* Check that we receive an Invalid Args error when we forget to * pass the property name. */ TEST_FEATURE ("with missing property name"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that we receive an Invalid Args error when we forget to * pass any arguments. */ TEST_FEATURE ("with missing arguments"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that we receive an Invalid Args error when we pass too * many arguments. */ TEST_FEATURE ("with too many arguments"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Get"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); str_value = "pink"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str_value)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_object_property_get_all (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihDBusObject * object; DBusMessage * message; DBusMessageIter iter; DBusMessageIter arrayiter; DBusMessageIter dictiter; DBusMessageIter subiter; const char * interface_name; dbus_uint32_t serial; DBusMessage * reply; const char * property_name; const char * str_value; dbus_uint32_t uint32_value; DBusError dbus_error; TEST_FUNCTION ("nih_dbus_object_property_get_all"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can get the values of all properties on a given * interface, receiving a reply containing an array of dictionary * entries mapping property name to its variant value. */ TEST_FEATURE ("with known interface"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; colour = "blue"; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (colour_get_called); TEST_TRUE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "a{sv}")); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_DICT_ENTRY); dbus_message_iter_recurse (&arrayiter, &dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&dictiter, &property_name); TEST_EQ_STR (property_name, "Colour"); dbus_message_iter_next (&dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&dictiter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "blue"); dbus_message_iter_next (&dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_DICT_ENTRY); dbus_message_iter_recurse (&arrayiter, &dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&dictiter, &property_name); TEST_EQ_STR (property_name, "Size"); dbus_message_iter_next (&dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&dictiter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UINT32); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 34); dbus_message_iter_next (&dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_INVALID); dbus_message_unref (reply); } nih_free (object); /* Check that when we don't given an interface, the values of all * properties on all interfaces are received - except where a * property with the same name exists on multiple in which case * the first matching name is returned. */ TEST_FEATURE ("with property registered to multiple interfaces"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; colour = "blue"; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = ""; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (colour_get_called); TEST_TRUE (size_get_called); TEST_TRUE (other_get_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "a{sv}")); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_DICT_ENTRY); dbus_message_iter_recurse (&arrayiter, &dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&dictiter, &property_name); TEST_EQ_STR (property_name, "Colour"); dbus_message_iter_next (&dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&dictiter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&subiter, &str_value); TEST_EQ_STR (str_value, "blue"); dbus_message_iter_next (&dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_DICT_ENTRY); dbus_message_iter_recurse (&arrayiter, &dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&dictiter, &property_name); TEST_EQ_STR (property_name, "Size"); dbus_message_iter_next (&dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&dictiter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UINT32); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 34); dbus_message_iter_next (&dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_DICT_ENTRY); dbus_message_iter_recurse (&arrayiter, &dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_STRING); dbus_message_iter_get_basic (&dictiter, &property_name); TEST_EQ_STR (property_name, "Height"); dbus_message_iter_next (&dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_VARIANT); dbus_message_iter_recurse (&dictiter, &subiter); TEST_EQ (dbus_message_iter_get_arg_type (&subiter), DBUS_TYPE_UINT32); dbus_message_iter_get_basic (&subiter, &uint32_value); TEST_EQ (uint32_value, 186); dbus_message_iter_next (&dictiter); TEST_EQ (dbus_message_iter_get_arg_type (&dictiter), DBUS_TYPE_INVALID); dbus_message_iter_next (&arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_INVALID); dbus_message_unref (reply); } nih_free (object); /* Check that attempting to get the values of all properties on * an interface which has none results in a reply containing an empty * array, rather than an error. */ TEST_FEATURE ("with known interface but no properties"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestA"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "a{sv}")); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_INVALID); dbus_message_unref (reply); } nih_free (object); /* Check that attempting to get the values of all properties on * an unknown interface results in a reply containing an empty * array, rather than an error. */ TEST_FEATURE ("with unknown interface"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.FooBar"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "a{sv}")); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_INVALID); dbus_message_unref (reply); } nih_free (object); /* Check that attempting to get the values of all properties when * there are no interfaces results in a reply containing an empty * array, rather than an error. */ TEST_FEATURE ("with no interfaces"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", no_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestA"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "a{sv}")); dbus_message_iter_init (reply, &iter); dbus_message_iter_recurse (&iter, &arrayiter); TEST_EQ (dbus_message_iter_get_arg_type (&arrayiter), DBUS_TYPE_INVALID); dbus_message_unref (reply); } nih_free (object); /* Check that trying to get the values of all properties when one * returns a D-Bus error returns that D-Bus error. */ TEST_FEATURE ("with D-Bus error from handler"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; colour = "secret"; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_ACCESS_DENIED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that trying to get the values of all properties when one * returns a generic error means that property is simply not included * in the returned set. */ TEST_FEATURE ("with generic error from handler"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; colour = "chicken"; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, strerror (EBADF)); dbus_error_free (&dbus_error); dbus_message_unref (reply); } nih_free (object); /* Check that we receive an Invalid Args error when we forget to * pass any arguments. */ TEST_FEATURE ("with missing arguments"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that we receive an Invalid Args error when we pass too * many arguments. */ TEST_FEATURE ("with too many arguments"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_get_called = FALSE; size_get_called = FALSE; other_get_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "GetAll"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_get_called); TEST_FALSE (size_get_called); TEST_FALSE (other_get_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } void test_object_property_set (void) { pid_t dbus_pid; DBusConnection * server_conn; DBusConnection * client_conn; NihDBusObject * object; DBusMessage * message; DBusMessageIter iter; DBusMessageIter subiter; const char * interface_name; const char * property_name; dbus_uint32_t serial; DBusMessage * reply; const char * str_value; double double_value; dbus_uint32_t uint32_value; DBusError dbus_error; TEST_FUNCTION ("nih_dbus_object_property_set"); TEST_DBUS (dbus_pid); TEST_DBUS_OPEN (server_conn); TEST_DBUS_OPEN (client_conn); /* Check that we can set the value of a read/write property, with the * registered setter function being called to do so with the * right value. */ TEST_FEATURE ("with read/write property"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", prop_interface, &server_conn); TEST_ALLOC_FAIL { colour_set_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter)); str_value = "red"; assert (dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value)); assert (dbus_message_iter_close_container (&iter, &subiter)); assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (colour_set_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "")); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (reply); } nih_free (object); /* Check that we can set the value of a write-only property, with the * registered setter function being called to do so with the * right value. */ TEST_FEATURE ("with write-only property"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", prop_interface, &server_conn); TEST_ALLOC_FAIL { poke_set_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Poke"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &subiter)); double_value = 3.14; assert (dbus_message_iter_append_basic (&subiter, DBUS_TYPE_DOUBLE, &double_value)); assert (dbus_message_iter_close_container (&iter, &subiter)); assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (poke_set_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "")); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (reply); } nih_free (object); /* Check that we cannot set the value of a read-only property, and * that the access denied error is returned instead. */ TEST_FEATURE ("with read-only property"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", prop_interface, &server_conn); TEST_ALLOC_FAIL { last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Size"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT32_AS_STRING, &subiter)); uint32_value = 34; assert (dbus_message_iter_append_basic (&subiter, DBUS_TYPE_UINT32, &uint32_value)); assert (dbus_message_iter_close_container (&iter, &subiter)); assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_ACCESS_DENIED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that the first of two properties with the same name * but on different interfaces is used when the property interface * is not given. */ TEST_FEATURE ("with property registered to multiple interfaces"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_set_called = FALSE; poke_set_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = ""; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter)); str_value = "red"; assert (dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value)); assert (dbus_message_iter_close_container (&iter, &subiter)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (colour_set_called); TEST_FALSE (poke_set_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_EQ (dbus_message_get_type (reply), DBUS_MESSAGE_TYPE_METHOD_RETURN); TEST_EQ (dbus_message_get_reply_serial (reply), serial); TEST_TRUE (dbus_message_has_signature (reply, "")); dbus_message_iter_init (reply, &iter); TEST_EQ (dbus_message_iter_get_arg_type (&iter), DBUS_TYPE_INVALID); dbus_message_unref (reply); } nih_free (object); /* Check that attempting to set an unknown property on a known * interface results in an error reply. */ TEST_FEATURE ("with unknown property on known interface"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_set_called = FALSE; poke_set_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Height"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter)); str_value = "red"; assert (dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value)); assert (dbus_message_iter_close_container (&iter, &subiter)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_set_called); TEST_FALSE (poke_set_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_UNKNOWN_METHOD)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that a property on an unknown interface always results in * an error reply. */ TEST_FEATURE ("with unknown property on unknown interface"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_set_called = FALSE; poke_set_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.FooBar"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter)); str_value = "red"; assert (dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value)); assert (dbus_message_iter_close_container (&iter, &subiter)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_set_called); TEST_FALSE (poke_set_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_UNKNOWN_METHOD)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that an unknown property when no interface was specified * results in an error reply. */ TEST_FEATURE ("with unknown property with no interface"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_set_called = FALSE; poke_set_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = ""; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Width"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter)); str_value = "red"; assert (dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value)); assert (dbus_message_iter_close_container (&iter, &subiter)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_set_called); TEST_FALSE (poke_set_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_UNKNOWN_METHOD)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that an error reply is always received when no interfaces * were defined. */ TEST_FEATURE ("with no interfaces"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", no_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_set_called = FALSE; poke_set_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = ""; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Width"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter)); str_value = "red"; assert (dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value)); assert (dbus_message_iter_close_container (&iter, &subiter)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_set_called); TEST_FALSE (poke_set_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_UNKNOWN_METHOD)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that when the setter function returns a D-Bus error, * that is returned as a reply to the caller. */ TEST_FEATURE ("with D-Bus error from handler"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", prop_interface, &server_conn); TEST_ALLOC_FAIL { colour_set_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter)); str_value = "pig"; assert (dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value)); assert (dbus_message_iter_close_container (&iter, &subiter)); assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (colour_set_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, "com.netsplit.Nih.NotAColour")); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that when the setter function returns a generic error, * the message is returned inside a D-Bus failed error. */ TEST_FEATURE ("with generic error from handler"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", prop_interface, &server_conn); TEST_ALLOC_FAIL { colour_set_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter)); str_value = ""; assert (dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value)); assert (dbus_message_iter_close_container (&iter, &subiter)); assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_TRUE (colour_set_called); TEST_EQ_P (last_object, object); TEST_FREE (last_message); TEST_EQ_P (last_message_conn, server_conn); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_FAILED)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_error_init (&dbus_error); dbus_set_error_from_message (&dbus_error, reply); TEST_EQ_STR (dbus_error.message, strerror (EBADF)); dbus_error_free (&dbus_error); dbus_message_unref (reply); } nih_free (object); /* Check that we receive an Invalid Args error when we forget to * pass the property value. */ TEST_FEATURE ("with missing property value"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_set_called = FALSE; poke_set_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_set_called); TEST_FALSE (poke_set_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that we receive an Invalid Args error when we forget to * pass the property name or value. */ TEST_FEATURE ("with missing property name and value"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_set_called = FALSE; poke_set_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_set_called); TEST_FALSE (poke_set_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that we receive an Invalid Args error when we forget to * pass any arguments. */ TEST_FEATURE ("with missing arguments"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_set_called = FALSE; poke_set_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_set_called); TEST_FALSE (poke_set_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); /* Check that we receive an Invalid Args error when we pass too * many arguments. */ TEST_FEATURE ("with too many arguments"); object = nih_dbus_object_new (NULL, server_conn, "/com/netsplit/Nih", all_interfaces, &server_conn); TEST_ALLOC_FAIL { colour_set_called = FALSE; poke_set_called = FALSE; last_object = NULL; last_message = NULL; last_message_conn = NULL; message = dbus_message_new_method_call ( dbus_bus_get_unique_name (server_conn), "/com/netsplit/Nih", DBUS_INTERFACE_PROPERTIES, "Set"); assert (message != NULL); dbus_message_iter_init_append (message, &iter); interface_name = "Nih.TestB"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name)); property_name = "Colour"; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &property_name)); assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &subiter)); str_value = "red"; assert (dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &str_value)); assert (dbus_message_iter_close_container (&iter, &subiter)); uint32_value = 32; assert (dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &uint32_value)); TEST_ALLOC_SAFE { assert (dbus_connection_send (client_conn, message, &serial)); dbus_connection_flush (client_conn); } dbus_message_unref (message); TEST_DBUS_DISPATCH (server_conn); TEST_FALSE (colour_set_called); TEST_FALSE (poke_set_called); TEST_EQ_P (last_object, NULL); TEST_EQ_P (last_message_conn, NULL); TEST_DBUS_MESSAGE (client_conn, reply); TEST_TRUE (dbus_message_is_error (reply, DBUS_ERROR_INVALID_ARGS)); TEST_EQ (dbus_message_get_reply_serial (reply), serial); dbus_message_unref (reply); } nih_free (object); TEST_DBUS_CLOSE (client_conn); TEST_DBUS_CLOSE (server_conn); TEST_DBUS_END (dbus_pid); dbus_shutdown (); } int main (int argc, char *argv[]) { nih_error_init (); test_object_new (); test_object_destroy (); test_object_unregister (); test_object_message (); test_object_introspect (); test_object_property_get (); test_object_property_get_all (); test_object_property_set (); return 0; } libnih-1.0.3/nih-dbus/dbus_util.c0000644000175000017500000000605411445765555013576 00000000000000/* libnih * * dbus_util.c - D-Bus utility functions * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include "dbus_util.h" /** * nih_dbus_path: * @parent: parent object for new string, * @root: root of path. * * Generates a D-Bus path suitable for object registration rooted at * @root with each of the further elements joined with "/" separators and * appended after non-permissible characters are removed. * * The final argument to this function must be NULL to signify the end * of elements. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL if insufficient memory. **/ char * nih_dbus_path (const void *parent, const char *root, ...) { const char *arg; const char *ptr; char * path; va_list args; size_t len; nih_assert (root != NULL); /* First work out how much space we'll need */ len = strlen (root); va_start (args, root); for (arg = va_arg (args, const char *); arg != NULL; arg = va_arg (args, const char *)) { len += 1; if (! *arg) len += 1; for (ptr = arg; *ptr != '\0'; ptr++) { if ( ((*ptr >= 'a') && (*ptr <= 'z')) || ((*ptr >= 'A') && (*ptr <= 'Z')) || ((*ptr >= '0') && (*ptr <= '9'))) { len += 1; } else { len += 3; } } } va_end (args); /* Now we can allocate it */ path = nih_alloc (parent, len + 1); if (! path) return NULL; /* And copy the elements in */ strcpy (path, root); len = strlen (root); va_start (args, root); for (arg = va_arg (args, const char *); arg != NULL; arg = va_arg (args, const char *)) { path[len++] = '/'; if (! *arg) path[len++] = '_'; for (ptr = arg; *ptr != '\0'; ptr++) { if ( ((*ptr >= 'a') && (*ptr <= 'z')) || ((*ptr >= 'A') && (*ptr <= 'Z')) || ((*ptr >= '0') && (*ptr <= '9'))) { path[len++] = *ptr; } else { path[len++] = '_'; sprintf (path + len, "%02x", *ptr); len += 2; } } } va_end (args); path[len] = '\0'; return path; } libnih-1.0.3/nih-dbus/libnih-dbus.pc.in0000644000175000017500000000032511445765555014564 00000000000000prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: libnih-dbus Description: NIH D-Bus Bindings Library Version: @VERSION@ Libs: -L${libdir} -lnih-dbus Cflags: -I${includedir} libnih-1.0.3/nih-dbus/dbus_proxy.h0000644000175000017500000001160011445765555014000 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_PROXY_H #define NIH_DBUS_PROXY_H #include #include #include #include /** * NIH_DBUS_TIMEOUT_DEFAULT: * * This macro expands to the timeout value used by D-Bus to mean the * default timeout (25s). **/ #define NIH_DBUS_TIMEOUT_DEFAULT -1 /** * NIH_DBUS_TIMEOUT_NEVER: * * This macro expands to the timeout value used by D-Bus to mean that * the call should never timeout. **/ #define NIH_DBUS_TIMEOUT_NEVER INT_MAX /** * NihDBusLostHandler: * @data: data pointer passed to nih_dbus_proxy_new(), * @proxy: proxy object. * * The D-Bus Lost Handler function is called when a proxied remote object * is no longer available, due to the owner of the name being changed or * leaving the bus. * * A common activity is to free the proxy. **/ typedef void (*NihDBusLostHandler) (void *data, NihDBusProxy *proxy); /** * NihDBusSignalHandler: * @data: data pointer passed to nih_dbus_proxy_new(), * @message: NihDBusMessage context for signal arguments. * * A D-Bus Signal Handler is called when the expected signal is emitted * and caught by the signal filter function, generally they will be called * with additional arguments representing the demarshalled data from the * signal itself. **/ typedef void (*NihDBusSignalHandler) (void *data, NihDBusMessage *message, ...); /** * NihDBusProxy: * @connection: associated connection, * @name: D-Bus name of object owner, * @owner: actual unique D-Bus owner, * @path: path of object, * @auto_start: whether method calls should auto-start the service, * @lost_handler: handler to call when the proxied object is lost, * @data: data to pass to handler functions. * * Proxy objects represent a remote D-Bus object accessible over the bus. * The primary purpose of this object is to combine the three elements * of data that uniquely identify that remote object: the connection, * the bus name (either well known or unique) and the path. * * @name may be NULL for peer-to-peer D-Bus connections. * * @auto_start is an advisory flag for method calls only, it is used by * nih-dbus-tool generated method calls. * * Proxies are not generally bound to the life-time of the connection or * the remote object, thus there may be periods when functions will fail * or signal filter functions left dormant due to unavailability of the * remote object or even cease permanently when the bus connection is * disconnected. * * Passing a @lost_handler function means that @name will be tracked on * the bus. Should the owner of @name change @lost_handler will be called * to allow clean-up of the proxy. **/ struct nih_dbus_proxy { DBusConnection * connection; char * name; char * owner; char * path; int auto_start; NihDBusLostHandler lost_handler; void * data; }; /** * NihDBusProxySignal: * @proxy: proxy structure, * @interface: signal interface definition, * @signal: signal definition, * @handler: signal handler function, * @data: data to pass to @handler function. * * This structure represents a connected signal handler @handler which * should be run when a matching signal @signal on interface @interface * is emitted by a proxied object @proxied. * * @name may be NULL for peer-to-peer D-Bus connections. * * Proxied signals are bound to the life cycle of @proxy. **/ struct nih_dbus_proxy_signal { NihDBusProxy * proxy; const NihDBusInterface *interface; const NihDBusSignal * signal; NihDBusSignalHandler handler; void * data; }; NIH_BEGIN_EXTERN NihDBusProxy * nih_dbus_proxy_new (const void *parent, DBusConnection *connection, const char *name, const char *path, NihDBusLostHandler lost_handler, void *data) __attribute__ ((warn_unused_result, malloc)); NihDBusProxySignal *nih_dbus_proxy_connect (NihDBusProxy *proxy, const NihDBusInterface *interface, const char *name, NihDBusSignalHandler handler, void *data) __attribute__ ((warn_unused_result, malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_PROXY_H */ libnih-1.0.3/nih-dbus/libnih-dbus.h0000644000175000017500000000222111445765555014001 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_LIBNIH_DBUS_H #define NIH_LIBNIH_DBUS_H #include #include #include #include #include #include #include #include #include #endif /* NIH_LIBNIH_DBUS_H */ libnih-1.0.3/nih-dbus/dbus_object.h0000644000175000017500000000413211445765555014067 00000000000000/* libnih * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef NIH_DBUS_OBJECT_H #define NIH_DBUS_OBJECT_H #include #include #include /** * NihDBusObject: * @path: path of object, * @connection: associated connection, * @data: pointer to object data, * @interfaces: NULL-terminated array of interfaces the object supports, * @registered: TRUE while the object is registered. * * This structure represents an object visible on the given @connection * at @path and being handled by libnih-dbus. It connects the @data * pointer to the individual method and property handler functions * defined by the @interfaces. * * Automatic introspection is provided based on @interfaces. * * No reference is held to @connection, therefore you may not assume that * it is valid. In general, the object will be automatically freed should * @connection be cleaned up. **/ struct nih_dbus_object { char * path; DBusConnection * connection; void * data; const NihDBusInterface **interfaces; int registered; }; NIH_BEGIN_EXTERN NihDBusObject *nih_dbus_object_new (const void *parent, DBusConnection *connection, const char *path, const NihDBusInterface **interfaces, void *data) __attribute__ ((malloc)); NIH_END_EXTERN #endif /* NIH_DBUS_OBJECT_H */ libnih-1.0.3/nih-dbus/dbus_proxy.c0000644000175000017500000004245211445765555014004 00000000000000/* libnih * * dbus_proxy.c - D-Bus remote object proxy implementation * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include "dbus_proxy.h" /* Prototypes for static functions */ static int nih_dbus_proxy_destroy (NihDBusProxy *proxy); static int nih_dbus_proxy_name_track (NihDBusProxy *proxy) __attribute__ ((warn_unused_result)); static char *nih_dbus_proxy_name_rule (const void *parent, NihDBusProxy *proxy) __attribute__ ((warn_unused_result, malloc)); static int nih_dbus_proxy_signal_destroy (NihDBusProxySignal *proxied); static char *nih_dbus_proxy_signal_rule (const void *parent, NihDBusProxySignal *proxied) __attribute__ ((warn_unused_result, malloc)); /* Prototypes for handler functions */ static DBusHandlerResult nih_dbus_proxy_name_owner_changed (DBusConnection *connection, DBusMessage *message, NihDBusProxy *proxy); /** * nih_dbus_proxy_new: * @parent: parent object for new proxy, * @connection: D-Bus connection to associate with, * @name: well-known name of object owner, * @path: path of object, * @lost_handler: optional handler for remote object loss. * @data: data pointer for handlers. * * Creates a new D-Bus proxy for a remote object on @connection with the * well-known or unique bus name @name at @path. The returned structure * is allocated with nih_alloc() and holds a reference to @connection. * * @name may be NULL for peer-to-peer D-Bus connections. * * Proxies are not generally bound to the life-time of the connection or * the remote object, thus there may be periods when functions will fail * or signal filter functions left dormant due to unavailability of the * remote object or even cease permanently when the bus connection is * disconnected. * * @name will be tracked on the bus, with the current owner's unique name * being available in the returned structure's owner member. Should the * name be lost from the bus, the optional @lost_handler function will be * called to allow clean-up of the proxy. * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned proxy. When all parents * of the returned proxy are freed, the returned proxy will also be * freed. * * Returns: new NihDBusProxy structure on success, or NULL on raised * error. **/ NihDBusProxy * nih_dbus_proxy_new (const void * parent, DBusConnection * connection, const char * name, const char * path, NihDBusLostHandler lost_handler, void * data) { NihDBusProxy *proxy; nih_assert (connection != NULL); nih_assert (path != NULL); nih_assert ((lost_handler == NULL) || (name != NULL)); proxy = nih_new (parent, NihDBusProxy); if (! proxy) nih_return_no_memory_error (NULL); proxy->connection = connection; proxy->name = NULL; if (name) { proxy->name = nih_strdup (proxy, name); if (! proxy->name) { nih_free (proxy); nih_return_no_memory_error (NULL); } } proxy->owner = NULL; proxy->path = nih_strdup (proxy, path); if (! proxy->path) { nih_free (proxy); nih_return_no_memory_error (NULL); } proxy->auto_start = TRUE; proxy->lost_handler = lost_handler; proxy->data = data; if (proxy->name) { if (nih_dbus_proxy_name_track (proxy) < 0) { nih_free (proxy); return NULL; } } dbus_connection_ref (proxy->connection); nih_alloc_set_destructor (proxy, nih_dbus_proxy_destroy); return proxy; } /** * nih_dbus_proxy_destroy: * @proxy: proxy object being destroyed. * * Destructor function for an NihDBusProxy structure; drops the bus rule * matching the NameOwnerChanged signal, the associated filter function, * and the reference to the D-Bus connection it holds. * * Returns: always zero. **/ static int nih_dbus_proxy_destroy (NihDBusProxy *proxy) { nih_local char *rule = NULL; DBusError dbus_error; nih_assert (proxy != NULL); if (proxy->name) { rule = NIH_MUST (nih_dbus_proxy_name_rule (NULL, proxy)); dbus_error_init (&dbus_error); dbus_bus_remove_match (proxy->connection, rule, &dbus_error); dbus_error_free (&dbus_error); dbus_connection_remove_filter (proxy->connection, (DBusHandleMessageFunction)nih_dbus_proxy_name_owner_changed, proxy); } dbus_connection_unref (proxy->connection); return 0; } /** * nih_dbus_proxy_name_track: * @proxy: proxy object. * * Set up name tracking for the given @proxy object. We get the current * owner of the name in a synchronous call and set the connection up to * watch for a change in that owner updating the proxy's owner member in * both cases. * * If the proxy has no owner, the connection is instead set up to wait * for it to come onto the bus, and then reset later. * * Returns: 0 on success, negative value on raised error. **/ static int nih_dbus_proxy_name_track (NihDBusProxy *proxy) { nih_local char *rule = NULL; DBusError dbus_error; DBusMessage * method_call; DBusMessage * reply; const char * owner; nih_assert (proxy != NULL); nih_assert (proxy->name != NULL); /* Add the filter function that handles the NameOwnerChanged * signal. We need to do this first so that we can handle anything * that arrives after we add the signal match. */ if (! dbus_connection_add_filter (proxy->connection, (DBusHandleMessageFunction)nih_dbus_proxy_name_owner_changed, proxy, NULL)) nih_return_no_memory_error (-1); /* Ask the bus to send us matching signals. We've put the filter * function in place so we'll get callbacks straight away; but we * still need to do this before asking for the current name so * we don't miss something. */ rule = nih_dbus_proxy_name_rule (NULL, proxy); if (! rule) { nih_error_raise_no_memory (); goto error_after_filter; } dbus_error_init (&dbus_error); dbus_bus_add_match (proxy->connection, rule, &dbus_error); if (dbus_error_is_set (&dbus_error)) { if (dbus_error_has_name (&dbus_error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (dbus_error.name, dbus_error.message); } dbus_error_free (&dbus_error); goto error_after_filter; } /* Now that the bus will send us signals about changes in the name's * owner, and we'll handle them, we can get the current owner of the * name. We may have some signals in the queue that predate this, * but the end result will be the same. */ method_call = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetNameOwner"); if (! method_call) { nih_error_raise_no_memory (); dbus_error_free (&dbus_error); goto error_after_match; } if (! dbus_message_append_args (method_call, DBUS_TYPE_STRING, &proxy->name, DBUS_TYPE_INVALID)) { nih_error_raise_no_memory (); dbus_message_unref (method_call); dbus_error_free (&dbus_error); goto error_after_match; } /* Parse the reply; an owner is returned, we fill in the owner * member of the proxy - otherwise we set it to NULL. */ reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &dbus_error); if (! reply) { if (dbus_error_has_name (&dbus_error, DBUS_ERROR_NAME_HAS_NO_OWNER)) { nih_debug ("%s is not currently owned", proxy->name); dbus_message_unref (method_call); dbus_error_free (&dbus_error); /* Not an error */ return 0; } else if (dbus_error_has_name (&dbus_error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (dbus_error.name, dbus_error.message); } dbus_message_unref (method_call); dbus_error_free (&dbus_error); goto error_after_match; } dbus_message_unref (method_call); if (! dbus_message_get_args (reply, &dbus_error, DBUS_TYPE_STRING, &owner, DBUS_TYPE_INVALID)) { if (dbus_error_has_name (&dbus_error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (dbus_error.name, dbus_error.message); } dbus_message_unref (reply); dbus_error_free (&dbus_error); goto error_after_match; } dbus_error_free (&dbus_error); proxy->owner = nih_strdup (proxy, owner); if (! proxy->owner) { nih_error_raise_no_memory (); dbus_message_unref (reply); goto error_after_match; } dbus_message_unref (reply); nih_debug ("%s is currently owned by %s", proxy->name, proxy->owner); return 0; error_after_match: dbus_error_init (&dbus_error); dbus_bus_remove_match (proxy->connection, rule, &dbus_error); dbus_error_free (&dbus_error); error_after_filter: dbus_connection_remove_filter (proxy->connection, (DBusHandleMessageFunction)nih_dbus_proxy_name_owner_changed, proxy); return -1; } /** * nih_dbus_proxy_name_rule: * @parent: parent object for new string, * @proxy: proxy object. * * Generates a D-Bus match rule for the NameOwnerChanged signal for the * given @proxy. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL on insufficient memory. **/ static char * nih_dbus_proxy_name_rule (const void * parent, NihDBusProxy *proxy) { char *rule; nih_assert (proxy != NULL); nih_assert (proxy->name != NULL); rule = nih_sprintf (parent, ("type='%s',sender='%s',path='%s'," "interface='%s',member='%s'," "arg0='%s'"), "signal", DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "NameOwnerChanged", proxy->name); return rule; } /** * nih_dbus_proxy_name_owner_changed: * @connection: D-Bus connection signal received on, * @message: signal message, * @proxy: associated proxy object. * * This function is called by D-Bus on receipt of the NameOwnerChanged * signal for the registered name that @proxy represents. The proxy's * lost_handler function is called to decide what to do about it. * * Returns: usually DBUS_HANDLER_RESULT_NOT_YET_HANDLED so other signal * handlers also get a look-in, DBUS_HANDLED_RESULT_NEED_MEMORY if * insufficient memory. **/ static DBusHandlerResult nih_dbus_proxy_name_owner_changed (DBusConnection *connection, DBusMessage * message, NihDBusProxy * proxy) { DBusError dbus_error; const char *name; const char *old_owner; const char *new_owner; nih_assert (connection != NULL); nih_assert (message != NULL); nih_assert (proxy->connection == connection); nih_assert (proxy->name != NULL); if (! dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (message, DBUS_PATH_DBUS)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_sender (message, DBUS_SERVICE_DBUS)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; dbus_error_init (&dbus_error); if (! dbus_message_get_args (message, &dbus_error, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &old_owner, DBUS_TYPE_STRING, &new_owner, DBUS_TYPE_INVALID)) { dbus_error_free (&dbus_error); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } dbus_error_free (&dbus_error); if (strcmp (name, proxy->name)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; /* Ok, it's really the right NameOwnerChanged signal. If the name * has a new owner, update the owner property (tracking a well known * name between instances) otherwise call the lost handler. */ if (strlen (new_owner)) { nih_debug ("%s changed owner from %s to %s", proxy->name, old_owner, new_owner); if (proxy->owner) nih_unref (proxy->owner, proxy); proxy->owner = NIH_MUST (nih_strdup (proxy, new_owner)); } else { nih_debug ("%s owner left the bus", proxy->name); if (proxy->owner) nih_unref (proxy->owner, proxy); proxy->owner = NULL; if (proxy->lost_handler) { nih_error_push_context (); proxy->lost_handler (proxy->data, proxy); nih_error_pop_context (); } } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /** * nih_dbus_proxy_connect: * @proxy: proxy for remote object, * @interface: signal interface definition, * @name: name of signal, * @handler: signal handler function, * @data: data to pass to @handler. * * Connect the signal @name on @interface to @proxy so that the @handler * function is passed to the filter function defined by @signal when it * is received on the proxied D-Bus connection. * * The signal can be disconnected by freeing the returned structure, the * signal is also bound to the lifetime of @proxy so that the signal is * disconnected when the proxy is freed. * * Returns: newly allocated NihDBusProxySignal structure or NULL on raised * error. **/ NihDBusProxySignal * nih_dbus_proxy_connect (NihDBusProxy * proxy, const NihDBusInterface *interface, const char * name, NihDBusSignalHandler handler, void * data) { NihDBusProxySignal *proxied; nih_local char * rule = NULL; DBusError dbus_error; nih_assert (proxy != NULL); nih_assert (interface != NULL); nih_assert (name != NULL); nih_assert (handler != NULL); proxied = nih_new (proxy, NihDBusProxySignal); if (! proxied) nih_return_no_memory_error (NULL); proxied->proxy = proxy; proxied->interface = interface; proxied->signal = NULL; proxied->handler = handler; proxied->data = data; for (const NihDBusSignal *signal = interface->signals; signal && signal->name; signal++) { if (! strcmp (signal->name, name)) { proxied->signal = signal; break; } } nih_assert (proxied->signal != NULL); if (! dbus_connection_add_filter (proxied->proxy->connection, (DBusHandleMessageFunction)proxied->signal->filter, proxied, NULL)) { nih_free (proxied); nih_return_no_memory_error (NULL); } if (proxied->proxy->name) { rule = nih_dbus_proxy_signal_rule (NULL, proxied); if (! rule) { nih_error_raise_no_memory (); goto error; } dbus_error_init (&dbus_error); dbus_bus_add_match (proxied->proxy->connection, rule, &dbus_error); if (dbus_error_is_set (&dbus_error)) { if (dbus_error_has_name (&dbus_error, DBUS_ERROR_NO_MEMORY)) { nih_error_raise_no_memory (); } else { nih_dbus_error_raise (dbus_error.name, dbus_error.message); } dbus_error_free (&dbus_error); goto error; } } nih_alloc_set_destructor (proxied, nih_dbus_proxy_signal_destroy); return proxied; error: dbus_connection_remove_filter (proxied->proxy->connection, (DBusHandleMessageFunction)proxied->signal->filter, proxied); nih_free (proxied); return NULL; } /** * nih_dbus_proxy_signal_destroy: * @proxied: proxied signal being destroyed. * * Destructor function for an NihDBusProxySignal structure; drops the bus * rule matching the signal and the associated filter function. * * Returns: always zero. **/ static int nih_dbus_proxy_signal_destroy (NihDBusProxySignal *proxied) { nih_local char *rule = NULL; DBusError dbus_error; nih_assert (proxied != NULL); if (proxied->proxy->name) { rule = NIH_MUST (nih_dbus_proxy_signal_rule (NULL, proxied)); dbus_error_init (&dbus_error); dbus_bus_remove_match (proxied->proxy->connection, rule, &dbus_error); dbus_error_free (&dbus_error); } dbus_connection_remove_filter (proxied->proxy->connection, (DBusHandleMessageFunction)proxied->signal->filter, proxied); return 0; } /** * nih_dbus_proxy_signal_rule: * @parent: parent object for new string, * @proxied: proxied signal. * * Generates a D-Bus match rule for the @proxied signal. * * If @parent is not NULL, it should be a pointer to another object which * will be used as a parent for the returned string. When all parents * of the returned string are freed, the returned string will also be * freed. * * Returns: newly allocated string or NULL on insufficient memory. **/ static char * nih_dbus_proxy_signal_rule (const void * parent, NihDBusProxySignal *proxied) { char *rule; nih_assert (proxied != NULL); nih_assert (proxied->proxy->name != NULL); rule = nih_sprintf (parent, ("type='%s',sender='%s',path='%s'," "interface='%s',member='%s'"), "signal", proxied->proxy->name, proxied->proxy->path, proxied->interface->name, proxied->signal->name); return rule; } libnih-1.0.3/nih-dbus/dbus_connection.c0000644000175000017500000005354311445765555014765 00000000000000/* libnih * * dbus_connection.c - D-Bus client, bus and server connection handling * * Copyright © 2009 Scott James Remnant . * Copyright © 2009 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H # include #endif /* HAVE_CONFIG_H */ #include #include #include #include #include #include #include #include #include #include #include "dbus_connection.h" /* Prototypes for static functions */ static dbus_bool_t nih_dbus_add_watch (DBusWatch *watch, void *data); static void nih_dbus_remove_watch (DBusWatch *watch, void *data); static void nih_dbus_watch_toggled (DBusWatch *watch, void *data); static void nih_dbus_watcher (DBusWatch *watch, NihIoWatch *io_watch, NihIoEvents events); static dbus_bool_t nih_dbus_add_timeout (DBusTimeout *timeout, void *data); static void nih_dbus_remove_timeout (DBusTimeout *timeout, void *data); static void nih_dbus_timeout_toggled (DBusTimeout *timeout, void *data); static void nih_dbus_timer (DBusTimeout *timeout, NihTimer *timer); static void nih_dbus_wakeup_main (void *data); static void nih_dbus_callback (DBusConnection *connection, NihMainLoopFunc *loop); static DBusHandlerResult nih_dbus_connection_disconnected (DBusConnection *connection, DBusMessage *message, NihDBusDisconnectHandler handler); static void nih_dbus_new_connection (DBusServer *server, DBusConnection *connection, void *data); /** * main_loop_slot: * * Slot we use to store the main loop function in the connection. **/ static dbus_int32_t main_loop_slot = -1; /** * connect_handler_slot: * * Slot we use to store the connection handler in the server. **/ static dbus_int32_t connect_handler_slot = -1; /** * disconnect_handler_slot: * * Slot we use to store the disconnect handler in the server. **/ static dbus_int32_t disconnect_handler_slot = -1; /** * nih_dbus_connect: * @address: address of D-Bus bus or server, * @disconnect_handler: function to call on disconnection. * * Establishes a connection to the D-Bus bus or server at @address * (specified in D-Bus's own address syntax) and sets up the connection * within libnih's own main loop so that messages will be received, sent * and dispatched automatically. * * The returned connection object IS NOT allocated with nih_alloc() and * is instead allocated and managed by the D-Bus library, it may not be * used as a context for other allocations. Instead you should use * D-Bus data slots and free functions to attach other data to this. * * The connection object is shared and will persist as long as the * server maintains the connection. You may prematurely terminate the * connection with dbus_connection_unref(). * * Returns: new D-Bus connection object or NULL on raised error. **/ DBusConnection * nih_dbus_connect (const char * address, NihDBusDisconnectHandler disconnect_handler) { DBusConnection *connection; DBusError error; nih_assert (address != NULL); dbus_error_init (&error); connection = dbus_connection_open (address, &error); if (! connection) { if (! strcmp (error.name, DBUS_ERROR_NO_MEMORY)) { nih_error_raise (ENOMEM, strerror (ENOMEM)); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return NULL; } if (nih_dbus_setup (connection, disconnect_handler) < 0) { dbus_connection_unref (connection); nih_return_no_memory_error (NULL); } return connection; } /** * nih_dbus_bus: * @bus: D-Bus bus type to connect to, * @disconnect_handler: function to call on disconnection. * * Establishes a connection to the given D-Bus @bus and sets up * the connection within libnih's own main loop so that messages will be * received, sent and dispatched automatically. * * Unlike the ordinary D-Bus API, this connection will not cause the exit() * function to be called should the bus go away. * * The returned connection object IS NOT allocated with nih_alloc() and * is instead allocated and managed by the D-Bus library, it may not be * used as a context for other allocations. Instead you should use * D-Bus data slots and free functions to attach other data to this. * * The connection object is shared and will persist as long as the * server maintains the connection. You may prematurely terminate the * connection with dbus_connection_unref(). * * Returns: new D-Bus connection object or NULL on raised error. **/ DBusConnection * nih_dbus_bus (DBusBusType bus, NihDBusDisconnectHandler disconnect_handler) { DBusConnection *connection; DBusError error; dbus_error_init (&error); connection = dbus_bus_get (bus, &error); if (! connection) { if (! strcmp (error.name, DBUS_ERROR_NO_MEMORY)) { nih_error_raise (ENOMEM, strerror (ENOMEM)); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return NULL; } dbus_connection_set_exit_on_disconnect (connection, FALSE); if (nih_dbus_setup (connection, disconnect_handler) < 0) { dbus_connection_unref (connection); nih_return_no_memory_error (NULL); } return connection; } /** * nih_dbus_setup: * @connection: D-Bus connection to setup, * @disconnect_handler: function to call on disconnection. * * Sets up the given connection @connection so that it may use libnih's own * main loop meaning that messages will be received, sent and dispatched * automatically. * * This will also set up a handler for the disconnected signal that will * automatically unreference the connection after calling the given * @disconnect_handler. * * It's safe to call this function multiple times for a single @connection, * for example for setting an additional @disconnect_handler for a shared * connection. * * Returns: zero on success, negative value on insufficient memory. **/ int nih_dbus_setup (DBusConnection * connection, NihDBusDisconnectHandler disconnect_handler) { NihMainLoopFunc *loop; nih_assert (connection != NULL); /* Allocate a data slot for storing the main loop function; if * this is set for the structure, we've already set it up before * and this is being shared so we can skip down to just adding * the new disconnect handler. */ if (! dbus_connection_allocate_data_slot (&main_loop_slot)) return -1; if (! dbus_connection_get_data (connection, main_loop_slot)) { /* Allow the connection to watch its file descriptors */ if (! dbus_connection_set_watch_functions (connection, nih_dbus_add_watch, nih_dbus_remove_watch, nih_dbus_watch_toggled, NULL, NULL)) goto error; /* Allow the connection to set up timers */ if (! dbus_connection_set_timeout_functions (connection, nih_dbus_add_timeout, nih_dbus_remove_timeout, nih_dbus_timeout_toggled, NULL, NULL)) goto error; /* Allow the connection to wake up the main loop */ dbus_connection_set_wakeup_main_function (connection, nih_dbus_wakeup_main, NULL, NULL); /* Add the main loop function and store it in the data slot, * this means it will be automatically freed. Until this * succeeds, all of the above functions will be reset each * time. */ loop = nih_main_loop_add_func (NULL, (NihMainLoopCb)nih_dbus_callback, connection); if (! loop) goto error; if (! dbus_connection_set_data (connection, main_loop_slot, loop, (DBusFreeFunction)nih_discard)) { nih_free (loop); goto error; } } /* Add the filter for the disconnect handler (which may be NULL, * but even then we have to unreference it). If this fails, and * we call again, we'll act as though it's a shared connection * which has the right effect. */ if (! dbus_connection_add_filter ( connection, (DBusHandleMessageFunction)nih_dbus_connection_disconnected, disconnect_handler, NULL)) return -1; return 0; error: /* Unwind setup of a non-shared connection so that next time we call, * we're not in a strange half-done state. */ dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL); dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL); dbus_connection_set_wakeup_main_function (connection, NULL, NULL, NULL); return -1; } /** * nih_dbus_server: * @address: intended address of D-Bus server, * @connect_handler: function to call on new connections, * @disconnect_handler: function to call on disconnection of connections. * * Creates a listening D-Bus server at @address (specified in D-Bus's own * address syntax) and sets up the server within libnih's own main loop * so that socket events will be handled automatically. * * New connections are accepted if the @connect_handler returns TRUE and * they too set up within libnih's own main loop so that messages will be * received, sent and dispatched. If those connections are disconnected, * @disconnect_handler will be called for them and they will be * automatically unreferenced. * * The returned server object and any created connection objects ARE NOT * allocated with nih_alloc() and are instead allocated and managed by the * D-Bus library, they may not be used as a context for other allocations. * Instead you should use D-Bus data slots and free functions to attach * other data to them. * * Both the server object and any created connection objects are private, * you may close and unreference them when you are finished with them. * * Returns: new D-Bus server object or NULL on raised error. **/ DBusServer * nih_dbus_server (const char * address, NihDBusConnectHandler connect_handler, NihDBusDisconnectHandler disconnect_handler) { DBusServer *server; DBusError error; nih_assert (address != NULL); dbus_error_init (&error); server = dbus_server_listen (address, &error); if (! server) { if (! strcmp (error.name, DBUS_ERROR_NO_MEMORY)) { nih_error_raise (ENOMEM, strerror (ENOMEM)); } else { nih_dbus_error_raise (error.name, error.message); } dbus_error_free (&error); return NULL; } /* Allocate a slot to store the connect handler */ if (! dbus_server_allocate_data_slot (&connect_handler_slot)) goto error; if (! dbus_server_set_data (server, connect_handler_slot, connect_handler, NULL)) goto error; /* Allocate a slot to store the disconnect handler */ if (! dbus_server_allocate_data_slot (&disconnect_handler_slot)) goto error; if (! dbus_server_set_data (server, disconnect_handler_slot, disconnect_handler, NULL)) goto error; /* Allow the server to watch its file descriptors */ if (! dbus_server_set_watch_functions (server, nih_dbus_add_watch, nih_dbus_remove_watch, nih_dbus_watch_toggled, NULL, NULL)) goto error; /* Allow the server to set up timers */ if (! dbus_server_set_timeout_functions (server, nih_dbus_add_timeout, nih_dbus_remove_timeout, nih_dbus_timeout_toggled, NULL, NULL)) goto error; /* Set the function to be called for new connectoins */ dbus_server_set_new_connection_function (server, nih_dbus_new_connection, NULL, NULL); return server; error: dbus_server_disconnect (server); dbus_server_unref (server); nih_return_no_memory_error (NULL); } /** * nih_dbus_add_watch: * @watch: D-Bus watch to be added, * @data: not used. * * Called by D-Bus to register the given file descriptor @watch in our main * loop; we create an NihIoWatch structure for it with events matching the * watch's flags - even if the watch is not enabled (in which case we remove * it from the watch list). * * The NihIoWatch is stored in the watch's data member. * * Returns: TRUE if the watch could be added, FALSE on insufficient memory. **/ static dbus_bool_t nih_dbus_add_watch (DBusWatch *watch, void * data) { NihIoWatch *io_watch; int fd; int flags; NihIoEvents events = NIH_IO_EXCEPT; nih_assert (watch != NULL); nih_assert (dbus_watch_get_data (watch) == NULL); fd = dbus_watch_get_unix_fd (watch); nih_assert (fd >= 0); flags = dbus_watch_get_flags (watch); if (flags & DBUS_WATCH_READABLE) events |= NIH_IO_READ; if (flags & DBUS_WATCH_WRITABLE) events |= NIH_IO_WRITE; io_watch = nih_io_add_watch (NULL, fd, events, (NihIoWatcher)nih_dbus_watcher, watch); if (! io_watch) return FALSE; dbus_watch_set_data (watch, io_watch, (DBusFreeFunction)nih_discard); if (! dbus_watch_get_enabled (watch)) nih_list_remove (&io_watch->entry); return TRUE; } /** * nih_dbus_remove_watch: * @watch: D-Bus watch to be removed, * @data: not used. * * Called by D-Bus to unregister the given file descriptor @watch from our * main loop; we take the NihIoWatch structure from the watch's data member * and free it. **/ static void nih_dbus_remove_watch (DBusWatch *watch, void * data) { NihIoWatch *io_watch; nih_assert (watch != NULL); io_watch = dbus_watch_get_data (watch); nih_assert (io_watch != NULL); /* Only remove it from the list, D-Bus will call nih_free for us * when we set the data to NULL. **/ nih_list_remove (&io_watch->entry); dbus_watch_set_data (watch, NULL, NULL); } /** * nih_dbus_watch_toggled: * @watch: D-Bus watch to be toggled, * @data: not used. * * Called by D-Bus because the given file descriptor @watch has been enabled * or disabled; we take the NihIoWatch structure from the watch's data member * and either add it to or remove it from the watches list. **/ static void nih_dbus_watch_toggled (DBusWatch *watch, void * data) { NihIoWatch *io_watch; int flags; NihIoEvents events = NIH_IO_EXCEPT; nih_assert (watch != NULL); io_watch = dbus_watch_get_data (watch); nih_assert (io_watch != NULL); /* D-Bus may toggle the watch in an attempt to change the flags */ flags = dbus_watch_get_flags (watch); if (flags & DBUS_WATCH_READABLE) events |= NIH_IO_READ; if (flags & DBUS_WATCH_WRITABLE) events |= NIH_IO_WRITE; if (dbus_watch_get_enabled (watch)) { nih_list_add (nih_io_watches, &io_watch->entry); } else { nih_list_remove (&io_watch->entry); } } /** * nih_dbus_watcher: * @watch: D-Bus watch event occurred for, * @io_watch: NihIoWatch for which an event occurred, * @events: events that occurred. * * Called because an event has occurred on @io_watch that we need to pass * onto the underlying @watch. **/ static void nih_dbus_watcher (DBusWatch * watch, NihIoWatch *io_watch, NihIoEvents events) { int flags = 0; nih_assert (watch != NULL); nih_assert (io_watch != NULL); if (events & NIH_IO_READ) flags |= DBUS_WATCH_READABLE; if (events & NIH_IO_WRITE) flags |= DBUS_WATCH_WRITABLE; if (events & NIH_IO_EXCEPT) flags |= DBUS_WATCH_ERROR; dbus_watch_handle (watch, flags); } /** * nih_dbus_add_timeout: * @timeout: D-Bus timeout to be added, * @data: not used. * * Called by D-Bus to register the given @timeout in our main loop; we create * a periodic NihTimer structure for it with the correct interval even if * the timeout is not enabled (in which case we remove it from the timer * list). * * The NihTimer is stored in the timeout's data member. * * Returns: TRUE if the timeout could be added, FALSE on insufficient memory. **/ static dbus_bool_t nih_dbus_add_timeout (DBusTimeout *timeout, void * data) { NihTimer *timer; int interval; nih_assert (timeout != NULL); nih_assert (dbus_timeout_get_data (timeout) == NULL); interval = dbus_timeout_get_interval (timeout); timer = nih_timer_add_periodic (NULL, (interval - 1) / 1000 + 1, (NihTimerCb)nih_dbus_timer, timeout); if (! timer) return FALSE; dbus_timeout_set_data (timeout, timer, (DBusFreeFunction)nih_discard); if (! dbus_timeout_get_enabled (timeout)) nih_list_remove (&timer->entry); return TRUE; } /** * nih_dbus_remove_timeout: * @timeout: D-Bus timeout to be removed, * @data: not used. * * Called by D-Bus to unregister the given @timeout from our main loop; we * take the NihTimer structure from the timeout's data member and free it. **/ static void nih_dbus_remove_timeout (DBusTimeout *timeout, void * data) { NihTimer *timer; nih_assert (timeout != NULL); timer = dbus_timeout_get_data (timeout); nih_assert (timer != NULL); /* Only remove it from the list, D-Bus will call nih_free for us * when we set the data to NULL. */ nih_list_remove (&timer->entry); dbus_timeout_set_data (timeout, NULL, NULL); } /** * nih_dbus_timeout_toggled: * @timeout: D-Bus timeout to be toggled, * @data: not used. * * Called by D-Bus because the @timeout has been enabled or disabled; we * take the NihTimer structure from the timeout's data member and either * add it to or remove it from the timers list. **/ static void nih_dbus_timeout_toggled (DBusTimeout *timeout, void * data) { NihTimer * timer; int interval; struct timespec now; nih_assert (timeout != NULL); timer = dbus_timeout_get_data (timeout); nih_assert (timer != NULL); /* D-Bus may toggle the timer in an attempt to change the timeout */ interval = dbus_timeout_get_interval (timeout); nih_assert (clock_gettime (CLOCK_MONOTONIC, &now) == 0); timer->period = (interval - 1) / 1000 + 1; timer->due = now.tv_sec + timer->period; if (dbus_timeout_get_enabled (timeout)) { nih_list_add (nih_timers, &timer->entry); } else { nih_list_remove (&timer->entry); } } /** * nih_dbus_timer: * @timeout: D-Bus timeout event occurred for, * @timer: timer that triggered the call. * * Called because @timer has elapsed and we need to pass that onto the * underlying @timeout. **/ static void nih_dbus_timer (DBusTimeout *timeout, NihTimer * timer) { nih_assert (timeout != NULL); nih_assert (timer != NULL); dbus_timeout_handle (timeout); } /** * nih_dbus_wakeup_main: * @data: not used. * * Called by D-Bus to wakeup the main loop. **/ static void nih_dbus_wakeup_main (void *data) { nih_main_loop_interrupt (); } /** * nih_dbus_callback: * @connection: D-Bus connection, * @loop: loop callback structure. * * Called on each iteration of our main loop to dispatch any remaining items * of data from the given D-Bus connection @conn so that messages will be * handled automatically. **/ static void nih_dbus_callback (DBusConnection * connection, NihMainLoopFunc *loop) { nih_assert (connection != NULL); nih_assert (loop != NULL); while (dbus_connection_dispatch (connection) == DBUS_DISPATCH_DATA_REMAINS) ; } /** * nih_dbus_connection_disconnected: * @connection: D-Bus connection, * @message: D-Bus message received, * @handler: Disconnection handler. * * Called as a filter function to determine whether @connection has been * disconnected, and if so, call the user disconnect @handler function. * * Once the handler has been called, the connection will be automatically * unreferenced. * * Returns: result of handling the message. **/ static DBusHandlerResult nih_dbus_connection_disconnected (DBusConnection * connection, DBusMessage * message, NihDBusDisconnectHandler handler) { nih_assert (connection != NULL); nih_assert (message != NULL); if (! dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected")) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (! dbus_message_has_path (message, DBUS_PATH_LOCAL)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; /* Ok, it's really the disconnected signal, call the handler. */ nih_error_push_context (); if (handler) handler (connection); nih_error_pop_context (); dbus_connection_unref (connection); /* Lie. We want other filter functions for this to be called so * we unreference for each copy we hold. */ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } /** * nih_dbus_new_connection: * @server: D-Bus server, * @connection: new D-Bus connection, * @data: not used. * * Called by D-Bus because a new connection @connection has been made to * @server; we call the connect handler if set, and if that returns TRUE * (or not set), we reference the connection so it is not dropped and set * it up with our main loop. **/ static void nih_dbus_new_connection (DBusServer * server, DBusConnection *connection, void * data) { NihDBusConnectHandler connect_handler; NihDBusDisconnectHandler disconnect_handler; nih_assert (server != NULL); nih_assert (connection != NULL); /* Call the connect handler if set, if it returns FALSE, drop the * connection. */ connect_handler = dbus_server_get_data (server, connect_handler_slot); if (connect_handler) { int ret; nih_error_push_context (); ret = connect_handler (server, connection); nih_error_pop_context (); if (! ret) return; } /* We're keeping the connection, reference it and hook it up to the * main loop. */ dbus_connection_ref (connection); disconnect_handler = dbus_server_get_data (server, disconnect_handler_slot); NIH_ZERO (nih_dbus_setup (connection, disconnect_handler)); } libnih-1.0.3/configure0000755000175000017500000216126011461165302011617 00000000000000#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.67 for libnih 1.0.3. # # Report bugs to . # # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software # Foundation, Inc. # # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. # # Copyright © 2010 Scott James Remnant . ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 test \$(( 1 + 1 )) = 2 || exit 1" if (eval "$as_required") 2>/dev/null; then : as_have_required=yes else as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV export CONFIG_SHELL exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} fi if test x$as_have_required = xno; then : $as_echo "$0: This script requires a shell more modern than all" $as_echo "$0: the shells that I found on your system." if test x${ZSH_VERSION+set} = xset ; then $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else $as_echo "$0: Please tell bug-autoconf@gnu.org and $0: http://bugs.launchpad.net/libnih/ about your system, $0: including any error possibly output before this $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -p' fi else as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi if test -x / >/dev/null 2>&1; then as_test_x='test -x' else if ls -dL / >/dev/null 2>&1; then as_ls_L_option=L else as_ls_L_option= fi as_test_x=' eval sh -c '\'' if test -d "$1"; then test -d "$1/."; else case $1 in #( -*)set "./$1";; esac; case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( ???[sx]*):;;*)false;;esac;fi '\'' sh ' fi as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" # Check that we are running under the correct shell. SHELL=${CONFIG_SHELL-/bin/sh} case X$lt_ECHO in X*--fallback-echo) # Remove one level of quotation (which was required for Make). ECHO=`echo "$lt_ECHO" | sed 's,\\\\\$\\$0,'$0','` ;; esac ECHO=${lt_ECHO-echo} if test "X$1" = X--no-reexec; then # Discard the --no-reexec flag, and continue. shift elif test "X$1" = X--fallback-echo; then # Avoid inline document here, it may be left over : elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then # Yippee, $ECHO works! : else # Restart under the correct shell. exec $SHELL "$0" --no-reexec ${1+"$@"} fi if test "X$1" = X--fallback-echo; then # used as fallback echo shift cat <<_LT_EOF $* _LT_EOF exit 0 fi # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH if test -z "$lt_ECHO"; then if test "X${echo_test_string+set}" != Xset; then # find a string as large as possible, as long as the shell can cope with it for cmd in 'sed 50q "$0"' 'sed 20q "$0"' 'sed 10q "$0"' 'sed 2q "$0"' 'echo test'; do # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ... if { echo_test_string=`eval $cmd`; } 2>/dev/null && { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null then break fi done fi if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && test "X$echo_testing_string" = "X$echo_test_string"; then : else # The Solaris, AIX, and Digital Unix default echo programs unquote # backslashes. This makes it impossible to quote backslashes using # echo "$something" | sed 's/\\/\\\\/g' # # So, first we look for a working echo in the user's PATH. lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR for dir in $PATH /usr/ucb; do IFS="$lt_save_ifs" if (test -f $dir/echo || test -f $dir/echo$ac_exeext) && test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' && echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` && test "X$echo_testing_string" = "X$echo_test_string"; then ECHO="$dir/echo" break fi done IFS="$lt_save_ifs" if test "X$ECHO" = Xecho; then # We didn't find a better echo, so look for alternatives. if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' && echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` && test "X$echo_testing_string" = "X$echo_test_string"; then # This shell has a builtin print -r that does the trick. ECHO='print -r' elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } && test "X$CONFIG_SHELL" != X/bin/ksh; then # If we have ksh, try running configure again with it. ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh} export ORIGINAL_CONFIG_SHELL CONFIG_SHELL=/bin/ksh export CONFIG_SHELL exec $CONFIG_SHELL "$0" --no-reexec ${1+"$@"} else # Try using printf. ECHO='printf %s\n' if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' && echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` && test "X$echo_testing_string" = "X$echo_test_string"; then # Cool, printf works : elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` && test "X$echo_testing_string" = 'X\t' && echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` && test "X$echo_testing_string" = "X$echo_test_string"; then CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL export CONFIG_SHELL SHELL="$CONFIG_SHELL" export SHELL ECHO="$CONFIG_SHELL $0 --fallback-echo" elif echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` && test "X$echo_testing_string" = 'X\t' && echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` && test "X$echo_testing_string" = "X$echo_test_string"; then ECHO="$CONFIG_SHELL $0 --fallback-echo" else # maybe with a smaller string... prev=: for cmd in 'echo test' 'sed 2q "$0"' 'sed 10q "$0"' 'sed 20q "$0"' 'sed 50q "$0"'; do if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null then break fi prev="$cmd" done if test "$prev" != 'sed 50q "$0"'; then echo_test_string=`eval $prev` export echo_test_string exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "$0" ${1+"$@"} else # Oops. We lost completely, so just stick with echo. ECHO=echo fi fi fi fi fi fi # Copy echo and quote the copy suitably for passing to libtool from # the Makefile, instead of quoting the original, which is used later. lt_ECHO=$ECHO if test "X$lt_ECHO" = "X$CONFIG_SHELL $0 --fallback-echo"; then lt_ECHO="$CONFIG_SHELL \\\$\$0 --fallback-echo" fi test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIBOBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='libnih' PACKAGE_TARNAME='libnih' PACKAGE_VERSION='1.0.3' PACKAGE_STRING='libnih 1.0.3' PACKAGE_BUGREPORT='http://bugs.launchpad.net/libnih/' PACKAGE_URL='' ac_unique_file="nih/libnih.h" # Factoring default headers for most tests. ac_includes_default="\ #include #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef STDC_HEADERS # include # include #else # ifdef HAVE_STDLIB_H # include # endif #endif #ifdef HAVE_STRING_H # if !defined STDC_HEADERS && defined HAVE_MEMORY_H # include # endif # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif" gt_needs= ac_header_list= ac_subst_vars='am__EXEEXT_FALSE am__EXEEXT_TRUE LTLIBOBJS LIBOBJS NIH_DBUS_TOOL HAVE_VERSION_SCRIPT_ARG_FALSE HAVE_VERSION_SCRIPT_ARG_TRUE VERSION_SCRIPT_ARG EXPAT_LIBS DBUS_LIBS DBUS_CFLAGS PKG_CONFIG_LIBDIR PKG_CONFIG_PATH PKG_CONFIG POSUB LTLIBINTL LIBINTL INTLLIBS INTL_LIBTOOL_SUFFIX_PREFIX INTLOBJS GENCAT INSTOBJEXT DATADIRNAME CATOBJEXT USE_INCLUDED_LIBINTL BUILD_INCLUDED_LIBINTL LTLIBC WINDRES WOE32 WOE32DLL HAVE_WPRINTF HAVE_SNPRINTF HAVE_ASPRINTF HAVE_POSIX_PRINTF INTL_MACOSX_LIBS GLIBC21 INTLBISON LTLIBICONV LIBICONV LTLIBMULTITHREAD LIBMULTITHREAD LTLIBTHREAD LIBTHREAD LIBPTH_PREFIX LTLIBPTH LIBPTH PRI_MACROS_BROKEN ALLOCA HAVE_VISIBILITY CFLAG_VISIBILITY GLIBC2 XGETTEXT_EXTRA_OPTIONS MSGMERGE XGETTEXT_015 XGETTEXT GMSGFMT_015 MSGFMT_015 GMSGFMT MSGFMT GETTEXT_MACRO_VERSION USE_NLS OTOOL64 OTOOL LIPO NMEDIT DSYMUTIL lt_ECHO RANLIB AR OBJDUMP LN_S NM ac_ct_DUMPBIN DUMPBIN LD FGREP SED host_os host_vendor host_cpu host build_os build_vendor build_cpu build LIBTOOL MAINT MAINTAINER_MODE_FALSE MAINTAINER_MODE_TRUE AM_BACKSLASH AM_DEFAULT_VERBOSITY am__fastdepCC_FALSE am__fastdepCC_TRUE CCDEPMODE AMDEPBACKSLASH AMDEP_FALSE AMDEP_TRUE am__quote am__include DEPDIR am__untar am__tar AMTAR am__leading_dot SET_MAKE AWK mkdir_p MKDIR_P INSTALL_STRIP_PROGRAM STRIP install_sh MAKEINFO AUTOHEADER AUTOMAKE AUTOCONF ACLOCAL VERSION PACKAGE CYGPATH_W am__isrc INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM EGREP GREP CPP OBJEXT EXEEXT ac_ct_CC CPPFLAGS LDFLAGS CFLAGS CC PACKAGE_COPYRIGHT target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking enable_dependency_tracking enable_silent_rules enable_maintainer_mode enable_shared enable_static with_pic enable_fast_install with_gnu_ld enable_libtool_lock enable_nls enable_threads enable_rpath with_libpth_prefix with_libiconv_prefix with_included_gettext with_libintl_prefix enable_threading enable_compiler_warnings enable_compiler_optimisations enable_compiler_coverage enable_linker_optimisations ' ac_precious_vars='build_alias host_alias target_alias CC CFLAGS LDFLAGS LIBS CPPFLAGS CPP PKG_CONFIG PKG_CONFIG_PATH PKG_CONFIG_LIBDIR DBUS_CFLAGS DBUS_LIBS NIH_DBUS_TOOL' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host. If a cross compiler is detected then cross compile mode will be used" >&2 elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF \`configure' configures libnih 1.0.3 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/libnih] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF Program names: --program-prefix=PREFIX prepend PREFIX to installed program names --program-suffix=SUFFIX append SUFFIX to installed program names --program-transform-name=PROGRAM run sed PROGRAM on installed program names System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in short | recursive ) echo "Configuration of libnih 1.0.3:";; esac cat <<\_ACEOF Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --disable-dependency-tracking speeds up one-time build --enable-dependency-tracking do not reject slow dependency extractors --enable-silent-rules less verbose build output (undo: `make V=1') --disable-silent-rules verbose build output (undo: `make V=0') --disable-maintainer-mode disable make rules and dependencies not useful (and sometimes confusing) to the casual installer --enable-shared[=PKGS] build shared libraries [default=yes] --enable-static[=PKGS] build static libraries [default=yes] --enable-fast-install[=PKGS] optimize for fast installation [default=yes] --disable-libtool-lock avoid locking (might break parallel builds) --disable-nls do not use Native Language Support --enable-threads={posix|solaris|pth|win32} specify multithreading API --disable-threads build without multithread safety --disable-rpath do not hardcode runtime library paths --enable-threading Enable support for multi-threading --enable-compiler-warnings Enable additional compiler warnings --disable-compiler-optimisations Disable compiler optimisations --enable-compiler-coverage Enable generation of coverage data --disable-linker-optimisations Disable linker optimisations Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-pic try to use only PIC/non-PIC objects [default=use both] --with-gnu-ld assume the C compiler uses GNU ld [default=no] --with-gnu-ld assume the C compiler uses GNU ld default=no --with-libpth-prefix[=DIR] search for libpth in DIR/include and DIR/lib --without-libpth-prefix don't search for libpth in includedir and libdir --with-libiconv-prefix[=DIR] search for libiconv in DIR/include and DIR/lib --without-libiconv-prefix don't search for libiconv in includedir and libdir --with-included-gettext use the GNU gettext library included here --with-libintl-prefix[=DIR] search for libintl in DIR/include and DIR/lib --without-libintl-prefix don't search for libintl in includedir and libdir Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory CPP C preprocessor PKG_CONFIG path to pkg-config utility PKG_CONFIG_PATH directories to add to pkg-config's search path PKG_CONFIG_LIBDIR path overriding pkg-config's built-in search path DBUS_CFLAGS C compiler flags for DBUS, overriding pkg-config DBUS_LIBS linker flags for DBUS, overriding pkg-config NIH_DBUS_TOOL Path to external nih-dbus-tool when cross-compiling Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to . _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for guested configure. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF libnih configure 1.0.3 generated by GNU Autoconf 2.67 Copyright (C) 2010 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. Copyright © 2010 Scott James Remnant . _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## # ac_fn_c_try_compile LINENO # -------------------------- # Try to compile conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest.$ac_objext; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} as_fn_set_status $ac_retval } # ac_fn_c_try_compile # ac_fn_c_try_cpp LINENO # ---------------------- # Try to preprocess conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_cpp () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_cpp conftest.$ac_ext" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } > conftest.i && { test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || test ! -s conftest.err }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} as_fn_set_status $ac_retval } # ac_fn_c_try_cpp # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists, giving a warning if it cannot be compiled using # the include files in INCLUDES and setting the cache variable VAR # accordingly. ac_fn_c_check_header_mongrel () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if eval "test \"\${$3+set}\"" = set; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval "test \"\${$3+set}\"" = set; then : $as_echo_n "(cached) " >&6 fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } else # Is the header compilable? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 $as_echo_n "checking $2 usability... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_header_compiler=yes else ac_header_compiler=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 $as_echo "$ac_header_compiler" >&6; } # Is the header present? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 $as_echo_n "checking $2 presence... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <$2> _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : ac_header_preproc=yes else ac_header_preproc=no fi rm -f conftest.err conftest.i conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 $as_echo "$ac_header_preproc" >&6; } # So? What about this header? case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( yes:no: ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 $as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ;; no:yes:* ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 $as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 $as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 $as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 $as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ( $as_echo "## ------------------------------------------------ ## ## Report this to http://bugs.launchpad.net/libnih/ ## ## ------------------------------------------------ ##" ) | sed "s/^/$as_me: WARNING: /" >&2 ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval "test \"\${$3+set}\"" = set; then : $as_echo_n "(cached) " >&6 else eval "$3=\$ac_header_compiler" fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } fi eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} } # ac_fn_c_check_header_mongrel # ac_fn_c_try_run LINENO # ---------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. Assumes # that executables *can* be run. ac_fn_c_try_run () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then : ac_retval=0 else $as_echo "$as_me: program exited with status $ac_status" >&5 $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=$ac_status fi rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} as_fn_set_status $ac_retval } # ac_fn_c_try_run # ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists and can be compiled using the include files in # INCLUDES, setting the cache variable VAR accordingly. ac_fn_c_check_header_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval "test \"\${$3+set}\"" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} } # ac_fn_c_check_header_compile # ac_fn_c_try_link LINENO # ----------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_link () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext conftest$ac_exeext if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || $as_test_x conftest$ac_exeext }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would # interfere with the next link command; also delete a directory that is # left behind by Apple's compiler. We do this before executing the actions. rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} as_fn_set_status $ac_retval } # ac_fn_c_try_link # ac_fn_c_check_func LINENO FUNC VAR # ---------------------------------- # Tests whether FUNC exists, setting the cache variable VAR accordingly ac_fn_c_check_func () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval "test \"\${$3+set}\"" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Define $2 to an innocuous variant, in case declares $2. For example, HP-UX 11i declares gettimeofday. */ #define $2 innocuous_$2 /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $2 (); below. Prefer to if __STDC__ is defined, since exists even on freestanding compilers. */ #ifdef __STDC__ # include #else # include #endif #undef $2 /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char $2 (); /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ #if defined __stub_$2 || defined __stub___$2 choke me #endif int main () { return $2 (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} } # ac_fn_c_check_func # ac_fn_c_check_type LINENO TYPE VAR INCLUDES # ------------------------------------------- # Tests whether TYPE exists after having included INCLUDES, setting cache # variable VAR accordingly. ac_fn_c_check_type () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval "test \"\${$3+set}\"" = set; then : $as_echo_n "(cached) " >&6 else eval "$3=no" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { if (sizeof ($2)) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { if (sizeof (($2))) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else eval "$3=yes" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} } # ac_fn_c_check_type # ac_fn_c_compute_int LINENO EXPR VAR INCLUDES # -------------------------------------------- # Tries to find the compile-time value of EXPR in a program that includes # INCLUDES, setting VAR accordingly. Returns whether the value could be # computed ac_fn_c_compute_int () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if test "$cross_compiling" = yes; then # Depending upon the size, compute the lo and hi bounds. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) >= 0)]; test_array [0] = 0 ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_lo=0 ac_mid=0 while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; test_array [0] = 0 ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_hi=$ac_mid; break else as_fn_arith $ac_mid + 1 && ac_lo=$as_val if test $ac_lo -le $ac_mid; then ac_lo= ac_hi= break fi as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext done else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) < 0)]; test_array [0] = 0 ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_hi=-1 ac_mid=-1 while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) >= $ac_mid)]; test_array [0] = 0 ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_lo=$ac_mid; break else as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val if test $ac_mid -le $ac_hi; then ac_lo= ac_hi= break fi as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext done else ac_lo= ac_hi= fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext # Binary search between lo and hi bounds. while test "x$ac_lo" != "x$ac_hi"; do as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; test_array [0] = 0 ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_hi=$ac_mid else as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext done case $ac_lo in #(( ?*) eval "$3=\$ac_lo"; ac_retval=0 ;; '') ac_retval=1 ;; esac else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 static long int longval () { return $2; } static unsigned long int ulongval () { return $2; } #include #include int main () { FILE *f = fopen ("conftest.val", "w"); if (! f) return 1; if (($2) < 0) { long int i = longval (); if (i != ($2)) return 1; fprintf (f, "%ld", i); } else { unsigned long int i = ulongval (); if (i != ($2)) return 1; fprintf (f, "%lu", i); } /* Do not output a trailing newline, as this causes \r\n confusion on some platforms. */ return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : echo >>conftest.val; read $3 config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by libnih $as_me 1.0.3, which was generated by GNU Autoconf 2.67. Invocation command line was $ $0 $@ _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. $as_echo "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Save into config.log some information that might help in debugging. { echo $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && $as_echo "$as_me: caught signal $ac_signal" $as_echo "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h $as_echo "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. cat >>confdefs.h <<_ACEOF #define PACKAGE_NAME "$PACKAGE_NAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_TARNAME "$PACKAGE_TARNAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_VERSION "$PACKAGE_VERSION" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_STRING "$PACKAGE_STRING" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_URL "$PACKAGE_URL" _ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then # We do not want a PATH search for config.site. case $CONFIG_SITE in #(( -*) ac_site_file1=./$CONFIG_SITE;; */*) ac_site_file1=$CONFIG_SITE;; *) ac_site_file1=./$CONFIG_SITE;; esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site else ac_site_file1=$ac_default_prefix/share/config.site ac_site_file2=$ac_default_prefix/etc/config.site fi for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5 ; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 $as_echo "$as_me: creating cache $cache_file" >&6;} >$cache_file fi gt_needs="$gt_needs " as_fn_append ac_header_list " stdlib.h" as_fn_append ac_header_list " unistd.h" as_fn_append ac_header_list " sys/param.h" # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu $as_echo "#define PACKAGE_COPYRIGHT \"Copyright (C) 2010 Scott James Remnant .\"" >>confdefs.h PACKAGE_COPYRIGHT="Copyright © 2010 Scott James Remnant ." ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. set dummy ${ac_tool_prefix}gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_CC"; then ac_ct_CC=$CC # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi else CC="$ac_cv_prog_CC" fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. set dummy ${ac_tool_prefix}cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else ac_prog_rejected=no as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue fi ac_cv_prog_CC="cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" fi fi fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then for ac_prog in cl.exe do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$CC" && break done fi if test -z "$CC"; then ac_ct_CC=$CC for ac_prog in cl.exe do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$ac_ct_CC" && break done if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi fi test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See \`config.log' for more details" "$LINENO" 5 ; } # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 $as_echo_n "checking whether the C compiler works... " >&6; } ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ac_rmfiles= for ac_file in $ac_files do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; * ) ac_rmfiles="$ac_rmfiles $ac_file";; esac done rm -f $ac_rmfiles if { { ac_try="$ac_link_default" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. # So ignore a value of `no', otherwise this would lead to `EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. for ac_file in $ac_files '' do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; [ab].out ) # We found the default executable, but exeext='' is most # certainly right. break;; *.* ) if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi # We set ac_cv_exeext here because the later test for it is not # safe: cross compilers may not add the suffix if given an `-o' # argument, so we may need to know it at that point already. # Even if this section looks crufty: it has the advantage of # actually working. break;; * ) break;; esac done test "$ac_cv_exeext" = no && ac_cv_exeext= else ac_file='' fi if test -z "$ac_file"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5 ; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 $as_echo_n "checking for C compiler default output file name... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 $as_echo "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 $as_echo_n "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # If both `conftest.exe' and `conftest' are `present' (well, observable) # catch `conftest.exe'. For instance with Cygwin, `ls conftest' will # work properly (i.e., refer to `conftest.exe'), while it won't with # `rm'. for ac_file in conftest.exe conftest conftest.*; do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` break;; * ) break;; esac done else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See \`config.log' for more details" "$LINENO" 5 ; } fi rm -f conftest conftest$ac_cv_exeext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 $as_echo "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext ac_exeext=$EXEEXT cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 $as_echo_n "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5 ; } fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 $as_echo "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 $as_echo_n "checking for suffix of object files... " >&6; } if test "${ac_cv_objext+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF rm -f conftest.o conftest.obj if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : for ac_file in conftest.o conftest.obj conftest.*; do test -f "$ac_file" || continue; case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` break;; esac done else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See \`config.log' for more details" "$LINENO" 5 ; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 $as_echo "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; } if test "${ac_cv_c_compiler_gnu+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_compiler_gnu=yes else ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 $as_echo "$ac_cv_c_compiler_gnu" >&6; } if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 $as_echo_n "checking whether $CC accepts -g... " >&6; } if test "${ac_cv_prog_cc_g+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes else CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 $as_echo "$ac_cv_prog_cc_g" >&6; } if test "$ac_test_CFLAGS" = set; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; } if test "${ac_cv_prog_cc_c89+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); static char *e (p, i) char **p; int i; { return p[i]; } static char *f (char * (*g) (char **, int), char **p, ...) { char *s; va_list v; va_start (v,p); s = g (p, va_arg (v,int)); va_end (v); return s; } /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has function prototypes and stuff, but not '\xHH' hex character constants. These don't provoke an error unfortunately, instead are silently treated as 'x'. The following induces an error, until -std is added to get proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an array size at least. It's necessary to write '\x00'==0 to get something that's true only with -std. */ int osf4_cc_array ['\x00' == 0 ? 1 : -1]; /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters inside strings and character constants. */ #define FOO(x) 'x' int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; int test (int i, double x); struct s1 {int (*f) (int a);}; struct s2 {int (*f) (double a);}; int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); int argc; char **argv; int main () { return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; ; return 0; } _ACEOF for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_c89=$ac_arg fi rm -f core conftest.err conftest.$ac_objext test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi # AC_CACHE_VAL case "x$ac_cv_prog_cc_c89" in x) { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 $as_echo "none needed" >&6; } ;; xno) { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 $as_echo "unsupported" >&6; } ;; *) CC="$CC $ac_cv_prog_cc_c89" { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 $as_echo "$ac_cv_prog_cc_c89" >&6; } ;; esac if test "x$ac_cv_prog_cc_c89" != xno; then : fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 $as_echo_n "checking how to run the C preprocessor... " >&6; } # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= fi if test -z "$CPP"; then if test "${ac_cv_prog_CPP+set}" = set; then : $as_echo_n "(cached) " >&6 else # Double quotes because CPP needs to be expanded for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" do ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : break fi done ac_cv_prog_CPP=$CPP fi CPP=$ac_cv_prog_CPP else ac_cv_prog_CPP=$CPP fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 $as_echo "$CPP" >&6; } ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C preprocessor \"$CPP\" fails sanity check See \`config.log' for more details" "$LINENO" 5 ; } fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 $as_echo_n "checking for grep that handles long lines and -e... " >&6; } if test "${ac_cv_path_GREP+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in *GNU*) ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'GREP' >> "conftest.nl" "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_GREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_GREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_GREP"; then as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_GREP=$GREP fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 $as_echo "$ac_cv_path_GREP" >&6; } GREP="$ac_cv_path_GREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 $as_echo_n "checking for egrep... " >&6; } if test "${ac_cv_path_EGREP+set}" = set; then : $as_echo_n "(cached) " >&6 else if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else if test -z "$EGREP"; then ac_path_EGREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in *GNU*) ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'EGREP' >> "conftest.nl" "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_EGREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_EGREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_EGREP"; then as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_EGREP=$EGREP fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 $as_echo "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } if test "${ac_cv_header_stdc+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_header_stdc=yes else ac_cv_header_stdc=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "memchr" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "free" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. if test "$cross_compiling" = yes; then : : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #if ((' ' & 0x0FF) == 0x020) # define ISLOWER(c) ('a' <= (c) && (c) <= 'z') # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #else # define ISLOWER(c) \ (('a' <= (c) && (c) <= 'i') \ || ('j' <= (c) && (c) <= 'r') \ || ('s' <= (c) && (c) <= 'z')) # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) #endif #define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int main () { int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) return 2; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : else ac_cv_header_stdc=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 $as_echo "$ac_cv_header_stdc" >&6; } if test $ac_cv_header_stdc = yes; then $as_echo "#define STDC_HEADERS 1" >>confdefs.h fi # On IRIX 5.3, sys/types and inttypes.h are conflicting. for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ inttypes.h stdint.h unistd.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default " if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done ac_fn_c_check_header_mongrel "$LINENO" "minix/config.h" "ac_cv_header_minix_config_h" "$ac_includes_default" if test "x$ac_cv_header_minix_config_h" = x""yes; then : MINIX=yes else MINIX= fi if test "$MINIX" = yes; then $as_echo "#define _POSIX_SOURCE 1" >>confdefs.h $as_echo "#define _POSIX_1_SOURCE 2" >>confdefs.h $as_echo "#define _MINIX 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether it is safe to define __EXTENSIONS__" >&5 $as_echo_n "checking whether it is safe to define __EXTENSIONS__... " >&6; } if test "${ac_cv_safe_to_define___extensions__+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ # define __EXTENSIONS__ 1 $ac_includes_default int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_safe_to_define___extensions__=yes else ac_cv_safe_to_define___extensions__=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_safe_to_define___extensions__" >&5 $as_echo "$ac_cv_safe_to_define___extensions__" >&6; } test $ac_cv_safe_to_define___extensions__ = yes && $as_echo "#define __EXTENSIONS__ 1" >>confdefs.h $as_echo "#define _ALL_SOURCE 1" >>confdefs.h $as_echo "#define _GNU_SOURCE 1" >>confdefs.h $as_echo "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h $as_echo "#define _TANDEM_SOURCE 1" >>confdefs.h am__api_version='1.11' ac_aux_dir= for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do if test -f "$ac_dir/install-sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install-sh -c" break elif test -f "$ac_dir/install.sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install.sh -c" break elif test -f "$ac_dir/shtool"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/shtool install -c" break fi done if test -z "$ac_aux_dir"; then as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 fi # These three variables are undocumented and unsupported, # and are intended to be withdrawn in a future Autoconf release. # They can cause serious problems if a builder's source tree is in a directory # whose full name contains unusual characters. ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: # SysV /etc/install, /usr/sbin/install # SunOS /usr/etc/install # IRIX /sbin/install # AIX /bin/install # AmigaOS /C/install, which installs bootblocks on floppy discs # AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag # AFS /usr/afsws/bin/install, which mishandles nonexistent args # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # OS/2's system install, which has a completely different semantic # ./install, which can be erroneously created by make from ./install.sh. # Reject install programs that cannot install multiple files. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 $as_echo_n "checking for a BSD-compatible install... " >&6; } if test -z "$INSTALL"; then if test "${ac_cv_path_install+set}" = set; then : $as_echo_n "(cached) " >&6 else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. # Account for people who put trailing slashes in PATH elements. case $as_dir/ in #(( ./ | .// | /[cC]/* | \ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ /usr/ucb/* ) ;; *) # OSF1 and SCO ODT 3.0 have their own names for install. # Don't use installbsd from OSF since it installs stuff as root # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then if test $ac_prog = install && grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. : elif test $ac_prog = install && grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # program-specific install script used by HP pwplus--don't use. : else rm -rf conftest.one conftest.two conftest.dir echo one > conftest.one echo two > conftest.two mkdir conftest.dir if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && test -s conftest.one && test -s conftest.two && test -s conftest.dir/conftest.one && test -s conftest.dir/conftest.two then ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" break 3 fi fi fi done done ;; esac done IFS=$as_save_IFS rm -rf conftest.one conftest.two conftest.dir fi if test "${ac_cv_path_install+set}" = set; then INSTALL=$ac_cv_path_install else # As a last resort, use the slow shell script. Don't cache a # value for INSTALL within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the value is a relative name. INSTALL=$ac_install_sh fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 $as_echo "$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 $as_echo_n "checking whether build environment is sane... " >&6; } # Just in case sleep 1 echo timestamp > conftest.file # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' ' case `pwd` in *[\\\"\#\$\&\'\`$am_lf]*) as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5 ;; esac case $srcdir in *[\\\"\#\$\&\'\`$am_lf\ \ ]*) as_fn_error $? "unsafe srcdir value: \`$srcdir'" "$LINENO" 5 ;; esac # Do `set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` if test "$*" = "X"; then # -L didn't work. set X `ls -t "$srcdir/configure" conftest.file` fi rm -f conftest.file if test "$*" != "X $srcdir/configure conftest.file" \ && test "$*" != "X conftest.file $srcdir/configure"; then # If neither matched, then we have a broken ls. This can happen # if, for instance, CONFIG_SHELL is bash and it inherits a # broken ls alias from the environment. This has actually # happened. Such a system could not be considered "sane". as_fn_error $? "ls -t appears to fail. Make sure there is not a broken alias in your environment" "$LINENO" 5 fi test "$2" = conftest.file ) then # Ok. : else as_fn_error $? "newly created file is older than distributed files! Check your system clock" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } test "$program_prefix" != NONE && program_transform_name="s&^&$program_prefix&;$program_transform_name" # Use a double $ so make ignores it. test "$program_suffix" != NONE && program_transform_name="s&\$&$program_suffix&;$program_transform_name" # Double any \ or $. # By default was `s,x,x', remove it if useless. ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` # expand $ac_aux_dir to an absolute path am_aux_dir=`cd $ac_aux_dir && pwd` if test x"${MISSING+set}" != xset; then case $am_aux_dir in *\ * | *\ *) MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; *) MISSING="\${SHELL} $am_aux_dir/missing" ;; esac fi # Use eval to expand $SHELL if eval "$MISSING --run true"; then am_missing_run="$MISSING --run " else am_missing_run= { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`missing' script is too old or missing" >&5 $as_echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;} fi if test x"${install_sh}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; *) install_sh="\${SHELL} $am_aux_dir/install-sh" esac fi # Installed binaries are usually stripped using `strip' when the user # run `make install-strip'. However `strip' might not be the right # tool to use in cross-compilation environments, therefore Automake # will honor the `STRIP' environment variable to overrule this program. if test "$cross_compiling" != no; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. set dummy ${ac_tool_prefix}strip; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_STRIP+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi STRIP=$ac_cv_prog_STRIP if test -n "$STRIP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 $as_echo "$STRIP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_STRIP"; then ac_ct_STRIP=$STRIP # Extract the first word of "strip", so it can be a program name with args. set dummy strip; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_STRIP="strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP if test -n "$ac_ct_STRIP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 $as_echo "$ac_ct_STRIP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then STRIP=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP fi else STRIP="$ac_cv_prog_STRIP" fi fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 $as_echo_n "checking for a thread-safe mkdir -p... " >&6; } if test -z "$MKDIR_P"; then if test "${ac_cv_path_mkdir+set}" = set; then : $as_echo_n "(cached) " >&6 else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in mkdir gmkdir; do for ac_exec_ext in '' $ac_executable_extensions; do { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( 'mkdir (GNU coreutils) '* | \ 'mkdir (coreutils) '* | \ 'mkdir (fileutils) '4.1*) ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext break 3;; esac done done done IFS=$as_save_IFS fi test -d ./--version && rmdir ./--version if test "${ac_cv_path_mkdir+set}" = set; then MKDIR_P="$ac_cv_path_mkdir -p" else # As a last resort, use the slow shell script. Don't cache a # value for MKDIR_P within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the value is a relative name. MKDIR_P="$ac_install_sh -d" fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 $as_echo "$MKDIR_P" >&6; } mkdir_p="$MKDIR_P" case $mkdir_p in [\\/$]* | ?:[\\/]*) ;; */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; esac for ac_prog in gawk mawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_AWK+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$AWK"; then ac_cv_prog_AWK="$AWK" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_AWK="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi AWK=$ac_cv_prog_AWK if test -n "$AWK"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 $as_echo "$AWK" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$AWK" && break done { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 $as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } set x ${MAKE-make} ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\"" = set; then : $as_echo_n "(cached) " >&6 else cat >conftest.make <<\_ACEOF SHELL = /bin/sh all: @echo '@@@%%%=$(MAKE)=@@@%%%' _ACEOF # GNU make sometimes prints "make[1]: Entering ...", which would confuse us. case `${MAKE-make} -f conftest.make 2>/dev/null` in *@@@%%%=?*=@@@%%%*) eval ac_cv_prog_make_${ac_make}_set=yes;; *) eval ac_cv_prog_make_${ac_make}_set=no;; esac rm -f conftest.make fi if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } SET_MAKE= else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi rm -rf .tst 2>/dev/null mkdir .tst 2>/dev/null if test -d .tst; then am__leading_dot=. else am__leading_dot=_ fi rmdir .tst 2>/dev/null DEPDIR="${am__leading_dot}deps" ac_config_commands="$ac_config_commands depfiles" am_make=${MAKE-make} cat > confinc << 'END' am__doit: @echo this is the am__doit target .PHONY: am__doit END # If we don't find an include directive, just comment out the code. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for style of include used by $am_make" >&5 $as_echo_n "checking for style of include used by $am_make... " >&6; } am__include="#" am__quote= _am_result=none # First try GNU make style include. echo "include confinc" > confmf # Ignore all kinds of additional output from `make'. case `$am_make -s -f confmf 2> /dev/null` in #( *the\ am__doit\ target*) am__include=include am__quote= _am_result=GNU ;; esac # Now try BSD make style include. if test "$am__include" = "#"; then echo '.include "confinc"' > confmf case `$am_make -s -f confmf 2> /dev/null` in #( *the\ am__doit\ target*) am__include=.include am__quote="\"" _am_result=BSD ;; esac fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5 $as_echo "$_am_result" >&6; } rm -f confinc confmf # Check whether --enable-dependency-tracking was given. if test "${enable_dependency_tracking+set}" = set; then : enableval=$enable_dependency_tracking; fi if test "x$enable_dependency_tracking" != xno; then am_depcomp="$ac_aux_dir/depcomp" AMDEPBACKSLASH='\' fi if test "x$enable_dependency_tracking" != xno; then AMDEP_TRUE= AMDEP_FALSE='#' else AMDEP_TRUE='#' AMDEP_FALSE= fi # Check whether --enable-silent-rules was given. if test "${enable_silent_rules+set}" = set; then : enableval=$enable_silent_rules; fi case $enable_silent_rules in yes) AM_DEFAULT_VERBOSITY=0;; no) AM_DEFAULT_VERBOSITY=1;; *) AM_DEFAULT_VERBOSITY=1;; esac AM_BACKSLASH='\' if test "`cd $srcdir && pwd`" != "`pwd`"; then # Use -I$(srcdir) only when $(srcdir) != ., so that make's output # is not polluted with repeated "-I." am__isrc=' -I$(srcdir)' # test to see if srcdir already configured if test -f $srcdir/config.status; then as_fn_error $? "source directory already configured; run \"make distclean\" there first" "$LINENO" 5 fi fi # test whether we have cygpath if test -z "$CYGPATH_W"; then if (cygpath --version) >/dev/null 2>/dev/null; then CYGPATH_W='cygpath -w' else CYGPATH_W=echo fi fi # Define the identity of the package. PACKAGE='libnih' VERSION='1.0.3' cat >>confdefs.h <<_ACEOF #define PACKAGE "$PACKAGE" _ACEOF cat >>confdefs.h <<_ACEOF #define VERSION "$VERSION" _ACEOF # Some tools Automake needs. ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"} AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"} AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"} AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} # We need awk for the "check" target. The system "awk" is bad on # some platforms. # Always define AMTAR for backward compatibility. AMTAR=${AMTAR-"${am_missing_run}tar"} am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -' depcc="$CC" am_compiler_list= { $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 $as_echo_n "checking dependency style of $depcc... " >&6; } if test "${am_cv_CC_dependencies_compiler_type+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up # making a dummy file named `D' -- because `-MD' means `put the output # in D'. mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're # using a relative directory. cp "$am_depcomp" conftest.dir cd conftest.dir # We will build objects and dependencies in a subdirectory because # it helps to detect inapplicable dependency modes. For instance # both Tru64's cc and ICC support -MD to output dependencies as a # side effect of compilation, but ICC will put the dependencies in # the current directory while Tru64 will put them in the object # directory. mkdir sub am_cv_CC_dependencies_compiler_type=none if test "$am_compiler_list" = ""; then am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` fi am__universal=false case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac for depmode in $am_compiler_list; do # Setup a source with many dependencies, because some compilers # like to wrap large dependency lists on column 80 (with \), and # we should not choose a depcomp mode which is confused by this. # # We need to recreate these files for each test, as the compiler may # overwrite some of them when testing with obscure command lines. # This happens at least with the AIX C compiler. : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with # Solaris 8's {/usr,}/bin/sh. touch sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf # We check with `-c' and `-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly # handle `-M -o', and we need to detect this. Also, some Intel # versions had trouble with output in subdirs am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in gcc) # This depmode causes a compiler race in universal mode. test "$am__universal" = false || continue ;; nosideeffect) # after this tag, mechanisms are not by side-effect, so they'll # only be used when explicitly requested if test "x$enable_dependency_tracking" = xyes; then continue else break fi ;; msvisualcpp | msvcmsys) # This compiler won't grok `-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} am__minus_obj= ;; none) break ;; esac if depmode=$depmode \ source=sub/conftest.c object=$am__obj \ depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ >/dev/null 2>conftest.err && grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && grep $am__obj sub/conftest.Po > /dev/null 2>&1 && ${MAKE-make} -s -f confmf > /dev/null 2>&1; then # icc doesn't choke on unknown options, it will just issue warnings # or remarks (even with -Werror). So we grep stderr for any message # that says an option was ignored or not supported. # When given -MP, icc 7.0 and 7.1 complain thusly: # icc: Command line warning: ignoring option '-M'; no argument required # The diagnosis changed in icc 8.0: # icc: Command line remark: option '-MP' not supported if (grep 'ignoring option' conftest.err || grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else am_cv_CC_dependencies_compiler_type=$depmode break fi fi done cd .. rm -rf conftest.dir else am_cv_CC_dependencies_compiler_type=none fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 $as_echo "$am_cv_CC_dependencies_compiler_type" >&6; } CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type if test "x$enable_dependency_tracking" != xno \ && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then am__fastdepCC_TRUE= am__fastdepCC_FALSE='#' else am__fastdepCC_TRUE='#' am__fastdepCC_FALSE= fi # Check whether --enable-silent-rules was given. if test "${enable_silent_rules+set}" = set; then : enableval=$enable_silent_rules; fi case $enable_silent_rules in yes) AM_DEFAULT_VERBOSITY=0;; no) AM_DEFAULT_VERBOSITY=1;; *) AM_DEFAULT_VERBOSITY=0;; esac AM_BACKSLASH='\' { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to disable maintainer-specific portions of Makefiles" >&5 $as_echo_n "checking whether to disable maintainer-specific portions of Makefiles... " >&6; } # Check whether --enable-maintainer-mode was given. if test "${enable_maintainer_mode+set}" = set; then : enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval else USE_MAINTAINER_MODE=yes fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5 $as_echo "$USE_MAINTAINER_MODE" >&6; } if test $USE_MAINTAINER_MODE = yes; then MAINTAINER_MODE_TRUE= MAINTAINER_MODE_FALSE='#' else MAINTAINER_MODE_TRUE='#' MAINTAINER_MODE_FALSE= fi MAINT=$MAINTAINER_MODE_TRUE case `pwd` in *\ * | *\ *) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 $as_echo "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;; esac macro_version='2.2.6b' macro_revision='1.3017' ltmain="$ac_aux_dir/ltmain.sh" # Make sure we can run config.sub. $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 $as_echo_n "checking build system type... " >&6; } if test "${ac_cv_build+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_build_alias=$build_alias test "x$ac_build_alias" = x && ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` test "x$ac_build_alias" = x && as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 $as_echo "$ac_cv_build" >&6; } case $ac_cv_build in *-*-*) ;; *) as_fn_error $? "invalid value of canonical build" "$LINENO" 5 ;; esac build=$ac_cv_build ac_save_IFS=$IFS; IFS='-' set x $ac_cv_build shift build_cpu=$1 build_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: build_os=$* IFS=$ac_save_IFS case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 $as_echo_n "checking host system type... " >&6; } if test "${ac_cv_host+set}" = set; then : $as_echo_n "(cached) " >&6 else if test "x$host_alias" = x; then ac_cv_host=$ac_cv_build else ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 $as_echo "$ac_cv_host" >&6; } case $ac_cv_host in *-*-*) ;; *) as_fn_error $? "invalid value of canonical host" "$LINENO" 5 ;; esac host=$ac_cv_host ac_save_IFS=$IFS; IFS='-' set x $ac_cv_host shift host_cpu=$1 host_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: host_os=$* IFS=$ac_save_IFS case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 $as_echo_n "checking for a sed that does not truncate output... " >&6; } if test "${ac_cv_path_SED+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ for ac_i in 1 2 3 4 5 6 7; do ac_script="$ac_script$as_nl$ac_script" done echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed { ac_script=; unset ac_script;} if test -z "$SED"; then ac_path_SED_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in sed gsed; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_SED="$as_dir/$ac_prog$ac_exec_ext" { test -f "$ac_path_SED" && $as_test_x "$ac_path_SED"; } || continue # Check for GNU ac_path_SED and select it if it is found. # Check for GNU $ac_path_SED case `"$ac_path_SED" --version 2>&1` in *GNU*) ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo '' >> "conftest.nl" "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_SED_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_SED="$ac_path_SED" ac_path_SED_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_SED_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_SED"; then as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5 fi else ac_cv_path_SED=$SED fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 $as_echo "$ac_cv_path_SED" >&6; } SED="$ac_cv_path_SED" rm -f conftest.sed test -z "$SED" && SED=sed Xsed="$SED -e 1s/^X//" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5 $as_echo_n "checking for fgrep... " >&6; } if test "${ac_cv_path_FGREP+set}" = set; then : $as_echo_n "(cached) " >&6 else if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1 then ac_cv_path_FGREP="$GREP -F" else if test -z "$FGREP"; then ac_path_FGREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in fgrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext" { test -f "$ac_path_FGREP" && $as_test_x "$ac_path_FGREP"; } || continue # Check for GNU ac_path_FGREP and select it if it is found. # Check for GNU $ac_path_FGREP case `"$ac_path_FGREP" --version 2>&1` in *GNU*) ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'FGREP' >> "conftest.nl" "$ac_path_FGREP" FGREP < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_FGREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_FGREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_FGREP"; then as_fn_error $? "no acceptable fgrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_FGREP=$FGREP fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 $as_echo "$ac_cv_path_FGREP" >&6; } FGREP="$ac_cv_path_FGREP" test -z "$GREP" && GREP=grep # Check whether --with-gnu-ld was given. if test "${with_gnu_ld+set}" = set; then : withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes else with_gnu_ld=no fi ac_prog=ld if test "$GCC" = yes; then # Check if gcc -print-prog-name=ld gives a path. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 $as_echo_n "checking for ld used by $CC... " >&6; } case $host in *-*-mingw*) # gcc leaves a trailing carriage return which upsets mingw ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; *) ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; esac case $ac_prog in # Accept absolute paths. [\\/]* | ?:[\\/]*) re_direlt='/[^/][^/]*/\.\./' # Canonicalize the pathname of ld ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` done test -z "$LD" && LD="$ac_prog" ;; "") # If it fails, then pretend we aren't using GCC. ac_prog=ld ;; *) # If it is relative, then search for the first ld in PATH. with_gnu_ld=unknown ;; esac elif test "$with_gnu_ld" = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 $as_echo_n "checking for GNU ld... " >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 $as_echo_n "checking for non-GNU ld... " >&6; } fi if test "${lt_cv_path_LD+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -z "$LD"; then lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then lt_cv_path_LD="$ac_dir/$ac_prog" # Check to see if the program is GNU ld. I'd rather use --version, # but apparently some variants of GNU ld only accept -v. # Break only if it was the GNU/non-GNU ld that we prefer. case `"$lt_cv_path_LD" -v 2>&1 &5 $as_echo "$LD" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 $as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } if test "${lt_cv_prog_gnu_ld+set}" = set; then : $as_echo_n "(cached) " >&6 else # I'd rather use --version here, but apparently some GNU lds only accept -v. case `$LD -v 2>&1 &5 $as_echo "$lt_cv_prog_gnu_ld" >&6; } with_gnu_ld=$lt_cv_prog_gnu_ld { $as_echo "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5 $as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; } if test "${lt_cv_path_NM+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$NM"; then # Let the user override the test. lt_cv_path_NM="$NM" else lt_nm_to_check="${ac_tool_prefix}nm" if test -n "$ac_tool_prefix" && test "$build" = "$host"; then lt_nm_to_check="$lt_nm_to_check nm" fi for lt_tmp_nm in $lt_nm_to_check; do lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. tmp_nm="$ac_dir/$lt_tmp_nm" if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then # Check to see if the nm accepts a BSD-compat flag. # Adding the `sed 1q' prevents false positives on HP-UX, which says: # nm: unknown option "B" ignored # Tru64's nm complains that /dev/null is an invalid object file case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in */dev/null* | *'Invalid file or object type'*) lt_cv_path_NM="$tmp_nm -B" break ;; *) case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in */dev/null*) lt_cv_path_NM="$tmp_nm -p" break ;; *) lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but continue # so that we can try to find one that supports BSD flags ;; esac ;; esac fi done IFS="$lt_save_ifs" done : ${lt_cv_path_NM=no} fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5 $as_echo "$lt_cv_path_NM" >&6; } if test "$lt_cv_path_NM" != "no"; then NM="$lt_cv_path_NM" else # Didn't find any BSD compatible name lister, look for dumpbin. if test -n "$ac_tool_prefix"; then for ac_prog in "dumpbin -symbols" "link -dump -symbols" do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_DUMPBIN+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$DUMPBIN"; then ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi DUMPBIN=$ac_cv_prog_DUMPBIN if test -n "$DUMPBIN"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5 $as_echo "$DUMPBIN" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$DUMPBIN" && break done fi if test -z "$DUMPBIN"; then ac_ct_DUMPBIN=$DUMPBIN for ac_prog in "dumpbin -symbols" "link -dump -symbols" do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_DUMPBIN+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_DUMPBIN"; then ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_DUMPBIN="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN if test -n "$ac_ct_DUMPBIN"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5 $as_echo "$ac_ct_DUMPBIN" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$ac_ct_DUMPBIN" && break done if test "x$ac_ct_DUMPBIN" = x; then DUMPBIN=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DUMPBIN=$ac_ct_DUMPBIN fi fi if test "$DUMPBIN" != ":"; then NM="$DUMPBIN" fi fi test -z "$NM" && NM=nm { $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5 $as_echo_n "checking the name lister ($NM) interface... " >&6; } if test "${lt_cv_nm_interface+set}" = set; then : $as_echo_n "(cached) " >&6 else lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext (eval echo "\"\$as_me:5220: $ac_compile\"" >&5) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&5 (eval echo "\"\$as_me:5223: $NM \\\"conftest.$ac_objext\\\"\"" >&5) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&5 (eval echo "\"\$as_me:5226: output\"" >&5) cat conftest.out >&5 if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" fi rm -f conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5 $as_echo "$lt_cv_nm_interface" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 $as_echo_n "checking whether ln -s works... " >&6; } LN_S=$as_ln_s if test "$LN_S" = "ln -s"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 $as_echo "no, using $LN_S" >&6; } fi # find the maximum length of command line arguments { $as_echo "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5 $as_echo_n "checking the maximum length of command line arguments... " >&6; } if test "${lt_cv_sys_max_cmd_len+set}" = set; then : $as_echo_n "(cached) " >&6 else i=0 teststring="ABCD" case $build_os in msdosdjgpp*) # On DJGPP, this test can blow up pretty badly due to problems in libc # (any single argument exceeding 2000 bytes causes a buffer overrun # during glob expansion). Even if it were fixed, the result of this # check would be larger than it should be. lt_cv_sys_max_cmd_len=12288; # 12K is about right ;; gnu*) # Under GNU Hurd, this test is not required because there is # no limit to the length of command line arguments. # Libtool will interpret -1 as no limit whatsoever lt_cv_sys_max_cmd_len=-1; ;; cygwin* | mingw* | cegcc*) # On Win9x/ME, this test blows up -- it succeeds, but takes # about 5 minutes as the teststring grows exponentially. # Worse, since 9x/ME are not pre-emptively multitasking, # you end up with a "frozen" computer, even though with patience # the test eventually succeeds (with a max line length of 256k). # Instead, let's just punt: use the minimum linelength reported by # all of the supported platforms: 8192 (on NT/2K/XP). lt_cv_sys_max_cmd_len=8192; ;; amigaos*) # On AmigaOS with pdksh, this test takes hours, literally. # So we just punt and use a minimum line length of 8192. lt_cv_sys_max_cmd_len=8192; ;; netbsd* | freebsd* | openbsd* | darwin* | dragonfly*) # This has been around since 386BSD, at least. Likely further. if test -x /sbin/sysctl; then lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` elif test -x /usr/sbin/sysctl; then lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` else lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs fi # And add a safety zone lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` ;; interix*) # We know the value 262144 and hardcode it with a safety zone (like BSD) lt_cv_sys_max_cmd_len=196608 ;; osf*) # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not # nice to cause kernel panics so lets avoid the loop below. # First set a reasonable default. lt_cv_sys_max_cmd_len=16384 # if test -x /sbin/sysconfig; then case `/sbin/sysconfig -q proc exec_disable_arg_limit` in *1*) lt_cv_sys_max_cmd_len=-1 ;; esac fi ;; sco3.2v5*) lt_cv_sys_max_cmd_len=102400 ;; sysv5* | sco5v6* | sysv4.2uw2*) kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` if test -n "$kargmax"; then lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[ ]//'` else lt_cv_sys_max_cmd_len=32768 fi ;; *) lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` if test -n "$lt_cv_sys_max_cmd_len"; then lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` else # Make teststring a little bigger before we do anything with it. # a 1K string should be a reasonable start. for i in 1 2 3 4 5 6 7 8 ; do teststring=$teststring$teststring done SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} # If test is not a shell built-in, we'll probably end up computing a # maximum length that is only half of the actual maximum length, but # we can't tell. while { test "X"`$SHELL $0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \ = "XX$teststring$teststring"; } >/dev/null 2>&1 && test $i != 17 # 1/2 MB should be enough do i=`expr $i + 1` teststring=$teststring$teststring done # Only check the string length outside the loop. lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` teststring= # Add a significant safety factor because C++ compilers can tack on # massive amounts of additional arguments before passing them to the # linker. It appears as though 1/2 is a usable value. lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` fi ;; esac fi if test -n $lt_cv_sys_max_cmd_len ; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5 $as_echo "$lt_cv_sys_max_cmd_len" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5 $as_echo "none" >&6; } fi max_cmd_len=$lt_cv_sys_max_cmd_len : ${CP="cp -f"} : ${MV="mv -f"} : ${RM="rm -f"} { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the shell understands some XSI constructs" >&5 $as_echo_n "checking whether the shell understands some XSI constructs... " >&6; } # Try some XSI features xsi_shell=no ( _lt_dummy="a/b/c" test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \ = c,a/b,, \ && eval 'test $(( 1 + 1 )) -eq 2 \ && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \ && xsi_shell=yes { $as_echo "$as_me:${as_lineno-$LINENO}: result: $xsi_shell" >&5 $as_echo "$xsi_shell" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the shell understands \"+=\"" >&5 $as_echo_n "checking whether the shell understands \"+=\"... " >&6; } lt_shell_append=no ( foo=bar; set foo baz; eval "$1+=\$2" && test "$foo" = barbaz ) \ >/dev/null 2>&1 \ && lt_shell_append=yes { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_shell_append" >&5 $as_echo "$lt_shell_append" >&6; } if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then lt_unset=unset else lt_unset=false fi # test EBCDIC or ASCII case `echo X|tr X '\101'` in A) # ASCII based system # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr lt_SP2NL='tr \040 \012' lt_NL2SP='tr \015\012 \040\040' ;; *) # EBCDIC based system lt_SP2NL='tr \100 \n' lt_NL2SP='tr \r\n \100\100' ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5 $as_echo_n "checking for $LD option to reload object files... " >&6; } if test "${lt_cv_ld_reload_flag+set}" = set; then : $as_echo_n "(cached) " >&6 else lt_cv_ld_reload_flag='-r' fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5 $as_echo "$lt_cv_ld_reload_flag" >&6; } reload_flag=$lt_cv_ld_reload_flag case $reload_flag in "" | " "*) ;; *) reload_flag=" $reload_flag" ;; esac reload_cmds='$LD$reload_flag -o $output$reload_objs' case $host_os in darwin*) if test "$GCC" = yes; then reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs' else reload_cmds='$LD$reload_flag -o $output$reload_objs' fi ;; esac if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args. set dummy ${ac_tool_prefix}objdump; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_OBJDUMP+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$OBJDUMP"; then ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OBJDUMP=$ac_cv_prog_OBJDUMP if test -n "$OBJDUMP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 $as_echo "$OBJDUMP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OBJDUMP"; then ac_ct_OBJDUMP=$OBJDUMP # Extract the first word of "objdump", so it can be a program name with args. set dummy objdump; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_OBJDUMP+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OBJDUMP"; then ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_OBJDUMP="objdump" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP if test -n "$ac_ct_OBJDUMP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 $as_echo "$ac_ct_OBJDUMP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OBJDUMP" = x; then OBJDUMP="false" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OBJDUMP=$ac_ct_OBJDUMP fi else OBJDUMP="$ac_cv_prog_OBJDUMP" fi test -z "$OBJDUMP" && OBJDUMP=objdump { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5 $as_echo_n "checking how to recognize dependent libraries... " >&6; } if test "${lt_cv_deplibs_check_method+set}" = set; then : $as_echo_n "(cached) " >&6 else lt_cv_file_magic_cmd='$MAGIC_CMD' lt_cv_file_magic_test_file= lt_cv_deplibs_check_method='unknown' # Need to set the preceding variable on all platforms that support # interlibrary dependencies. # 'none' -- dependencies not supported. # `unknown' -- same as none, but documents that we really don't know. # 'pass_all' -- all dependencies passed with no checks. # 'test_compile' -- check by making test program. # 'file_magic [[regex]]' -- check by looking for files in library path # which responds to the $file_magic_cmd with a given extended regex. # If you have `file' or equivalent on your system and you're not sure # whether `pass_all' will *always* work, you probably want this one. case $host_os in aix[4-9]*) lt_cv_deplibs_check_method=pass_all ;; beos*) lt_cv_deplibs_check_method=pass_all ;; bsdi[45]*) lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)' lt_cv_file_magic_cmd='/usr/bin/file -L' lt_cv_file_magic_test_file=/shlib/libc.so ;; cygwin*) # func_win32_libid is a shell function defined in ltmain.sh lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' lt_cv_file_magic_cmd='func_win32_libid' ;; mingw* | pw32*) # Base MSYS/MinGW do not provide the 'file' command needed by # func_win32_libid shell function, so use a weaker test based on 'objdump', # unless we find 'file', for example because we are cross-compiling. if ( file / ) >/dev/null 2>&1; then lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' lt_cv_file_magic_cmd='func_win32_libid' else lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?' lt_cv_file_magic_cmd='$OBJDUMP -f' fi ;; cegcc) # use the weaker test based on 'objdump'. See mingw*. lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' lt_cv_file_magic_cmd='$OBJDUMP -f' ;; darwin* | rhapsody*) lt_cv_deplibs_check_method=pass_all ;; freebsd* | dragonfly*) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then case $host_cpu in i*86 ) # Not sure whether the presence of OpenBSD here was a mistake. # Let's accept both of them until this is cleared up. lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library' lt_cv_file_magic_cmd=/usr/bin/file lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` ;; esac else lt_cv_deplibs_check_method=pass_all fi ;; gnu*) lt_cv_deplibs_check_method=pass_all ;; hpux10.20* | hpux11*) lt_cv_file_magic_cmd=/usr/bin/file case $host_cpu in ia64*) lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64' lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so ;; hppa*64*) lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]' lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl ;; *) lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9].[0-9]) shared library' lt_cv_file_magic_test_file=/usr/lib/libc.sl ;; esac ;; interix[3-9]*) # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$' ;; irix5* | irix6* | nonstopux*) case $LD in *-32|*"-32 ") libmagic=32-bit;; *-n32|*"-n32 ") libmagic=N32;; *-64|*"-64 ") libmagic=64-bit;; *) libmagic=never-match;; esac lt_cv_deplibs_check_method=pass_all ;; # This must be Linux ELF. linux* | k*bsd*-gnu | kopensolaris*-gnu) lt_cv_deplibs_check_method=pass_all ;; netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' else lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$' fi ;; newos6*) lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)' lt_cv_file_magic_cmd=/usr/bin/file lt_cv_file_magic_test_file=/usr/lib/libnls.so ;; *nto* | *qnx*) lt_cv_deplibs_check_method=pass_all ;; openbsd*) if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$' else lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' fi ;; osf3* | osf4* | osf5*) lt_cv_deplibs_check_method=pass_all ;; rdos*) lt_cv_deplibs_check_method=pass_all ;; solaris*) lt_cv_deplibs_check_method=pass_all ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) lt_cv_deplibs_check_method=pass_all ;; sysv4 | sysv4.3*) case $host_vendor in motorola) lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]' lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` ;; ncr) lt_cv_deplibs_check_method=pass_all ;; sequent) lt_cv_file_magic_cmd='/bin/file' lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )' ;; sni) lt_cv_file_magic_cmd='/bin/file' lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib" lt_cv_file_magic_test_file=/lib/libc.so ;; siemens) lt_cv_deplibs_check_method=pass_all ;; pc) lt_cv_deplibs_check_method=pass_all ;; esac ;; tpf*) lt_cv_deplibs_check_method=pass_all ;; esac fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 $as_echo "$lt_cv_deplibs_check_method" >&6; } file_magic_cmd=$lt_cv_file_magic_cmd deplibs_check_method=$lt_cv_deplibs_check_method test -z "$deplibs_check_method" && deplibs_check_method=unknown if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args. set dummy ${ac_tool_prefix}ar; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_AR+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$AR"; then ac_cv_prog_AR="$AR" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_AR="${ac_tool_prefix}ar" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi AR=$ac_cv_prog_AR if test -n "$AR"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 $as_echo "$AR" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_AR"; then ac_ct_AR=$AR # Extract the first word of "ar", so it can be a program name with args. set dummy ar; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_AR+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_AR"; then ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_AR="ar" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_AR=$ac_cv_prog_ac_ct_AR if test -n "$ac_ct_AR"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 $as_echo "$ac_ct_AR" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_AR" = x; then AR="false" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac AR=$ac_ct_AR fi else AR="$ac_cv_prog_AR" fi test -z "$AR" && AR=ar test -z "$AR_FLAGS" && AR_FLAGS=cru if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. set dummy ${ac_tool_prefix}strip; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_STRIP+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi STRIP=$ac_cv_prog_STRIP if test -n "$STRIP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 $as_echo "$STRIP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_STRIP"; then ac_ct_STRIP=$STRIP # Extract the first word of "strip", so it can be a program name with args. set dummy strip; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_STRIP="strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP if test -n "$ac_ct_STRIP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 $as_echo "$ac_ct_STRIP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then STRIP=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP fi else STRIP="$ac_cv_prog_STRIP" fi test -z "$STRIP" && STRIP=: if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. set dummy ${ac_tool_prefix}ranlib; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_RANLIB+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi RANLIB=$ac_cv_prog_RANLIB if test -n "$RANLIB"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 $as_echo "$RANLIB" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_RANLIB"; then ac_ct_RANLIB=$RANLIB # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_RANLIB"; then ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_RANLIB="ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB if test -n "$ac_ct_RANLIB"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 $as_echo "$ac_ct_RANLIB" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_RANLIB" = x; then RANLIB=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac RANLIB=$ac_ct_RANLIB fi else RANLIB="$ac_cv_prog_RANLIB" fi test -z "$RANLIB" && RANLIB=: # Determine commands to create old-style static archives. old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' old_postinstall_cmds='chmod 644 $oldlib' old_postuninstall_cmds= if test -n "$RANLIB"; then case $host_os in openbsd*) old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib" ;; *) old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib" ;; esac old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib" fi # If no C compiler was specified, use CC. LTCC=${LTCC-"$CC"} # If no C compiler flags were specified, use CFLAGS. LTCFLAGS=${LTCFLAGS-"$CFLAGS"} # Allow CC to be a program name with arguments. compiler=$CC # Check for command to grab the raw symbol name followed by C symbol from nm. { $as_echo "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5 $as_echo_n "checking command to parse $NM output from $compiler object... " >&6; } if test "${lt_cv_sys_global_symbol_pipe+set}" = set; then : $as_echo_n "(cached) " >&6 else # These are sane defaults that work on at least a few old systems. # [They come from Ultrix. What could be older than Ultrix?!! ;)] # Character class describing NM global symbol codes. symcode='[BCDEGRST]' # Regexp to match symbols that can be accessed directly from C. sympat='\([_A-Za-z][_A-Za-z0-9]*\)' # Define system-specific variables. case $host_os in aix*) symcode='[BCDT]' ;; cygwin* | mingw* | pw32* | cegcc*) symcode='[ABCDGISTW]' ;; hpux*) if test "$host_cpu" = ia64; then symcode='[ABCDEGRST]' fi ;; irix* | nonstopux*) symcode='[BCDEGRST]' ;; osf*) symcode='[BCDEGQRST]' ;; solaris*) symcode='[BDRT]' ;; sco3.2v5*) symcode='[DT]' ;; sysv4.2uw2*) symcode='[DT]' ;; sysv5* | sco5v6* | unixware* | OpenUNIX*) symcode='[ABDT]' ;; sysv4) symcode='[DFNSTU]' ;; esac # If we're using GNU nm, then use its standard symbol codes. case `$NM -V 2>&1` in *GNU* | *'with BFD'*) symcode='[ABCDGIRSTW]' ;; esac # Transform an extracted symbol line into a proper C declaration. # Some systems (esp. on ia64) link data and code symbols differently, # so use this general approach. lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" # Transform an extracted symbol line into symbol name and symbol address lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/ {\"\2\", (void *) \&\2},/p'" lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([^ ]*\) $/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \(lib[^ ]*\)$/ {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/ {\"lib\2\", (void *) \&\2},/p'" # Handle CRLF in mingw tool chain opt_cr= case $build_os in mingw*) opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp ;; esac # Try without a prefix underscore, then with it. for ac_symprfx in "" "_"; do # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. symxfrm="\\1 $ac_symprfx\\2 \\2" # Write the raw and C identifiers. if test "$lt_cv_nm_interface" = "MS dumpbin"; then # Fake it for dumpbin and say T for any non-static function # and D for any global variable. # Also find C++ and __fastcall symbols from MSVC++, # which start with @ or ?. lt_cv_sys_global_symbol_pipe="$AWK '"\ " {last_section=section; section=\$ 3};"\ " /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ " \$ 0!~/External *\|/{next};"\ " / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ " {if(hide[section]) next};"\ " {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\ " {split(\$ 0, a, /\||\r/); split(a[2], s)};"\ " s[1]~/^[@?]/{print s[1], s[1]; next};"\ " s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\ " ' prfx=^$ac_symprfx" else lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[ ]\($symcode$symcode*\)[ ][ ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" fi # Check to see that the pipe works correctly. pipe_works=no rm -f conftest* cat > conftest.$ac_ext <<_LT_EOF #ifdef __cplusplus extern "C" { #endif char nm_test_var; void nm_test_func(void); void nm_test_func(void){} #ifdef __cplusplus } #endif int main(){nm_test_var='a';nm_test_func();return(0);} _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then # Now try to grab the symbols. nlist=conftest.nm if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist\""; } >&5 (eval $NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s "$nlist"; then # Try sorting and uniquifying the output. if sort "$nlist" | uniq > "$nlist"T; then mv -f "$nlist"T "$nlist" else rm -f "$nlist"T fi # Make sure that we snagged all the symbols we need. if $GREP ' nm_test_var$' "$nlist" >/dev/null; then if $GREP ' nm_test_func$' "$nlist" >/dev/null; then cat <<_LT_EOF > conftest.$ac_ext #ifdef __cplusplus extern "C" { #endif _LT_EOF # Now generate the symbol file. eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' cat <<_LT_EOF >> conftest.$ac_ext /* The mapping between symbol names and symbols. */ const struct { const char *name; void *address; } lt__PROGRAM__LTX_preloaded_symbols[] = { { "@PROGRAM@", (void *) 0 }, _LT_EOF $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/ {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext cat <<\_LT_EOF >> conftest.$ac_ext {0, (void *) 0} }; /* This works around a problem in FreeBSD linker */ #ifdef FREEBSD_WORKAROUND static const void *lt_preloaded_setup() { return lt__PROGRAM__LTX_preloaded_symbols; } #endif #ifdef __cplusplus } #endif _LT_EOF # Now try linking the two files. mv conftest.$ac_objext conftstm.$ac_objext lt_save_LIBS="$LIBS" lt_save_CFLAGS="$CFLAGS" LIBS="conftstm.$ac_objext" CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag" if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 (eval $ac_link) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s conftest${ac_exeext}; then pipe_works=yes fi LIBS="$lt_save_LIBS" CFLAGS="$lt_save_CFLAGS" else echo "cannot find nm_test_func in $nlist" >&5 fi else echo "cannot find nm_test_var in $nlist" >&5 fi else echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5 fi else echo "$progname: failed program was:" >&5 cat conftest.$ac_ext >&5 fi rm -rf conftest* conftst* # Do not use the global_symbol_pipe unless it works. if test "$pipe_works" = yes; then break else lt_cv_sys_global_symbol_pipe= fi done fi if test -z "$lt_cv_sys_global_symbol_pipe"; then lt_cv_sys_global_symbol_to_cdecl= fi if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5 $as_echo "failed" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 $as_echo "ok" >&6; } fi # Check whether --enable-libtool-lock was given. if test "${enable_libtool_lock+set}" = set; then : enableval=$enable_libtool_lock; fi test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes # Some flags need to be propagated to the compiler or linker for good # libtool support. case $host in ia64-*-hpux*) # Find out which ABI we are using. echo 'int i;' > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.$ac_objext` in *ELF-32*) HPUX_IA64_MODE="32" ;; *ELF-64*) HPUX_IA64_MODE="64" ;; esac fi rm -rf conftest* ;; *-*-irix6*) # Find out which ABI we are using. echo '#line 6431 "configure"' > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then if test "$lt_cv_prog_gnu_ld" = yes; then case `/usr/bin/file conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -melf32bsmip" ;; *N32*) LD="${LD-ld} -melf32bmipn32" ;; *64-bit*) LD="${LD-ld} -melf64bmip" ;; esac else case `/usr/bin/file conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -32" ;; *N32*) LD="${LD-ld} -n32" ;; *64-bit*) LD="${LD-ld} -64" ;; esac fi fi rm -rf conftest* ;; x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) # Find out which ABI we are using. echo 'int i;' > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.o` in *32-bit*) case $host in x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_i386_fbsd" ;; x86_64-*linux*) LD="${LD-ld} -m elf_i386" ;; ppc64-*linux*|powerpc64-*linux*) LD="${LD-ld} -m elf32ppclinux" ;; s390x-*linux*) LD="${LD-ld} -m elf_s390" ;; sparc64-*linux*) LD="${LD-ld} -m elf32_sparc" ;; esac ;; *64-bit*) case $host in x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_x86_64_fbsd" ;; x86_64-*linux*) LD="${LD-ld} -m elf_x86_64" ;; ppc*-*linux*|powerpc*-*linux*) LD="${LD-ld} -m elf64ppc" ;; s390*-*linux*|s390*-*tpf*) LD="${LD-ld} -m elf64_s390" ;; sparc*-*linux*) LD="${LD-ld} -m elf64_sparc" ;; esac ;; esac fi rm -rf conftest* ;; *-*-sco3.2v5*) # On SCO OpenServer 5, we need -belf to get full-featured binaries. SAVE_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -belf" { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5 $as_echo_n "checking whether the C compiler needs -belf... " >&6; } if test "${lt_cv_cc_needs_belf+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : lt_cv_cc_needs_belf=yes else lt_cv_cc_needs_belf=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5 $as_echo "$lt_cv_cc_needs_belf" >&6; } if test x"$lt_cv_cc_needs_belf" != x"yes"; then # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf CFLAGS="$SAVE_CFLAGS" fi ;; sparc*-*solaris*) # Find out which ABI we are using. echo 'int i;' > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.o` in *64-bit*) case $lt_cv_prog_gnu_ld in yes*) LD="${LD-ld} -m elf64_sparc" ;; *) if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then LD="${LD-ld} -64" fi ;; esac ;; esac fi rm -rf conftest* ;; esac need_locks="$enable_libtool_lock" case $host_os in rhapsody* | darwin*) if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args. set dummy ${ac_tool_prefix}dsymutil; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_DSYMUTIL+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$DSYMUTIL"; then ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi DSYMUTIL=$ac_cv_prog_DSYMUTIL if test -n "$DSYMUTIL"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5 $as_echo "$DSYMUTIL" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_DSYMUTIL"; then ac_ct_DSYMUTIL=$DSYMUTIL # Extract the first word of "dsymutil", so it can be a program name with args. set dummy dsymutil; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_DSYMUTIL+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_DSYMUTIL"; then ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_DSYMUTIL="dsymutil" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL if test -n "$ac_ct_DSYMUTIL"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5 $as_echo "$ac_ct_DSYMUTIL" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_DSYMUTIL" = x; then DSYMUTIL=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DSYMUTIL=$ac_ct_DSYMUTIL fi else DSYMUTIL="$ac_cv_prog_DSYMUTIL" fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args. set dummy ${ac_tool_prefix}nmedit; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_NMEDIT+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$NMEDIT"; then ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi NMEDIT=$ac_cv_prog_NMEDIT if test -n "$NMEDIT"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5 $as_echo "$NMEDIT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_NMEDIT"; then ac_ct_NMEDIT=$NMEDIT # Extract the first word of "nmedit", so it can be a program name with args. set dummy nmedit; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_NMEDIT+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_NMEDIT"; then ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_NMEDIT="nmedit" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT if test -n "$ac_ct_NMEDIT"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5 $as_echo "$ac_ct_NMEDIT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_NMEDIT" = x; then NMEDIT=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac NMEDIT=$ac_ct_NMEDIT fi else NMEDIT="$ac_cv_prog_NMEDIT" fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args. set dummy ${ac_tool_prefix}lipo; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_LIPO+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$LIPO"; then ac_cv_prog_LIPO="$LIPO" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_LIPO="${ac_tool_prefix}lipo" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi LIPO=$ac_cv_prog_LIPO if test -n "$LIPO"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5 $as_echo "$LIPO" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_LIPO"; then ac_ct_LIPO=$LIPO # Extract the first word of "lipo", so it can be a program name with args. set dummy lipo; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_LIPO+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_LIPO"; then ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_LIPO="lipo" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO if test -n "$ac_ct_LIPO"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5 $as_echo "$ac_ct_LIPO" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_LIPO" = x; then LIPO=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac LIPO=$ac_ct_LIPO fi else LIPO="$ac_cv_prog_LIPO" fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args. set dummy ${ac_tool_prefix}otool; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_OTOOL+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$OTOOL"; then ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_OTOOL="${ac_tool_prefix}otool" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OTOOL=$ac_cv_prog_OTOOL if test -n "$OTOOL"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5 $as_echo "$OTOOL" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OTOOL"; then ac_ct_OTOOL=$OTOOL # Extract the first word of "otool", so it can be a program name with args. set dummy otool; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_OTOOL+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OTOOL"; then ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_OTOOL="otool" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL if test -n "$ac_ct_OTOOL"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5 $as_echo "$ac_ct_OTOOL" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OTOOL" = x; then OTOOL=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OTOOL=$ac_ct_OTOOL fi else OTOOL="$ac_cv_prog_OTOOL" fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args. set dummy ${ac_tool_prefix}otool64; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_OTOOL64+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$OTOOL64"; then ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OTOOL64=$ac_cv_prog_OTOOL64 if test -n "$OTOOL64"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5 $as_echo "$OTOOL64" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OTOOL64"; then ac_ct_OTOOL64=$OTOOL64 # Extract the first word of "otool64", so it can be a program name with args. set dummy otool64; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_OTOOL64+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OTOOL64"; then ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_OTOOL64="otool64" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64 if test -n "$ac_ct_OTOOL64"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5 $as_echo "$ac_ct_OTOOL64" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OTOOL64" = x; then OTOOL64=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OTOOL64=$ac_ct_OTOOL64 fi else OTOOL64="$ac_cv_prog_OTOOL64" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5 $as_echo_n "checking for -single_module linker flag... " >&6; } if test "${lt_cv_apple_cc_single_mod+set}" = set; then : $as_echo_n "(cached) " >&6 else lt_cv_apple_cc_single_mod=no if test -z "${LT_MULTI_MODULE}"; then # By default we will add the -single_module flag. You can override # by either setting the environment variable LT_MULTI_MODULE # non-empty at configure time, or by adding -multi_module to the # link flags. rm -rf libconftest.dylib* echo "int foo(void){return 1;}" > conftest.c echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ -dynamiclib -Wl,-single_module conftest.c" >&5 $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ -dynamiclib -Wl,-single_module conftest.c 2>conftest.err _lt_result=$? if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then lt_cv_apple_cc_single_mod=yes else cat conftest.err >&5 fi rm -rf libconftest.dylib* rm -f conftest.* fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5 $as_echo "$lt_cv_apple_cc_single_mod" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5 $as_echo_n "checking for -exported_symbols_list linker flag... " >&6; } if test "${lt_cv_ld_exported_symbols_list+set}" = set; then : $as_echo_n "(cached) " >&6 else lt_cv_ld_exported_symbols_list=no save_LDFLAGS=$LDFLAGS echo "_main" > conftest.sym LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : lt_cv_ld_exported_symbols_list=yes else lt_cv_ld_exported_symbols_list=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LDFLAGS="$save_LDFLAGS" fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5 $as_echo "$lt_cv_ld_exported_symbols_list" >&6; } case $host_os in rhapsody* | darwin1.[012]) _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; darwin1.*) _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; darwin*) # darwin 5.x on # if running on 10.5 or later, the deployment target defaults # to the OS version, if on x86, and 10.4, the deployment # target defaults to 10.4. Don't you love it? case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in 10.0,*86*-darwin8*|10.0,*-darwin[91]*) _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; 10.[012]*) _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; 10.*) _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; esac ;; esac if test "$lt_cv_apple_cc_single_mod" = "yes"; then _lt_dar_single_mod='$single_module' fi if test "$lt_cv_ld_exported_symbols_list" = "yes"; then _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym' else _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}' fi if test "$DSYMUTIL" != ":"; then _lt_dsymutil='~$DSYMUTIL $lib || :' else _lt_dsymutil= fi ;; esac for ac_header in dlfcn.h do : ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default " if test "x$ac_cv_header_dlfcn_h" = x""yes; then : cat >>confdefs.h <<_ACEOF #define HAVE_DLFCN_H 1 _ACEOF fi done # Set options enable_dlopen=no enable_win32_dll=no # Check whether --enable-shared was given. if test "${enable_shared+set}" = set; then : enableval=$enable_shared; p=${PACKAGE-default} case $enableval in yes) enable_shared=yes ;; no) enable_shared=no ;; *) enable_shared=no # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for pkg in $enableval; do IFS="$lt_save_ifs" if test "X$pkg" = "X$p"; then enable_shared=yes fi done IFS="$lt_save_ifs" ;; esac else enable_shared=yes fi # Check whether --enable-static was given. if test "${enable_static+set}" = set; then : enableval=$enable_static; p=${PACKAGE-default} case $enableval in yes) enable_static=yes ;; no) enable_static=no ;; *) enable_static=no # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for pkg in $enableval; do IFS="$lt_save_ifs" if test "X$pkg" = "X$p"; then enable_static=yes fi done IFS="$lt_save_ifs" ;; esac else enable_static=yes fi # Check whether --with-pic was given. if test "${with_pic+set}" = set; then : withval=$with_pic; pic_mode="$withval" else pic_mode=default fi test -z "$pic_mode" && pic_mode=default # Check whether --enable-fast-install was given. if test "${enable_fast_install+set}" = set; then : enableval=$enable_fast_install; p=${PACKAGE-default} case $enableval in yes) enable_fast_install=yes ;; no) enable_fast_install=no ;; *) enable_fast_install=no # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for pkg in $enableval; do IFS="$lt_save_ifs" if test "X$pkg" = "X$p"; then enable_fast_install=yes fi done IFS="$lt_save_ifs" ;; esac else enable_fast_install=yes fi # This can be used to rebuild libtool when needed LIBTOOL_DEPS="$ltmain" # Always use our own libtool. LIBTOOL='$(SHELL) $(top_builddir)/libtool' test -z "$LN_S" && LN_S="ln -s" if test -n "${ZSH_VERSION+set}" ; then setopt NO_GLOB_SUBST fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 $as_echo_n "checking for objdir... " >&6; } if test "${lt_cv_objdir+set}" = set; then : $as_echo_n "(cached) " >&6 else rm -f .libs 2>/dev/null mkdir .libs 2>/dev/null if test -d .libs; then lt_cv_objdir=.libs else # MS-DOS does not allow filenames that begin with a dot. lt_cv_objdir=_libs fi rmdir .libs 2>/dev/null fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5 $as_echo "$lt_cv_objdir" >&6; } objdir=$lt_cv_objdir cat >>confdefs.h <<_ACEOF #define LT_OBJDIR "$lt_cv_objdir/" _ACEOF case $host_os in aix3*) # AIX sometimes has problems with the GCC collect2 program. For some # reason, if we set the COLLECT_NAMES environment variable, the problems # vanish in a puff of smoke. if test "X${COLLECT_NAMES+set}" != Xset; then COLLECT_NAMES= export COLLECT_NAMES fi ;; esac # Sed substitution that helps us do robust quoting. It backslashifies # metacharacters that are still active within double-quoted strings. sed_quote_subst='s/\(["`$\\]\)/\\\1/g' # Same as above, but do not quote variable references. double_quote_subst='s/\(["`\\]\)/\\\1/g' # Sed substitution to delay expansion of an escaped shell variable in a # double_quote_subst'ed string. delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' # Sed substitution to delay expansion of an escaped single quote. delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' # Sed substitution to avoid accidental globbing in evaled expressions no_glob_subst='s/\*/\\\*/g' # Global variables: ofile=libtool can_build_shared=yes # All known linkers require a `.a' archive for static linking (except MSVC, # which needs '.lib'). libext=a with_gnu_ld="$lt_cv_prog_gnu_ld" old_CC="$CC" old_CFLAGS="$CFLAGS" # Set sane defaults for various variables test -z "$CC" && CC=cc test -z "$LTCC" && LTCC=$CC test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS test -z "$LD" && LD=ld test -z "$ac_objext" && ac_objext=o for cc_temp in $compiler""; do case $cc_temp in compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; \-*) ;; *) break;; esac done cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` # Only perform the check for file, if the check method requires it test -z "$MAGIC_CMD" && MAGIC_CMD=file case $deplibs_check_method in file_magic*) if test "$file_magic_cmd" = '$MAGIC_CMD'; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5 $as_echo_n "checking for ${ac_tool_prefix}file... " >&6; } if test "${lt_cv_path_MAGIC_CMD+set}" = set; then : $as_echo_n "(cached) " >&6 else case $MAGIC_CMD in [\\/*] | ?:[\\/]*) lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. ;; *) lt_save_MAGIC_CMD="$MAGIC_CMD" lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" for ac_dir in $ac_dummy; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/${ac_tool_prefix}file; then lt_cv_path_MAGIC_CMD="$ac_dir/${ac_tool_prefix}file" if test -n "$file_magic_test_file"; then case $deplibs_check_method in "file_magic "*) file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` MAGIC_CMD="$lt_cv_path_MAGIC_CMD" if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | $EGREP "$file_magic_regex" > /dev/null; then : else cat <<_LT_EOF 1>&2 *** Warning: the command libtool uses to detect shared libraries, *** $file_magic_cmd, produces output that libtool cannot recognize. *** The result is that libtool may fail to recognize shared libraries *** as such. This will affect the creation of libtool libraries that *** depend on shared libraries, but programs linked with such libtool *** libraries will work regardless of this problem. Nevertheless, you *** may want to report the problem to your system manager and/or to *** bug-libtool@gnu.org _LT_EOF fi ;; esac fi break fi done IFS="$lt_save_ifs" MAGIC_CMD="$lt_save_MAGIC_CMD" ;; esac fi MAGIC_CMD="$lt_cv_path_MAGIC_CMD" if test -n "$MAGIC_CMD"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 $as_echo "$MAGIC_CMD" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test -z "$lt_cv_path_MAGIC_CMD"; then if test -n "$ac_tool_prefix"; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for file" >&5 $as_echo_n "checking for file... " >&6; } if test "${lt_cv_path_MAGIC_CMD+set}" = set; then : $as_echo_n "(cached) " >&6 else case $MAGIC_CMD in [\\/*] | ?:[\\/]*) lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. ;; *) lt_save_MAGIC_CMD="$MAGIC_CMD" lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" for ac_dir in $ac_dummy; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/file; then lt_cv_path_MAGIC_CMD="$ac_dir/file" if test -n "$file_magic_test_file"; then case $deplibs_check_method in "file_magic "*) file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` MAGIC_CMD="$lt_cv_path_MAGIC_CMD" if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | $EGREP "$file_magic_regex" > /dev/null; then : else cat <<_LT_EOF 1>&2 *** Warning: the command libtool uses to detect shared libraries, *** $file_magic_cmd, produces output that libtool cannot recognize. *** The result is that libtool may fail to recognize shared libraries *** as such. This will affect the creation of libtool libraries that *** depend on shared libraries, but programs linked with such libtool *** libraries will work regardless of this problem. Nevertheless, you *** may want to report the problem to your system manager and/or to *** bug-libtool@gnu.org _LT_EOF fi ;; esac fi break fi done IFS="$lt_save_ifs" MAGIC_CMD="$lt_save_MAGIC_CMD" ;; esac fi MAGIC_CMD="$lt_cv_path_MAGIC_CMD" if test -n "$MAGIC_CMD"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 $as_echo "$MAGIC_CMD" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi else MAGIC_CMD=: fi fi fi ;; esac # Use C for the default configuration in the libtool script lt_save_CC="$CC" ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu # Source file extension for C test sources. ac_ext=c # Object file extension for compiled C test sources. objext=o objext=$objext # Code to be used in simple compile tests lt_simple_compile_test_code="int some_variable = 0;" # Code to be used in simple link tests lt_simple_link_test_code='int main(){return(0);}' # If no C compiler was specified, use CC. LTCC=${LTCC-"$CC"} # If no C compiler flags were specified, use CFLAGS. LTCFLAGS=${LTCFLAGS-"$CFLAGS"} # Allow CC to be a program name with arguments. compiler=$CC # Save the default compiler, since it gets overwritten when the other # tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. compiler_DEFAULT=$CC # save warnings/boilerplate of simple test code ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" >conftest.$ac_ext eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err _lt_compiler_boilerplate=`cat conftest.err` $RM conftest* ac_outfile=conftest.$ac_objext echo "$lt_simple_link_test_code" >conftest.$ac_ext eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err _lt_linker_boilerplate=`cat conftest.err` $RM -r conftest* ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... if test -n "$compiler"; then lt_prog_compiler_no_builtin_flag= if test "$GCC" = yes; then lt_prog_compiler_no_builtin_flag=' -fno-builtin' { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 $as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; } if test "${lt_cv_prog_compiler_rtti_exceptions+set}" = set; then : $as_echo_n "(cached) " >&6 else lt_cv_prog_compiler_rtti_exceptions=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="-fno-rtti -fno-exceptions" # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. # The option is referenced via a variable to avoid confusing sed. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:7693: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 echo "$as_me:7697: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then lt_cv_prog_compiler_rtti_exceptions=yes fi fi $RM conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 $as_echo "$lt_cv_prog_compiler_rtti_exceptions" >&6; } if test x"$lt_cv_prog_compiler_rtti_exceptions" = xyes; then lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions" else : fi fi lt_prog_compiler_wl= lt_prog_compiler_pic= lt_prog_compiler_static= { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 $as_echo_n "checking for $compiler option to produce PIC... " >&6; } if test "$GCC" = yes; then lt_prog_compiler_wl='-Wl,' lt_prog_compiler_static='-static' case $host_os in aix*) # All AIX code is PIC. if test "$host_cpu" = ia64; then # AIX 5 now supports IA64 processor lt_prog_compiler_static='-Bstatic' fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support lt_prog_compiler_pic='-fPIC' ;; m68k) # FIXME: we need at least 68020 code to build shared libraries, but # adding the `-m68020' flag to GCC prevents building anything better, # like `-m68040'. lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4' ;; esac ;; beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) # PIC is the default for these OSes. ;; mingw* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style # (--disable-auto-import) libraries lt_prog_compiler_pic='-DDLL_EXPORT' ;; darwin* | rhapsody*) # PIC is the default on this platform # Common symbols not allowed in MH_DYLIB files lt_prog_compiler_pic='-fno-common' ;; hpux*) # PIC is the default for 64-bit PA HP-UX, but not for 32-bit # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag # sets the default TLS model and affects inlining. case $host_cpu in hppa*64*) # +Z the default ;; *) lt_prog_compiler_pic='-fPIC' ;; esac ;; interix[3-9]*) # Interix 3.x gcc -fpic/-fPIC options generate broken code. # Instead, we relocate shared libraries at runtime. ;; msdosdjgpp*) # Just because we use GCC doesn't mean we suddenly get shared libraries # on systems that don't support them. lt_prog_compiler_can_build_shared=no enable_shared=no ;; *nto* | *qnx*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. lt_prog_compiler_pic='-fPIC -shared' ;; sysv4*MP*) if test -d /usr/nec; then lt_prog_compiler_pic=-Kconform_pic fi ;; *) lt_prog_compiler_pic='-fPIC' ;; esac else # PORTME Check for flag to pass linker flags through the system compiler. case $host_os in aix*) lt_prog_compiler_wl='-Wl,' if test "$host_cpu" = ia64; then # AIX 5 now supports IA64 processor lt_prog_compiler_static='-Bstatic' else lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp' fi ;; mingw* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). lt_prog_compiler_pic='-DDLL_EXPORT' ;; hpux9* | hpux10* | hpux11*) lt_prog_compiler_wl='-Wl,' # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but # not for PA HP-UX. case $host_cpu in hppa*64*|ia64*) # +Z the default ;; *) lt_prog_compiler_pic='+Z' ;; esac # Is there a better lt_prog_compiler_static that works with the bundled CC? lt_prog_compiler_static='${wl}-a ${wl}archive' ;; irix5* | irix6* | nonstopux*) lt_prog_compiler_wl='-Wl,' # PIC (with -KPIC) is the default. lt_prog_compiler_static='-non_shared' ;; linux* | k*bsd*-gnu | kopensolaris*-gnu) case $cc_basename in # old Intel for x86_64 which still supported -KPIC. ecc*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-static' ;; # icc used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. icc* | ifort*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-fPIC' lt_prog_compiler_static='-static' ;; # Lahey Fortran 8.1. lf95*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='--shared' lt_prog_compiler_static='--static' ;; pgcc* | pgf77* | pgf90* | pgf95*) # Portland Group compilers (*not* the Pentium gcc compiler, # which looks to be a dead project) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-fpic' lt_prog_compiler_static='-Bstatic' ;; ccc*) lt_prog_compiler_wl='-Wl,' # All Alpha code is PIC. lt_prog_compiler_static='-non_shared' ;; xl*) # IBM XL C 8.0/Fortran 10.1 on PPC lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-qpic' lt_prog_compiler_static='-qstaticlink' ;; *) case `$CC -V 2>&1 | sed 5q` in *Sun\ C*) # Sun C 5.9 lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-Bstatic' lt_prog_compiler_wl='-Wl,' ;; *Sun\ F*) # Sun Fortran 8.3 passes all unrecognized flags to the linker lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-Bstatic' lt_prog_compiler_wl='' ;; esac ;; esac ;; newsos6) lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-Bstatic' ;; *nto* | *qnx*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. lt_prog_compiler_pic='-fPIC -shared' ;; osf3* | osf4* | osf5*) lt_prog_compiler_wl='-Wl,' # All OSF/1 code is PIC. lt_prog_compiler_static='-non_shared' ;; rdos*) lt_prog_compiler_static='-non_shared' ;; solaris*) lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-Bstatic' case $cc_basename in f77* | f90* | f95*) lt_prog_compiler_wl='-Qoption ld ';; *) lt_prog_compiler_wl='-Wl,';; esac ;; sunos4*) lt_prog_compiler_wl='-Qoption ld ' lt_prog_compiler_pic='-PIC' lt_prog_compiler_static='-Bstatic' ;; sysv4 | sysv4.2uw2* | sysv4.3*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-Bstatic' ;; sysv4*MP*) if test -d /usr/nec ;then lt_prog_compiler_pic='-Kconform_pic' lt_prog_compiler_static='-Bstatic' fi ;; sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-Bstatic' ;; unicos*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_can_build_shared=no ;; uts4*) lt_prog_compiler_pic='-pic' lt_prog_compiler_static='-Bstatic' ;; *) lt_prog_compiler_can_build_shared=no ;; esac fi case $host_os in # For platforms which do not support PIC, -DPIC is meaningless: *djgpp*) lt_prog_compiler_pic= ;; *) lt_prog_compiler_pic="$lt_prog_compiler_pic -DPIC" ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_prog_compiler_pic" >&5 $as_echo "$lt_prog_compiler_pic" >&6; } # # Check to make sure the PIC flag actually works. # if test -n "$lt_prog_compiler_pic"; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 $as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; } if test "${lt_cv_prog_compiler_pic_works+set}" = set; then : $as_echo_n "(cached) " >&6 else lt_cv_prog_compiler_pic_works=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="$lt_prog_compiler_pic -DPIC" # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. # The option is referenced via a variable to avoid confusing sed. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:8032: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 echo "$as_me:8036: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then lt_cv_prog_compiler_pic_works=yes fi fi $RM conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5 $as_echo "$lt_cv_prog_compiler_pic_works" >&6; } if test x"$lt_cv_prog_compiler_pic_works" = xyes; then case $lt_prog_compiler_pic in "" | " "*) ;; *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;; esac else lt_prog_compiler_pic= lt_prog_compiler_can_build_shared=no fi fi # # Check to make sure the static flag actually works. # wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\" { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 $as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } if test "${lt_cv_prog_compiler_static_works+set}" = set; then : $as_echo_n "(cached) " >&6 else lt_cv_prog_compiler_static_works=no save_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS $lt_tmp_static_flag" echo "$lt_simple_link_test_code" > conftest.$ac_ext if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then # The linker can only warn and ignore the option if not recognized # So say no if there are warnings if test -s conftest.err; then # Append any errors to the config.log. cat conftest.err 1>&5 $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 if diff conftest.exp conftest.er2 >/dev/null; then lt_cv_prog_compiler_static_works=yes fi else lt_cv_prog_compiler_static_works=yes fi fi $RM -r conftest* LDFLAGS="$save_LDFLAGS" fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5 $as_echo "$lt_cv_prog_compiler_static_works" >&6; } if test x"$lt_cv_prog_compiler_static_works" = xyes; then : else lt_prog_compiler_static= fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 $as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } if test "${lt_cv_prog_compiler_c_o+set}" = set; then : $as_echo_n "(cached) " >&6 else lt_cv_prog_compiler_c_o=no $RM -r conftest 2>/dev/null mkdir conftest cd conftest mkdir out echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="-o out/conftest2.$ac_objext" # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:8137: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 echo "$as_me:8141: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then lt_cv_prog_compiler_c_o=yes fi fi chmod u+w . 2>&5 $RM conftest* # SGI C++ compiler will create directory out/ii_files/ for # template instantiation test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files $RM out/* && rmdir out cd .. $RM -r conftest $RM conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 $as_echo "$lt_cv_prog_compiler_c_o" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 $as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } if test "${lt_cv_prog_compiler_c_o+set}" = set; then : $as_echo_n "(cached) " >&6 else lt_cv_prog_compiler_c_o=no $RM -r conftest 2>/dev/null mkdir conftest cd conftest mkdir out echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="-o out/conftest2.$ac_objext" # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:8192: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 echo "$as_me:8196: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then lt_cv_prog_compiler_c_o=yes fi fi chmod u+w . 2>&5 $RM conftest* # SGI C++ compiler will create directory out/ii_files/ for # template instantiation test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files $RM out/* && rmdir out cd .. $RM -r conftest $RM conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 $as_echo "$lt_cv_prog_compiler_c_o" >&6; } hard_links="nottested" if test "$lt_cv_prog_compiler_c_o" = no && test "$need_locks" != no; then # do not overwrite the value of need_locks provided by the user { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 $as_echo_n "checking if we can lock with hard links... " >&6; } hard_links=yes $RM conftest* ln conftest.a conftest.b 2>/dev/null && hard_links=no touch conftest.a ln conftest.a conftest.b 2>&5 || hard_links=no ln conftest.a conftest.b 2>/dev/null && hard_links=no { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 $as_echo "$hard_links" >&6; } if test "$hard_links" = no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5 $as_echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;} need_locks=warn fi else need_locks=no fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 $as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } runpath_var= allow_undefined_flag= always_export_symbols=no archive_cmds= archive_expsym_cmds= compiler_needs_object=no enable_shared_with_static_runtimes=no export_dynamic_flag_spec= export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' hardcode_automatic=no hardcode_direct=no hardcode_direct_absolute=no hardcode_libdir_flag_spec= hardcode_libdir_flag_spec_ld= hardcode_libdir_separator= hardcode_minus_L=no hardcode_shlibpath_var=unsupported inherit_rpath=no link_all_deplibs=unknown module_cmds= module_expsym_cmds= old_archive_from_new_cmds= old_archive_from_expsyms_cmds= thread_safe_flag_spec= whole_archive_flag_spec= # include_expsyms should be a list of space-separated symbols to be *always* # included in the symbol list include_expsyms= # exclude_expsyms can be an extended regexp of symbols to exclude # it will be wrapped by ` (' and `)$', so one must not match beginning or # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', # as well as any symbol that contains `d'. exclude_expsyms='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*' # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out # platforms (ab)use it in PIC code, but their linkers get confused if # the symbol is explicitly referenced. Since portable code cannot # rely on this symbol name, it's probably fine to never include it in # preloaded symbol tables. # Exclude shared library initialization/finalization symbols. extract_expsyms_cmds= case $host_os in cygwin* | mingw* | pw32* | cegcc*) # FIXME: the MSVC++ port hasn't been tested in a loooong time # When not using gcc, we currently assume that we are using # Microsoft Visual C++. if test "$GCC" != yes; then with_gnu_ld=no fi ;; interix*) # we just hope/assume this is gcc and not c89 (= MSVC++) with_gnu_ld=yes ;; openbsd*) with_gnu_ld=no ;; linux* | k*bsd*-gnu) link_all_deplibs=no ;; esac ld_shlibs=yes if test "$with_gnu_ld" = yes; then # If archive_cmds runs LD, not CC, wlarc should be empty wlarc='${wl}' # Set some defaults for GNU ld with shared library support. These # are reset later if shared libraries are not supported. Putting them # here allows them to be overridden if necessary. runpath_var=LD_RUN_PATH hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' export_dynamic_flag_spec='${wl}--export-dynamic' # ancient GNU ld didn't support --whole-archive et. al. if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then whole_archive_flag_spec="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' else whole_archive_flag_spec= fi supports_anon_versioning=no case `$LD -v 2>&1` in *GNU\ gold*) supports_anon_versioning=yes ;; *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11 *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... *\ 2.11.*) ;; # other 2.11 versions *) supports_anon_versioning=yes ;; esac # See if GNU ld supports shared libraries. case $host_os in aix[3-9]*) # On AIX/PPC, the GNU linker is very broken if test "$host_cpu" != ia64; then ld_shlibs=no cat <<_LT_EOF 1>&2 *** Warning: the GNU linker, at least up to release 2.9.1, is reported *** to be unable to reliably create shared libraries on AIX. *** Therefore, libtool is disabling shared libraries support. If you *** really care for shared libraries, you may want to modify your PATH *** so that a non-GNU linker is found, and then restart. _LT_EOF fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' archive_expsym_cmds='' ;; m68k) archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' hardcode_libdir_flag_spec='-L$libdir' hardcode_minus_L=yes ;; esac ;; beos*) if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then allow_undefined_flag=unsupported # Joseph Beckenbach says some releases of gcc # support --undefined. This deserves some investigation. FIXME archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' else ld_shlibs=no fi ;; cygwin* | mingw* | pw32* | cegcc*) # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless, # as there is no search path for DLLs. hardcode_libdir_flag_spec='-L$libdir' allow_undefined_flag=unsupported always_export_symbols=no enable_shared_with_static_runtimes=yes export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/'\'' | $SED -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols' if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' # If the export-symbols file already is a .def file (1st line # is EXPORTS), use it as is; otherwise, prepend... archive_expsym_cmds='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then cp $export_symbols $output_objdir/$soname.def; else echo EXPORTS > $output_objdir/$soname.def; cat $export_symbols >> $output_objdir/$soname.def; fi~ $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' else ld_shlibs=no fi ;; interix[3-9]*) hardcode_direct=no hardcode_shlibpath_var=no hardcode_libdir_flag_spec='${wl}-rpath,$libdir' export_dynamic_flag_spec='${wl}-E' # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. # Instead, shared libraries are loaded at an image base (0x10000000 by # default) and relocated if they conflict, which is a slow very memory # consuming and fragmenting process. To avoid this, we pick a random, # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link # time. Moving up from 0x10000000 also allows more sbrk(2) space. archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' archive_expsym_cmds='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' ;; gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) tmp_diet=no if test "$host_os" = linux-dietlibc; then case $cc_basename in diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) esac fi if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ && test "$tmp_diet" = no then tmp_addflag= tmp_sharedflag='-shared' case $cc_basename,$host_cpu in pgcc*) # Portland Group C compiler whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' tmp_addflag=' $pic_flag' ;; pgf77* | pgf90* | pgf95*) # Portland Group f77 and f90 compilers whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' tmp_addflag=' $pic_flag -Mnomain' ;; ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 tmp_addflag=' -i_dynamic' ;; efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 tmp_addflag=' -i_dynamic -nofor_main' ;; ifc* | ifort*) # Intel Fortran compiler tmp_addflag=' -nofor_main' ;; lf95*) # Lahey Fortran 8.1 whole_archive_flag_spec= tmp_sharedflag='--shared' ;; xl[cC]*) # IBM XL C 8.0 on PPC (deal with xlf below) tmp_sharedflag='-qmkshrobj' tmp_addflag= ;; esac case `$CC -V 2>&1 | sed 5q` in *Sun\ C*) # Sun C 5.9 whole_archive_flag_spec='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive' compiler_needs_object=yes tmp_sharedflag='-G' ;; *Sun\ F*) # Sun Fortran 8.3 tmp_sharedflag='-G' ;; esac archive_cmds='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' if test "x$supports_anon_versioning" = xyes; then archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' fi case $cc_basename in xlf*) # IBM XL Fortran 10.1 on PPC cannot create shared libs itself whole_archive_flag_spec='--whole-archive$convenience --no-whole-archive' hardcode_libdir_flag_spec= hardcode_libdir_flag_spec_ld='-rpath $libdir' archive_cmds='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib' if test "x$supports_anon_versioning" = xyes; then archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' fi ;; esac else ld_shlibs=no fi ;; netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= else archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' fi ;; solaris*) if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then ld_shlibs=no cat <<_LT_EOF 1>&2 *** Warning: The releases 2.8.* of the GNU linker cannot reliably *** create shared libraries on Solaris systems. Therefore, libtool *** is disabling shared libraries support. We urge you to upgrade GNU *** binutils to release 2.9.1 or newer. Another option is to modify *** your PATH or compiler configuration so that the native linker is *** used, and then restart. _LT_EOF elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' else ld_shlibs=no fi ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) case `$LD -v 2>&1` in *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) ld_shlibs=no cat <<_LT_EOF 1>&2 *** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not *** reliably create shared libraries on SCO systems. Therefore, libtool *** is disabling shared libraries support. We urge you to upgrade GNU *** binutils to release 2.16.91.0.3 or newer. Another option is to modify *** your PATH or compiler configuration so that the native linker is *** used, and then restart. _LT_EOF ;; *) # For security reasons, it is highly recommended that you always # use absolute paths for naming shared libraries, and exclude the # DT_RUNPATH tag from executables and libraries. But doing so # requires that you compile everything twice, which is a pain. if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' else ld_shlibs=no fi ;; esac ;; sunos4*) archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' wlarc= hardcode_direct=yes hardcode_shlibpath_var=no ;; *) if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' else ld_shlibs=no fi ;; esac if test "$ld_shlibs" = no; then runpath_var= hardcode_libdir_flag_spec= export_dynamic_flag_spec= whole_archive_flag_spec= fi else # PORTME fill in a description of your system's linker (not GNU ld) case $host_os in aix3*) allow_undefined_flag=unsupported always_export_symbols=yes archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' # Note: this linker hardcodes the directories in LIBPATH if there # are no directories specified by -L. hardcode_minus_L=yes if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then # Neither direct hardcoding nor static linking is supported with a # broken collect2. hardcode_direct=unsupported fi ;; aix[4-9]*) if test "$host_cpu" = ia64; then # On IA64, the linker does run time linking by default, so we don't # have to do anything special. aix_use_runtimelinking=no exp_sym_flag='-Bexport' no_entry_flag="" else # If we're using GNU nm, then we don't want the "-C" option. # -C means demangle to AIX nm, but means don't demangle with GNU nm if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' else export_symbols_cmds='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' fi aix_use_runtimelinking=no # Test if we are trying to use run time linking or normal # AIX style linking. If -brtl is somewhere in LDFLAGS, we # need to do runtime linking. case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) for ld_flag in $LDFLAGS; do if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then aix_use_runtimelinking=yes break fi done ;; esac exp_sym_flag='-bexport' no_entry_flag='-bnoentry' fi # When large executables or shared objects are built, AIX ld can # have problems creating the table of contents. If linking a library # or program results in "error TOC overflow" add -mminimal-toc to # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. archive_cmds='' hardcode_direct=yes hardcode_direct_absolute=yes hardcode_libdir_separator=':' link_all_deplibs=yes file_list_spec='${wl}-f,' if test "$GCC" = yes; then case $host_os in aix4.[012]|aix4.[012].*) # We only want to do this on AIX 4.2 and lower, the check # below for broken collect2 doesn't work under 4.3+ collect2name=`${CC} -print-prog-name=collect2` if test -f "$collect2name" && strings "$collect2name" | $GREP resolve_lib_name >/dev/null then # We have reworked collect2 : else # We have old collect2 hardcode_direct=unsupported # It fails to find uninstalled libraries when the uninstalled # path is not listed in the libpath. Setting hardcode_minus_L # to unsupported forces relinking hardcode_minus_L=yes hardcode_libdir_flag_spec='-L$libdir' hardcode_libdir_separator= fi ;; esac shared_flag='-shared' if test "$aix_use_runtimelinking" = yes; then shared_flag="$shared_flag "'${wl}-G' fi link_all_deplibs=no else # not using gcc if test "$host_cpu" = ia64; then # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release # chokes on -Wl,-G. The following line is correct: shared_flag='-G' else if test "$aix_use_runtimelinking" = yes; then shared_flag='${wl}-G' else shared_flag='${wl}-bM:SRE' fi fi fi export_dynamic_flag_spec='${wl}-bexpall' # It seems that -bexpall does not export symbols beginning with # underscore (_), so it is better to generate a list of symbols to export. always_export_symbols=yes if test "$aix_use_runtimelinking" = yes; then # Warning - without using the other runtime loading flags (-brtl), # -berok will link without error, but may produce a broken library. allow_undefined_flag='-berok' # Determine the default libpath from the value encoded in an # empty executable. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/ p } }' aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` # Check for a 64-bit object if we didn't find anything. if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" archive_expsym_cmds='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" else if test "$host_cpu" = ia64; then hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib' allow_undefined_flag="-z nodefs" archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" else # Determine the default libpath from the value encoded in an # empty executable. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/ p } }' aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` # Check for a 64-bit object if we didn't find anything. if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" # Warning - without using the other run time loading flags, # -berok will link without error, but may produce a broken library. no_undefined_flag=' ${wl}-bernotok' allow_undefined_flag=' ${wl}-berok' # Exported symbols can be pulled into shared objects from archives whole_archive_flag_spec='$convenience' archive_cmds_need_lc=yes # This is similar to how AIX traditionally builds its shared libraries. archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' fi fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' archive_expsym_cmds='' ;; m68k) archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' hardcode_libdir_flag_spec='-L$libdir' hardcode_minus_L=yes ;; esac ;; bsdi[45]*) export_dynamic_flag_spec=-rdynamic ;; cygwin* | mingw* | pw32* | cegcc*) # When not using gcc, we currently assume that we are using # Microsoft Visual C++. # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. hardcode_libdir_flag_spec=' ' allow_undefined_flag=unsupported # Tell ltmain to make .lib files, not .a files. libext=lib # Tell ltmain to make .dll files, not .so files. shrext_cmds=".dll" # FIXME: Setting linknames here is a bad hack. archive_cmds='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames=' # The linker will automatically build a .lib file if we build a DLL. old_archive_from_new_cmds='true' # FIXME: Should let the user specify the lib program. old_archive_cmds='lib -OUT:$oldlib$oldobjs$old_deplibs' fix_srcfile_path='`cygpath -w "$srcfile"`' enable_shared_with_static_runtimes=yes ;; darwin* | rhapsody*) archive_cmds_need_lc=no hardcode_direct=no hardcode_automatic=yes hardcode_shlibpath_var=unsupported whole_archive_flag_spec='' link_all_deplibs=yes allow_undefined_flag="$_lt_dar_allow_undefined" case $cc_basename in ifort*) _lt_dar_can_shared=yes ;; *) _lt_dar_can_shared=$GCC ;; esac if test "$_lt_dar_can_shared" = "yes"; then output_verbose_link_cmd=echo archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" else ld_shlibs=no fi ;; dgux*) archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_libdir_flag_spec='-L$libdir' hardcode_shlibpath_var=no ;; freebsd1*) ld_shlibs=no ;; # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor # support. Future versions do this automatically, but an explicit c++rt0.o # does not break anything, and helps significantly (at the cost of a little # extra space). freebsd2.2*) archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' hardcode_libdir_flag_spec='-R$libdir' hardcode_direct=yes hardcode_shlibpath_var=no ;; # Unfortunately, older versions of FreeBSD 2 do not have this feature. freebsd2*) archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' hardcode_direct=yes hardcode_minus_L=yes hardcode_shlibpath_var=no ;; # FreeBSD 3 and greater uses gcc -shared to do shared libraries. freebsd* | dragonfly*) archive_cmds='$CC -shared -o $lib $libobjs $deplibs $compiler_flags' hardcode_libdir_flag_spec='-R$libdir' hardcode_direct=yes hardcode_shlibpath_var=no ;; hpux9*) if test "$GCC" = yes; then archive_cmds='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' else archive_cmds='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' fi hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' hardcode_libdir_separator=: hardcode_direct=yes # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. hardcode_minus_L=yes export_dynamic_flag_spec='${wl}-E' ;; hpux10*) if test "$GCC" = yes -a "$with_gnu_ld" = no; then archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' else archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' fi if test "$with_gnu_ld" = no; then hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' hardcode_libdir_flag_spec_ld='+b $libdir' hardcode_libdir_separator=: hardcode_direct=yes hardcode_direct_absolute=yes export_dynamic_flag_spec='${wl}-E' # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. hardcode_minus_L=yes fi ;; hpux11*) if test "$GCC" = yes -a "$with_gnu_ld" = no; then case $host_cpu in hppa*64*) archive_cmds='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' ;; ia64*) archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' ;; *) archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' ;; esac else case $host_cpu in hppa*64*) archive_cmds='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' ;; ia64*) archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' ;; *) archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' ;; esac fi if test "$with_gnu_ld" = no; then hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' hardcode_libdir_separator=: case $host_cpu in hppa*64*|ia64*) hardcode_direct=no hardcode_shlibpath_var=no ;; *) hardcode_direct=yes hardcode_direct_absolute=yes export_dynamic_flag_spec='${wl}-E' # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. hardcode_minus_L=yes ;; esac fi ;; irix5* | irix6* | nonstopux*) if test "$GCC" = yes; then archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' # Try to use the -exported_symbol ld option, if it does not # work, assume that -exports_file does not work either and # implicitly export all symbols. save_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int foo(void) {} _ACEOF if ac_fn_c_try_link "$LINENO"; then : archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib' fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LDFLAGS="$save_LDFLAGS" else archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib' fi archive_cmds_need_lc='no' hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' hardcode_libdir_separator=: inherit_rpath=yes link_all_deplibs=yes ;; netbsd* | netbsdelf*-gnu) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF fi hardcode_libdir_flag_spec='-R$libdir' hardcode_direct=yes hardcode_shlibpath_var=no ;; newsos6) archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_direct=yes hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' hardcode_libdir_separator=: hardcode_shlibpath_var=no ;; *nto* | *qnx*) ;; openbsd*) if test -f /usr/libexec/ld.so; then hardcode_direct=yes hardcode_shlibpath_var=no hardcode_direct_absolute=yes if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' hardcode_libdir_flag_spec='${wl}-rpath,$libdir' export_dynamic_flag_spec='${wl}-E' else case $host_os in openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*) archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' hardcode_libdir_flag_spec='-R$libdir' ;; *) archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' hardcode_libdir_flag_spec='${wl}-rpath,$libdir' ;; esac fi else ld_shlibs=no fi ;; os2*) hardcode_libdir_flag_spec='-L$libdir' hardcode_minus_L=yes allow_undefined_flag=unsupported archive_cmds='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' old_archive_from_new_cmds='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' ;; osf3*) if test "$GCC" = yes; then allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*' archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' else allow_undefined_flag=' -expect_unresolved \*' archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' fi archive_cmds_need_lc='no' hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' hardcode_libdir_separator=: ;; osf4* | osf5*) # as osf3* with the addition of -msym flag if test "$GCC" = yes; then allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*' archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' else allow_undefined_flag=' -expect_unresolved \*' archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib' archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp' # Both c and cxx compiler support -rpath directly hardcode_libdir_flag_spec='-rpath $libdir' fi archive_cmds_need_lc='no' hardcode_libdir_separator=: ;; solaris*) no_undefined_flag=' -z defs' if test "$GCC" = yes; then wlarc='${wl}' archive_cmds='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' else case `$CC -V 2>&1` in *"Compilers 5.0"*) wlarc='' archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' ;; *) wlarc='${wl}' archive_cmds='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' ;; esac fi hardcode_libdir_flag_spec='-R$libdir' hardcode_shlibpath_var=no case $host_os in solaris2.[0-5] | solaris2.[0-5].*) ;; *) # The compiler driver will combine and reorder linker options, # but understands `-z linker_flag'. GCC discards it without `$wl', # but is careful enough not to reorder. # Supported since Solaris 2.6 (maybe 2.5.1?) if test "$GCC" = yes; then whole_archive_flag_spec='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' else whole_archive_flag_spec='-z allextract$convenience -z defaultextract' fi ;; esac link_all_deplibs=yes ;; sunos4*) if test "x$host_vendor" = xsequent; then # Use $CC to link under sequent, because it throws in some extra .o # files that make .init and .fini sections work. archive_cmds='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' else archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' fi hardcode_libdir_flag_spec='-L$libdir' hardcode_direct=yes hardcode_minus_L=yes hardcode_shlibpath_var=no ;; sysv4) case $host_vendor in sni) archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_direct=yes # is this really true??? ;; siemens) ## LD is ld it makes a PLAMLIB ## CC just makes a GrossModule. archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags' reload_cmds='$CC -r -o $output$reload_objs' hardcode_direct=no ;; motorola) archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_direct=no #Motorola manual says yes, but my tests say they lie ;; esac runpath_var='LD_RUN_PATH' hardcode_shlibpath_var=no ;; sysv4.3*) archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_shlibpath_var=no export_dynamic_flag_spec='-Bexport' ;; sysv4*MP*) if test -d /usr/nec; then archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_shlibpath_var=no runpath_var=LD_RUN_PATH hardcode_runpath_var=yes ld_shlibs=yes fi ;; sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) no_undefined_flag='${wl}-z,text' archive_cmds_need_lc=no hardcode_shlibpath_var=no runpath_var='LD_RUN_PATH' if test "$GCC" = yes; then archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' else archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' fi ;; sysv5* | sco3.2v5* | sco5v6*) # Note: We can NOT use -z defs as we might desire, because we do not # link with -lc, and that would cause any symbols used from libc to # always be unresolved, which means just about no library would # ever link correctly. If we're not using GNU ld we use -z text # though, which does catch some bad symbols but isn't as heavy-handed # as -z defs. no_undefined_flag='${wl}-z,text' allow_undefined_flag='${wl}-z,nodefs' archive_cmds_need_lc=no hardcode_shlibpath_var=no hardcode_libdir_flag_spec='${wl}-R,$libdir' hardcode_libdir_separator=':' link_all_deplibs=yes export_dynamic_flag_spec='${wl}-Bexport' runpath_var='LD_RUN_PATH' if test "$GCC" = yes; then archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' else archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' fi ;; uts4*) archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_libdir_flag_spec='-L$libdir' hardcode_shlibpath_var=no ;; *) ld_shlibs=no ;; esac if test x$host_vendor = xsni; then case $host in sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) export_dynamic_flag_spec='${wl}-Blargedynsym' ;; esac fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 $as_echo "$ld_shlibs" >&6; } test "$ld_shlibs" = no && can_build_shared=no with_gnu_ld=$with_gnu_ld # # Do we need to explicitly link libc? # case "x$archive_cmds_need_lc" in x|xyes) # Assume -lc should be added archive_cmds_need_lc=yes if test "$enable_shared" = yes && test "$GCC" = yes; then case $archive_cmds in *'~'*) # FIXME: we may have to deal with multi-command sequences. ;; '$CC '*) # Test whether the compiler implicitly links with -lc since on some # systems, -lgcc has to come before -lc. If gcc already passes -lc # to ld, don't add -lc before -lgcc. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 $as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } $RM conftest* echo "$lt_simple_compile_test_code" > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } 2>conftest.err; then soname=conftest lib=conftest libobjs=conftest.$ac_objext deplibs= wl=$lt_prog_compiler_wl pic_flag=$lt_prog_compiler_pic compiler_flags=-v linker_flags=-v verstring= output_objdir=. libname=conftest lt_save_allow_undefined_flag=$allow_undefined_flag allow_undefined_flag= if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then archive_cmds_need_lc=no else archive_cmds_need_lc=yes fi allow_undefined_flag=$lt_save_allow_undefined_flag else cat conftest.err 1>&5 fi $RM conftest* { $as_echo "$as_me:${as_lineno-$LINENO}: result: $archive_cmds_need_lc" >&5 $as_echo "$archive_cmds_need_lc" >&6; } ;; esac fi ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 $as_echo_n "checking dynamic linker characteristics... " >&6; } if test "$GCC" = yes; then case $host_os in darwin*) lt_awk_arg="/^libraries:/,/LR/" ;; *) lt_awk_arg="/^libraries:/" ;; esac lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"` if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then # if the path contains ";" then we assume it to be the separator # otherwise default to the standard path separator (i.e. ":") - it is # assumed that no part of a normal pathname contains ";" but that should # okay in the real world where ";" in dirpaths is itself problematic. lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'` else lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` fi # Ok, now we have the path, separated by spaces, we can step through it # and add multilib dir if necessary. lt_tmp_lt_search_path_spec= lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` for lt_sys_path in $lt_search_path_spec; do if test -d "$lt_sys_path/$lt_multi_os_dir"; then lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir" else test -d "$lt_sys_path" && \ lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" fi done lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk ' BEGIN {RS=" "; FS="/|\n";} { lt_foo=""; lt_count=0; for (lt_i = NF; lt_i > 0; lt_i--) { if ($lt_i != "" && $lt_i != ".") { if ($lt_i == "..") { lt_count++; } else { if (lt_count == 0) { lt_foo="/" $lt_i lt_foo; } else { lt_count--; } } } } if (lt_foo != "") { lt_freq[lt_foo]++; } if (lt_freq[lt_foo] == 1) { print lt_foo; } }'` sys_lib_search_path_spec=`$ECHO $lt_search_path_spec` else sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" fi library_names_spec= libname_spec='lib$name' soname_spec= shrext_cmds=".so" postinstall_cmds= postuninstall_cmds= finish_cmds= finish_eval= shlibpath_var= shlibpath_overrides_runpath=unknown version_type=none dynamic_linker="$host_os ld.so" sys_lib_dlsearch_path_spec="/lib /usr/lib" need_lib_prefix=unknown hardcode_into_libs=no # when you set need_version to no, make sure it does not cause -set_version # flags to be left without arguments need_version=unknown case $host_os in aix3*) version_type=linux library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' shlibpath_var=LIBPATH # AIX 3 has no versioning support, so we append a major version to the name. soname_spec='${libname}${release}${shared_ext}$major' ;; aix[4-9]*) version_type=linux need_lib_prefix=no need_version=no hardcode_into_libs=yes if test "$host_cpu" = ia64; then # AIX 5 supports IA64 library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH else # With GCC up to 2.95.x, collect2 would create an import file # for dependence libraries. The import file would start with # the line `#! .'. This would cause the generated library to # depend on `.', always an invalid library. This was fixed in # development snapshots of GCC prior to 3.0. case $host_os in aix4 | aix4.[01] | aix4.[01].*) if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' echo ' yes ' echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then : else can_build_shared=no fi ;; esac # AIX (on Power*) has no versioning support, so currently we can not hardcode correct # soname into executable. Probably we can add versioning support to # collect2, so additional links can be useful in future. if test "$aix_use_runtimelinking" = yes; then # If using run time linking (on AIX 4.2 or later) use lib.so # instead of lib.a to let people know that these are not # typical AIX shared libraries. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' else # We preserve .a as extension for shared libraries through AIX4.2 # and later when we are not doing run time linking. library_names_spec='${libname}${release}.a $libname.a' soname_spec='${libname}${release}${shared_ext}$major' fi shlibpath_var=LIBPATH fi ;; amigaos*) case $host_cpu in powerpc) # Since July 2007 AmigaOS4 officially supports .so libraries. # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' ;; m68k) library_names_spec='$libname.ixlibrary $libname.a' # Create ${libname}_ixlibrary.a entries in /sys/libs. finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' ;; esac ;; beos*) library_names_spec='${libname}${shared_ext}' dynamic_linker="$host_os ld.so" shlibpath_var=LIBRARY_PATH ;; bsdi[45]*) version_type=linux need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' shlibpath_var=LD_LIBRARY_PATH sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" # the default ld.so.conf also contains /usr/contrib/lib and # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow # libtool to hard-code these into programs ;; cygwin* | mingw* | pw32* | cegcc*) version_type=windows shrext_cmds=".dll" need_version=no need_lib_prefix=no case $GCC,$host_os in yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*) library_names_spec='$libname.dll.a' # DLL is installed to $(libdir)/../bin by postinstall_cmds postinstall_cmds='base_file=`basename \${file}`~ dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~ dldir=$destdir/`dirname \$dlpath`~ test -d \$dldir || mkdir -p \$dldir~ $install_prog $dir/$dlname \$dldir/$dlname~ chmod a+x \$dldir/$dlname~ if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; fi' postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ dlpath=$dir/\$dldll~ $RM \$dlpath' shlibpath_overrides_runpath=yes case $host_os in cygwin*) # Cygwin DLLs use 'cyg' prefix rather than 'lib' soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib" ;; mingw* | cegcc*) # MinGW DLLs use traditional 'lib' prefix soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then # It is most probably a Windows format PATH printed by # mingw gcc, but we are running on Cygwin. Gcc prints its search # path with ; separators, and with drive letters. We can handle the # drive letters (cygwin fileutils understands them), so leave them, # especially as we might pass files found there to a mingw objdump, # which wouldn't understand a cygwinified path. Ahh. sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` else sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` fi ;; pw32*) # pw32 DLLs use 'pw' prefix rather than 'lib' library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' ;; esac ;; *) library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib' ;; esac dynamic_linker='Win32 ld.exe' # FIXME: first we should search . and the directory the executable is in shlibpath_var=PATH ;; darwin* | rhapsody*) dynamic_linker="$host_os dyld" version_type=darwin need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext' soname_spec='${libname}${release}${major}$shared_ext' shlibpath_overrides_runpath=yes shlibpath_var=DYLD_LIBRARY_PATH shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib" sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' ;; dgux*) version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH ;; freebsd1*) dynamic_linker=no ;; freebsd* | dragonfly*) # DragonFly does not have aout. When/if they implement a new # versioning mechanism, adjust this. if test -x /usr/bin/objformat; then objformat=`/usr/bin/objformat` else case $host_os in freebsd[123]*) objformat=aout ;; *) objformat=elf ;; esac fi version_type=freebsd-$objformat case $version_type in freebsd-elf*) library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' need_version=no need_lib_prefix=no ;; freebsd-*) library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' need_version=yes ;; esac shlibpath_var=LD_LIBRARY_PATH case $host_os in freebsd2*) shlibpath_overrides_runpath=yes ;; freebsd3.[01]* | freebsdelf3.[01]*) shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; *) # from 4.6 on, and DragonFly shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; esac ;; gnu*) version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH hardcode_into_libs=yes ;; hpux9* | hpux10* | hpux11*) # Give a soname corresponding to the major version so that dld.sl refuses to # link against other versions. version_type=sunos need_lib_prefix=no need_version=no case $host_cpu in ia64*) shrext_cmds='.so' hardcode_into_libs=yes dynamic_linker="$host_os dld.so" shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' if test "X$HPUX_IA64_MODE" = X32; then sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" else sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" fi sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec ;; hppa*64*) shrext_cmds='.sl' hardcode_into_libs=yes dynamic_linker="$host_os dld.sl" shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec ;; *) shrext_cmds='.sl' dynamic_linker="$host_os dld.sl" shlibpath_var=SHLIB_PATH shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' ;; esac # HP-UX runs *really* slowly unless shared libraries are mode 555. postinstall_cmds='chmod 555 $lib' ;; interix[3-9]*) version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; irix5* | irix6* | nonstopux*) case $host_os in nonstopux*) version_type=nonstopux ;; *) if test "$lt_cv_prog_gnu_ld" = yes; then version_type=linux else version_type=irix fi ;; esac need_lib_prefix=no need_version=no soname_spec='${libname}${release}${shared_ext}$major' library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' case $host_os in irix5* | nonstopux*) libsuff= shlibsuff= ;; *) case $LD in # libtool.m4 will add one of these switches to LD *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") libsuff= shlibsuff= libmagic=32-bit;; *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") libsuff=32 shlibsuff=N32 libmagic=N32;; *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") libsuff=64 shlibsuff=64 libmagic=64-bit;; *) libsuff= shlibsuff= libmagic=never-match;; esac ;; esac shlibpath_var=LD_LIBRARY${shlibsuff}_PATH shlibpath_overrides_runpath=no sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" hardcode_into_libs=yes ;; # No shared lib support for Linux oldld, aout, or coff. linux*oldld* | linux*aout* | linux*coff*) dynamic_linker=no ;; # This must be Linux ELF. linux* | k*bsd*-gnu | kopensolaris*-gnu) version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no # Some binutils ld are patched to set DT_RUNPATH save_LDFLAGS=$LDFLAGS save_libdir=$libdir eval "libdir=/foo; wl=\"$lt_prog_compiler_wl\"; \ LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec\"" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : shlibpath_overrides_runpath=yes fi fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS libdir=$save_libdir # This implies no fast_install, which is unacceptable. # Some rework will be needed to allow for fast_install # before this can be enabled. hardcode_into_libs=yes # Append ld.so.conf contents to the search path if test -f /etc/ld.so.conf; then lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '` sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" fi # We used to test for /lib/ld.so.1 and disable shared libraries on # powerpc, because MkLinux only supported shared libraries with the # GNU dynamic linker. Since this was broken with cross compilers, # most powerpc-linux boxes support dynamic linking these days and # people can always --disable-shared, the test was removed, and we # assume the GNU/Linux dynamic linker is in use. dynamic_linker='GNU/Linux ld.so' ;; netbsdelf*-gnu) version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes dynamic_linker='NetBSD ld.elf_so' ;; netbsd*) version_type=sunos need_lib_prefix=no need_version=no if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' dynamic_linker='NetBSD (a.out) ld.so' else library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' dynamic_linker='NetBSD ld.elf_so' fi shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; newsos6) version_type=linux library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes ;; *nto* | *qnx*) version_type=qnx need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes dynamic_linker='ldqnx.so' ;; openbsd*) version_type=sunos sys_lib_dlsearch_path_spec="/usr/lib" need_lib_prefix=no # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. case $host_os in openbsd3.3 | openbsd3.3.*) need_version=yes ;; *) need_version=no ;; esac library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' shlibpath_var=LD_LIBRARY_PATH if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then case $host_os in openbsd2.[89] | openbsd2.[89].*) shlibpath_overrides_runpath=no ;; *) shlibpath_overrides_runpath=yes ;; esac else shlibpath_overrides_runpath=yes fi ;; os2*) libname_spec='$name' shrext_cmds=".dll" need_lib_prefix=no library_names_spec='$libname${shared_ext} $libname.a' dynamic_linker='OS/2 ld.exe' shlibpath_var=LIBPATH ;; osf3* | osf4* | osf5*) version_type=osf need_lib_prefix=no need_version=no soname_spec='${libname}${release}${shared_ext}$major' library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" ;; rdos*) dynamic_linker=no ;; solaris*) version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes # ldd complains unless libraries are executable postinstall_cmds='chmod +x $lib' ;; sunos4*) version_type=sunos library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes if test "$with_gnu_ld" = yes; then need_lib_prefix=no fi need_version=yes ;; sysv4 | sysv4.3*) version_type=linux library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH case $host_vendor in sni) shlibpath_overrides_runpath=no need_lib_prefix=no runpath_var=LD_RUN_PATH ;; siemens) need_lib_prefix=no ;; motorola) need_lib_prefix=no need_version=no shlibpath_overrides_runpath=no sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' ;; esac ;; sysv4*MP*) if test -d /usr/nec ;then version_type=linux library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' soname_spec='$libname${shared_ext}.$major' shlibpath_var=LD_LIBRARY_PATH fi ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) version_type=freebsd-elf need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes if test "$with_gnu_ld" = yes; then sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' else sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' case $host_os in sco3.2v5*) sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" ;; esac fi sys_lib_dlsearch_path_spec='/usr/lib' ;; tpf*) # TPF is a cross-target only. Preferred cross-host = GNU/Linux. version_type=linux need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; uts4*) version_type=linux library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH ;; *) dynamic_linker=no ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 $as_echo "$dynamic_linker" >&6; } test "$dynamic_linker" = no && can_build_shared=no variables_saved_for_relink="PATH $shlibpath_var $runpath_var" if test "$GCC" = yes; then variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" fi if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec" fi if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 $as_echo_n "checking how to hardcode library paths into programs... " >&6; } hardcode_action= if test -n "$hardcode_libdir_flag_spec" || test -n "$runpath_var" || test "X$hardcode_automatic" = "Xyes" ; then # We can hardcode non-existent directories. if test "$hardcode_direct" != no && # If the only mechanism to avoid hardcoding is shlibpath_var, we # have to relink, otherwise we might link with an installed library # when we should be linking with a yet-to-be-installed one ## test "$_LT_TAGVAR(hardcode_shlibpath_var, )" != no && test "$hardcode_minus_L" != no; then # Linking always hardcodes the temporary library directory. hardcode_action=relink else # We can link without hardcoding, and we can hardcode nonexisting dirs. hardcode_action=immediate fi else # We cannot hardcode anything, or else we can only hardcode existing # directories. hardcode_action=unsupported fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 $as_echo "$hardcode_action" >&6; } if test "$hardcode_action" = relink || test "$inherit_rpath" = yes; then # Fast installation is not supported enable_fast_install=no elif test "$shlibpath_overrides_runpath" = yes || test "$enable_shared" = no; then # Fast installation is not necessary enable_fast_install=needless fi if test "x$enable_dlopen" != xyes; then enable_dlopen=unknown enable_dlopen_self=unknown enable_dlopen_self_static=unknown else lt_cv_dlopen=no lt_cv_dlopen_libs= case $host_os in beos*) lt_cv_dlopen="load_add_on" lt_cv_dlopen_libs= lt_cv_dlopen_self=yes ;; mingw* | pw32* | cegcc*) lt_cv_dlopen="LoadLibrary" lt_cv_dlopen_libs= ;; cygwin*) lt_cv_dlopen="dlopen" lt_cv_dlopen_libs= ;; darwin*) # if libdl is installed we need to link against it { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 $as_echo_n "checking for dlopen in -ldl... " >&6; } if test "${ac_cv_lib_dl_dlopen+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char dlopen (); int main () { return dlopen (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_dl_dlopen=yes else ac_cv_lib_dl_dlopen=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 $as_echo "$ac_cv_lib_dl_dlopen" >&6; } if test "x$ac_cv_lib_dl_dlopen" = x""yes; then : lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl" else lt_cv_dlopen="dyld" lt_cv_dlopen_libs= lt_cv_dlopen_self=yes fi ;; *) ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load" if test "x$ac_cv_func_shl_load" = x""yes; then : lt_cv_dlopen="shl_load" else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 $as_echo_n "checking for shl_load in -ldld... " >&6; } if test "${ac_cv_lib_dld_shl_load+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char shl_load (); int main () { return shl_load (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_dld_shl_load=yes else ac_cv_lib_dld_shl_load=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 $as_echo "$ac_cv_lib_dld_shl_load" >&6; } if test "x$ac_cv_lib_dld_shl_load" = x""yes; then : lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld" else ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen" if test "x$ac_cv_func_dlopen" = x""yes; then : lt_cv_dlopen="dlopen" else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 $as_echo_n "checking for dlopen in -ldl... " >&6; } if test "${ac_cv_lib_dl_dlopen+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char dlopen (); int main () { return dlopen (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_dl_dlopen=yes else ac_cv_lib_dl_dlopen=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 $as_echo "$ac_cv_lib_dl_dlopen" >&6; } if test "x$ac_cv_lib_dl_dlopen" = x""yes; then : lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl" else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 $as_echo_n "checking for dlopen in -lsvld... " >&6; } if test "${ac_cv_lib_svld_dlopen+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lsvld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char dlopen (); int main () { return dlopen (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_svld_dlopen=yes else ac_cv_lib_svld_dlopen=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 $as_echo "$ac_cv_lib_svld_dlopen" >&6; } if test "x$ac_cv_lib_svld_dlopen" = x""yes; then : lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld" else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 $as_echo_n "checking for dld_link in -ldld... " >&6; } if test "${ac_cv_lib_dld_dld_link+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char dld_link (); int main () { return dld_link (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_dld_dld_link=yes else ac_cv_lib_dld_dld_link=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 $as_echo "$ac_cv_lib_dld_dld_link" >&6; } if test "x$ac_cv_lib_dld_dld_link" = x""yes; then : lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld" fi fi fi fi fi fi ;; esac if test "x$lt_cv_dlopen" != xno; then enable_dlopen=yes else enable_dlopen=no fi case $lt_cv_dlopen in dlopen) save_CPPFLAGS="$CPPFLAGS" test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" save_LDFLAGS="$LDFLAGS" wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" save_LIBS="$LIBS" LIBS="$lt_cv_dlopen_libs $LIBS" { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5 $as_echo_n "checking whether a program can dlopen itself... " >&6; } if test "${lt_cv_dlopen_self+set}" = set; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : lt_cv_dlopen_self=cross else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF #line 10576 "configure" #include "confdefs.h" #if HAVE_DLFCN_H #include #endif #include #ifdef RTLD_GLOBAL # define LT_DLGLOBAL RTLD_GLOBAL #else # ifdef DL_GLOBAL # define LT_DLGLOBAL DL_GLOBAL # else # define LT_DLGLOBAL 0 # endif #endif /* We may have to define LT_DLLAZY_OR_NOW in the command line if we find out it does not work in some platform. */ #ifndef LT_DLLAZY_OR_NOW # ifdef RTLD_LAZY # define LT_DLLAZY_OR_NOW RTLD_LAZY # else # ifdef DL_LAZY # define LT_DLLAZY_OR_NOW DL_LAZY # else # ifdef RTLD_NOW # define LT_DLLAZY_OR_NOW RTLD_NOW # else # ifdef DL_NOW # define LT_DLLAZY_OR_NOW DL_NOW # else # define LT_DLLAZY_OR_NOW 0 # endif # endif # endif # endif #endif void fnord() { int i=42;} int main () { void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); int status = $lt_dlunknown; if (self) { if (dlsym (self,"fnord")) status = $lt_dlno_uscore; else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; /* dlclose (self); */ } else puts (dlerror ()); return status; } _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 (eval $ac_link) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then (./conftest; exit; ) >&5 2>/dev/null lt_status=$? case x$lt_status in x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;; x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;; x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;; esac else : # compilation failed lt_cv_dlopen_self=no fi fi rm -fr conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 $as_echo "$lt_cv_dlopen_self" >&6; } if test "x$lt_cv_dlopen_self" = xyes; then wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5 $as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; } if test "${lt_cv_dlopen_self_static+set}" = set; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : lt_cv_dlopen_self_static=cross else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF #line 10672 "configure" #include "confdefs.h" #if HAVE_DLFCN_H #include #endif #include #ifdef RTLD_GLOBAL # define LT_DLGLOBAL RTLD_GLOBAL #else # ifdef DL_GLOBAL # define LT_DLGLOBAL DL_GLOBAL # else # define LT_DLGLOBAL 0 # endif #endif /* We may have to define LT_DLLAZY_OR_NOW in the command line if we find out it does not work in some platform. */ #ifndef LT_DLLAZY_OR_NOW # ifdef RTLD_LAZY # define LT_DLLAZY_OR_NOW RTLD_LAZY # else # ifdef DL_LAZY # define LT_DLLAZY_OR_NOW DL_LAZY # else # ifdef RTLD_NOW # define LT_DLLAZY_OR_NOW RTLD_NOW # else # ifdef DL_NOW # define LT_DLLAZY_OR_NOW DL_NOW # else # define LT_DLLAZY_OR_NOW 0 # endif # endif # endif # endif #endif void fnord() { int i=42;} int main () { void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); int status = $lt_dlunknown; if (self) { if (dlsym (self,"fnord")) status = $lt_dlno_uscore; else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; /* dlclose (self); */ } else puts (dlerror ()); return status; } _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 (eval $ac_link) 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then (./conftest; exit; ) >&5 2>/dev/null lt_status=$? case x$lt_status in x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;; x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;; x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;; esac else : # compilation failed lt_cv_dlopen_self_static=no fi fi rm -fr conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 $as_echo "$lt_cv_dlopen_self_static" >&6; } fi CPPFLAGS="$save_CPPFLAGS" LDFLAGS="$save_LDFLAGS" LIBS="$save_LIBS" ;; esac case $lt_cv_dlopen_self in yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; *) enable_dlopen_self=unknown ;; esac case $lt_cv_dlopen_self_static in yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; *) enable_dlopen_self_static=unknown ;; esac fi striplib= old_striplib= { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 $as_echo_n "checking whether stripping libraries is possible... " >&6; } if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" test -z "$striplib" && striplib="$STRIP --strip-unneeded" { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } else # FIXME - insert some real tests, host_os isn't really good enough case $host_os in darwin*) if test -n "$STRIP" ; then striplib="$STRIP -x" old_striplib="$STRIP -S" { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi ;; *) { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } ;; esac fi # Report which library types will actually be built { $as_echo "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 $as_echo_n "checking if libtool supports shared libraries... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 $as_echo "$can_build_shared" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 $as_echo_n "checking whether to build shared libraries... " >&6; } test "$can_build_shared" = "no" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and # are all built from PIC. case $host_os in aix3*) test "$enable_shared" = yes && enable_static=no if test -n "$RANLIB"; then archive_cmds="$archive_cmds~\$RANLIB \$lib" postinstall_cmds='$RANLIB $lib' fi ;; aix[4-9]*) if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then test "$enable_shared" = yes && enable_static=no fi ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 $as_echo "$enable_shared" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 $as_echo_n "checking whether to build static libraries... " >&6; } # Make sure either enable_shared or enable_static is yes. test "$enable_shared" = yes || enable_static=yes { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 $as_echo "$enable_static" >&6; } fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu CC="$lt_save_CC" ac_config_commands="$ac_config_commands libtool" # Only expand once: { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether NLS is requested" >&5 $as_echo_n "checking whether NLS is requested... " >&6; } # Check whether --enable-nls was given. if test "${enable_nls+set}" = set; then : enableval=$enable_nls; USE_NLS=$enableval else USE_NLS=yes fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_NLS" >&5 $as_echo "$USE_NLS" >&6; } GETTEXT_MACRO_VERSION=0.17 # Prepare PATH_SEPARATOR. # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then echo "#! /bin/sh" >conf$$.sh echo "exit 0" >>conf$$.sh chmod +x conf$$.sh if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then PATH_SEPARATOR=';' else PATH_SEPARATOR=: fi rm -f conf$$.sh fi # Find out how to test for executable files. Don't use a zero-byte file, # as systems may use methods other than mode bits to determine executability. cat >conf$$.file <<_ASEOF #! /bin/sh exit 0 _ASEOF chmod +x conf$$.file if test -x conf$$.file >/dev/null 2>&1; then ac_executable_p="test -x" else ac_executable_p="test -f" fi rm -f conf$$.file # Extract the first word of "msgfmt", so it can be a program name with args. set dummy msgfmt; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_path_MSGFMT+set}" = set; then : $as_echo_n "(cached) " >&6 else case "$MSGFMT" in [\\/]* | ?:[\\/]*) ac_cv_path_MSGFMT="$MSGFMT" # Let the user override the test with a path. ;; *) ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do IFS="$ac_save_IFS" test -z "$ac_dir" && ac_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then echo "$as_me: trying $ac_dir/$ac_word..." >&5 if $ac_dir/$ac_word --statistics /dev/null >&5 2>&1 && (if $ac_dir/$ac_word --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then ac_cv_path_MSGFMT="$ac_dir/$ac_word$ac_exec_ext" break 2 fi fi done done IFS="$ac_save_IFS" test -z "$ac_cv_path_MSGFMT" && ac_cv_path_MSGFMT=":" ;; esac fi MSGFMT="$ac_cv_path_MSGFMT" if test "$MSGFMT" != ":"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MSGFMT" >&5 $as_echo "$MSGFMT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi # Extract the first word of "gmsgfmt", so it can be a program name with args. set dummy gmsgfmt; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_path_GMSGFMT+set}" = set; then : $as_echo_n "(cached) " >&6 else case $GMSGFMT in [\\/]* | ?:[\\/]*) ac_cv_path_GMSGFMT="$GMSGFMT" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_GMSGFMT="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS test -z "$ac_cv_path_GMSGFMT" && ac_cv_path_GMSGFMT="$MSGFMT" ;; esac fi GMSGFMT=$ac_cv_path_GMSGFMT if test -n "$GMSGFMT"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GMSGFMT" >&5 $as_echo "$GMSGFMT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi case `$MSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) MSGFMT_015=: ;; *) MSGFMT_015=$MSGFMT ;; esac case `$GMSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) GMSGFMT_015=: ;; *) GMSGFMT_015=$GMSGFMT ;; esac # Prepare PATH_SEPARATOR. # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then echo "#! /bin/sh" >conf$$.sh echo "exit 0" >>conf$$.sh chmod +x conf$$.sh if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then PATH_SEPARATOR=';' else PATH_SEPARATOR=: fi rm -f conf$$.sh fi # Find out how to test for executable files. Don't use a zero-byte file, # as systems may use methods other than mode bits to determine executability. cat >conf$$.file <<_ASEOF #! /bin/sh exit 0 _ASEOF chmod +x conf$$.file if test -x conf$$.file >/dev/null 2>&1; then ac_executable_p="test -x" else ac_executable_p="test -f" fi rm -f conf$$.file # Extract the first word of "xgettext", so it can be a program name with args. set dummy xgettext; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_path_XGETTEXT+set}" = set; then : $as_echo_n "(cached) " >&6 else case "$XGETTEXT" in [\\/]* | ?:[\\/]*) ac_cv_path_XGETTEXT="$XGETTEXT" # Let the user override the test with a path. ;; *) ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do IFS="$ac_save_IFS" test -z "$ac_dir" && ac_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then echo "$as_me: trying $ac_dir/$ac_word..." >&5 if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >&5 2>&1 && (if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi); then ac_cv_path_XGETTEXT="$ac_dir/$ac_word$ac_exec_ext" break 2 fi fi done done IFS="$ac_save_IFS" test -z "$ac_cv_path_XGETTEXT" && ac_cv_path_XGETTEXT=":" ;; esac fi XGETTEXT="$ac_cv_path_XGETTEXT" if test "$XGETTEXT" != ":"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XGETTEXT" >&5 $as_echo "$XGETTEXT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi rm -f messages.po case `$XGETTEXT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) XGETTEXT_015=: ;; *) XGETTEXT_015=$XGETTEXT ;; esac # Prepare PATH_SEPARATOR. # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then echo "#! /bin/sh" >conf$$.sh echo "exit 0" >>conf$$.sh chmod +x conf$$.sh if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then PATH_SEPARATOR=';' else PATH_SEPARATOR=: fi rm -f conf$$.sh fi # Find out how to test for executable files. Don't use a zero-byte file, # as systems may use methods other than mode bits to determine executability. cat >conf$$.file <<_ASEOF #! /bin/sh exit 0 _ASEOF chmod +x conf$$.file if test -x conf$$.file >/dev/null 2>&1; then ac_executable_p="test -x" else ac_executable_p="test -f" fi rm -f conf$$.file # Extract the first word of "msgmerge", so it can be a program name with args. set dummy msgmerge; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_path_MSGMERGE+set}" = set; then : $as_echo_n "(cached) " >&6 else case "$MSGMERGE" in [\\/]* | ?:[\\/]*) ac_cv_path_MSGMERGE="$MSGMERGE" # Let the user override the test with a path. ;; *) ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do IFS="$ac_save_IFS" test -z "$ac_dir" && ac_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then echo "$as_me: trying $ac_dir/$ac_word..." >&5 if $ac_dir/$ac_word --update -q /dev/null /dev/null >&5 2>&1; then ac_cv_path_MSGMERGE="$ac_dir/$ac_word$ac_exec_ext" break 2 fi fi done done IFS="$ac_save_IFS" test -z "$ac_cv_path_MSGMERGE" && ac_cv_path_MSGMERGE=":" ;; esac fi MSGMERGE="$ac_cv_path_MSGMERGE" if test "$MSGMERGE" != ":"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MSGMERGE" >&5 $as_echo "$MSGMERGE" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$localedir" || localedir='${datadir}/locale' test -n "${XGETTEXT_EXTRA_OPTIONS+set}" || XGETTEXT_EXTRA_OPTIONS= ac_config_commands="$ac_config_commands po-directories" { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C Library 2 or newer" >&5 $as_echo_n "checking whether we are using the GNU C Library 2 or newer... " >&6; } if test "${ac_cv_gnu_library_2+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #ifdef __GNU_LIBRARY__ #if (__GLIBC__ >= 2) Lucky GNU user #endif #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "Lucky GNU user" >/dev/null 2>&1; then : ac_cv_gnu_library_2=yes else ac_cv_gnu_library_2=no fi rm -f conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_gnu_library_2" >&5 $as_echo "$ac_cv_gnu_library_2" >&6; } GLIBC2="$ac_cv_gnu_library_2" if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. set dummy ${ac_tool_prefix}ranlib; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_RANLIB+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi RANLIB=$ac_cv_prog_RANLIB if test -n "$RANLIB"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 $as_echo "$RANLIB" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_RANLIB"; then ac_ct_RANLIB=$RANLIB # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_RANLIB"; then ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_RANLIB="ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB if test -n "$ac_ct_RANLIB"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 $as_echo "$ac_ct_RANLIB" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_RANLIB" = x; then RANLIB=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac RANLIB=$ac_ct_RANLIB fi else RANLIB="$ac_cv_prog_RANLIB" fi CFLAG_VISIBILITY= HAVE_VISIBILITY=0 if test -n "$GCC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for simple visibility declarations" >&5 $as_echo_n "checking for simple visibility declarations... " >&6; } if test "${gl_cv_cc_visibility+set}" = set; then : $as_echo_n "(cached) " >&6 else gl_save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -fvisibility=hidden" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ extern __attribute__((__visibility__("hidden"))) int hiddenvar; extern __attribute__((__visibility__("default"))) int exportedvar; extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void); extern __attribute__((__visibility__("default"))) int exportedfunc (void); int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : gl_cv_cc_visibility=yes else gl_cv_cc_visibility=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext CFLAGS="$gl_save_CFLAGS" fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_cc_visibility" >&5 $as_echo "$gl_cv_cc_visibility" >&6; } if test $gl_cv_cc_visibility = yes; then CFLAG_VISIBILITY="-fvisibility=hidden" HAVE_VISIBILITY=1 fi fi cat >>confdefs.h <<_ACEOF #define HAVE_VISIBILITY $HAVE_VISIBILITY _ACEOF { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline" >&5 $as_echo_n "checking for inline... " >&6; } if test "${ac_cv_c_inline+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_cv_c_inline=no for ac_kw in inline __inline__ __inline; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifndef __cplusplus typedef int foo_t; static $ac_kw foo_t static_foo () {return 0; } $ac_kw foo_t foo () {return 0; } #endif _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_inline=$ac_kw fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext test "$ac_cv_c_inline" != no && break done fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5 $as_echo "$ac_cv_c_inline" >&6; } case $ac_cv_c_inline in inline | yes) ;; *) case $ac_cv_c_inline in no) ac_val=;; *) ac_val=$ac_cv_c_inline;; esac cat >>confdefs.h <<_ACEOF #ifndef __cplusplus #define inline $ac_val #endif _ACEOF ;; esac ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default" if test "x$ac_cv_type_size_t" = x""yes; then : else cat >>confdefs.h <<_ACEOF #define size_t unsigned int _ACEOF fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdint.h" >&5 $as_echo_n "checking for stdint.h... " >&6; } if test "${gl_cv_header_stdint_h+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main () { uintmax_t i = (uintmax_t) -1; return !i; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : gl_cv_header_stdint_h=yes else gl_cv_header_stdint_h=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_header_stdint_h" >&5 $as_echo "$gl_cv_header_stdint_h" >&6; } if test $gl_cv_header_stdint_h = yes; then cat >>confdefs.h <<_ACEOF #define HAVE_STDINT_H_WITH_UINTMAX 1 _ACEOF fi # The Ultrix 4.2 mips builtin alloca declared by alloca.h only works # for constant arguments. Useless! { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working alloca.h" >&5 $as_echo_n "checking for working alloca.h... " >&6; } if test "${ac_cv_working_alloca_h+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { char *p = (char *) alloca (2 * sizeof (int)); if (p) return 0; ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_working_alloca_h=yes else ac_cv_working_alloca_h=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_working_alloca_h" >&5 $as_echo "$ac_cv_working_alloca_h" >&6; } if test $ac_cv_working_alloca_h = yes; then $as_echo "#define HAVE_ALLOCA_H 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for alloca" >&5 $as_echo_n "checking for alloca... " >&6; } if test "${ac_cv_func_alloca_works+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __GNUC__ # define alloca __builtin_alloca #else # ifdef _MSC_VER # include # define alloca _alloca # else # ifdef HAVE_ALLOCA_H # include # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ char *alloca (); # endif # endif # endif # endif #endif int main () { char *p = (char *) alloca (1); if (p) return 0; ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_func_alloca_works=yes else ac_cv_func_alloca_works=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_alloca_works" >&5 $as_echo "$ac_cv_func_alloca_works" >&6; } if test $ac_cv_func_alloca_works = yes; then $as_echo "#define HAVE_ALLOCA 1" >>confdefs.h else # The SVR3 libPW and SVR4 libucb both contain incompatible functions # that cause trouble. Some versions do not even contain alloca or # contain a buggy version. If you still want to use their alloca, # use ar to extract alloca.o from them instead of compiling alloca.c. ALLOCA=\${LIBOBJDIR}alloca.$ac_objext $as_echo "#define C_ALLOCA 1" >>confdefs.h { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether \`alloca.c' needs Cray hooks" >&5 $as_echo_n "checking whether \`alloca.c' needs Cray hooks... " >&6; } if test "${ac_cv_os_cray+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #if defined CRAY && ! defined CRAY2 webecray #else wenotbecray #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "webecray" >/dev/null 2>&1; then : ac_cv_os_cray=yes else ac_cv_os_cray=no fi rm -f conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_os_cray" >&5 $as_echo "$ac_cv_os_cray" >&6; } if test $ac_cv_os_cray = yes; then for ac_func in _getb67 GETB67 getb67; do as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define CRAY_STACKSEG_END $ac_func _ACEOF break fi done fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking stack direction for C alloca" >&5 $as_echo_n "checking stack direction for C alloca... " >&6; } if test "${ac_cv_c_stack_direction+set}" = set; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : ac_cv_c_stack_direction=0 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int find_stack_direction () { static char *addr = 0; auto char dummy; if (addr == 0) { addr = &dummy; return find_stack_direction (); } else return (&dummy > addr) ? 1 : -1; } int main () { return find_stack_direction () < 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_c_stack_direction=1 else ac_cv_c_stack_direction=-1 fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_stack_direction" >&5 $as_echo "$ac_cv_c_stack_direction" >&6; } cat >>confdefs.h <<_ACEOF #define STACK_DIRECTION $ac_cv_c_stack_direction _ACEOF fi for ac_header in $ac_header_list do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default " if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done for ac_func in getpagesize do : ac_fn_c_check_func "$LINENO" "getpagesize" "ac_cv_func_getpagesize" if test "x$ac_cv_func_getpagesize" = x""yes; then : cat >>confdefs.h <<_ACEOF #define HAVE_GETPAGESIZE 1 _ACEOF fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working mmap" >&5 $as_echo_n "checking for working mmap... " >&6; } if test "${ac_cv_func_mmap_fixed_mapped+set}" = set; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : ac_cv_func_mmap_fixed_mapped=no else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default /* malloc might have been renamed as rpl_malloc. */ #undef malloc /* Thanks to Mike Haertel and Jim Avera for this test. Here is a matrix of mmap possibilities: mmap private not fixed mmap private fixed at somewhere currently unmapped mmap private fixed at somewhere already mapped mmap shared not fixed mmap shared fixed at somewhere currently unmapped mmap shared fixed at somewhere already mapped For private mappings, we should verify that changes cannot be read() back from the file, nor mmap's back from the file at a different address. (There have been systems where private was not correctly implemented like the infamous i386 svr4.0, and systems where the VM page cache was not coherent with the file system buffer cache like early versions of FreeBSD and possibly contemporary NetBSD.) For shared mappings, we should conversely verify that changes get propagated back to all the places they're supposed to be. Grep wants private fixed already mapped. The main things grep needs to know about mmap are: * does it exist and is it safe to write into the mmap'd area * how to use it (BSD variants) */ #include #include #if !defined STDC_HEADERS && !defined HAVE_STDLIB_H char *malloc (); #endif /* This mess was copied from the GNU getpagesize.h. */ #ifndef HAVE_GETPAGESIZE # ifdef _SC_PAGESIZE # define getpagesize() sysconf(_SC_PAGESIZE) # else /* no _SC_PAGESIZE */ # ifdef HAVE_SYS_PARAM_H # include # ifdef EXEC_PAGESIZE # define getpagesize() EXEC_PAGESIZE # else /* no EXEC_PAGESIZE */ # ifdef NBPG # define getpagesize() NBPG * CLSIZE # ifndef CLSIZE # define CLSIZE 1 # endif /* no CLSIZE */ # else /* no NBPG */ # ifdef NBPC # define getpagesize() NBPC # else /* no NBPC */ # ifdef PAGESIZE # define getpagesize() PAGESIZE # endif /* PAGESIZE */ # endif /* no NBPC */ # endif /* no NBPG */ # endif /* no EXEC_PAGESIZE */ # else /* no HAVE_SYS_PARAM_H */ # define getpagesize() 8192 /* punt totally */ # endif /* no HAVE_SYS_PARAM_H */ # endif /* no _SC_PAGESIZE */ #endif /* no HAVE_GETPAGESIZE */ int main () { char *data, *data2, *data3; const char *cdata2; int i, pagesize; int fd, fd2; pagesize = getpagesize (); /* First, make a file with some known garbage in it. */ data = (char *) malloc (pagesize); if (!data) return 1; for (i = 0; i < pagesize; ++i) *(data + i) = rand (); umask (0); fd = creat ("conftest.mmap", 0600); if (fd < 0) return 2; if (write (fd, data, pagesize) != pagesize) return 3; close (fd); /* Next, check that the tail of a page is zero-filled. File must have non-zero length, otherwise we risk SIGBUS for entire page. */ fd2 = open ("conftest.txt", O_RDWR | O_CREAT | O_TRUNC, 0600); if (fd2 < 0) return 4; cdata2 = ""; if (write (fd2, cdata2, 1) != 1) return 5; data2 = (char *) mmap (0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd2, 0L); if (data2 == MAP_FAILED) return 6; for (i = 0; i < pagesize; ++i) if (*(data2 + i)) return 7; close (fd2); if (munmap (data2, pagesize)) return 8; /* Next, try to mmap the file at a fixed address which already has something else allocated at it. If we can, also make sure that we see the same garbage. */ fd = open ("conftest.mmap", O_RDWR); if (fd < 0) return 9; if (data2 != mmap (data2, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, fd, 0L)) return 10; for (i = 0; i < pagesize; ++i) if (*(data + i) != *(data2 + i)) return 11; /* Finally, make sure that changes to the mapped area do not percolate back to the file as seen by read(). (This is a bug on some variants of i386 svr4.0.) */ for (i = 0; i < pagesize; ++i) *(data2 + i) = *(data2 + i) + 1; data3 = (char *) malloc (pagesize); if (!data3) return 12; if (read (fd, data3, pagesize) != pagesize) return 13; for (i = 0; i < pagesize; ++i) if (*(data + i) != *(data3 + i)) return 14; close (fd); return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_func_mmap_fixed_mapped=yes else ac_cv_func_mmap_fixed_mapped=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_mmap_fixed_mapped" >&5 $as_echo "$ac_cv_func_mmap_fixed_mapped" >&6; } if test $ac_cv_func_mmap_fixed_mapped = yes; then $as_echo "#define HAVE_MMAP 1" >>confdefs.h fi rm -f conftest.mmap conftest.txt { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether integer division by zero raises SIGFPE" >&5 $as_echo_n "checking whether integer division by zero raises SIGFPE... " >&6; } if test "${gt_cv_int_divbyzero_sigfpe+set}" = set; then : $as_echo_n "(cached) " >&6 else gt_cv_int_divbyzero_sigfpe= case "$host_os" in macos* | darwin[6-9]* | darwin[1-9][0-9]*) # On MacOS X 10.2 or newer, just assume the same as when cross- # compiling. If we were to perform the real test, 1 Crash Report # dialog window would pop up. case "$host_cpu" in i[34567]86 | x86_64) gt_cv_int_divbyzero_sigfpe="guessing yes" ;; esac ;; esac if test -z "$gt_cv_int_divbyzero_sigfpe"; then if test "$cross_compiling" = yes; then : # Guess based on the CPU. case "$host_cpu" in alpha* | i[34567]86 | x86_64 | m68k | s390*) gt_cv_int_divbyzero_sigfpe="guessing yes";; *) gt_cv_int_divbyzero_sigfpe="guessing no";; esac else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include static void sigfpe_handler (int sig) { /* Exit with code 0 if SIGFPE, with code 1 if any other signal. */ exit (sig != SIGFPE); } int x = 1; int y = 0; int z; int nan; int main () { signal (SIGFPE, sigfpe_handler); /* IRIX and AIX (when "xlc -qcheck" is used) yield signal SIGTRAP. */ #if (defined (__sgi) || defined (_AIX)) && defined (SIGTRAP) signal (SIGTRAP, sigfpe_handler); #endif /* Linux/SPARC yields signal SIGILL. */ #if defined (__sparc__) && defined (__linux__) signal (SIGILL, sigfpe_handler); #endif z = x / y; nan = y / y; exit (1); } _ACEOF if ac_fn_c_try_run "$LINENO"; then : gt_cv_int_divbyzero_sigfpe=yes else gt_cv_int_divbyzero_sigfpe=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_int_divbyzero_sigfpe" >&5 $as_echo "$gt_cv_int_divbyzero_sigfpe" >&6; } case "$gt_cv_int_divbyzero_sigfpe" in *yes) value=1;; *) value=0;; esac cat >>confdefs.h <<_ACEOF #define INTDIV0_RAISES_SIGFPE $value _ACEOF { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inttypes.h" >&5 $as_echo_n "checking for inttypes.h... " >&6; } if test "${gl_cv_header_inttypes_h+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main () { uintmax_t i = (uintmax_t) -1; return !i; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : gl_cv_header_inttypes_h=yes else gl_cv_header_inttypes_h=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_header_inttypes_h" >&5 $as_echo "$gl_cv_header_inttypes_h" >&6; } if test $gl_cv_header_inttypes_h = yes; then cat >>confdefs.h <<_ACEOF #define HAVE_INTTYPES_H_WITH_UINTMAX 1 _ACEOF fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for unsigned long long int" >&5 $as_echo_n "checking for unsigned long long int... " >&6; } if test "${ac_cv_type_unsigned_long_long_int+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Test preprocessor. */ #if ! (-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) error in preprocessor; #endif #if ! (18446744073709551615ULL <= -1ull) error in preprocessor; #endif /* Test literals. */ long long int ll = 9223372036854775807ll; long long int nll = -9223372036854775807LL; unsigned long long int ull = 18446744073709551615ULL; /* Test constant expressions. */ typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) ? 1 : -1)]; typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1 ? 1 : -1)]; int i = 63; int main () { /* Test availability of runtime routines for shift and division. */ long long int llmax = 9223372036854775807ll; unsigned long long int ullmax = 18446744073709551615ull; return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) | (llmax / ll) | (llmax % ll) | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i) | (ullmax / ull) | (ullmax % ull)); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_type_unsigned_long_long_int=yes else ac_cv_type_unsigned_long_long_int=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_unsigned_long_long_int" >&5 $as_echo "$ac_cv_type_unsigned_long_long_int" >&6; } if test $ac_cv_type_unsigned_long_long_int = yes; then $as_echo "#define HAVE_UNSIGNED_LONG_LONG_INT 1" >>confdefs.h fi if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then test $ac_cv_type_unsigned_long_long_int = yes \ && ac_type='unsigned long long' \ || ac_type='unsigned long' cat >>confdefs.h <<_ACEOF #define uintmax_t $ac_type _ACEOF else $as_echo "#define HAVE_UINTMAX_T 1" >>confdefs.h fi for ac_header in inttypes.h do : ac_fn_c_check_header_mongrel "$LINENO" "inttypes.h" "ac_cv_header_inttypes_h" "$ac_includes_default" if test "x$ac_cv_header_inttypes_h" = x""yes; then : cat >>confdefs.h <<_ACEOF #define HAVE_INTTYPES_H 1 _ACEOF fi done if test $ac_cv_header_inttypes_h = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the inttypes.h PRIxNN macros are broken" >&5 $as_echo_n "checking whether the inttypes.h PRIxNN macros are broken... " >&6; } if test "${gt_cv_inttypes_pri_broken+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #ifdef PRId32 char *p = PRId32; #endif int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : gt_cv_inttypes_pri_broken=no else gt_cv_inttypes_pri_broken=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_inttypes_pri_broken" >&5 $as_echo "$gt_cv_inttypes_pri_broken" >&6; } fi if test "$gt_cv_inttypes_pri_broken" = yes; then cat >>confdefs.h <<_ACEOF #define PRI_MACROS_BROKEN 1 _ACEOF PRI_MACROS_BROKEN=1 else PRI_MACROS_BROKEN=0 fi # Check whether --enable-threads was given. if test "${enable_threads+set}" = set; then : enableval=$enable_threads; gl_use_threads=$enableval else case "$host_os" in osf*) gl_use_threads=no ;; *) gl_use_threads=yes ;; esac fi if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then # For using : case "$host_os" in osf*) # On OSF/1, the compiler needs the flag -D_REENTRANT so that it # groks . cc also understands the flag -pthread, but # we don't use it because 1. gcc-2.95 doesn't understand -pthread, # 2. putting a flag into CPPFLAGS that has an effect on the linker # causes the AC_TRY_LINK test below to succeed unexpectedly, # leading to wrong values of LIBTHREAD and LTLIBTHREAD. CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;; esac # Some systems optimize for single-threaded programs by default, and # need special flags to disable these optimizations. For example, the # definition of 'errno' in . case "$host_os" in aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;; solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;; esac fi if test "X$prefix" = "XNONE"; then acl_final_prefix="$ac_default_prefix" else acl_final_prefix="$prefix" fi if test "X$exec_prefix" = "XNONE"; then acl_final_exec_prefix='${prefix}' else acl_final_exec_prefix="$exec_prefix" fi acl_save_prefix="$prefix" prefix="$acl_final_prefix" eval acl_final_exec_prefix=\"$acl_final_exec_prefix\" prefix="$acl_save_prefix" # Check whether --with-gnu-ld was given. if test "${with_gnu_ld+set}" = set; then : withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes else with_gnu_ld=no fi # Prepare PATH_SEPARATOR. # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then echo "#! /bin/sh" >conf$$.sh echo "exit 0" >>conf$$.sh chmod +x conf$$.sh if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then PATH_SEPARATOR=';' else PATH_SEPARATOR=: fi rm -f conf$$.sh fi ac_prog=ld if test "$GCC" = yes; then # Check if gcc -print-prog-name=ld gives a path. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by GCC" >&5 $as_echo_n "checking for ld used by GCC... " >&6; } case $host in *-*-mingw*) # gcc leaves a trailing carriage return which upsets mingw ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; *) ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; esac case $ac_prog in # Accept absolute paths. [\\/]* | [A-Za-z]:[\\/]*) re_direlt='/[^/][^/]*/\.\./' # Canonicalize the path of ld ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'` while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` done test -z "$LD" && LD="$ac_prog" ;; "") # If it fails, then pretend we aren't using GCC. ac_prog=ld ;; *) # If it is relative, then search for the first ld in PATH. with_gnu_ld=unknown ;; esac elif test "$with_gnu_ld" = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 $as_echo_n "checking for GNU ld... " >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 $as_echo_n "checking for non-GNU ld... " >&6; } fi if test "${acl_cv_path_LD+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -z "$LD"; then IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}" for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then acl_cv_path_LD="$ac_dir/$ac_prog" # Check to see if the program is GNU ld. I'd rather use --version, # but apparently some GNU ld's only accept -v. # Break only if it was the GNU/non-GNU ld that we prefer. case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in *GNU* | *'with BFD'*) test "$with_gnu_ld" != no && break ;; *) test "$with_gnu_ld" != yes && break ;; esac fi done IFS="$ac_save_ifs" else acl_cv_path_LD="$LD" # Let the user override the test with a path. fi fi LD="$acl_cv_path_LD" if test -n "$LD"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 $as_echo "$LD" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 $as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } if test "${acl_cv_prog_gnu_ld+set}" = set; then : $as_echo_n "(cached) " >&6 else # I'd rather use --version here, but apparently some GNU ld's only accept -v. case `$LD -v 2>&1 &5 $as_echo "$acl_cv_prog_gnu_ld" >&6; } with_gnu_ld=$acl_cv_prog_gnu_ld { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shared library run path origin" >&5 $as_echo_n "checking for shared library run path origin... " >&6; } if test "${acl_cv_rpath+set}" = set; then : $as_echo_n "(cached) " >&6 else CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \ ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh . ./conftest.sh rm -f ./conftest.sh acl_cv_rpath=done fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $acl_cv_rpath" >&5 $as_echo "$acl_cv_rpath" >&6; } wl="$acl_cv_wl" acl_libext="$acl_cv_libext" acl_shlibext="$acl_cv_shlibext" acl_libname_spec="$acl_cv_libname_spec" acl_library_names_spec="$acl_cv_library_names_spec" acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" acl_hardcode_direct="$acl_cv_hardcode_direct" acl_hardcode_minus_L="$acl_cv_hardcode_minus_L" # Check whether --enable-rpath was given. if test "${enable_rpath+set}" = set; then : enableval=$enable_rpath; : else enable_rpath=yes fi acl_libdirstem=lib searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'` if test -n "$searchpath"; then acl_save_IFS="${IFS= }"; IFS=":" for searchdir in $searchpath; do if test -d "$searchdir"; then case "$searchdir" in */lib64/ | */lib64 ) acl_libdirstem=lib64 ;; *) searchdir=`cd "$searchdir" && pwd` case "$searchdir" in */lib64 ) acl_libdirstem=lib64 ;; esac ;; esac fi done IFS="$acl_save_IFS" fi gl_threads_api=none LIBTHREAD= LTLIBTHREAD= LIBMULTITHREAD= LTLIBMULTITHREAD= if test "$gl_use_threads" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether imported symbols can be declared weak" >&5 $as_echo_n "checking whether imported symbols can be declared weak... " >&6; } gl_have_weak=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ extern void xyzzy (); #pragma weak xyzzy int main () { xyzzy(); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : gl_have_weak=yes fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_have_weak" >&5 $as_echo "$gl_have_weak" >&6; } if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that # it groks . It's added above, in gl_LOCK_EARLY_BODY. ac_fn_c_check_header_mongrel "$LINENO" "pthread.h" "ac_cv_header_pthread_h" "$ac_includes_default" if test "x$ac_cv_header_pthread_h" = x""yes; then : gl_have_pthread_h=yes else gl_have_pthread_h=no fi if test "$gl_have_pthread_h" = yes; then # Other possible tests: # -lpthreads (FSU threads, PCthreads) # -lgthreads gl_have_pthread= # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist # in libc. IRIX 6.5 has the first one in both libc and libpthread, but # the second one only in libpthread, and lock.c needs it. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { pthread_mutex_lock((pthread_mutex_t*)0); pthread_mutexattr_init((pthread_mutexattr_t*)0); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : gl_have_pthread=yes fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext # Test for libpthread by looking for pthread_kill. (Not pthread_self, # since it is defined as a macro on OSF/1.) if test -n "$gl_have_pthread"; then # The program links fine without libpthread. But it may actually # need to link with libpthread in order to create multiple threads. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_kill in -lpthread" >&5 $as_echo_n "checking for pthread_kill in -lpthread... " >&6; } if test "${ac_cv_lib_pthread_pthread_kill+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lpthread $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char pthread_kill (); int main () { return pthread_kill (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_pthread_pthread_kill=yes else ac_cv_lib_pthread_pthread_kill=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_kill" >&5 $as_echo "$ac_cv_lib_pthread_pthread_kill" >&6; } if test "x$ac_cv_lib_pthread_pthread_kill" = x""yes; then : LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread # On Solaris and HP-UX, most pthread functions exist also in libc. # Therefore pthread_in_use() needs to actually try to create a # thread: pthread_create from libc will fail, whereas # pthread_create will actually create a thread. case "$host_os" in solaris* | hpux*) $as_echo "#define PTHREAD_IN_USE_DETECTION_HARD 1" >>confdefs.h esac fi else # Some library is needed. Try libpthread and libc_r. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_kill in -lpthread" >&5 $as_echo_n "checking for pthread_kill in -lpthread... " >&6; } if test "${ac_cv_lib_pthread_pthread_kill+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lpthread $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char pthread_kill (); int main () { return pthread_kill (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_pthread_pthread_kill=yes else ac_cv_lib_pthread_pthread_kill=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_kill" >&5 $as_echo "$ac_cv_lib_pthread_pthread_kill" >&6; } if test "x$ac_cv_lib_pthread_pthread_kill" = x""yes; then : gl_have_pthread=yes LIBTHREAD=-lpthread LTLIBTHREAD=-lpthread LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread fi if test -z "$gl_have_pthread"; then # For FreeBSD 4. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_kill in -lc_r" >&5 $as_echo_n "checking for pthread_kill in -lc_r... " >&6; } if test "${ac_cv_lib_c_r_pthread_kill+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lc_r $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char pthread_kill (); int main () { return pthread_kill (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_c_r_pthread_kill=yes else ac_cv_lib_c_r_pthread_kill=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_r_pthread_kill" >&5 $as_echo "$ac_cv_lib_c_r_pthread_kill" >&6; } if test "x$ac_cv_lib_c_r_pthread_kill" = x""yes; then : gl_have_pthread=yes LIBTHREAD=-lc_r LTLIBTHREAD=-lc_r LIBMULTITHREAD=-lc_r LTLIBMULTITHREAD=-lc_r fi fi fi if test -n "$gl_have_pthread"; then gl_threads_api=posix $as_echo "#define USE_POSIX_THREADS 1" >>confdefs.h if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then if test $gl_have_weak = yes; then $as_echo "#define USE_POSIX_THREADS_WEAK 1" >>confdefs.h LIBTHREAD= LTLIBTHREAD= fi fi # OSF/1 4.0 and MacOS X 10.1 lack the pthread_rwlock_t type and the # pthread_rwlock_* functions. ac_fn_c_check_type "$LINENO" "pthread_rwlock_t" "ac_cv_type_pthread_rwlock_t" "#include " if test "x$ac_cv_type_pthread_rwlock_t" = x""yes; then : $as_echo "#define HAVE_PTHREAD_RWLOCK 1" >>confdefs.h fi # glibc defines PTHREAD_MUTEX_RECURSIVE as enum, not as a macro. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { #if __FreeBSD__ == 4 error "No, in FreeBSD 4.0 recursive mutexes actually don't work." #else int x = (int)PTHREAD_MUTEX_RECURSIVE; return !x; #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : $as_echo "#define HAVE_PTHREAD_MUTEX_RECURSIVE 1" >>confdefs.h fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi fi fi if test -z "$gl_have_pthread"; then if test "$gl_use_threads" = yes || test "$gl_use_threads" = solaris; then gl_have_solaristhread= gl_save_LIBS="$LIBS" LIBS="$LIBS -lthread" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main () { thr_self(); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : gl_have_solaristhread=yes fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS="$gl_save_LIBS" if test -n "$gl_have_solaristhread"; then gl_threads_api=solaris LIBTHREAD=-lthread LTLIBTHREAD=-lthread LIBMULTITHREAD="$LIBTHREAD" LTLIBMULTITHREAD="$LTLIBTHREAD" $as_echo "#define USE_SOLARIS_THREADS 1" >>confdefs.h if test $gl_have_weak = yes; then $as_echo "#define USE_SOLARIS_THREADS_WEAK 1" >>confdefs.h LIBTHREAD= LTLIBTHREAD= fi fi fi fi if test "$gl_use_threads" = pth; then gl_save_CPPFLAGS="$CPPFLAGS" { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libpth" >&5 $as_echo_n "checking how to link with libpth... " >&6; } if test "${ac_cv_libpth_libs+set}" = set; then : $as_echo_n "(cached) " >&6 else use_additional=yes acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" # Check whether --with-libpth-prefix was given. if test "${with_libpth_prefix+set}" = set; then : withval=$with_libpth_prefix; if test "X$withval" = "Xno"; then use_additional=no else if test "X$withval" = "X"; then acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" else additional_includedir="$withval/include" additional_libdir="$withval/$acl_libdirstem" fi fi fi LIBPTH= LTLIBPTH= INCPTH= LIBPTH_PREFIX= rpathdirs= ltrpathdirs= names_already_handled= names_next_round='pth ' while test -n "$names_next_round"; do names_this_round="$names_next_round" names_next_round= for name in $names_this_round; do already_handled= for n in $names_already_handled; do if test "$n" = "$name"; then already_handled=yes break fi done if test -z "$already_handled"; then names_already_handled="$names_already_handled $name" uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'` eval value=\"\$HAVE_LIB$uppername\" if test -n "$value"; then if test "$value" = yes; then eval value=\"\$LIB$uppername\" test -z "$value" || LIBPTH="${LIBPTH}${LIBPTH:+ }$value" eval value=\"\$LTLIB$uppername\" test -z "$value" || LTLIBPTH="${LTLIBPTH}${LTLIBPTH:+ }$value" else : fi else found_dir= found_la= found_so= found_a= eval libname=\"$acl_libname_spec\" # typically: libname=lib$name if test -n "$acl_shlibext"; then shrext=".$acl_shlibext" # typically: shrext=.so else shrext= fi if test $use_additional = yes; then dir="$additional_libdir" if test -n "$acl_shlibext"; then if test -f "$dir/$libname$shrext"; then found_dir="$dir" found_so="$dir/$libname$shrext" else if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then ver=`(cd "$dir" && \ for f in "$libname$shrext".*; do echo "$f"; done \ | sed -e "s,^$libname$shrext\\\\.,," \ | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | sed 1q ) 2>/dev/null` if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then found_dir="$dir" found_so="$dir/$libname$shrext.$ver" fi else eval library_names=\"$acl_library_names_spec\" for f in $library_names; do if test -f "$dir/$f"; then found_dir="$dir" found_so="$dir/$f" break fi done fi fi fi if test "X$found_dir" = "X"; then if test -f "$dir/$libname.$acl_libext"; then found_dir="$dir" found_a="$dir/$libname.$acl_libext" fi fi if test "X$found_dir" != "X"; then if test -f "$dir/$libname.la"; then found_la="$dir/$libname.la" fi fi fi if test "X$found_dir" = "X"; then for x in $LDFLAGS $LTLIBPTH; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" case "$x" in -L*) dir=`echo "X$x" | sed -e 's/^X-L//'` if test -n "$acl_shlibext"; then if test -f "$dir/$libname$shrext"; then found_dir="$dir" found_so="$dir/$libname$shrext" else if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then ver=`(cd "$dir" && \ for f in "$libname$shrext".*; do echo "$f"; done \ | sed -e "s,^$libname$shrext\\\\.,," \ | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | sed 1q ) 2>/dev/null` if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then found_dir="$dir" found_so="$dir/$libname$shrext.$ver" fi else eval library_names=\"$acl_library_names_spec\" for f in $library_names; do if test -f "$dir/$f"; then found_dir="$dir" found_so="$dir/$f" break fi done fi fi fi if test "X$found_dir" = "X"; then if test -f "$dir/$libname.$acl_libext"; then found_dir="$dir" found_a="$dir/$libname.$acl_libext" fi fi if test "X$found_dir" != "X"; then if test -f "$dir/$libname.la"; then found_la="$dir/$libname.la" fi fi ;; esac if test "X$found_dir" != "X"; then break fi done fi if test "X$found_dir" != "X"; then LTLIBPTH="${LTLIBPTH}${LTLIBPTH:+ }-L$found_dir -l$name" if test "X$found_so" != "X"; then if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/$acl_libdirstem"; then LIBPTH="${LIBPTH}${LIBPTH:+ }$found_so" else haveit= for x in $ltrpathdirs; do if test "X$x" = "X$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then ltrpathdirs="$ltrpathdirs $found_dir" fi if test "$acl_hardcode_direct" = yes; then LIBPTH="${LIBPTH}${LIBPTH:+ }$found_so" else if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then LIBPTH="${LIBPTH}${LIBPTH:+ }$found_so" haveit= for x in $rpathdirs; do if test "X$x" = "X$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then rpathdirs="$rpathdirs $found_dir" fi else haveit= for x in $LDFLAGS $LIBPTH; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-L$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then LIBPTH="${LIBPTH}${LIBPTH:+ }-L$found_dir" fi if test "$acl_hardcode_minus_L" != no; then LIBPTH="${LIBPTH}${LIBPTH:+ }$found_so" else LIBPTH="${LIBPTH}${LIBPTH:+ }-l$name" fi fi fi fi else if test "X$found_a" != "X"; then LIBPTH="${LIBPTH}${LIBPTH:+ }$found_a" else LIBPTH="${LIBPTH}${LIBPTH:+ }-L$found_dir -l$name" fi fi additional_includedir= case "$found_dir" in */$acl_libdirstem | */$acl_libdirstem/) basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'` LIBPTH_PREFIX="$basedir" additional_includedir="$basedir/include" ;; esac if test "X$additional_includedir" != "X"; then if test "X$additional_includedir" != "X/usr/include"; then haveit= if test "X$additional_includedir" = "X/usr/local/include"; then if test -n "$GCC"; then case $host_os in linux* | gnu* | k*bsd*-gnu) haveit=yes;; esac fi fi if test -z "$haveit"; then for x in $CPPFLAGS $INCPTH; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-I$additional_includedir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_includedir"; then INCPTH="${INCPTH}${INCPTH:+ }-I$additional_includedir" fi fi fi fi fi if test -n "$found_la"; then save_libdir="$libdir" case "$found_la" in */* | *\\*) . "$found_la" ;; *) . "./$found_la" ;; esac libdir="$save_libdir" for dep in $dependency_libs; do case "$dep" in -L*) additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'` if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then haveit= if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then if test -n "$GCC"; then case $host_os in linux* | gnu* | k*bsd*-gnu) haveit=yes;; esac fi fi if test -z "$haveit"; then haveit= for x in $LDFLAGS $LIBPTH; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-L$additional_libdir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_libdir"; then LIBPTH="${LIBPTH}${LIBPTH:+ }-L$additional_libdir" fi fi haveit= for x in $LDFLAGS $LTLIBPTH; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-L$additional_libdir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_libdir"; then LTLIBPTH="${LTLIBPTH}${LTLIBPTH:+ }-L$additional_libdir" fi fi fi fi ;; -R*) dir=`echo "X$dep" | sed -e 's/^X-R//'` if test "$enable_rpath" != no; then haveit= for x in $rpathdirs; do if test "X$x" = "X$dir"; then haveit=yes break fi done if test -z "$haveit"; then rpathdirs="$rpathdirs $dir" fi haveit= for x in $ltrpathdirs; do if test "X$x" = "X$dir"; then haveit=yes break fi done if test -z "$haveit"; then ltrpathdirs="$ltrpathdirs $dir" fi fi ;; -l*) names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'` ;; *.la) names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'` ;; *) LIBPTH="${LIBPTH}${LIBPTH:+ }$dep" LTLIBPTH="${LTLIBPTH}${LTLIBPTH:+ }$dep" ;; esac done fi else LIBPTH="${LIBPTH}${LIBPTH:+ }-l$name" LTLIBPTH="${LTLIBPTH}${LTLIBPTH:+ }-l$name" fi fi fi done done if test "X$rpathdirs" != "X"; then if test -n "$acl_hardcode_libdir_separator"; then alldirs= for found_dir in $rpathdirs; do alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir" done acl_save_libdir="$libdir" libdir="$alldirs" eval flag=\"$acl_hardcode_libdir_flag_spec\" libdir="$acl_save_libdir" LIBPTH="${LIBPTH}${LIBPTH:+ }$flag" else for found_dir in $rpathdirs; do acl_save_libdir="$libdir" libdir="$found_dir" eval flag=\"$acl_hardcode_libdir_flag_spec\" libdir="$acl_save_libdir" LIBPTH="${LIBPTH}${LIBPTH:+ }$flag" done fi fi if test "X$ltrpathdirs" != "X"; then for found_dir in $ltrpathdirs; do LTLIBPTH="${LTLIBPTH}${LTLIBPTH:+ }-R$found_dir" done fi ac_cv_libpth_libs="$LIBPTH" ac_cv_libpth_ltlibs="$LTLIBPTH" ac_cv_libpth_cppflags="$INCPTH" ac_cv_libpth_prefix="$LIBPTH_PREFIX" fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_libpth_libs" >&5 $as_echo "$ac_cv_libpth_libs" >&6; } LIBPTH="$ac_cv_libpth_libs" LTLIBPTH="$ac_cv_libpth_ltlibs" INCPTH="$ac_cv_libpth_cppflags" LIBPTH_PREFIX="$ac_cv_libpth_prefix" for element in $INCPTH; do haveit= for x in $CPPFLAGS; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X$element"; then haveit=yes break fi done if test -z "$haveit"; then CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element" fi done HAVE_LIBPTH=yes gl_have_pth= gl_save_LIBS="$LIBS" LIBS="$LIBS -lpth" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { pth_self(); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : gl_have_pth=yes fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS="$gl_save_LIBS" if test -n "$gl_have_pth"; then gl_threads_api=pth LIBTHREAD="$LIBPTH" LTLIBTHREAD="$LTLIBPTH" LIBMULTITHREAD="$LIBTHREAD" LTLIBMULTITHREAD="$LTLIBTHREAD" $as_echo "#define USE_PTH_THREADS 1" >>confdefs.h if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then if test $gl_have_weak = yes; then $as_echo "#define USE_PTH_THREADS_WEAK 1" >>confdefs.h LIBTHREAD= LTLIBTHREAD= fi fi else CPPFLAGS="$gl_save_CPPFLAGS" fi fi if test -z "$gl_have_pthread"; then if test "$gl_use_threads" = yes || test "$gl_use_threads" = win32; then if { case "$host_os" in mingw*) true;; *) false;; esac }; then gl_threads_api=win32 $as_echo "#define USE_WIN32_THREADS 1" >>confdefs.h fi fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for multithread API to use" >&5 $as_echo_n "checking for multithread API to use... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_threads_api" >&5 $as_echo "$gl_threads_api" >&6; } use_additional=yes acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" # Check whether --with-libiconv-prefix was given. if test "${with_libiconv_prefix+set}" = set; then : withval=$with_libiconv_prefix; if test "X$withval" = "Xno"; then use_additional=no else if test "X$withval" = "X"; then acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" else additional_includedir="$withval/include" additional_libdir="$withval/$acl_libdirstem" fi fi fi LIBICONV= LTLIBICONV= INCICONV= LIBICONV_PREFIX= rpathdirs= ltrpathdirs= names_already_handled= names_next_round='iconv ' while test -n "$names_next_round"; do names_this_round="$names_next_round" names_next_round= for name in $names_this_round; do already_handled= for n in $names_already_handled; do if test "$n" = "$name"; then already_handled=yes break fi done if test -z "$already_handled"; then names_already_handled="$names_already_handled $name" uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'` eval value=\"\$HAVE_LIB$uppername\" if test -n "$value"; then if test "$value" = yes; then eval value=\"\$LIB$uppername\" test -z "$value" || LIBICONV="${LIBICONV}${LIBICONV:+ }$value" eval value=\"\$LTLIB$uppername\" test -z "$value" || LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }$value" else : fi else found_dir= found_la= found_so= found_a= eval libname=\"$acl_libname_spec\" # typically: libname=lib$name if test -n "$acl_shlibext"; then shrext=".$acl_shlibext" # typically: shrext=.so else shrext= fi if test $use_additional = yes; then dir="$additional_libdir" if test -n "$acl_shlibext"; then if test -f "$dir/$libname$shrext"; then found_dir="$dir" found_so="$dir/$libname$shrext" else if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then ver=`(cd "$dir" && \ for f in "$libname$shrext".*; do echo "$f"; done \ | sed -e "s,^$libname$shrext\\\\.,," \ | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | sed 1q ) 2>/dev/null` if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then found_dir="$dir" found_so="$dir/$libname$shrext.$ver" fi else eval library_names=\"$acl_library_names_spec\" for f in $library_names; do if test -f "$dir/$f"; then found_dir="$dir" found_so="$dir/$f" break fi done fi fi fi if test "X$found_dir" = "X"; then if test -f "$dir/$libname.$acl_libext"; then found_dir="$dir" found_a="$dir/$libname.$acl_libext" fi fi if test "X$found_dir" != "X"; then if test -f "$dir/$libname.la"; then found_la="$dir/$libname.la" fi fi fi if test "X$found_dir" = "X"; then for x in $LDFLAGS $LTLIBICONV; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" case "$x" in -L*) dir=`echo "X$x" | sed -e 's/^X-L//'` if test -n "$acl_shlibext"; then if test -f "$dir/$libname$shrext"; then found_dir="$dir" found_so="$dir/$libname$shrext" else if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then ver=`(cd "$dir" && \ for f in "$libname$shrext".*; do echo "$f"; done \ | sed -e "s,^$libname$shrext\\\\.,," \ | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | sed 1q ) 2>/dev/null` if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then found_dir="$dir" found_so="$dir/$libname$shrext.$ver" fi else eval library_names=\"$acl_library_names_spec\" for f in $library_names; do if test -f "$dir/$f"; then found_dir="$dir" found_so="$dir/$f" break fi done fi fi fi if test "X$found_dir" = "X"; then if test -f "$dir/$libname.$acl_libext"; then found_dir="$dir" found_a="$dir/$libname.$acl_libext" fi fi if test "X$found_dir" != "X"; then if test -f "$dir/$libname.la"; then found_la="$dir/$libname.la" fi fi ;; esac if test "X$found_dir" != "X"; then break fi done fi if test "X$found_dir" != "X"; then LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-L$found_dir -l$name" if test "X$found_so" != "X"; then if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/$acl_libdirstem"; then LIBICONV="${LIBICONV}${LIBICONV:+ }$found_so" else haveit= for x in $ltrpathdirs; do if test "X$x" = "X$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then ltrpathdirs="$ltrpathdirs $found_dir" fi if test "$acl_hardcode_direct" = yes; then LIBICONV="${LIBICONV}${LIBICONV:+ }$found_so" else if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then LIBICONV="${LIBICONV}${LIBICONV:+ }$found_so" haveit= for x in $rpathdirs; do if test "X$x" = "X$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then rpathdirs="$rpathdirs $found_dir" fi else haveit= for x in $LDFLAGS $LIBICONV; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-L$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then LIBICONV="${LIBICONV}${LIBICONV:+ }-L$found_dir" fi if test "$acl_hardcode_minus_L" != no; then LIBICONV="${LIBICONV}${LIBICONV:+ }$found_so" else LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name" fi fi fi fi else if test "X$found_a" != "X"; then LIBICONV="${LIBICONV}${LIBICONV:+ }$found_a" else LIBICONV="${LIBICONV}${LIBICONV:+ }-L$found_dir -l$name" fi fi additional_includedir= case "$found_dir" in */$acl_libdirstem | */$acl_libdirstem/) basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'` LIBICONV_PREFIX="$basedir" additional_includedir="$basedir/include" ;; esac if test "X$additional_includedir" != "X"; then if test "X$additional_includedir" != "X/usr/include"; then haveit= if test "X$additional_includedir" = "X/usr/local/include"; then if test -n "$GCC"; then case $host_os in linux* | gnu* | k*bsd*-gnu) haveit=yes;; esac fi fi if test -z "$haveit"; then for x in $CPPFLAGS $INCICONV; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-I$additional_includedir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_includedir"; then INCICONV="${INCICONV}${INCICONV:+ }-I$additional_includedir" fi fi fi fi fi if test -n "$found_la"; then save_libdir="$libdir" case "$found_la" in */* | *\\*) . "$found_la" ;; *) . "./$found_la" ;; esac libdir="$save_libdir" for dep in $dependency_libs; do case "$dep" in -L*) additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'` if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then haveit= if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then if test -n "$GCC"; then case $host_os in linux* | gnu* | k*bsd*-gnu) haveit=yes;; esac fi fi if test -z "$haveit"; then haveit= for x in $LDFLAGS $LIBICONV; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-L$additional_libdir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_libdir"; then LIBICONV="${LIBICONV}${LIBICONV:+ }-L$additional_libdir" fi fi haveit= for x in $LDFLAGS $LTLIBICONV; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-L$additional_libdir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_libdir"; then LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-L$additional_libdir" fi fi fi fi ;; -R*) dir=`echo "X$dep" | sed -e 's/^X-R//'` if test "$enable_rpath" != no; then haveit= for x in $rpathdirs; do if test "X$x" = "X$dir"; then haveit=yes break fi done if test -z "$haveit"; then rpathdirs="$rpathdirs $dir" fi haveit= for x in $ltrpathdirs; do if test "X$x" = "X$dir"; then haveit=yes break fi done if test -z "$haveit"; then ltrpathdirs="$ltrpathdirs $dir" fi fi ;; -l*) names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'` ;; *.la) names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'` ;; *) LIBICONV="${LIBICONV}${LIBICONV:+ }$dep" LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }$dep" ;; esac done fi else LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name" LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name" fi fi fi done done if test "X$rpathdirs" != "X"; then if test -n "$acl_hardcode_libdir_separator"; then alldirs= for found_dir in $rpathdirs; do alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir" done acl_save_libdir="$libdir" libdir="$alldirs" eval flag=\"$acl_hardcode_libdir_flag_spec\" libdir="$acl_save_libdir" LIBICONV="${LIBICONV}${LIBICONV:+ }$flag" else for found_dir in $rpathdirs; do acl_save_libdir="$libdir" libdir="$found_dir" eval flag=\"$acl_hardcode_libdir_flag_spec\" libdir="$acl_save_libdir" LIBICONV="${LIBICONV}${LIBICONV:+ }$flag" done fi fi if test "X$ltrpathdirs" != "X"; then for found_dir in $ltrpathdirs; do LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-R$found_dir" done fi cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int foo (int a) { a = __builtin_expect (a, 10); return a == 10 ? 0 : 1; } int main () { ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : $as_echo "#define HAVE_BUILTIN_EXPECT 1" >>confdefs.h fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext for ac_header in argz.h inttypes.h limits.h unistd.h sys/param.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done for ac_func in getcwd getegid geteuid getgid getuid mempcpy munmap \ stpcpy strcasecmp strdup strtoul tsearch argz_count argz_stringify \ argz_next __fsetlocking do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether feof_unlocked is declared" >&5 $as_echo_n "checking whether feof_unlocked is declared... " >&6; } if test "${ac_cv_have_decl_feof_unlocked+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { #ifndef feof_unlocked char *p = (char *) feof_unlocked; #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_have_decl_feof_unlocked=yes else ac_cv_have_decl_feof_unlocked=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_decl_feof_unlocked" >&5 $as_echo "$ac_cv_have_decl_feof_unlocked" >&6; } if test $ac_cv_have_decl_feof_unlocked = yes; then gt_value=1 else gt_value=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_FEOF_UNLOCKED $gt_value _ACEOF { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether fgets_unlocked is declared" >&5 $as_echo_n "checking whether fgets_unlocked is declared... " >&6; } if test "${ac_cv_have_decl_fgets_unlocked+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { #ifndef fgets_unlocked char *p = (char *) fgets_unlocked; #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_have_decl_fgets_unlocked=yes else ac_cv_have_decl_fgets_unlocked=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_decl_fgets_unlocked" >&5 $as_echo "$ac_cv_have_decl_fgets_unlocked" >&6; } if test $ac_cv_have_decl_fgets_unlocked = yes; then gt_value=1 else gt_value=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_FGETS_UNLOCKED $gt_value _ACEOF am_save_CPPFLAGS="$CPPFLAGS" for element in $INCICONV; do haveit= for x in $CPPFLAGS; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X$element"; then haveit=yes break fi done if test -z "$haveit"; then CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element" fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5 $as_echo_n "checking for iconv... " >&6; } if test "${am_cv_func_iconv+set}" = set; then : $as_echo_n "(cached) " >&6 else am_cv_func_iconv="no, consider installing GNU libiconv" am_cv_lib_iconv=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main () { iconv_t cd = iconv_open("",""); iconv(cd,NULL,NULL,NULL,NULL); iconv_close(cd); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : am_cv_func_iconv=yes fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext if test "$am_cv_func_iconv" != yes; then am_save_LIBS="$LIBS" LIBS="$LIBS $LIBICONV" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main () { iconv_t cd = iconv_open("",""); iconv(cd,NULL,NULL,NULL,NULL); iconv_close(cd); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : am_cv_lib_iconv=yes am_cv_func_iconv=yes fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS="$am_save_LIBS" fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv" >&5 $as_echo "$am_cv_func_iconv" >&6; } if test "$am_cv_func_iconv" = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working iconv" >&5 $as_echo_n "checking for working iconv... " >&6; } if test "${am_cv_func_iconv_works+set}" = set; then : $as_echo_n "(cached) " >&6 else am_save_LIBS="$LIBS" if test $am_cv_lib_iconv = yes; then LIBS="$LIBS $LIBICONV" fi if test "$cross_compiling" = yes; then : case "$host_os" in aix* | hpux*) am_cv_func_iconv_works="guessing no" ;; *) am_cv_func_iconv_works="guessing yes" ;; esac else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main () { /* Test against AIX 5.1 bug: Failures are not distinguishable from successful returns. */ { iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8"); if (cd_utf8_to_88591 != (iconv_t)(-1)) { static const char input[] = "\342\202\254"; /* EURO SIGN */ char buf[10]; const char *inptr = input; size_t inbytesleft = strlen (input); char *outptr = buf; size_t outbytesleft = sizeof (buf); size_t res = iconv (cd_utf8_to_88591, (char **) &inptr, &inbytesleft, &outptr, &outbytesleft); if (res == 0) return 1; } } #if 0 /* This bug could be worked around by the caller. */ /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */ { iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591"); if (cd_88591_to_utf8 != (iconv_t)(-1)) { static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; char buf[50]; const char *inptr = input; size_t inbytesleft = strlen (input); char *outptr = buf; size_t outbytesleft = sizeof (buf); size_t res = iconv (cd_88591_to_utf8, (char **) &inptr, &inbytesleft, &outptr, &outbytesleft); if ((int)res > 0) return 1; } } #endif /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is provided. */ if (/* Try standardized names. */ iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1) /* Try IRIX, OSF/1 names. */ && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1) /* Try AIX names. */ && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1) /* Try HP-UX names. */ && iconv_open ("utf8", "eucJP") == (iconv_t)(-1)) return 1; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : am_cv_func_iconv_works=yes else am_cv_func_iconv_works=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi LIBS="$am_save_LIBS" fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv_works" >&5 $as_echo "$am_cv_func_iconv_works" >&6; } case "$am_cv_func_iconv_works" in *no) am_func_iconv=no am_cv_lib_iconv=no ;; *) am_func_iconv=yes ;; esac else am_func_iconv=no am_cv_lib_iconv=no fi if test "$am_func_iconv" = yes; then $as_echo "#define HAVE_ICONV 1" >>confdefs.h fi if test "$am_cv_lib_iconv" = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libiconv" >&5 $as_echo_n "checking how to link with libiconv... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5 $as_echo "$LIBICONV" >&6; } else CPPFLAGS="$am_save_CPPFLAGS" LIBICONV= LTLIBICONV= fi if test "$am_cv_func_iconv" = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv declaration" >&5 $as_echo_n "checking for iconv declaration... " >&6; } if test "${am_cv_proto_iconv+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include extern #ifdef __cplusplus "C" #endif #if defined(__STDC__) || defined(__cplusplus) size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); #else size_t iconv(); #endif int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : am_cv_proto_iconv_arg1="" else am_cv_proto_iconv_arg1="const" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);" fi am_cv_proto_iconv=`echo "$am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'` { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${ac_t:- }$am_cv_proto_iconv" >&5 $as_echo "${ac_t:- }$am_cv_proto_iconv" >&6; } cat >>confdefs.h <<_ACEOF #define ICONV_CONST $am_cv_proto_iconv_arg1 _ACEOF fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for NL_LOCALE_NAME macro" >&5 $as_echo_n "checking for NL_LOCALE_NAME macro... " >&6; } if test "${gt_cv_nl_locale_name+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main () { char* cs = nl_langinfo(_NL_LOCALE_NAME(LC_MESSAGES)); return !cs; ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : gt_cv_nl_locale_name=yes else gt_cv_nl_locale_name=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_nl_locale_name" >&5 $as_echo "$gt_cv_nl_locale_name" >&6; } if test $gt_cv_nl_locale_name = yes; then $as_echo "#define HAVE_NL_LOCALE_NAME 1" >>confdefs.h fi for ac_prog in bison do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_INTLBISON+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$INTLBISON"; then ac_cv_prog_INTLBISON="$INTLBISON" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_INTLBISON="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi INTLBISON=$ac_cv_prog_INTLBISON if test -n "$INTLBISON"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $INTLBISON" >&5 $as_echo "$INTLBISON" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$INTLBISON" && break done if test -z "$INTLBISON"; then ac_verc_fail=yes else { $as_echo "$as_me:${as_lineno-$LINENO}: checking version of bison" >&5 $as_echo_n "checking version of bison... " >&6; } ac_prog_version=`$INTLBISON --version 2>&1 | sed -n 's/^.*GNU Bison.* \([0-9]*\.[0-9.]*\).*$/\1/p'` case $ac_prog_version in '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; 1.2[6-9]* | 1.[3-9][0-9]* | [2-9].*) ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_prog_version" >&5 $as_echo "$ac_prog_version" >&6; } fi if test $ac_verc_fail = yes; then INTLBISON=: fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for long long int" >&5 $as_echo_n "checking for long long int... " >&6; } if test "${ac_cv_type_long_long_int+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Test preprocessor. */ #if ! (-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) error in preprocessor; #endif #if ! (18446744073709551615ULL <= -1ull) error in preprocessor; #endif /* Test literals. */ long long int ll = 9223372036854775807ll; long long int nll = -9223372036854775807LL; unsigned long long int ull = 18446744073709551615ULL; /* Test constant expressions. */ typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) ? 1 : -1)]; typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1 ? 1 : -1)]; int i = 63; int main () { /* Test availability of runtime routines for shift and division. */ long long int llmax = 9223372036854775807ll; unsigned long long int ullmax = 18446744073709551615ull; return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) | (llmax / ll) | (llmax % ll) | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i) | (ullmax / ull) | (ullmax % ull)); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : if test "$cross_compiling" = yes; then : ac_cv_type_long_long_int=yes else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #ifndef LLONG_MAX # define HALF \ (1LL << (sizeof (long long int) * CHAR_BIT - 2)) # define LLONG_MAX (HALF - 1 + HALF) #endif int main () { long long int n = 1; int i; for (i = 0; ; i++) { long long int m = n << i; if (m >> i != n) return 1; if (LLONG_MAX / 2 < m) break; } return 0; ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_type_long_long_int=yes else ac_cv_type_long_long_int=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi else ac_cv_type_long_long_int=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_long_long_int" >&5 $as_echo "$ac_cv_type_long_long_int" >&6; } if test $ac_cv_type_long_long_int = yes; then $as_echo "#define HAVE_LONG_LONG_INT 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for wchar_t" >&5 $as_echo_n "checking for wchar_t... " >&6; } if test "${gt_cv_c_wchar_t+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include wchar_t foo = (wchar_t)'\0'; int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : gt_cv_c_wchar_t=yes else gt_cv_c_wchar_t=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_c_wchar_t" >&5 $as_echo "$gt_cv_c_wchar_t" >&6; } if test $gt_cv_c_wchar_t = yes; then $as_echo "#define HAVE_WCHAR_T 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for wint_t" >&5 $as_echo_n "checking for wint_t... " >&6; } if test "${gt_cv_c_wint_t+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Tru64 with Desktop Toolkit C has a bug: must be included before . BSD/OS 4.0.1 has a bug: , and must be included before . */ #include #include #include #include wint_t foo = (wchar_t)'\0'; int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : gt_cv_c_wint_t=yes else gt_cv_c_wint_t=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_c_wint_t" >&5 $as_echo "$gt_cv_c_wint_t" >&6; } if test $gt_cv_c_wint_t = yes; then $as_echo "#define HAVE_WINT_T 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for intmax_t" >&5 $as_echo_n "checking for intmax_t... " >&6; } if test "${gt_cv_c_intmax_t+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #if HAVE_STDINT_H_WITH_UINTMAX #include #endif #if HAVE_INTTYPES_H_WITH_UINTMAX #include #endif int main () { intmax_t x = -1; return !x; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : gt_cv_c_intmax_t=yes else gt_cv_c_intmax_t=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_c_intmax_t" >&5 $as_echo "$gt_cv_c_intmax_t" >&6; } if test $gt_cv_c_intmax_t = yes; then $as_echo "#define HAVE_INTMAX_T 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether printf() supports POSIX/XSI format strings" >&5 $as_echo_n "checking whether printf() supports POSIX/XSI format strings... " >&6; } if test "${gt_cv_func_printf_posix+set}" = set; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #if defined __NetBSD__ || defined __BEOS__ || defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__ notposix #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "notposix" >/dev/null 2>&1; then : gt_cv_func_printf_posix="guessing no" else gt_cv_func_printf_posix="guessing yes" fi rm -f conftest* else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include /* The string "%2$d %1$d", with dollar characters protected from the shell's dollar expansion (possibly an autoconf bug). */ static char format[] = { '%', '2', '$', 'd', ' ', '%', '1', '$', 'd', '\0' }; static char buf[100]; int main () { sprintf (buf, format, 33, 55); return (strcmp (buf, "55 33") != 0); } _ACEOF if ac_fn_c_try_run "$LINENO"; then : gt_cv_func_printf_posix=yes else gt_cv_func_printf_posix=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_printf_posix" >&5 $as_echo "$gt_cv_func_printf_posix" >&6; } case $gt_cv_func_printf_posix in *yes) $as_echo "#define HAVE_POSIX_PRINTF 1" >>confdefs.h ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C Library 2.1 or newer" >&5 $as_echo_n "checking whether we are using the GNU C Library 2.1 or newer... " >&6; } if test "${ac_cv_gnu_library_2_1+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #ifdef __GNU_LIBRARY__ #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2) Lucky GNU user #endif #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "Lucky GNU user" >/dev/null 2>&1; then : ac_cv_gnu_library_2_1=yes else ac_cv_gnu_library_2_1=no fi rm -f conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_gnu_library_2_1" >&5 $as_echo "$ac_cv_gnu_library_2_1" >&6; } GLIBC21="$ac_cv_gnu_library_2_1" for ac_header in stdint.h do : ac_fn_c_check_header_mongrel "$LINENO" "stdint.h" "ac_cv_header_stdint_h" "$ac_includes_default" if test "x$ac_cv_header_stdint_h" = x""yes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STDINT_H 1 _ACEOF fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SIZE_MAX" >&5 $as_echo_n "checking for SIZE_MAX... " >&6; } if test "${gl_cv_size_max+set}" = set; then : $as_echo_n "(cached) " >&6 else gl_cv_size_max= cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #if HAVE_STDINT_H #include #endif #ifdef SIZE_MAX Found it #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "Found it" >/dev/null 2>&1; then : gl_cv_size_max=yes fi rm -f conftest* if test -z "$gl_cv_size_max"; then if ac_fn_c_compute_int "$LINENO" "sizeof (size_t) * CHAR_BIT - 1" "size_t_bits_minus_1" "#include #include "; then : else size_t_bits_minus_1= fi if ac_fn_c_compute_int "$LINENO" "sizeof (size_t) <= sizeof (unsigned int)" "fits_in_uint" "#include "; then : else fits_in_uint= fi if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then if test $fits_in_uint = 1; then cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include extern size_t foo; extern unsigned long foo; int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : fits_in_uint=0 fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi if test $fits_in_uint = 1; then gl_cv_size_max="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)" else gl_cv_size_max="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)" fi else gl_cv_size_max='((size_t)~(size_t)0)' fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_size_max" >&5 $as_echo "$gl_cv_size_max" >&6; } if test "$gl_cv_size_max" != yes; then cat >>confdefs.h <<_ACEOF #define SIZE_MAX $gl_cv_size_max _ACEOF fi for ac_header in stdint.h do : ac_fn_c_check_header_mongrel "$LINENO" "stdint.h" "ac_cv_header_stdint_h" "$ac_includes_default" if test "x$ac_cv_header_stdint_h" = x""yes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STDINT_H 1 _ACEOF fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFPreferencesCopyAppValue" >&5 $as_echo_n "checking for CFPreferencesCopyAppValue... " >&6; } if test "${gt_cv_func_CFPreferencesCopyAppValue+set}" = set; then : $as_echo_n "(cached) " >&6 else gt_save_LIBS="$LIBS" LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { CFPreferencesCopyAppValue(NULL, NULL) ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : gt_cv_func_CFPreferencesCopyAppValue=yes else gt_cv_func_CFPreferencesCopyAppValue=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS="$gt_save_LIBS" fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_CFPreferencesCopyAppValue" >&5 $as_echo "$gt_cv_func_CFPreferencesCopyAppValue" >&6; } if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then $as_echo "#define HAVE_CFPREFERENCESCOPYAPPVALUE 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFLocaleCopyCurrent" >&5 $as_echo_n "checking for CFLocaleCopyCurrent... " >&6; } if test "${gt_cv_func_CFLocaleCopyCurrent+set}" = set; then : $as_echo_n "(cached) " >&6 else gt_save_LIBS="$LIBS" LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { CFLocaleCopyCurrent(); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : gt_cv_func_CFLocaleCopyCurrent=yes else gt_cv_func_CFLocaleCopyCurrent=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS="$gt_save_LIBS" fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_CFLocaleCopyCurrent" >&5 $as_echo "$gt_cv_func_CFLocaleCopyCurrent" >&6; } if test $gt_cv_func_CFLocaleCopyCurrent = yes; then $as_echo "#define HAVE_CFLOCALECOPYCURRENT 1" >>confdefs.h fi INTL_MACOSX_LIBS= if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation" fi ac_fn_c_check_type "$LINENO" "ptrdiff_t" "ac_cv_type_ptrdiff_t" "$ac_includes_default" if test "x$ac_cv_type_ptrdiff_t" = x""yes; then : else $as_echo "#define ptrdiff_t long" >>confdefs.h fi for ac_header in stddef.h stdlib.h string.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done for ac_func in asprintf fwprintf putenv setenv setlocale snprintf wcslen do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether _snprintf is declared" >&5 $as_echo_n "checking whether _snprintf is declared... " >&6; } if test "${ac_cv_have_decl__snprintf+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { #ifndef _snprintf char *p = (char *) _snprintf; #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_have_decl__snprintf=yes else ac_cv_have_decl__snprintf=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_decl__snprintf" >&5 $as_echo "$ac_cv_have_decl__snprintf" >&6; } if test $ac_cv_have_decl__snprintf = yes; then gt_value=1 else gt_value=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL__SNPRINTF $gt_value _ACEOF { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether _snwprintf is declared" >&5 $as_echo_n "checking whether _snwprintf is declared... " >&6; } if test "${ac_cv_have_decl__snwprintf+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { #ifndef _snwprintf char *p = (char *) _snwprintf; #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_have_decl__snwprintf=yes else ac_cv_have_decl__snwprintf=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_decl__snwprintf" >&5 $as_echo "$ac_cv_have_decl__snwprintf" >&6; } if test $ac_cv_have_decl__snwprintf = yes; then gt_value=1 else gt_value=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL__SNWPRINTF $gt_value _ACEOF { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether getc_unlocked is declared" >&5 $as_echo_n "checking whether getc_unlocked is declared... " >&6; } if test "${ac_cv_have_decl_getc_unlocked+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { #ifndef getc_unlocked char *p = (char *) getc_unlocked; #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_have_decl_getc_unlocked=yes else ac_cv_have_decl_getc_unlocked=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_decl_getc_unlocked" >&5 $as_echo "$ac_cv_have_decl_getc_unlocked" >&6; } if test $ac_cv_have_decl_getc_unlocked = yes; then gt_value=1 else gt_value=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_GETC_UNLOCKED $gt_value _ACEOF case $gt_cv_func_printf_posix in *yes) HAVE_POSIX_PRINTF=1 ;; *) HAVE_POSIX_PRINTF=0 ;; esac if test "$ac_cv_func_asprintf" = yes; then HAVE_ASPRINTF=1 else HAVE_ASPRINTF=0 fi if test "$ac_cv_func_snprintf" = yes; then HAVE_SNPRINTF=1 else HAVE_SNPRINTF=0 fi if test "$ac_cv_func_wprintf" = yes; then HAVE_WPRINTF=1 else HAVE_WPRINTF=0 fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for nl_langinfo and CODESET" >&5 $as_echo_n "checking for nl_langinfo and CODESET... " >&6; } if test "${am_cv_langinfo_codeset+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { char* cs = nl_langinfo(CODESET); return !cs; ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : am_cv_langinfo_codeset=yes else am_cv_langinfo_codeset=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_langinfo_codeset" >&5 $as_echo "$am_cv_langinfo_codeset" >&6; } if test $am_cv_langinfo_codeset = yes; then $as_echo "#define HAVE_LANGINFO_CODESET 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for LC_MESSAGES" >&5 $as_echo_n "checking for LC_MESSAGES... " >&6; } if test "${gt_cv_val_LC_MESSAGES+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { return LC_MESSAGES ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : gt_cv_val_LC_MESSAGES=yes else gt_cv_val_LC_MESSAGES=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_val_LC_MESSAGES" >&5 $as_echo "$gt_cv_val_LC_MESSAGES" >&6; } if test $gt_cv_val_LC_MESSAGES = yes; then $as_echo "#define HAVE_LC_MESSAGES 1" >>confdefs.h fi if test "$enable_shared" = yes; then case "$host_os" in mingw* | cygwin*) is_woe32dll=yes ;; *) is_woe32dll=no ;; esac else is_woe32dll=no fi WOE32DLL=$is_woe32dll case "$host_os" in mingw* | cygwin*) is_woe32=yes ;; *) is_woe32=no ;; esac WOE32=$is_woe32 if test $WOE32 = yes; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}windres", so it can be a program name with args. set dummy ${ac_tool_prefix}windres; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_WINDRES+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$WINDRES"; then ac_cv_prog_WINDRES="$WINDRES" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_WINDRES="${ac_tool_prefix}windres" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi WINDRES=$ac_cv_prog_WINDRES if test -n "$WINDRES"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $WINDRES" >&5 $as_echo "$WINDRES" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_WINDRES"; then ac_ct_WINDRES=$WINDRES # Extract the first word of "windres", so it can be a program name with args. set dummy windres; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_WINDRES+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_WINDRES"; then ac_cv_prog_ac_ct_WINDRES="$ac_ct_WINDRES" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_WINDRES="windres" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_WINDRES=$ac_cv_prog_ac_ct_WINDRES if test -n "$ac_ct_WINDRES"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_WINDRES" >&5 $as_echo "$ac_ct_WINDRES" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_WINDRES" = x; then WINDRES="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac WINDRES=$ac_ct_WINDRES fi else WINDRES="$ac_cv_prog_WINDRES" fi fi case "$host_os" in hpux*) LTLIBC="" ;; *) LTLIBC="-lc" ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFPreferencesCopyAppValue" >&5 $as_echo_n "checking for CFPreferencesCopyAppValue... " >&6; } if test "${gt_cv_func_CFPreferencesCopyAppValue+set}" = set; then : $as_echo_n "(cached) " >&6 else gt_save_LIBS="$LIBS" LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { CFPreferencesCopyAppValue(NULL, NULL) ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : gt_cv_func_CFPreferencesCopyAppValue=yes else gt_cv_func_CFPreferencesCopyAppValue=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS="$gt_save_LIBS" fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_CFPreferencesCopyAppValue" >&5 $as_echo "$gt_cv_func_CFPreferencesCopyAppValue" >&6; } if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then $as_echo "#define HAVE_CFPREFERENCESCOPYAPPVALUE 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFLocaleCopyCurrent" >&5 $as_echo_n "checking for CFLocaleCopyCurrent... " >&6; } if test "${gt_cv_func_CFLocaleCopyCurrent+set}" = set; then : $as_echo_n "(cached) " >&6 else gt_save_LIBS="$LIBS" LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { CFLocaleCopyCurrent(); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : gt_cv_func_CFLocaleCopyCurrent=yes else gt_cv_func_CFLocaleCopyCurrent=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS="$gt_save_LIBS" fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_CFLocaleCopyCurrent" >&5 $as_echo "$gt_cv_func_CFLocaleCopyCurrent" >&6; } if test $gt_cv_func_CFLocaleCopyCurrent = yes; then $as_echo "#define HAVE_CFLOCALECOPYCURRENT 1" >>confdefs.h fi INTL_MACOSX_LIBS= if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation" fi BUILD_INCLUDED_LIBINTL=no USE_INCLUDED_LIBINTL=no LIBINTL= LTLIBINTL= POSUB= case " $gt_needs " in *" need-formatstring-macros "*) gt_api_version=3 ;; *" need-ngettext "*) gt_api_version=2 ;; *) gt_api_version=1 ;; esac gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc" gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl" if test "$USE_NLS" = "yes"; then gt_use_preinstalled_gnugettext=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether included gettext is requested" >&5 $as_echo_n "checking whether included gettext is requested... " >&6; } # Check whether --with-included-gettext was given. if test "${with_included_gettext+set}" = set; then : withval=$with_included_gettext; nls_cv_force_use_gnu_gettext=$withval else nls_cv_force_use_gnu_gettext=no fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $nls_cv_force_use_gnu_gettext" >&5 $as_echo "$nls_cv_force_use_gnu_gettext" >&6; } nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext" if test "$nls_cv_force_use_gnu_gettext" != "yes"; then if test $gt_api_version -ge 3; then gt_revision_test_code=' #ifndef __GNU_GETTEXT_SUPPORTED_REVISION #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) #endif typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; ' else gt_revision_test_code= fi if test $gt_api_version -ge 2; then gt_expression_test_code=' + * ngettext ("", "", 0)' else gt_expression_test_code= fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU gettext in libc" >&5 $as_echo_n "checking for GNU gettext in libc... " >&6; } if eval "test \"\${$gt_func_gnugettext_libc+set}\"" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include $gt_revision_test_code extern int _nl_msg_cat_cntr; extern int *_nl_domain_bindings; int main () { bindtextdomain ("", ""); return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_bindings ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : eval "$gt_func_gnugettext_libc=yes" else eval "$gt_func_gnugettext_libc=no" fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi eval ac_res=\$$gt_func_gnugettext_libc { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then use_additional=yes acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" # Check whether --with-libintl-prefix was given. if test "${with_libintl_prefix+set}" = set; then : withval=$with_libintl_prefix; if test "X$withval" = "Xno"; then use_additional=no else if test "X$withval" = "X"; then acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval additional_includedir=\"$includedir\" eval additional_libdir=\"$libdir\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" else additional_includedir="$withval/include" additional_libdir="$withval/$acl_libdirstem" fi fi fi LIBINTL= LTLIBINTL= INCINTL= LIBINTL_PREFIX= rpathdirs= ltrpathdirs= names_already_handled= names_next_round='intl ' while test -n "$names_next_round"; do names_this_round="$names_next_round" names_next_round= for name in $names_this_round; do already_handled= for n in $names_already_handled; do if test "$n" = "$name"; then already_handled=yes break fi done if test -z "$already_handled"; then names_already_handled="$names_already_handled $name" uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'` eval value=\"\$HAVE_LIB$uppername\" if test -n "$value"; then if test "$value" = yes; then eval value=\"\$LIB$uppername\" test -z "$value" || LIBINTL="${LIBINTL}${LIBINTL:+ }$value" eval value=\"\$LTLIB$uppername\" test -z "$value" || LTLIBINTL="${LTLIBINTL}${LTLIBINTL:+ }$value" else : fi else found_dir= found_la= found_so= found_a= eval libname=\"$acl_libname_spec\" # typically: libname=lib$name if test -n "$acl_shlibext"; then shrext=".$acl_shlibext" # typically: shrext=.so else shrext= fi if test $use_additional = yes; then dir="$additional_libdir" if test -n "$acl_shlibext"; then if test -f "$dir/$libname$shrext"; then found_dir="$dir" found_so="$dir/$libname$shrext" else if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then ver=`(cd "$dir" && \ for f in "$libname$shrext".*; do echo "$f"; done \ | sed -e "s,^$libname$shrext\\\\.,," \ | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | sed 1q ) 2>/dev/null` if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then found_dir="$dir" found_so="$dir/$libname$shrext.$ver" fi else eval library_names=\"$acl_library_names_spec\" for f in $library_names; do if test -f "$dir/$f"; then found_dir="$dir" found_so="$dir/$f" break fi done fi fi fi if test "X$found_dir" = "X"; then if test -f "$dir/$libname.$acl_libext"; then found_dir="$dir" found_a="$dir/$libname.$acl_libext" fi fi if test "X$found_dir" != "X"; then if test -f "$dir/$libname.la"; then found_la="$dir/$libname.la" fi fi fi if test "X$found_dir" = "X"; then for x in $LDFLAGS $LTLIBINTL; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" case "$x" in -L*) dir=`echo "X$x" | sed -e 's/^X-L//'` if test -n "$acl_shlibext"; then if test -f "$dir/$libname$shrext"; then found_dir="$dir" found_so="$dir/$libname$shrext" else if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then ver=`(cd "$dir" && \ for f in "$libname$shrext".*; do echo "$f"; done \ | sed -e "s,^$libname$shrext\\\\.,," \ | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ | sed 1q ) 2>/dev/null` if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then found_dir="$dir" found_so="$dir/$libname$shrext.$ver" fi else eval library_names=\"$acl_library_names_spec\" for f in $library_names; do if test -f "$dir/$f"; then found_dir="$dir" found_so="$dir/$f" break fi done fi fi fi if test "X$found_dir" = "X"; then if test -f "$dir/$libname.$acl_libext"; then found_dir="$dir" found_a="$dir/$libname.$acl_libext" fi fi if test "X$found_dir" != "X"; then if test -f "$dir/$libname.la"; then found_la="$dir/$libname.la" fi fi ;; esac if test "X$found_dir" != "X"; then break fi done fi if test "X$found_dir" != "X"; then LTLIBINTL="${LTLIBINTL}${LTLIBINTL:+ }-L$found_dir -l$name" if test "X$found_so" != "X"; then if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/$acl_libdirstem"; then LIBINTL="${LIBINTL}${LIBINTL:+ }$found_so" else haveit= for x in $ltrpathdirs; do if test "X$x" = "X$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then ltrpathdirs="$ltrpathdirs $found_dir" fi if test "$acl_hardcode_direct" = yes; then LIBINTL="${LIBINTL}${LIBINTL:+ }$found_so" else if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then LIBINTL="${LIBINTL}${LIBINTL:+ }$found_so" haveit= for x in $rpathdirs; do if test "X$x" = "X$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then rpathdirs="$rpathdirs $found_dir" fi else haveit= for x in $LDFLAGS $LIBINTL; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-L$found_dir"; then haveit=yes break fi done if test -z "$haveit"; then LIBINTL="${LIBINTL}${LIBINTL:+ }-L$found_dir" fi if test "$acl_hardcode_minus_L" != no; then LIBINTL="${LIBINTL}${LIBINTL:+ }$found_so" else LIBINTL="${LIBINTL}${LIBINTL:+ }-l$name" fi fi fi fi else if test "X$found_a" != "X"; then LIBINTL="${LIBINTL}${LIBINTL:+ }$found_a" else LIBINTL="${LIBINTL}${LIBINTL:+ }-L$found_dir -l$name" fi fi additional_includedir= case "$found_dir" in */$acl_libdirstem | */$acl_libdirstem/) basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'` LIBINTL_PREFIX="$basedir" additional_includedir="$basedir/include" ;; esac if test "X$additional_includedir" != "X"; then if test "X$additional_includedir" != "X/usr/include"; then haveit= if test "X$additional_includedir" = "X/usr/local/include"; then if test -n "$GCC"; then case $host_os in linux* | gnu* | k*bsd*-gnu) haveit=yes;; esac fi fi if test -z "$haveit"; then for x in $CPPFLAGS $INCINTL; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-I$additional_includedir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_includedir"; then INCINTL="${INCINTL}${INCINTL:+ }-I$additional_includedir" fi fi fi fi fi if test -n "$found_la"; then save_libdir="$libdir" case "$found_la" in */* | *\\*) . "$found_la" ;; *) . "./$found_la" ;; esac libdir="$save_libdir" for dep in $dependency_libs; do case "$dep" in -L*) additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'` if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then haveit= if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then if test -n "$GCC"; then case $host_os in linux* | gnu* | k*bsd*-gnu) haveit=yes;; esac fi fi if test -z "$haveit"; then haveit= for x in $LDFLAGS $LIBINTL; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-L$additional_libdir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_libdir"; then LIBINTL="${LIBINTL}${LIBINTL:+ }-L$additional_libdir" fi fi haveit= for x in $LDFLAGS $LTLIBINTL; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X-L$additional_libdir"; then haveit=yes break fi done if test -z "$haveit"; then if test -d "$additional_libdir"; then LTLIBINTL="${LTLIBINTL}${LTLIBINTL:+ }-L$additional_libdir" fi fi fi fi ;; -R*) dir=`echo "X$dep" | sed -e 's/^X-R//'` if test "$enable_rpath" != no; then haveit= for x in $rpathdirs; do if test "X$x" = "X$dir"; then haveit=yes break fi done if test -z "$haveit"; then rpathdirs="$rpathdirs $dir" fi haveit= for x in $ltrpathdirs; do if test "X$x" = "X$dir"; then haveit=yes break fi done if test -z "$haveit"; then ltrpathdirs="$ltrpathdirs $dir" fi fi ;; -l*) names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'` ;; *.la) names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'` ;; *) LIBINTL="${LIBINTL}${LIBINTL:+ }$dep" LTLIBINTL="${LTLIBINTL}${LTLIBINTL:+ }$dep" ;; esac done fi else LIBINTL="${LIBINTL}${LIBINTL:+ }-l$name" LTLIBINTL="${LTLIBINTL}${LTLIBINTL:+ }-l$name" fi fi fi done done if test "X$rpathdirs" != "X"; then if test -n "$acl_hardcode_libdir_separator"; then alldirs= for found_dir in $rpathdirs; do alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir" done acl_save_libdir="$libdir" libdir="$alldirs" eval flag=\"$acl_hardcode_libdir_flag_spec\" libdir="$acl_save_libdir" LIBINTL="${LIBINTL}${LIBINTL:+ }$flag" else for found_dir in $rpathdirs; do acl_save_libdir="$libdir" libdir="$found_dir" eval flag=\"$acl_hardcode_libdir_flag_spec\" libdir="$acl_save_libdir" LIBINTL="${LIBINTL}${LIBINTL:+ }$flag" done fi fi if test "X$ltrpathdirs" != "X"; then for found_dir in $ltrpathdirs; do LTLIBINTL="${LTLIBINTL}${LTLIBINTL:+ }-R$found_dir" done fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU gettext in libintl" >&5 $as_echo_n "checking for GNU gettext in libintl... " >&6; } if eval "test \"\${$gt_func_gnugettext_libintl+set}\"" = set; then : $as_echo_n "(cached) " >&6 else gt_save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $INCINTL" gt_save_LIBS="$LIBS" LIBS="$LIBS $LIBINTL" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include $gt_revision_test_code extern int _nl_msg_cat_cntr; extern #ifdef __cplusplus "C" #endif const char *_nl_expand_alias (const char *); int main () { bindtextdomain ("", ""); return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("") ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : eval "$gt_func_gnugettext_libintl=yes" else eval "$gt_func_gnugettext_libintl=no" fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then LIBS="$LIBS $LIBICONV" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include $gt_revision_test_code extern int _nl_msg_cat_cntr; extern #ifdef __cplusplus "C" #endif const char *_nl_expand_alias (const char *); int main () { bindtextdomain ("", ""); return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("") ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : LIBINTL="$LIBINTL $LIBICONV" LTLIBINTL="$LTLIBINTL $LTLIBICONV" eval "$gt_func_gnugettext_libintl=yes" fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi CPPFLAGS="$gt_save_CPPFLAGS" LIBS="$gt_save_LIBS" fi eval ac_res=\$$gt_func_gnugettext_libintl { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } fi if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \ || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \ && test "$PACKAGE" != gettext-runtime \ && test "$PACKAGE" != gettext-tools; }; then gt_use_preinstalled_gnugettext=yes else LIBINTL= LTLIBINTL= INCINTL= fi if test "$gt_use_preinstalled_gnugettext" != "yes"; then nls_cv_use_gnu_gettext=yes fi fi if test "$nls_cv_use_gnu_gettext" = "yes"; then BUILD_INCLUDED_LIBINTL=yes USE_INCLUDED_LIBINTL=yes LIBINTL="\${top_builddir}/intl/libintl.a $LIBICONV $LIBTHREAD" LTLIBINTL="\${top_builddir}/intl/libintl.a $LTLIBICONV $LTLIBTHREAD" LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'` fi CATOBJEXT= if test "$gt_use_preinstalled_gnugettext" = "yes" \ || test "$nls_cv_use_gnu_gettext" = "yes"; then CATOBJEXT=.gmo fi if test -n "$INTL_MACOSX_LIBS"; then if test "$gt_use_preinstalled_gnugettext" = "yes" \ || test "$nls_cv_use_gnu_gettext" = "yes"; then LIBINTL="$LIBINTL $INTL_MACOSX_LIBS" LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS" fi fi if test "$gt_use_preinstalled_gnugettext" = "yes" \ || test "$nls_cv_use_gnu_gettext" = "yes"; then $as_echo "#define ENABLE_NLS 1" >>confdefs.h else USE_NLS=no fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use NLS" >&5 $as_echo_n "checking whether to use NLS... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_NLS" >&5 $as_echo "$USE_NLS" >&6; } if test "$USE_NLS" = "yes"; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking where the gettext function comes from" >&5 $as_echo_n "checking where the gettext function comes from... " >&6; } if test "$gt_use_preinstalled_gnugettext" = "yes"; then if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then gt_source="external libintl" else gt_source="libc" fi else gt_source="included intl directory" fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_source" >&5 $as_echo "$gt_source" >&6; } fi if test "$USE_NLS" = "yes"; then if test "$gt_use_preinstalled_gnugettext" = "yes"; then if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libintl" >&5 $as_echo_n "checking how to link with libintl... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBINTL" >&5 $as_echo "$LIBINTL" >&6; } for element in $INCINTL; do haveit= for x in $CPPFLAGS; do acl_save_prefix="$prefix" prefix="$acl_final_prefix" acl_save_exec_prefix="$exec_prefix" exec_prefix="$acl_final_exec_prefix" eval x=\"$x\" exec_prefix="$acl_save_exec_prefix" prefix="$acl_save_prefix" if test "X$x" = "X$element"; then haveit=yes break fi done if test -z "$haveit"; then CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element" fi done fi $as_echo "#define HAVE_GETTEXT 1" >>confdefs.h $as_echo "#define HAVE_DCGETTEXT 1" >>confdefs.h fi POSUB=po fi if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then BUILD_INCLUDED_LIBINTL=yes fi nls_cv_header_intl= nls_cv_header_libgt= DATADIRNAME=share INSTOBJEXT=.mo GENCAT=gencat INTLOBJS= if test "$USE_INCLUDED_LIBINTL" = yes; then INTLOBJS="\$(GETTOBJS)" fi INTL_LIBTOOL_SUFFIX_PREFIX= INTLLIBS="$LIBINTL" # Checks for programs. ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. set dummy ${ac_tool_prefix}gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_CC"; then ac_ct_CC=$CC # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi else CC="$ac_cv_prog_CC" fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. set dummy ${ac_tool_prefix}cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else ac_prog_rejected=no as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue fi ac_cv_prog_CC="cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" fi fi fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then for ac_prog in cl.exe do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$CC" && break done fi if test -z "$CC"; then ac_ct_CC=$CC for ac_prog in cl.exe do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$ac_ct_CC" && break done if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi fi test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See \`config.log' for more details" "$LINENO" 5 ; } # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; } if test "${ac_cv_c_compiler_gnu+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_compiler_gnu=yes else ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 $as_echo "$ac_cv_c_compiler_gnu" >&6; } if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 $as_echo_n "checking whether $CC accepts -g... " >&6; } if test "${ac_cv_prog_cc_g+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes else CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 $as_echo "$ac_cv_prog_cc_g" >&6; } if test "$ac_test_CFLAGS" = set; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; } if test "${ac_cv_prog_cc_c89+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); static char *e (p, i) char **p; int i; { return p[i]; } static char *f (char * (*g) (char **, int), char **p, ...) { char *s; va_list v; va_start (v,p); s = g (p, va_arg (v,int)); va_end (v); return s; } /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has function prototypes and stuff, but not '\xHH' hex character constants. These don't provoke an error unfortunately, instead are silently treated as 'x'. The following induces an error, until -std is added to get proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an array size at least. It's necessary to write '\x00'==0 to get something that's true only with -std. */ int osf4_cc_array ['\x00' == 0 ? 1 : -1]; /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters inside strings and character constants. */ #define FOO(x) 'x' int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; int test (int i, double x); struct s1 {int (*f) (int a);}; struct s2 {int (*f) (double a);}; int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); int argc; char **argv; int main () { return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; ; return 0; } _ACEOF for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_c89=$ac_arg fi rm -f core conftest.err conftest.$ac_objext test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi # AC_CACHE_VAL case "x$ac_cv_prog_cc_c89" in x) { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 $as_echo "none needed" >&6; } ;; xno) { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 $as_echo "unsupported" >&6; } ;; *) CC="$CC $ac_cv_prog_cc_c89" { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 $as_echo "$ac_cv_prog_cc_c89" >&6; } ;; esac if test "x$ac_cv_prog_cc_c89" != xno; then : fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args. set dummy ${ac_tool_prefix}pkg-config; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_path_PKG_CONFIG+set}" = set; then : $as_echo_n "(cached) " >&6 else case $PKG_CONFIG in [\\/]* | ?:[\\/]*) ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi PKG_CONFIG=$ac_cv_path_PKG_CONFIG if test -n "$PKG_CONFIG"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5 $as_echo "$PKG_CONFIG" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_path_PKG_CONFIG"; then ac_pt_PKG_CONFIG=$PKG_CONFIG # Extract the first word of "pkg-config", so it can be a program name with args. set dummy pkg-config; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_path_ac_pt_PKG_CONFIG+set}" = set; then : $as_echo_n "(cached) " >&6 else case $ac_pt_PKG_CONFIG in [\\/]* | ?:[\\/]*) ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG if test -n "$ac_pt_PKG_CONFIG"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5 $as_echo "$ac_pt_PKG_CONFIG" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_pt_PKG_CONFIG" = x; then PKG_CONFIG="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac PKG_CONFIG=$ac_pt_PKG_CONFIG fi else PKG_CONFIG="$ac_cv_path_PKG_CONFIG" fi fi if test -n "$PKG_CONFIG"; then _pkg_min_version=0.22 { $as_echo "$as_me:${as_lineno-$LINENO}: checking pkg-config is at least version $_pkg_min_version" >&5 $as_echo_n "checking pkg-config is at least version $_pkg_min_version... " >&6; } if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } PKG_CONFIG="" fi fi # Checks for libraries. pkg_failed=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking for DBUS" >&5 $as_echo_n "checking for DBUS... " >&6; } if test -n "$DBUS_CFLAGS"; then pkg_cv_DBUS_CFLAGS="$DBUS_CFLAGS" elif test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG" && \ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"dbus-1 >= 1.2.16\""; } >&5 ($PKG_CONFIG --exists --print-errors "dbus-1 >= 1.2.16") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then pkg_cv_DBUS_CFLAGS=`$PKG_CONFIG --cflags "dbus-1 >= 1.2.16" 2>/dev/null` else pkg_failed=yes fi else pkg_failed=untried fi if test -n "$DBUS_LIBS"; then pkg_cv_DBUS_LIBS="$DBUS_LIBS" elif test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG" && \ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"dbus-1 >= 1.2.16\""; } >&5 ($PKG_CONFIG --exists --print-errors "dbus-1 >= 1.2.16") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then pkg_cv_DBUS_LIBS=`$PKG_CONFIG --libs "dbus-1 >= 1.2.16" 2>/dev/null` else pkg_failed=yes fi else pkg_failed=untried fi if test $pkg_failed = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then _pkg_short_errors_supported=yes else _pkg_short_errors_supported=no fi if test $_pkg_short_errors_supported = yes; then DBUS_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "dbus-1 >= 1.2.16" 2>&1` else DBUS_PKG_ERRORS=`$PKG_CONFIG --print-errors "dbus-1 >= 1.2.16" 2>&1` fi # Put the nasty error message in config.log where it belongs echo "$DBUS_PKG_ERRORS" >&5 as_fn_error $? "Package requirements (dbus-1 >= 1.2.16) were not met: $DBUS_PKG_ERRORS Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables DBUS_CFLAGS and DBUS_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details." "$LINENO" 5 elif test $pkg_failed = untried; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config. Alternatively, you may set the environment variables DBUS_CFLAGS and DBUS_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details. To get pkg-config, see . See \`config.log' for more details" "$LINENO" 5 ; } else DBUS_CFLAGS=$pkg_cv_DBUS_CFLAGS DBUS_LIBS=$pkg_cv_DBUS_LIBS { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for XML_ParserCreate in -lexpat" >&5 $as_echo_n "checking for XML_ParserCreate in -lexpat... " >&6; } if test "${ac_cv_lib_expat_XML_ParserCreate+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lexpat $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char XML_ParserCreate (); int main () { return XML_ParserCreate (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_expat_XML_ParserCreate=yes else ac_cv_lib_expat_XML_ParserCreate=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_expat_XML_ParserCreate" >&5 $as_echo "$ac_cv_lib_expat_XML_ParserCreate" >&6; } if test "x$ac_cv_lib_expat_XML_ParserCreate" = x""yes; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking for XML_StopParser in -lexpat" >&5 $as_echo_n "checking for XML_StopParser in -lexpat... " >&6; } if test "${ac_cv_lib_expat_XML_StopParser+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lexpat $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char XML_StopParser (); int main () { return XML_StopParser (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_expat_XML_StopParser=yes else ac_cv_lib_expat_XML_StopParser=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_expat_XML_StopParser" >&5 $as_echo "$ac_cv_lib_expat_XML_StopParser" >&6; } if test "x$ac_cv_lib_expat_XML_StopParser" = x""yes; then : EXPAT_LIBS=-lexpat else as_fn_error $? "expat >= 2.0.0 required" "$LINENO" 5 fi else as_fn_error $? "expat library not found" "$LINENO" 5 fi # Checks for header files. for ac_header in valgrind/valgrind.h do : ac_fn_c_check_header_mongrel "$LINENO" "valgrind/valgrind.h" "ac_cv_header_valgrind_valgrind_h" "$ac_includes_default" if test "x$ac_cv_header_valgrind_valgrind_h" = x""yes; then : cat >>confdefs.h <<_ACEOF #define HAVE_VALGRIND_VALGRIND_H 1 _ACEOF fi done # Checks for typedefs, structures, and compiler characteristics. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C99" >&5 $as_echo_n "checking for $CC option to accept ISO C99... " >&6; } if test "${ac_cv_prog_cc_c99+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c99=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include #include // Check varargs macros. These examples are taken from C99 6.10.3.5. #define debug(...) fprintf (stderr, __VA_ARGS__) #define showlist(...) puts (#__VA_ARGS__) #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__)) static void test_varargs_macros (void) { int x = 1234; int y = 5678; debug ("Flag"); debug ("X = %d\n", x); showlist (The first, second, and third items.); report (x>y, "x is %d but y is %d", x, y); } // Check long long types. #define BIG64 18446744073709551615ull #define BIG32 4294967295ul #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0) #if !BIG_OK your preprocessor is broken; #endif #if BIG_OK #else your preprocessor is broken; #endif static long long int bignum = -9223372036854775807LL; static unsigned long long int ubignum = BIG64; struct incomplete_array { int datasize; double data[]; }; struct named_init { int number; const wchar_t *name; double average; }; typedef const char *ccp; static inline int test_restrict (ccp restrict text) { // See if C++-style comments work. // Iterate through items via the restricted pointer. // Also check for declarations in for loops. for (unsigned int i = 0; *(text+i) != '\0'; ++i) continue; return 0; } // Check varargs and va_copy. static void test_varargs (const char *format, ...) { va_list args; va_start (args, format); va_list args_copy; va_copy (args_copy, args); const char *str; int number; float fnumber; while (*format) { switch (*format++) { case 's': // string str = va_arg (args_copy, const char *); break; case 'd': // int number = va_arg (args_copy, int); break; case 'f': // float fnumber = va_arg (args_copy, double); break; default: break; } } va_end (args_copy); va_end (args); } int main () { // Check bool. _Bool success = false; // Check restrict. if (test_restrict ("String literal") == 0) success = true; char *restrict newvar = "Another string"; // Check varargs. test_varargs ("s, d' f .", "string", 65, 34.234); test_varargs_macros (); // Check flexible array members. struct incomplete_array *ia = malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10)); ia->datasize = 10; for (int i = 0; i < ia->datasize; ++i) ia->data[i] = i * 1.234; // Check named initializers. struct named_init ni = { .number = 34, .name = L"Test wide string", .average = 543.34343, }; ni.number = 58; int dynamic_array[ni.number]; dynamic_array[ni.number - 1] = 543; // work around unused variable warnings return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x' || dynamic_array[ni.number - 1] != 543); ; return 0; } _ACEOF for ac_arg in '' -std=gnu99 -std=c99 -c99 -AC99 -xc99=all -qlanglvl=extc99 do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_c99=$ac_arg fi rm -f core conftest.err conftest.$ac_objext test "x$ac_cv_prog_cc_c99" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi # AC_CACHE_VAL case "x$ac_cv_prog_cc_c99" in x) { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 $as_echo "none needed" >&6; } ;; xno) { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 $as_echo "unsupported" >&6; } ;; *) CC="$CC $ac_cv_prog_cc_c99" { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 $as_echo "$ac_cv_prog_cc_c99" >&6; } ;; esac if test "x$ac_cv_prog_cc_c99" != xno; then : fi if test "x$CC" != xcc; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC and cc understand -c and -o together" >&5 $as_echo_n "checking whether $CC and cc understand -c and -o together... " >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether cc understands -c and -o together" >&5 $as_echo_n "checking whether cc understands -c and -o together... " >&6; } fi set dummy $CC; ac_cc=`$as_echo "$2" | sed 's/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/'` if eval "test \"\${ac_cv_prog_cc_${ac_cc}_c_o+set}\"" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF # Make sure it works both with $CC and with simple cc. # We do the test twice because some compilers refuse to overwrite an # existing .o file with -o, though they will create one. ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&5' rm -f conftest2.* if { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -f conftest2.$ac_objext && { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then eval ac_cv_prog_cc_${ac_cc}_c_o=yes if test "x$CC" != xcc; then # Test first that cc exists at all. if { ac_try='cc -c conftest.$ac_ext >&5' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&5' rm -f conftest2.* if { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -f conftest2.$ac_objext && { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then # cc works too. : else # cc exists but doesn't like -o. eval ac_cv_prog_cc_${ac_cc}_c_o=no fi fi fi else eval ac_cv_prog_cc_${ac_cc}_c_o=no fi rm -f core conftest* fi if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } $as_echo "#define NO_MINUS_C_MINUS_O 1" >>confdefs.h fi # FIXME: we rely on the cache variable name because # there is no other way. set dummy $CC am_cc=`echo $2 | sed 's/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/'` eval am_t=\$ac_cv_prog_cc_${am_cc}_c_o if test "$am_t" != yes; then # Losing compiler, so override with the script. # FIXME: It is wrong to rewrite CC. # But if we don't then we get into trouble of one sort or another. # A longer-term fix would be to have automake use am__CC in this case, # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" CC="$am_aux_dir/compile $CC" fi # Check whether --enable-threading was given. if test "${enable_threading+set}" = set; then : enableval=$enable_threading; else enable_threading=no fi if test "x$enable_threading" != "xno" ; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiler supports __thread" >&5 $as_echo_n "checking whether compiler supports __thread... " >&6; } if test "${nih_cv_c_thread+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int __thread a; int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : nih_cv_c_thread=yes else nih_cv_c_thread=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $nih_cv_c_thread" >&5 $as_echo "$nih_cv_c_thread" >&6; } if test "x$nih_cv_c_thread" = "xno"; then : $as_echo "#define __thread /**/" >>confdefs.h fi else $as_echo "#define __thread /**/" >>confdefs.h fi # Checks for library functions. # Other checks # Check whether --enable-compiler-warnings was given. if test "${enable_compiler_warnings+set}" = set; then : enableval=$enable_compiler_warnings; if test "x$enable_compiler_warnings" = "xyes"; then : if test "x$GCC" = "xyes"; then : CFLAGS="-Wall -Wextra -Wno-empty-body -Wno-missing-field-initializers -Wno-unused-parameter -Wformat-security -Werror -D_FORTIFY_SOURCE=2 $CFLAGS" fi if test "x$GXX" = "xyes"; then : CXXFLAGS="-Wall -Wextra -Wno-empty-body -Wno-missing-field-initializers -Wno-unused-parameter -Wformat-security -Werror -D_FORTIFY_SOURCE=2 $CXXFLAGS" fi fi fi # Check whether --enable-compiler-optimisations was given. if test "${enable_compiler_optimisations+set}" = set; then : enableval=$enable_compiler_optimisations; if test "x$enable_compiler_optimisations" = "xno"; then : CFLAGS=`echo "$CFLAGS" | sed -e "s/ -O[1-9s]*\b/ -O0/g"` CXXFLAGS=`echo "$CXXFLAGS" | sed -e "s/ -O[1-9s]*\b/ -O0/g"` fi fi # Check whether --enable-compiler-coverage was given. if test "${enable_compiler_coverage+set}" = set; then : enableval=$enable_compiler_coverage; if test "x$enable_compiler_coverage" = "xyes"; then : if test "x$GCC" = "xyes"; then : CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage" fi if test "x$GXX" = "xyes"; then : CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage" fi fi fi # Check whether --enable-linker-optimisations was given. if test "${enable_linker_optimisations+set}" = set; then : enableval=$enable_linker_optimisations; if test "x$enable_linker_optimisations" = "xno"; then : LDFLAGS=`echo "$LDFLAGS" | sed -e "s/ -Wl,-O0-9*\b//g"` else LDFLAGS="$LDFLAGS -Wl,-O1" fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker version script argument" >&5 $as_echo_n "checking for linker version script argument... " >&6; } if test "${nih_cv_version_script+set}" = set; then : $as_echo_n "(cached) " >&6 else nih_cv_version_script=none for nih_try_arg in "-Wl,--version-script"; do nih_old_libs="$LIBS" LIBS="$LIBS $nih_try_arg=conftest.ver" cat >conftest.ver <conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : rm -f conftest.ver LIBS="$nih_old_libs" nih_cv_version_script="$nih_try_arg" break fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext rm -f conftest.ver LIBS="$nih_old_libs" done fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $nih_cv_version_script" >&5 $as_echo "$nih_cv_version_script" >&6; } if test "x$nih_cv_version_script" != "xnone"; then : VERSION_SCRIPT_ARG=$nih_cv_version_script fi if test "x$nih_cv_version_script" != "xnone"; then HAVE_VERSION_SCRIPT_ARG_TRUE= HAVE_VERSION_SCRIPT_ARG_FALSE='#' else HAVE_VERSION_SCRIPT_ARG_TRUE='#' HAVE_VERSION_SCRIPT_ARG_FALSE= fi # Allow a pre-build nih-dbus-tool to be used when cross-compiling. # Programs can just use AC_CHECK_PROGS for this if test "$cross_compiling" = "yes"; then : for ac_prog in nih-dbus-tool do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_NIH_DBUS_TOOL+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$NIH_DBUS_TOOL"; then ac_cv_prog_NIH_DBUS_TOOL="$NIH_DBUS_TOOL" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_NIH_DBUS_TOOL="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi NIH_DBUS_TOOL=$ac_cv_prog_NIH_DBUS_TOOL if test -n "$NIH_DBUS_TOOL"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NIH_DBUS_TOOL" >&5 $as_echo "$NIH_DBUS_TOOL" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$NIH_DBUS_TOOL" && break done if test -z "$NIH_DBUS_TOOL"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: nih-dbus-tool not found, but you are cross-compiling. Using built copy, which is probably not what you want. Set NIH_DBUS_TOOL maybe?" >&5 $as_echo "$as_me: WARNING: nih-dbus-tool not found, but you are cross-compiling. Using built copy, which is probably not what you want. Set NIH_DBUS_TOOL maybe?" >&2;} NIH_DBUS_TOOL="\${top_builddir}/nih-dbus-tool/nih-dbus-tool" fi else NIH_DBUS_TOOL="\${top_builddir}/nih-dbus-tool/nih-dbus-tool" fi ac_config_files="$ac_config_files Makefile m4/Makefile intl/Makefile nih/Makefile nih/libnih.pc nih-dbus/Makefile nih-dbus/libnih-dbus.pc nih-dbus-tool/Makefile po/Makefile.in" ac_config_headers="$ac_config_headers config.h" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs, see configure's option --config-cache. # It is not useful on other systems. If it contains results you don't # want to keep, you may remove or edit it. # # config.status only pays attention to the cache file if you give it # the --recheck option to rerun configure. # # `ac_cv_env_foo' variables (set or unset) will be overridden when # loading this file, other *unset* `ac_cv_foo' will be assigned the # following values. _ACEOF # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. ( for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space=' '; set) 2>&1` in #( *${as_nl}ac_space=\ *) # `set' does not quote correctly, so add quotes: double-quote # substitution turns \\\\ into \\, and sed turns \\ into \. sed -n \ "s/'/'\\\\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" ;; #( *) # `set' quotes correctly as required by POSIX, so do not add quotes. sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) | sed ' /^ac_cv_env_/b end t clear :clear s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ t end s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then test "x$cache_file" != "x/dev/null" && { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 $as_echo "$as_me: updating cache $cache_file" >&6;} cat confcache >$cache_file else { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' DEFS=-DHAVE_CONFIG_H ac_libobjs= ac_ltlibobjs= U= for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue # 1. Remove the extension, and $U if already installed. ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' ac_i=`$as_echo "$ac_i" | sed "$ac_script"` # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR # will be set to the directory where LIBOBJS objects are built. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' done LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then as_fn_error $? "conditional \"AMDEP\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then as_fn_error $? "conditional \"am__fastdepCC\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -n "$EXEEXT"; then am__EXEEXT_TRUE= am__EXEEXT_FALSE='#' else am__EXEEXT_TRUE='#' am__EXEEXT_FALSE= fi if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_VERSION_SCRIPT_ARG_TRUE}" && test -z "${HAVE_VERSION_SCRIPT_ARG_FALSE}"; then as_fn_error $? "conditional \"HAVE_VERSION_SCRIPT_ARG\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi : ${CONFIG_STATUS=./config.status} ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 $as_echo "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL # Generated by $as_me. # Run this file to recreate the current configuration. # Compiler output produced by configure, useful for debugging # configure, is in config.log if it exists. debug=false ac_cs_recheck=false ac_cs_silent=false SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -p' fi else as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi if test -x / >/dev/null 2>&1; then as_test_x='test -x' else if ls -dL / >/dev/null 2>&1; then as_ls_L_option=L else as_ls_L_option= fi as_test_x=' eval sh -c '\'' if test -d "$1"; then test -d "$1/."; else case $1 in #( -*)set "./$1";; esac; case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( ???[sx]*):;;*)false;;esac;fi '\'' sh ' fi as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" exec 6>&1 ## ----------------------------------- ## ## Main body of $CONFIG_STATUS script. ## ## ----------------------------------- ## _ASEOF test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" This file was extended by libnih $as_me 1.0.3, which was generated by GNU Autoconf 2.67. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS CONFIG_COMMANDS = $CONFIG_COMMANDS $ $0 $@ on `(hostname || uname -n) 2>/dev/null | sed 1q` " _ACEOF case $ac_config_files in *" "*) set x $ac_config_files; shift; ac_config_files=$*;; esac case $ac_config_headers in *" "*) set x $ac_config_headers; shift; ac_config_headers=$*;; esac cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # Files that config.status was made for. config_files="$ac_config_files" config_headers="$ac_config_headers" config_commands="$ac_config_commands" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 ac_cs_usage="\ \`$as_me' instantiates files and other configuration actions from templates according to the current configuration. Unless the files and actions are specified as TAGs, all are instantiated by default. Usage: $0 [OPTION]... [TAG]... -h, --help print this help, then exit -V, --version print version number and configuration settings, then exit --config print configuration, then exit -q, --quiet, --silent do not print progress messages -d, --debug don't remove temporary files --recheck update $as_me by reconfiguring in the same conditions --file=FILE[:TEMPLATE] instantiate the configuration file FILE --header=FILE[:TEMPLATE] instantiate the configuration header FILE Configuration files: $config_files Configuration headers: $config_headers Configuration commands: $config_commands Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ libnih config.status 1.0.3 configured by $0, generated by GNU Autoconf 2.67, with options \\"\$ac_cs_config\\" Copyright (C) 2010 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." ac_pwd='$ac_pwd' srcdir='$srcdir' INSTALL='$INSTALL' MKDIR_P='$MKDIR_P' AWK='$AWK' test -n "\$AWK" || AWK=awk _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # The default lists apply if the user does not specify any file. ac_need_defaults=: while test $# != 0 do case $1 in --*=?*) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` ac_shift=: ;; --*=) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg= ac_shift=: ;; *) ac_option=$1 ac_optarg=$2 ac_shift=shift ;; esac case $ac_option in # Handling of the options. -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) ac_cs_recheck=: ;; --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) $as_echo "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) $as_echo "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" ac_need_defaults=false;; --header | --heade | --head | --hea ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append CONFIG_HEADERS " '$ac_optarg'" ac_need_defaults=false;; --he | --h) # Conflict between --help and --header as_fn_error $? "ambiguous option: \`$1' Try \`$0 --help' for more information.";; --help | --hel | -h ) $as_echo "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; # This is an error. -*) as_fn_error $? "unrecognized option: \`$1' Try \`$0 --help' for more information." ;; *) as_fn_append ac_config_targets " $1" ac_need_defaults=false ;; esac shift done ac_configure_extra_args= if $ac_cs_silent; then exec 6>/dev/null ac_configure_extra_args="$ac_configure_extra_args --silent" fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" fi _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 exec 5>>config.log { echo sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX $as_echo "$ac_log" } >&5 _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # # INIT-COMMANDS # AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir" # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH sed_quote_subst='$sed_quote_subst' double_quote_subst='$double_quote_subst' delay_variable_subst='$delay_variable_subst' macro_version='`$ECHO "X$macro_version" | $Xsed -e "$delay_single_quote_subst"`' macro_revision='`$ECHO "X$macro_revision" | $Xsed -e "$delay_single_quote_subst"`' enable_shared='`$ECHO "X$enable_shared" | $Xsed -e "$delay_single_quote_subst"`' enable_static='`$ECHO "X$enable_static" | $Xsed -e "$delay_single_quote_subst"`' pic_mode='`$ECHO "X$pic_mode" | $Xsed -e "$delay_single_quote_subst"`' enable_fast_install='`$ECHO "X$enable_fast_install" | $Xsed -e "$delay_single_quote_subst"`' host_alias='`$ECHO "X$host_alias" | $Xsed -e "$delay_single_quote_subst"`' host='`$ECHO "X$host" | $Xsed -e "$delay_single_quote_subst"`' host_os='`$ECHO "X$host_os" | $Xsed -e "$delay_single_quote_subst"`' build_alias='`$ECHO "X$build_alias" | $Xsed -e "$delay_single_quote_subst"`' build='`$ECHO "X$build" | $Xsed -e "$delay_single_quote_subst"`' build_os='`$ECHO "X$build_os" | $Xsed -e "$delay_single_quote_subst"`' SED='`$ECHO "X$SED" | $Xsed -e "$delay_single_quote_subst"`' Xsed='`$ECHO "X$Xsed" | $Xsed -e "$delay_single_quote_subst"`' GREP='`$ECHO "X$GREP" | $Xsed -e "$delay_single_quote_subst"`' EGREP='`$ECHO "X$EGREP" | $Xsed -e "$delay_single_quote_subst"`' FGREP='`$ECHO "X$FGREP" | $Xsed -e "$delay_single_quote_subst"`' LD='`$ECHO "X$LD" | $Xsed -e "$delay_single_quote_subst"`' NM='`$ECHO "X$NM" | $Xsed -e "$delay_single_quote_subst"`' LN_S='`$ECHO "X$LN_S" | $Xsed -e "$delay_single_quote_subst"`' max_cmd_len='`$ECHO "X$max_cmd_len" | $Xsed -e "$delay_single_quote_subst"`' ac_objext='`$ECHO "X$ac_objext" | $Xsed -e "$delay_single_quote_subst"`' exeext='`$ECHO "X$exeext" | $Xsed -e "$delay_single_quote_subst"`' lt_unset='`$ECHO "X$lt_unset" | $Xsed -e "$delay_single_quote_subst"`' lt_SP2NL='`$ECHO "X$lt_SP2NL" | $Xsed -e "$delay_single_quote_subst"`' lt_NL2SP='`$ECHO "X$lt_NL2SP" | $Xsed -e "$delay_single_quote_subst"`' reload_flag='`$ECHO "X$reload_flag" | $Xsed -e "$delay_single_quote_subst"`' reload_cmds='`$ECHO "X$reload_cmds" | $Xsed -e "$delay_single_quote_subst"`' OBJDUMP='`$ECHO "X$OBJDUMP" | $Xsed -e "$delay_single_quote_subst"`' deplibs_check_method='`$ECHO "X$deplibs_check_method" | $Xsed -e "$delay_single_quote_subst"`' file_magic_cmd='`$ECHO "X$file_magic_cmd" | $Xsed -e "$delay_single_quote_subst"`' AR='`$ECHO "X$AR" | $Xsed -e "$delay_single_quote_subst"`' AR_FLAGS='`$ECHO "X$AR_FLAGS" | $Xsed -e "$delay_single_quote_subst"`' STRIP='`$ECHO "X$STRIP" | $Xsed -e "$delay_single_quote_subst"`' RANLIB='`$ECHO "X$RANLIB" | $Xsed -e "$delay_single_quote_subst"`' old_postinstall_cmds='`$ECHO "X$old_postinstall_cmds" | $Xsed -e "$delay_single_quote_subst"`' old_postuninstall_cmds='`$ECHO "X$old_postuninstall_cmds" | $Xsed -e "$delay_single_quote_subst"`' old_archive_cmds='`$ECHO "X$old_archive_cmds" | $Xsed -e "$delay_single_quote_subst"`' CC='`$ECHO "X$CC" | $Xsed -e "$delay_single_quote_subst"`' CFLAGS='`$ECHO "X$CFLAGS" | $Xsed -e "$delay_single_quote_subst"`' compiler='`$ECHO "X$compiler" | $Xsed -e "$delay_single_quote_subst"`' GCC='`$ECHO "X$GCC" | $Xsed -e "$delay_single_quote_subst"`' lt_cv_sys_global_symbol_pipe='`$ECHO "X$lt_cv_sys_global_symbol_pipe" | $Xsed -e "$delay_single_quote_subst"`' lt_cv_sys_global_symbol_to_cdecl='`$ECHO "X$lt_cv_sys_global_symbol_to_cdecl" | $Xsed -e "$delay_single_quote_subst"`' lt_cv_sys_global_symbol_to_c_name_address='`$ECHO "X$lt_cv_sys_global_symbol_to_c_name_address" | $Xsed -e "$delay_single_quote_subst"`' lt_cv_sys_global_symbol_to_c_name_address_lib_prefix='`$ECHO "X$lt_cv_sys_global_symbol_to_c_name_address_lib_prefix" | $Xsed -e "$delay_single_quote_subst"`' objdir='`$ECHO "X$objdir" | $Xsed -e "$delay_single_quote_subst"`' SHELL='`$ECHO "X$SHELL" | $Xsed -e "$delay_single_quote_subst"`' ECHO='`$ECHO "X$ECHO" | $Xsed -e "$delay_single_quote_subst"`' MAGIC_CMD='`$ECHO "X$MAGIC_CMD" | $Xsed -e "$delay_single_quote_subst"`' lt_prog_compiler_no_builtin_flag='`$ECHO "X$lt_prog_compiler_no_builtin_flag" | $Xsed -e "$delay_single_quote_subst"`' lt_prog_compiler_wl='`$ECHO "X$lt_prog_compiler_wl" | $Xsed -e "$delay_single_quote_subst"`' lt_prog_compiler_pic='`$ECHO "X$lt_prog_compiler_pic" | $Xsed -e "$delay_single_quote_subst"`' lt_prog_compiler_static='`$ECHO "X$lt_prog_compiler_static" | $Xsed -e "$delay_single_quote_subst"`' lt_cv_prog_compiler_c_o='`$ECHO "X$lt_cv_prog_compiler_c_o" | $Xsed -e "$delay_single_quote_subst"`' need_locks='`$ECHO "X$need_locks" | $Xsed -e "$delay_single_quote_subst"`' DSYMUTIL='`$ECHO "X$DSYMUTIL" | $Xsed -e "$delay_single_quote_subst"`' NMEDIT='`$ECHO "X$NMEDIT" | $Xsed -e "$delay_single_quote_subst"`' LIPO='`$ECHO "X$LIPO" | $Xsed -e "$delay_single_quote_subst"`' OTOOL='`$ECHO "X$OTOOL" | $Xsed -e "$delay_single_quote_subst"`' OTOOL64='`$ECHO "X$OTOOL64" | $Xsed -e "$delay_single_quote_subst"`' libext='`$ECHO "X$libext" | $Xsed -e "$delay_single_quote_subst"`' shrext_cmds='`$ECHO "X$shrext_cmds" | $Xsed -e "$delay_single_quote_subst"`' extract_expsyms_cmds='`$ECHO "X$extract_expsyms_cmds" | $Xsed -e "$delay_single_quote_subst"`' archive_cmds_need_lc='`$ECHO "X$archive_cmds_need_lc" | $Xsed -e "$delay_single_quote_subst"`' enable_shared_with_static_runtimes='`$ECHO "X$enable_shared_with_static_runtimes" | $Xsed -e "$delay_single_quote_subst"`' export_dynamic_flag_spec='`$ECHO "X$export_dynamic_flag_spec" | $Xsed -e "$delay_single_quote_subst"`' whole_archive_flag_spec='`$ECHO "X$whole_archive_flag_spec" | $Xsed -e "$delay_single_quote_subst"`' compiler_needs_object='`$ECHO "X$compiler_needs_object" | $Xsed -e "$delay_single_quote_subst"`' old_archive_from_new_cmds='`$ECHO "X$old_archive_from_new_cmds" | $Xsed -e "$delay_single_quote_subst"`' old_archive_from_expsyms_cmds='`$ECHO "X$old_archive_from_expsyms_cmds" | $Xsed -e "$delay_single_quote_subst"`' archive_cmds='`$ECHO "X$archive_cmds" | $Xsed -e "$delay_single_quote_subst"`' archive_expsym_cmds='`$ECHO "X$archive_expsym_cmds" | $Xsed -e "$delay_single_quote_subst"`' module_cmds='`$ECHO "X$module_cmds" | $Xsed -e "$delay_single_quote_subst"`' module_expsym_cmds='`$ECHO "X$module_expsym_cmds" | $Xsed -e "$delay_single_quote_subst"`' with_gnu_ld='`$ECHO "X$with_gnu_ld" | $Xsed -e "$delay_single_quote_subst"`' allow_undefined_flag='`$ECHO "X$allow_undefined_flag" | $Xsed -e "$delay_single_quote_subst"`' no_undefined_flag='`$ECHO "X$no_undefined_flag" | $Xsed -e "$delay_single_quote_subst"`' hardcode_libdir_flag_spec='`$ECHO "X$hardcode_libdir_flag_spec" | $Xsed -e "$delay_single_quote_subst"`' hardcode_libdir_flag_spec_ld='`$ECHO "X$hardcode_libdir_flag_spec_ld" | $Xsed -e "$delay_single_quote_subst"`' hardcode_libdir_separator='`$ECHO "X$hardcode_libdir_separator" | $Xsed -e "$delay_single_quote_subst"`' hardcode_direct='`$ECHO "X$hardcode_direct" | $Xsed -e "$delay_single_quote_subst"`' hardcode_direct_absolute='`$ECHO "X$hardcode_direct_absolute" | $Xsed -e "$delay_single_quote_subst"`' hardcode_minus_L='`$ECHO "X$hardcode_minus_L" | $Xsed -e "$delay_single_quote_subst"`' hardcode_shlibpath_var='`$ECHO "X$hardcode_shlibpath_var" | $Xsed -e "$delay_single_quote_subst"`' hardcode_automatic='`$ECHO "X$hardcode_automatic" | $Xsed -e "$delay_single_quote_subst"`' inherit_rpath='`$ECHO "X$inherit_rpath" | $Xsed -e "$delay_single_quote_subst"`' link_all_deplibs='`$ECHO "X$link_all_deplibs" | $Xsed -e "$delay_single_quote_subst"`' fix_srcfile_path='`$ECHO "X$fix_srcfile_path" | $Xsed -e "$delay_single_quote_subst"`' always_export_symbols='`$ECHO "X$always_export_symbols" | $Xsed -e "$delay_single_quote_subst"`' export_symbols_cmds='`$ECHO "X$export_symbols_cmds" | $Xsed -e "$delay_single_quote_subst"`' exclude_expsyms='`$ECHO "X$exclude_expsyms" | $Xsed -e "$delay_single_quote_subst"`' include_expsyms='`$ECHO "X$include_expsyms" | $Xsed -e "$delay_single_quote_subst"`' prelink_cmds='`$ECHO "X$prelink_cmds" | $Xsed -e "$delay_single_quote_subst"`' file_list_spec='`$ECHO "X$file_list_spec" | $Xsed -e "$delay_single_quote_subst"`' variables_saved_for_relink='`$ECHO "X$variables_saved_for_relink" | $Xsed -e "$delay_single_quote_subst"`' need_lib_prefix='`$ECHO "X$need_lib_prefix" | $Xsed -e "$delay_single_quote_subst"`' need_version='`$ECHO "X$need_version" | $Xsed -e "$delay_single_quote_subst"`' version_type='`$ECHO "X$version_type" | $Xsed -e "$delay_single_quote_subst"`' runpath_var='`$ECHO "X$runpath_var" | $Xsed -e "$delay_single_quote_subst"`' shlibpath_var='`$ECHO "X$shlibpath_var" | $Xsed -e "$delay_single_quote_subst"`' shlibpath_overrides_runpath='`$ECHO "X$shlibpath_overrides_runpath" | $Xsed -e "$delay_single_quote_subst"`' libname_spec='`$ECHO "X$libname_spec" | $Xsed -e "$delay_single_quote_subst"`' library_names_spec='`$ECHO "X$library_names_spec" | $Xsed -e "$delay_single_quote_subst"`' soname_spec='`$ECHO "X$soname_spec" | $Xsed -e "$delay_single_quote_subst"`' postinstall_cmds='`$ECHO "X$postinstall_cmds" | $Xsed -e "$delay_single_quote_subst"`' postuninstall_cmds='`$ECHO "X$postuninstall_cmds" | $Xsed -e "$delay_single_quote_subst"`' finish_cmds='`$ECHO "X$finish_cmds" | $Xsed -e "$delay_single_quote_subst"`' finish_eval='`$ECHO "X$finish_eval" | $Xsed -e "$delay_single_quote_subst"`' hardcode_into_libs='`$ECHO "X$hardcode_into_libs" | $Xsed -e "$delay_single_quote_subst"`' sys_lib_search_path_spec='`$ECHO "X$sys_lib_search_path_spec" | $Xsed -e "$delay_single_quote_subst"`' sys_lib_dlsearch_path_spec='`$ECHO "X$sys_lib_dlsearch_path_spec" | $Xsed -e "$delay_single_quote_subst"`' hardcode_action='`$ECHO "X$hardcode_action" | $Xsed -e "$delay_single_quote_subst"`' enable_dlopen='`$ECHO "X$enable_dlopen" | $Xsed -e "$delay_single_quote_subst"`' enable_dlopen_self='`$ECHO "X$enable_dlopen_self" | $Xsed -e "$delay_single_quote_subst"`' enable_dlopen_self_static='`$ECHO "X$enable_dlopen_self_static" | $Xsed -e "$delay_single_quote_subst"`' old_striplib='`$ECHO "X$old_striplib" | $Xsed -e "$delay_single_quote_subst"`' striplib='`$ECHO "X$striplib" | $Xsed -e "$delay_single_quote_subst"`' LTCC='$LTCC' LTCFLAGS='$LTCFLAGS' compiler='$compiler_DEFAULT' # Quote evaled strings. for var in SED \ GREP \ EGREP \ FGREP \ LD \ NM \ LN_S \ lt_SP2NL \ lt_NL2SP \ reload_flag \ OBJDUMP \ deplibs_check_method \ file_magic_cmd \ AR \ AR_FLAGS \ STRIP \ RANLIB \ CC \ CFLAGS \ compiler \ lt_cv_sys_global_symbol_pipe \ lt_cv_sys_global_symbol_to_cdecl \ lt_cv_sys_global_symbol_to_c_name_address \ lt_cv_sys_global_symbol_to_c_name_address_lib_prefix \ SHELL \ ECHO \ lt_prog_compiler_no_builtin_flag \ lt_prog_compiler_wl \ lt_prog_compiler_pic \ lt_prog_compiler_static \ lt_cv_prog_compiler_c_o \ need_locks \ DSYMUTIL \ NMEDIT \ LIPO \ OTOOL \ OTOOL64 \ shrext_cmds \ export_dynamic_flag_spec \ whole_archive_flag_spec \ compiler_needs_object \ with_gnu_ld \ allow_undefined_flag \ no_undefined_flag \ hardcode_libdir_flag_spec \ hardcode_libdir_flag_spec_ld \ hardcode_libdir_separator \ fix_srcfile_path \ exclude_expsyms \ include_expsyms \ file_list_spec \ variables_saved_for_relink \ libname_spec \ library_names_spec \ soname_spec \ finish_eval \ old_striplib \ striplib; do case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in *[\\\\\\\`\\"\\\$]*) eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" ;; *) eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" ;; esac done # Double-quote double-evaled strings. for var in reload_cmds \ old_postinstall_cmds \ old_postuninstall_cmds \ old_archive_cmds \ extract_expsyms_cmds \ old_archive_from_new_cmds \ old_archive_from_expsyms_cmds \ archive_cmds \ archive_expsym_cmds \ module_cmds \ module_expsym_cmds \ export_symbols_cmds \ prelink_cmds \ postinstall_cmds \ postuninstall_cmds \ finish_cmds \ sys_lib_search_path_spec \ sys_lib_dlsearch_path_spec; do case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in *[\\\\\\\`\\"\\\$]*) eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" ;; *) eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" ;; esac done # Fix-up fallback echo if it was mangled by the above quoting rules. case \$lt_ECHO in *'\\\$0 --fallback-echo"') lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\$0 --fallback-echo"\$/\$0 --fallback-echo"/'\` ;; esac ac_aux_dir='$ac_aux_dir' xsi_shell='$xsi_shell' lt_shell_append='$lt_shell_append' # See if we are running on zsh, and set the options which allow our # commands through without removal of \ escapes INIT. if test -n "\${ZSH_VERSION+set}" ; then setopt NO_GLOB_SUBST fi PACKAGE='$PACKAGE' VERSION='$VERSION' TIMESTAMP='$TIMESTAMP' RM='$RM' ofile='$ofile' # Capture the value of obsolete ALL_LINGUAS because we need it to compute # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it # from automake < 1.5. eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"' # Capture the value of LINGUAS because we need it to compute CATALOGS. LINGUAS="${LINGUAS-%UNSET%}" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Handling of arguments. for ac_config_target in $ac_config_targets do case $ac_config_target in "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;; "po-directories") CONFIG_COMMANDS="$CONFIG_COMMANDS po-directories" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; "m4/Makefile") CONFIG_FILES="$CONFIG_FILES m4/Makefile" ;; "intl/Makefile") CONFIG_FILES="$CONFIG_FILES intl/Makefile" ;; "nih/Makefile") CONFIG_FILES="$CONFIG_FILES nih/Makefile" ;; "nih/libnih.pc") CONFIG_FILES="$CONFIG_FILES nih/libnih.pc" ;; "nih-dbus/Makefile") CONFIG_FILES="$CONFIG_FILES nih-dbus/Makefile" ;; "nih-dbus/libnih-dbus.pc") CONFIG_FILES="$CONFIG_FILES nih-dbus/libnih-dbus.pc" ;; "nih-dbus-tool/Makefile") CONFIG_FILES="$CONFIG_FILES nih-dbus-tool/Makefile" ;; "po/Makefile.in") CONFIG_FILES="$CONFIG_FILES po/Makefile.in" ;; "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5 ;; esac done # If the user did not use the arguments to specify the items to instantiate, # then the envvar interface is used. Set only those that are not. # We use the long form for the default assignment because of an extremely # bizarre bug on SunOS 4.1.3. if $ac_need_defaults; then test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands fi # Have a temporary directory for convenience. Make it in the build tree # simply because there is no reason against having it here, and in addition, # creating and moving files from /tmp can sometimes cause problems. # Hook for its removal unless debugging. # Note that there is a small window in which the directory will not be cleaned: # after its creation but before its name has been assigned to `$tmp'. $debug || { tmp= trap 'exit_status=$? { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status ' 0 trap 'as_fn_exit 1' 1 2 13 15 } # Create a (secure) tmp directory for tmp files. { tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" } || { tmp=./conf$$-$RANDOM (umask 077 && mkdir "$tmp") } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 # Set up the scripts for CONFIG_FILES section. # No need to generate them if there are no CONFIG_FILES. # This happens for instance with `./config.status config.h'. if test -n "$CONFIG_FILES"; then ac_cr=`echo X | tr X '\015'` # On cygwin, bash can eat \r inside `` if the user requested igncr. # But we know of no other shell where ac_cr would be empty at this # point, so we can use a bashism as a fallback. if test "x$ac_cr" = x; then eval ac_cr=\$\'\\r\' fi ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then ac_cs_awk_cr='\\r' else ac_cs_awk_cr=$ac_cr fi echo 'BEGIN {' >"$tmp/subs1.awk" && _ACEOF { echo "cat >conf$$subs.awk <<_ACEOF" && echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && echo "_ACEOF" } >conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` ac_delim='%!_!# ' for ac_last_try in false false false false false :; do . ./conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` if test $ac_delim_n = $ac_delim_num; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done rm -f conf$$subs.sh cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>"\$tmp/subs1.awk" <<\\_ACAWK && _ACEOF sed -n ' h s/^/S["/; s/!.*/"]=/ p g s/^[^!]*!// :repl t repl s/'"$ac_delim"'$// t delim :nl h s/\(.\{148\}\)..*/\1/ t more1 s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ p n b repl :more1 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t nl :delim h s/\(.\{148\}\)..*/\1/ t more2 s/["\\]/\\&/g; s/^/"/; s/$/"/ p b :more2 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t delim ' >$CONFIG_STATUS || ac_write_fail=1 rm -f conf$$subs.awk cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACAWK cat >>"\$tmp/subs1.awk" <<_ACAWK && for (key in S) S_is_set[key] = 1 FS = "" } { line = $ 0 nfields = split(line, field, "@") substed = 0 len = length(field[1]) for (i = 2; i < nfields; i++) { key = field[i] keylen = length(key) if (S_is_set[key]) { value = S[key] line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) len += length(value) + length(field[++i]) substed = 1 } else len += 1 + keylen } print line } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" else cat fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 _ACEOF # VPATH may cause trouble with some makes, so we remove sole $(srcdir), # ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and # trailing colons and then remove the whole line if VPATH becomes empty # (actually we leave an empty line to preserve line numbers). if test "x$srcdir" = x.; then ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ h s/// s/^/:/ s/[ ]*$/:/ s/:\$(srcdir):/:/g s/:\${srcdir}:/:/g s/:@srcdir@:/:/g s/^:*// s/:*$// x s/\(=[ ]*\).*/\1/ G s/\n// s/^[^=]*=[ ]*$// }' fi cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 fi # test -n "$CONFIG_FILES" # Set up the scripts for CONFIG_HEADERS section. # No need to generate them if there are no CONFIG_HEADERS. # This happens for instance with `./config.status Makefile'. if test -n "$CONFIG_HEADERS"; then cat >"$tmp/defines.awk" <<\_ACAWK || BEGIN { _ACEOF # Transform confdefs.h into an awk script `defines.awk', embedded as # here-document in config.status, that substitutes the proper values into # config.h.in to produce config.h. # Create a delimiter string that does not exist in confdefs.h, to ease # handling of long lines. ac_delim='%!_!# ' for ac_last_try in false false :; do ac_t=`sed -n "/$ac_delim/p" confdefs.h` if test -z "$ac_t"; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done # For the awk script, D is an array of macro values keyed by name, # likewise P contains macro parameters if any. Preserve backslash # newline sequences. ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* sed -n ' s/.\{148\}/&'"$ac_delim"'/g t rset :rset s/^[ ]*#[ ]*define[ ][ ]*/ / t def d :def s/\\$// t bsnl s/["\\]/\\&/g s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3"/p s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p d :bsnl s/["\\]/\\&/g s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3\\\\\\n"\\/p t cont s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p t cont d :cont n s/.\{148\}/&'"$ac_delim"'/g t clear :clear s/\\$// t bsnlc s/["\\]/\\&/g; s/^/"/; s/$/"/p d :bsnlc s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p b cont ' >$CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 for (key in D) D_is_set[key] = 1 FS = "" } /^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { line = \$ 0 split(line, arg, " ") if (arg[1] == "#") { defundef = arg[2] mac1 = arg[3] } else { defundef = substr(arg[1], 2) mac1 = arg[2] } split(mac1, mac2, "(") #) macro = mac2[1] prefix = substr(line, 1, index(line, defundef) - 1) if (D_is_set[macro]) { # Preserve the white space surrounding the "#". print prefix "define", macro P[macro] D[macro] next } else { # Replace #undef with comments. This is necessary, for example, # in the case of _POSIX_SOURCE, which is predefined and required # on some systems where configure will not decide to define it. if (defundef == "undef") { print "/*", prefix defundef, macro, "*/" next } } } { print } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 as_fn_error $? "could not setup config headers machinery" "$LINENO" 5 fi # test -n "$CONFIG_HEADERS" eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS" shift for ac_tag do case $ac_tag in :[FHLC]) ac_mode=$ac_tag; continue;; esac case $ac_mode$ac_tag in :[FHL]*:*);; :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5 ;; :[FH]-) ac_tag=-:-;; :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; esac ac_save_IFS=$IFS IFS=: set x $ac_tag IFS=$ac_save_IFS shift ac_file=$1 shift case $ac_mode in :L) ac_source=$1;; :[FH]) ac_file_inputs= for ac_f do case $ac_f in -) ac_f="$tmp/stdin";; *) # Look for the file first in the build tree, then in the source tree # (if the path is not absolute). The absolute path cannot be DOS-style, # because $ac_f cannot contain `:'. test -f "$ac_f" || case $ac_f in [\\/$]*) false;; *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; esac || as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5 ;; esac case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done # Let's still pretend it is `configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 $as_echo "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) ac_sed_conf_input=`$as_echo "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac case $ac_tag in *:-:* | *:-) cat >"$tmp/stdin" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac ;; esac ac_dir=`$as_dirname -- "$ac_file" || $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` as_dir="$ac_dir"; as_fn_mkdir_p ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix case $ac_mode in :F) # # CONFIG_FILE # case $INSTALL in [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; esac ac_MKDIR_P=$MKDIR_P case $MKDIR_P in [\\/$]* | ?:[\\/]* ) ;; */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; esac _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # If the template does not know about datarootdir, expand it. # FIXME: This hack should be removed a few years after 2.60. ac_datarootdir_hack=; ac_datarootdir_seen= ac_sed_dataroot=' /datarootdir/ { p q } /@datadir@/p /@docdir@/p /@infodir@/p /@localedir@/p /@mandir@/p' case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in *datarootdir*) ac_datarootdir_seen=yes;; *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 $as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_datarootdir_hack=' s&@datadir@&$datadir&g s&@docdir@&$docdir&g s&@infodir@&$infodir&g s&@localedir@&$localedir&g s&@mandir@&$mandir&g s&\\\${datarootdir}&$datarootdir&g' ;; esac _ACEOF # Neutralize VPATH when `$srcdir' = `.'. # Shell code in configure.ac might set extrasub. # FIXME: do we really want to maintain this feature? cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_sed_extra="$ac_vpsub $extrasub _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 :t /@[a-zA-Z_][a-zA-Z_0-9]*@/!b s|@configure_input@|$ac_sed_conf_input|;t t s&@top_builddir@&$ac_top_builddir_sub&;t t s&@top_build_prefix@&$ac_top_build_prefix&;t t s&@srcdir@&$ac_srcdir&;t t s&@abs_srcdir@&$ac_abs_srcdir&;t t s&@top_srcdir@&$ac_top_srcdir&;t t s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t s&@builddir@&$ac_builddir&;t t s&@abs_builddir@&$ac_abs_builddir&;t t s&@abs_top_builddir@&$ac_abs_top_builddir&;t t s&@INSTALL@&$ac_INSTALL&;t t s&@MKDIR_P@&$ac_MKDIR_P&;t t $ac_datarootdir_hack " eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } && { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} rm -f "$tmp/stdin" case $ac_file in -) cat "$tmp/out" && rm -f "$tmp/out";; *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";; esac \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; :H) # # CONFIG_HEADER # if test x"$ac_file" != x-; then { $as_echo "/* $configure_input */" \ && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" } >"$tmp/config.h" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 $as_echo "$as_me: $ac_file is unchanged" >&6;} else rm -f "$ac_file" mv "$tmp/config.h" "$ac_file" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 fi else $as_echo "/* $configure_input */" \ && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \ || as_fn_error $? "could not create -" "$LINENO" 5 fi # Compute "$ac_file"'s index in $config_headers. _am_arg="$ac_file" _am_stamp_count=1 for _am_header in $config_headers :; do case $_am_header in $_am_arg | $_am_arg:* ) break ;; * ) _am_stamp_count=`expr $_am_stamp_count + 1` ;; esac done echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" || $as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$_am_arg" : 'X\(//\)[^/]' \| \ X"$_am_arg" : 'X\(//\)$' \| \ X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$_am_arg" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'`/stamp-h$_am_stamp_count ;; :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 $as_echo "$as_me: executing $ac_file commands" >&6;} ;; esac case $ac_file$ac_mode in "depfiles":C) test x"$AMDEP_TRUE" != x"" || { # Autoconf 2.62 quotes --file arguments for eval, but not when files # are listed without --file. Let's play safe and only enable the eval # if we detect the quoting. case $CONFIG_FILES in *\'*) eval set x "$CONFIG_FILES" ;; *) set x $CONFIG_FILES ;; esac shift for mf do # Strip MF so we end up with the name of the file. mf=`echo "$mf" | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile or not. # We used to match only the files named `Makefile.in', but # some people rename them; so instead we look at the file content. # Grep'ing the first line is not enough: some people post-process # each Makefile.in and add a new line on top of each file to say so. # Grep'ing the whole file is not good either: AIX grep has a line # limit of 2048, but all sed's we know have understand at least 4000. if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then dirpart=`$as_dirname -- "$mf" || $as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$mf" : 'X\(//\)[^/]' \| \ X"$mf" : 'X\(//\)$' \| \ X"$mf" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$mf" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` else continue fi # Extract the definition of DEPDIR, am__include, and am__quote # from the Makefile without running `make'. DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` test -z "$DEPDIR" && continue am__include=`sed -n 's/^am__include = //p' < "$mf"` test -z "am__include" && continue am__quote=`sed -n 's/^am__quote = //p' < "$mf"` # When using ansi2knr, U may be empty or an underscore; expand it U=`sed -n 's/^U = //p' < "$mf"` # Find all dependency output files, they are included files with # $(DEPDIR) in their names. We invoke sed twice because it is the # simplest approach to changing $(DEPDIR) to its actual value in the # expansion. for file in `sed -n " s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do # Make sure the directory exists. test -f "$dirpart/$file" && continue fdir=`$as_dirname -- "$file" || $as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$file" : 'X\(//\)[^/]' \| \ X"$file" : 'X\(//\)$' \| \ X"$file" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` as_dir=$dirpart/$fdir; as_fn_mkdir_p # echo "creating $dirpart/$file" echo '# dummy' > "$dirpart/$file" done done } ;; "libtool":C) # See if we are running on zsh, and set the options which allow our # commands through without removal of \ escapes. if test -n "${ZSH_VERSION+set}" ; then setopt NO_GLOB_SUBST fi cfgfile="${ofile}T" trap "$RM \"$cfgfile\"; exit 1" 1 2 15 $RM "$cfgfile" cat <<_LT_EOF >> "$cfgfile" #! $SHELL # `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services. # Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION # Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, # 2006, 2007, 2008 Free Software Foundation, Inc. # Written by Gordon Matzigkeit, 1996 # # This file is part of GNU Libtool. # # GNU Libtool is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # # As a special exception to the GNU General Public License, # if you distribute this file as part of a program or library that # is built using GNU Libtool, you may include this file under the # same distribution terms that you use for the rest of that program. # # GNU Libtool is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GNU Libtool; see the file COPYING. If not, a copy # can be downloaded from http://www.gnu.org/licenses/gpl.html, or # obtained by writing to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # The names of the tagged configurations supported by this script. available_tags="" # ### BEGIN LIBTOOL CONFIG # Which release of libtool.m4 was used? macro_version=$macro_version macro_revision=$macro_revision # Whether or not to build shared libraries. build_libtool_libs=$enable_shared # Whether or not to build static libraries. build_old_libs=$enable_static # What type of objects to build. pic_mode=$pic_mode # Whether or not to optimize for fast installation. fast_install=$enable_fast_install # The host system. host_alias=$host_alias host=$host host_os=$host_os # The build system. build_alias=$build_alias build=$build build_os=$build_os # A sed program that does not truncate output. SED=$lt_SED # Sed that helps us avoid accidentally triggering echo(1) options like -n. Xsed="\$SED -e 1s/^X//" # A grep program that handles long lines. GREP=$lt_GREP # An ERE matcher. EGREP=$lt_EGREP # A literal string matcher. FGREP=$lt_FGREP # A BSD- or MS-compatible name lister. NM=$lt_NM # Whether we need soft or hard links. LN_S=$lt_LN_S # What is the maximum length of a command? max_cmd_len=$max_cmd_len # Object file suffix (normally "o"). objext=$ac_objext # Executable file suffix (normally ""). exeext=$exeext # whether the shell understands "unset". lt_unset=$lt_unset # turn spaces into newlines. SP2NL=$lt_lt_SP2NL # turn newlines into spaces. NL2SP=$lt_lt_NL2SP # How to create reloadable object files. reload_flag=$lt_reload_flag reload_cmds=$lt_reload_cmds # An object symbol dumper. OBJDUMP=$lt_OBJDUMP # Method to check whether dependent libraries are shared objects. deplibs_check_method=$lt_deplibs_check_method # Command to use when deplibs_check_method == "file_magic". file_magic_cmd=$lt_file_magic_cmd # The archiver. AR=$lt_AR AR_FLAGS=$lt_AR_FLAGS # A symbol stripping program. STRIP=$lt_STRIP # Commands used to install an old-style archive. RANLIB=$lt_RANLIB old_postinstall_cmds=$lt_old_postinstall_cmds old_postuninstall_cmds=$lt_old_postuninstall_cmds # A C compiler. LTCC=$lt_CC # LTCC compiler flags. LTCFLAGS=$lt_CFLAGS # Take the output of nm and produce a listing of raw symbols and C names. global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe # Transform the output of nm in a proper C declaration. global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl # Transform the output of nm in a C name address pair. global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address # Transform the output of nm in a C name address pair when lib prefix is needed. global_symbol_to_c_name_address_lib_prefix=$lt_lt_cv_sys_global_symbol_to_c_name_address_lib_prefix # The name of the directory that contains temporary libtool files. objdir=$objdir # Shell to use when invoking shell scripts. SHELL=$lt_SHELL # An echo program that does not interpret backslashes. ECHO=$lt_ECHO # Used to examine libraries when file_magic_cmd begins with "file". MAGIC_CMD=$MAGIC_CMD # Must we lock files when doing compilation? need_locks=$lt_need_locks # Tool to manipulate archived DWARF debug symbol files on Mac OS X. DSYMUTIL=$lt_DSYMUTIL # Tool to change global to local symbols on Mac OS X. NMEDIT=$lt_NMEDIT # Tool to manipulate fat objects and archives on Mac OS X. LIPO=$lt_LIPO # ldd/readelf like tool for Mach-O binaries on Mac OS X. OTOOL=$lt_OTOOL # ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4. OTOOL64=$lt_OTOOL64 # Old archive suffix (normally "a"). libext=$libext # Shared library suffix (normally ".so"). shrext_cmds=$lt_shrext_cmds # The commands to extract the exported symbol list from a shared archive. extract_expsyms_cmds=$lt_extract_expsyms_cmds # Variables whose values should be saved in libtool wrapper scripts and # restored at link time. variables_saved_for_relink=$lt_variables_saved_for_relink # Do we need the "lib" prefix for modules? need_lib_prefix=$need_lib_prefix # Do we need a version for libraries? need_version=$need_version # Library versioning type. version_type=$version_type # Shared library runtime path variable. runpath_var=$runpath_var # Shared library path variable. shlibpath_var=$shlibpath_var # Is shlibpath searched before the hard-coded library search path? shlibpath_overrides_runpath=$shlibpath_overrides_runpath # Format of library name prefix. libname_spec=$lt_libname_spec # List of archive names. First name is the real one, the rest are links. # The last name is the one that the linker finds with -lNAME library_names_spec=$lt_library_names_spec # The coded name of the library, if different from the real name. soname_spec=$lt_soname_spec # Command to use after installation of a shared archive. postinstall_cmds=$lt_postinstall_cmds # Command to use after uninstallation of a shared archive. postuninstall_cmds=$lt_postuninstall_cmds # Commands used to finish a libtool library installation in a directory. finish_cmds=$lt_finish_cmds # As "finish_cmds", except a single script fragment to be evaled but # not shown. finish_eval=$lt_finish_eval # Whether we should hardcode library paths into libraries. hardcode_into_libs=$hardcode_into_libs # Compile-time system search path for libraries. sys_lib_search_path_spec=$lt_sys_lib_search_path_spec # Run-time system search path for libraries. sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec # Whether dlopen is supported. dlopen_support=$enable_dlopen # Whether dlopen of programs is supported. dlopen_self=$enable_dlopen_self # Whether dlopen of statically linked programs is supported. dlopen_self_static=$enable_dlopen_self_static # Commands to strip libraries. old_striplib=$lt_old_striplib striplib=$lt_striplib # The linker used to build libraries. LD=$lt_LD # Commands used to build an old-style archive. old_archive_cmds=$lt_old_archive_cmds # A language specific compiler. CC=$lt_compiler # Is the compiler the GNU compiler? with_gcc=$GCC # Compiler flag to turn off builtin functions. no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag # How to pass a linker flag through the compiler. wl=$lt_lt_prog_compiler_wl # Additional compiler flags for building library objects. pic_flag=$lt_lt_prog_compiler_pic # Compiler flag to prevent dynamic linking. link_static_flag=$lt_lt_prog_compiler_static # Does compiler simultaneously support -c and -o options? compiler_c_o=$lt_lt_cv_prog_compiler_c_o # Whether or not to add -lc for building shared libraries. build_libtool_need_lc=$archive_cmds_need_lc # Whether or not to disallow shared libs when runtime libs are static. allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes # Compiler flag to allow reflexive dlopens. export_dynamic_flag_spec=$lt_export_dynamic_flag_spec # Compiler flag to generate shared objects directly from archives. whole_archive_flag_spec=$lt_whole_archive_flag_spec # Whether the compiler copes with passing no objects directly. compiler_needs_object=$lt_compiler_needs_object # Create an old-style archive from a shared archive. old_archive_from_new_cmds=$lt_old_archive_from_new_cmds # Create a temporary old-style archive to link instead of a shared archive. old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds # Commands used to build a shared archive. archive_cmds=$lt_archive_cmds archive_expsym_cmds=$lt_archive_expsym_cmds # Commands used to build a loadable module if different from building # a shared archive. module_cmds=$lt_module_cmds module_expsym_cmds=$lt_module_expsym_cmds # Whether we are building with GNU ld or not. with_gnu_ld=$lt_with_gnu_ld # Flag that allows shared libraries with undefined symbols to be built. allow_undefined_flag=$lt_allow_undefined_flag # Flag that enforces no undefined symbols. no_undefined_flag=$lt_no_undefined_flag # Flag to hardcode \$libdir into a binary during linking. # This must work even if \$libdir does not exist hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec # If ld is used when linking, flag to hardcode \$libdir into a binary # during linking. This must work even if \$libdir does not exist. hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld # Whether we need a single "-rpath" flag with a separated argument. hardcode_libdir_separator=$lt_hardcode_libdir_separator # Set to "yes" if using DIR/libNAME\${shared_ext} during linking hardcodes # DIR into the resulting binary. hardcode_direct=$hardcode_direct # Set to "yes" if using DIR/libNAME\${shared_ext} during linking hardcodes # DIR into the resulting binary and the resulting library dependency is # "absolute",i.e impossible to change by setting \${shlibpath_var} if the # library is relocated. hardcode_direct_absolute=$hardcode_direct_absolute # Set to "yes" if using the -LDIR flag during linking hardcodes DIR # into the resulting binary. hardcode_minus_L=$hardcode_minus_L # Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR # into the resulting binary. hardcode_shlibpath_var=$hardcode_shlibpath_var # Set to "yes" if building a shared library automatically hardcodes DIR # into the library and all subsequent libraries and executables linked # against it. hardcode_automatic=$hardcode_automatic # Set to yes if linker adds runtime paths of dependent libraries # to runtime path list. inherit_rpath=$inherit_rpath # Whether libtool must link a program against all its dependency libraries. link_all_deplibs=$link_all_deplibs # Fix the shell variable \$srcfile for the compiler. fix_srcfile_path=$lt_fix_srcfile_path # Set to "yes" if exported symbols are required. always_export_symbols=$always_export_symbols # The commands to list exported symbols. export_symbols_cmds=$lt_export_symbols_cmds # Symbols that should not be listed in the preloaded symbols. exclude_expsyms=$lt_exclude_expsyms # Symbols that must always be exported. include_expsyms=$lt_include_expsyms # Commands necessary for linking programs (against libraries) with templates. prelink_cmds=$lt_prelink_cmds # Specify filename containing input files. file_list_spec=$lt_file_list_spec # How to hardcode a shared library path into an executable. hardcode_action=$hardcode_action # ### END LIBTOOL CONFIG _LT_EOF case $host_os in aix3*) cat <<\_LT_EOF >> "$cfgfile" # AIX sometimes has problems with the GCC collect2 program. For some # reason, if we set the COLLECT_NAMES environment variable, the problems # vanish in a puff of smoke. if test "X${COLLECT_NAMES+set}" != Xset; then COLLECT_NAMES= export COLLECT_NAMES fi _LT_EOF ;; esac ltmain="$ac_aux_dir/ltmain.sh" # We use sed instead of cat because bash on DJGPP gets confused if # if finds mixed CR/LF and LF-only lines. Since sed operates in # text mode, it properly converts lines to CR/LF. This bash problem # is reportedly fixed, but why not run on old versions too? sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \ || (rm -f "$cfgfile"; exit 1) case $xsi_shell in yes) cat << \_LT_EOF >> "$cfgfile" # func_dirname file append nondir_replacement # Compute the dirname of FILE. If nonempty, add APPEND to the result, # otherwise set result to NONDIR_REPLACEMENT. func_dirname () { case ${1} in */*) func_dirname_result="${1%/*}${2}" ;; * ) func_dirname_result="${3}" ;; esac } # func_basename file func_basename () { func_basename_result="${1##*/}" } # func_dirname_and_basename file append nondir_replacement # perform func_basename and func_dirname in a single function # call: # dirname: Compute the dirname of FILE. If nonempty, # add APPEND to the result, otherwise set result # to NONDIR_REPLACEMENT. # value returned in "$func_dirname_result" # basename: Compute filename of FILE. # value retuned in "$func_basename_result" # Implementation must be kept synchronized with func_dirname # and func_basename. For efficiency, we do not delegate to # those functions but instead duplicate the functionality here. func_dirname_and_basename () { case ${1} in */*) func_dirname_result="${1%/*}${2}" ;; * ) func_dirname_result="${3}" ;; esac func_basename_result="${1##*/}" } # func_stripname prefix suffix name # strip PREFIX and SUFFIX off of NAME. # PREFIX and SUFFIX must not contain globbing or regex special # characters, hashes, percent signs, but SUFFIX may contain a leading # dot (in which case that matches only a dot). func_stripname () { # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are # positional parameters, so assign one to ordinary parameter first. func_stripname_result=${3} func_stripname_result=${func_stripname_result#"${1}"} func_stripname_result=${func_stripname_result%"${2}"} } # func_opt_split func_opt_split () { func_opt_split_opt=${1%%=*} func_opt_split_arg=${1#*=} } # func_lo2o object func_lo2o () { case ${1} in *.lo) func_lo2o_result=${1%.lo}.${objext} ;; *) func_lo2o_result=${1} ;; esac } # func_xform libobj-or-source func_xform () { func_xform_result=${1%.*}.lo } # func_arith arithmetic-term... func_arith () { func_arith_result=$(( $* )) } # func_len string # STRING may not start with a hyphen. func_len () { func_len_result=${#1} } _LT_EOF ;; *) # Bourne compatible functions. cat << \_LT_EOF >> "$cfgfile" # func_dirname file append nondir_replacement # Compute the dirname of FILE. If nonempty, add APPEND to the result, # otherwise set result to NONDIR_REPLACEMENT. func_dirname () { # Extract subdirectory from the argument. func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"` if test "X$func_dirname_result" = "X${1}"; then func_dirname_result="${3}" else func_dirname_result="$func_dirname_result${2}" fi } # func_basename file func_basename () { func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"` } # func_stripname prefix suffix name # strip PREFIX and SUFFIX off of NAME. # PREFIX and SUFFIX must not contain globbing or regex special # characters, hashes, percent signs, but SUFFIX may contain a leading # dot (in which case that matches only a dot). # func_strip_suffix prefix name func_stripname () { case ${2} in .*) func_stripname_result=`$ECHO "X${3}" \ | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;; *) func_stripname_result=`$ECHO "X${3}" \ | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;; esac } # sed scripts: my_sed_long_opt='1s/^\(-[^=]*\)=.*/\1/;q' my_sed_long_arg='1s/^-[^=]*=//' # func_opt_split func_opt_split () { func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"` func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"` } # func_lo2o object func_lo2o () { func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"` } # func_xform libobj-or-source func_xform () { func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[^.]*$/.lo/'` } # func_arith arithmetic-term... func_arith () { func_arith_result=`expr "$@"` } # func_len string # STRING may not start with a hyphen. func_len () { func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len` } _LT_EOF esac case $lt_shell_append in yes) cat << \_LT_EOF >> "$cfgfile" # func_append var value # Append VALUE to the end of shell variable VAR. func_append () { eval "$1+=\$2" } _LT_EOF ;; *) cat << \_LT_EOF >> "$cfgfile" # func_append var value # Append VALUE to the end of shell variable VAR. func_append () { eval "$1=\$$1\$2" } _LT_EOF ;; esac sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \ || (rm -f "$cfgfile"; exit 1) mv -f "$cfgfile" "$ofile" || (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") chmod +x "$ofile" ;; "po-directories":C) for ac_file in $CONFIG_FILES; do # Support "outfile[:infile[:infile...]]" case "$ac_file" in *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; esac # PO directories have a Makefile.in generated from Makefile.in.in. case "$ac_file" in */Makefile.in) # Adjust a relative srcdir. ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'` ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`" ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'` # In autoconf-2.13 it is called $ac_given_srcdir. # In autoconf-2.50 it is called $srcdir. test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir" case "$ac_given_srcdir" in .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;; /*) top_srcdir="$ac_given_srcdir" ;; *) top_srcdir="$ac_dots$ac_given_srcdir" ;; esac # Treat a directory as a PO directory if and only if it has a # POTFILES.in file. This allows packages to have multiple PO # directories under different names or in different locations. if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then rm -f "$ac_dir/POTFILES" test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES" cat "$ac_given_srcdir/$ac_dir/POTFILES.in" | sed -e "/^#/d" -e "/^[ ]*\$/d" -e "s,.*, $top_srcdir/& \\\\," | sed -e "\$s/\(.*\) \\\\/\1/" > "$ac_dir/POTFILES" POMAKEFILEDEPS="POTFILES.in" # ALL_LINGUAS, POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES depend # on $ac_dir but don't depend on user-specified configuration # parameters. if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then # The LINGUAS file contains the set of available languages. if test -n "$OBSOLETE_ALL_LINGUAS"; then test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete" fi ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"` # Hide the ALL_LINGUAS assigment from automake < 1.5. eval 'ALL_LINGUAS''=$ALL_LINGUAS_' POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS" else # The set of available languages was given in configure.in. # Hide the ALL_LINGUAS assigment from automake < 1.5. eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS' fi # Compute POFILES # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po) # Compute UPDATEPOFILES # as $(foreach lang, $(ALL_LINGUAS), $(lang).po-update) # Compute DUMMYPOFILES # as $(foreach lang, $(ALL_LINGUAS), $(lang).nop) # Compute GMOFILES # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo) case "$ac_given_srcdir" in .) srcdirpre= ;; *) srcdirpre='$(srcdir)/' ;; esac POFILES= UPDATEPOFILES= DUMMYPOFILES= GMOFILES= for lang in $ALL_LINGUAS; do POFILES="$POFILES $srcdirpre$lang.po" UPDATEPOFILES="$UPDATEPOFILES $lang.po-update" DUMMYPOFILES="$DUMMYPOFILES $lang.nop" GMOFILES="$GMOFILES $srcdirpre$lang.gmo" done # CATALOGS depends on both $ac_dir and the user's LINGUAS # environment variable. INST_LINGUAS= if test -n "$ALL_LINGUAS"; then for presentlang in $ALL_LINGUAS; do useit=no if test "%UNSET%" != "$LINGUAS"; then desiredlanguages="$LINGUAS" else desiredlanguages="$ALL_LINGUAS" fi for desiredlang in $desiredlanguages; do # Use the presentlang catalog if desiredlang is # a. equal to presentlang, or # b. a variant of presentlang (because in this case, # presentlang can be used as a fallback for messages # which are not translated in the desiredlang catalog). case "$desiredlang" in "$presentlang"*) useit=yes;; esac done if test $useit = yes; then INST_LINGUAS="$INST_LINGUAS $presentlang" fi done fi CATALOGS= if test -n "$INST_LINGUAS"; then for lang in $INST_LINGUAS; do CATALOGS="$CATALOGS $lang.gmo" done fi test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile" sed -e "/^POTFILES =/r $ac_dir/POTFILES" -e "/^# Makevars/r $ac_given_srcdir/$ac_dir/Makevars" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@POMAKEFILEDEPS@|$POMAKEFILEDEPS|g" "$ac_dir/Makefile.in" > "$ac_dir/Makefile" for f in "$ac_given_srcdir/$ac_dir"/Rules-*; do if test -f "$f"; then case "$f" in *.orig | *.bak | *~) ;; *) cat "$f" >> "$ac_dir/Makefile" ;; esac fi done fi ;; esac done ;; esac done # for ac_tag as_fn_exit 0 _ACEOF ac_clean_files=$ac_clean_files_save test $ac_write_fail = 0 || as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 # configure is writing to config.log, and then calls config.status. # config.status does its own redirection, appending to config.log. # Unfortunately, on DOS this fails, as config.log is still kept open # by configure, so config.status won't be able to write to it; its # output is simply discarded. So we exec the FD to /dev/null, # effectively closing config.log, so it can be properly (re)opened and # appended to by config.status. When coming back to configure, we # need to make the FD available again. if test "$no_create" != yes; then ac_cs_success=: ac_config_status_args= test "$silent" = yes && ac_config_status_args="$ac_config_status_args --quiet" exec 5>/dev/null $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false exec 5>>config.log # Use ||, not &&, to avoid exiting from the if with $? = 1, which # would make configure fail if this is the last instruction. $ac_cs_success || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi libnih-1.0.3/COPYING0000644000175000017500000004310311445765555010756 00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. libnih-1.0.3/missing0000755000175000017500000002623311461165303011306 00000000000000#! /bin/sh # Common stub for a few missing GNU programs while installing. scriptversion=2009-04-28.21; # UTC # Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006, # 2008, 2009 Free Software Foundation, Inc. # Originally by Fran,cois Pinard , 1996. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. if test $# -eq 0; then echo 1>&2 "Try \`$0 --help' for more information" exit 1 fi run=: sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p' sed_minuso='s/.* -o \([^ ]*\).*/\1/p' # In the cases where this matters, `missing' is being run in the # srcdir already. if test -f configure.ac; then configure_ac=configure.ac else configure_ac=configure.in fi msg="missing on your system" case $1 in --run) # Try to run requested program, and just exit if it succeeds. run= shift "$@" && exit 0 # Exit code 63 means version mismatch. This often happens # when the user try to use an ancient version of a tool on # a file that requires a minimum version. In this case we # we should proceed has if the program had been absent, or # if --run hadn't been passed. if test $? = 63; then run=: msg="probably too old" fi ;; -h|--h|--he|--hel|--help) echo "\ $0 [OPTION]... PROGRAM [ARGUMENT]... Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an error status if there is no known handling for PROGRAM. Options: -h, --help display this help and exit -v, --version output version information and exit --run try to run the given command, and emulate it if it fails Supported PROGRAM values: aclocal touch file \`aclocal.m4' autoconf touch file \`configure' autoheader touch file \`config.h.in' autom4te touch the output file, or create a stub one automake touch all \`Makefile.in' files bison create \`y.tab.[ch]', if possible, from existing .[ch] flex create \`lex.yy.c', if possible, from existing .c help2man touch the output file lex create \`lex.yy.c', if possible, from existing .c makeinfo touch the output file tar try tar, gnutar, gtar, then tar without non-portable flags yacc create \`y.tab.[ch]', if possible, from existing .[ch] Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and \`g' are ignored when checking the name. Send bug reports to ." exit $? ;; -v|--v|--ve|--ver|--vers|--versi|--versio|--version) echo "missing $scriptversion (GNU Automake)" exit $? ;; -*) echo 1>&2 "$0: Unknown \`$1' option" echo 1>&2 "Try \`$0 --help' for more information" exit 1 ;; esac # normalize program name to check for. program=`echo "$1" | sed ' s/^gnu-//; t s/^gnu//; t s/^g//; t'` # Now exit if we have it, but it failed. Also exit now if we # don't have it and --version was passed (most likely to detect # the program). This is about non-GNU programs, so use $1 not # $program. case $1 in lex*|yacc*) # Not GNU programs, they don't have --version. ;; tar*) if test -n "$run"; then echo 1>&2 "ERROR: \`tar' requires --run" exit 1 elif test "x$2" = "x--version" || test "x$2" = "x--help"; then exit 1 fi ;; *) if test -z "$run" && ($1 --version) > /dev/null 2>&1; then # We have it, but it failed. exit 1 elif test "x$2" = "x--version" || test "x$2" = "x--help"; then # Could not run --version or --help. This is probably someone # running `$TOOL --version' or `$TOOL --help' to check whether # $TOOL exists and not knowing $TOOL uses missing. exit 1 fi ;; esac # If it does not exist, or fails to run (possibly an outdated version), # try to emulate it. case $program in aclocal*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified \`acinclude.m4' or \`${configure_ac}'. You might want to install the \`Automake' and \`Perl' packages. Grab them from any GNU archive site." touch aclocal.m4 ;; autoconf*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified \`${configure_ac}'. You might want to install the \`Autoconf' and \`GNU m4' packages. Grab them from any GNU archive site." touch configure ;; autoheader*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified \`acconfig.h' or \`${configure_ac}'. You might want to install the \`Autoconf' and \`GNU m4' packages. Grab them from any GNU archive site." files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` test -z "$files" && files="config.h" touch_files= for f in $files; do case $f in *:*) touch_files="$touch_files "`echo "$f" | sed -e 's/^[^:]*://' -e 's/:.*//'`;; *) touch_files="$touch_files $f.in";; esac done touch $touch_files ;; automake*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. You might want to install the \`Automake' and \`Perl' packages. Grab them from any GNU archive site." find . -type f -name Makefile.am -print | sed 's/\.am$/.in/' | while read f; do touch "$f"; done ;; autom4te*) echo 1>&2 "\ WARNING: \`$1' is needed, but is $msg. You might have modified some files without having the proper tools for further handling them. You can get \`$1' as part of \`Autoconf' from any GNU archive site." file=`echo "$*" | sed -n "$sed_output"` test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` if test -f "$file"; then touch $file else test -z "$file" || exec >$file echo "#! /bin/sh" echo "# Created by GNU Automake missing as a replacement of" echo "# $ $@" echo "exit 0" chmod +x $file exit 1 fi ;; bison*|yacc*) echo 1>&2 "\ WARNING: \`$1' $msg. You should only need it if you modified a \`.y' file. You may need the \`Bison' package in order for those modifications to take effect. You can get \`Bison' from any GNU archive site." rm -f y.tab.c y.tab.h if test $# -ne 1; then eval LASTARG="\${$#}" case $LASTARG in *.y) SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` if test -f "$SRCFILE"; then cp "$SRCFILE" y.tab.c fi SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` if test -f "$SRCFILE"; then cp "$SRCFILE" y.tab.h fi ;; esac fi if test ! -f y.tab.h; then echo >y.tab.h fi if test ! -f y.tab.c; then echo 'main() { return 0; }' >y.tab.c fi ;; lex*|flex*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified a \`.l' file. You may need the \`Flex' package in order for those modifications to take effect. You can get \`Flex' from any GNU archive site." rm -f lex.yy.c if test $# -ne 1; then eval LASTARG="\${$#}" case $LASTARG in *.l) SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` if test -f "$SRCFILE"; then cp "$SRCFILE" lex.yy.c fi ;; esac fi if test ! -f lex.yy.c; then echo 'main() { return 0; }' >lex.yy.c fi ;; help2man*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified a dependency of a manual page. You may need the \`Help2man' package in order for those modifications to take effect. You can get \`Help2man' from any GNU archive site." file=`echo "$*" | sed -n "$sed_output"` test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` if test -f "$file"; then touch $file else test -z "$file" || exec >$file echo ".ab help2man is required to generate this page" exit $? fi ;; makeinfo*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified a \`.texi' or \`.texinfo' file, or any other file indirectly affecting the aspect of the manual. The spurious call might also be the consequence of using a buggy \`make' (AIX, DU, IRIX). You might want to install the \`Texinfo' package or the \`GNU make' package. Grab either from any GNU archive site." # The file to touch is that specified with -o ... file=`echo "$*" | sed -n "$sed_output"` test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` if test -z "$file"; then # ... or it is the one specified with @setfilename ... infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` file=`sed -n ' /^@setfilename/{ s/.* \([^ ]*\) *$/\1/ p q }' $infile` # ... or it is derived from the source name (dir/f.texi becomes f.info) test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info fi # If the file does not exist, the user really needs makeinfo; # let's fail without touching anything. test -f $file || exit 1 touch $file ;; tar*) shift # We have already tried tar in the generic part. # Look for gnutar/gtar before invocation to avoid ugly error # messages. if (gnutar --version > /dev/null 2>&1); then gnutar "$@" && exit 0 fi if (gtar --version > /dev/null 2>&1); then gtar "$@" && exit 0 fi firstarg="$1" if shift; then case $firstarg in *o*) firstarg=`echo "$firstarg" | sed s/o//` tar "$firstarg" "$@" && exit 0 ;; esac case $firstarg in *h*) firstarg=`echo "$firstarg" | sed s/h//` tar "$firstarg" "$@" && exit 0 ;; esac fi echo 1>&2 "\ WARNING: I can't seem to be able to run \`tar' with the given arguments. You may want to install GNU tar or Free paxutils, or check the command line arguments." exit 1 ;; *) echo 1>&2 "\ WARNING: \`$1' is needed, and is $msg. You might have modified some files without having the proper tools for further handling them. Check the \`README' file, it often tells you about the needed prerequisites for installing this package. You may also peek at any GNU archive site, in case some other package would contain this missing \`$1' program." exit 1 ;; esac exit 0 # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: libnih-1.0.3/install-sh0000755000175000017500000003253711461165277011731 00000000000000#!/bin/sh # install - install a program, script, or datafile scriptversion=2009-04-28.21; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the # following copyright and license. # # Copyright (C) 1994 X Consortium # # 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 # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # Except as contained in this notice, the name of the X Consortium shall not # be used in advertising or otherwise to promote the sale, use or other deal- # ings in this Software without prior written authorization from the X Consor- # tium. # # # FSF changes to this file are in the public domain. # # Calling this script install-sh is preferred over install.sh, to prevent # `make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. nl=' ' IFS=" "" $nl" # set DOITPROG to echo to test this script # Don't use :- since 4.3BSD and earlier shells don't like it. doit=${DOITPROG-} if test -z "$doit"; then doit_exec=exec else doit_exec=$doit fi # Put in absolute file names if you don't have them in your path; # or use environment vars. chgrpprog=${CHGRPPROG-chgrp} chmodprog=${CHMODPROG-chmod} chownprog=${CHOWNPROG-chown} cmpprog=${CMPPROG-cmp} cpprog=${CPPROG-cp} mkdirprog=${MKDIRPROG-mkdir} mvprog=${MVPROG-mv} rmprog=${RMPROG-rm} stripprog=${STRIPPROG-strip} posix_glob='?' initialize_posix_glob=' test "$posix_glob" != "?" || { if (set -f) 2>/dev/null; then posix_glob= else posix_glob=: fi } ' posix_mkdir= # Desired mode of installed file. mode=0755 chgrpcmd= chmodcmd=$chmodprog chowncmd= mvcmd=$mvprog rmcmd="$rmprog -f" stripcmd= src= dst= dir_arg= dst_arg= copy_on_change=false no_target_directory= usage="\ Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY or: $0 [OPTION]... -t DIRECTORY SRCFILES... or: $0 [OPTION]... -d DIRECTORIES... In the 1st form, copy SRCFILE to DSTFILE. In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. In the 4th, create DIRECTORIES. Options: --help display this help and exit. --version display version info and exit. -c (ignored) -C install only if different (preserve the last data modification time) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. -s $stripprog installed files. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG " while test $# -ne 0; do case $1 in -c) ;; -C) copy_on_change=true;; -d) dir_arg=true;; -g) chgrpcmd="$chgrpprog $2" shift;; --help) echo "$usage"; exit $?;; -m) mode=$2 case $mode in *' '* | *' '* | *' '* | *'*'* | *'?'* | *'['*) echo "$0: invalid mode: $mode" >&2 exit 1;; esac shift;; -o) chowncmd="$chownprog $2" shift;; -s) stripcmd=$stripprog;; -t) dst_arg=$2 shift;; -T) no_target_directory=true;; --version) echo "$0 $scriptversion"; exit $?;; --) shift break;; -*) echo "$0: invalid option: $1" >&2 exit 1;; *) break;; esac shift done if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then # When -d is used, all remaining arguments are directories to create. # When -t is used, the destination is already specified. # Otherwise, the last argument is the destination. Remove it from $@. for arg do if test -n "$dst_arg"; then # $@ is not empty: it contains at least $arg. set fnord "$@" "$dst_arg" shift # fnord fi shift # arg dst_arg=$arg done fi if test $# -eq 0; then if test -z "$dir_arg"; then echo "$0: no input file specified." >&2 exit 1 fi # It's OK to call `install-sh -d' without argument. # This can happen when creating conditional directories. exit 0 fi if test -z "$dir_arg"; then trap '(exit $?); exit' 1 2 13 15 # Set umask so as not to create temps with too-generous modes. # However, 'strip' requires both read and write access to temps. case $mode in # Optimize common cases. *644) cp_umask=133;; *755) cp_umask=22;; *[0-7]) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw='% 200' fi cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; *) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw=,u+rw fi cp_umask=$mode$u_plus_rw;; esac fi for src do # Protect names starting with `-'. case $src in -*) src=./$src;; esac if test -n "$dir_arg"; then dst=$src dstdir=$dst test -d "$dstdir" dstdir_status=$? else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test ! -f "$src" && test ! -d "$src"; then echo "$0: $src does not exist." >&2 exit 1 fi if test -z "$dst_arg"; then echo "$0: no destination specified." >&2 exit 1 fi dst=$dst_arg # Protect names starting with `-'. case $dst in -*) dst=./$dst;; esac # If destination is a directory, append the input filename; won't work # if double slashes aren't ignored. if test -d "$dst"; then if test -n "$no_target_directory"; then echo "$0: $dst_arg: Is a directory" >&2 exit 1 fi dstdir=$dst dst=$dstdir/`basename "$src"` dstdir_status=0 else # Prefer dirname, but fall back on a substitute if dirname fails. dstdir=` (dirname "$dst") 2>/dev/null || expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$dst" : 'X\(//\)[^/]' \| \ X"$dst" : 'X\(//\)$' \| \ X"$dst" : 'X\(/\)' \| . 2>/dev/null || echo X"$dst" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q' ` test -d "$dstdir" dstdir_status=$? fi fi obsolete_mkdir_used=false if test $dstdir_status != 0; then case $posix_mkdir in '') # Create intermediate dirs using mode 755 as modified by the umask. # This is like FreeBSD 'install' as of 1997-10-28. umask=`umask` case $stripcmd.$umask in # Optimize common cases. *[2367][2367]) mkdir_umask=$umask;; .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; *[0-7]) mkdir_umask=`expr $umask + 22 \ - $umask % 100 % 40 + $umask % 20 \ - $umask % 10 % 4 + $umask % 2 `;; *) mkdir_umask=$umask,go-w;; esac # With -d, create the new directory with the user-specified mode. # Otherwise, rely on $mkdir_umask. if test -n "$dir_arg"; then mkdir_mode=-m$mode else mkdir_mode= fi posix_mkdir=false case $umask in *[123567][0-7][0-7]) # POSIX mkdir -p sets u+wx bits regardless of umask, which # is incompatible with FreeBSD 'install' when (umask & 300) != 0. ;; *) tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 if (umask $mkdir_umask && exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 then if test -z "$dir_arg" || { # Check for POSIX incompatibilities with -m. # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or # other-writeable bit of parent directory when it shouldn't. # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. ls_ld_tmpdir=`ls -ld "$tmpdir"` case $ls_ld_tmpdir in d????-?r-*) different_mode=700;; d????-?--*) different_mode=755;; *) false;; esac && $mkdirprog -m$different_mode -p -- "$tmpdir" && { ls_ld_tmpdir_1=`ls -ld "$tmpdir"` test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" } } then posix_mkdir=: fi rmdir "$tmpdir/d" "$tmpdir" else # Remove any dirs left behind by ancient mkdir implementations. rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null fi trap '' 0;; esac;; esac if $posix_mkdir && ( umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" ) then : else # The umask is ridiculous, or mkdir does not conform to POSIX, # or it failed possibly due to a race condition. Create the # directory the slow way, step by step, checking for races as we go. case $dstdir in /*) prefix='/';; -*) prefix='./';; *) prefix='';; esac eval "$initialize_posix_glob" oIFS=$IFS IFS=/ $posix_glob set -f set fnord $dstdir shift $posix_glob set +f IFS=$oIFS prefixes= for d do test -z "$d" && continue prefix=$prefix$d if test -d "$prefix"; then prefixes= else if $posix_mkdir; then (umask=$mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break # Don't fail if two instances are running concurrently. test -d "$prefix" || exit 1 else case $prefix in *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; *) qprefix=$prefix;; esac prefixes="$prefixes '$qprefix'" fi fi prefix=$prefix/ done if test -n "$prefixes"; then # Don't fail if two instances are running concurrently. (umask $mkdir_umask && eval "\$doit_exec \$mkdirprog $prefixes") || test -d "$dstdir" || exit 1 obsolete_mkdir_used=true fi fi fi if test -n "$dir_arg"; then { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 else # Make a couple of temp file names in the proper directory. dsttmp=$dstdir/_inst.$$_ rmtmp=$dstdir/_rm.$$_ # Trap to clean up those temp files at exit. trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 # Copy the file name to the temp name. (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $cpprog $src $dsttmp" command. # { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && # If -C, don't bother to copy if it wouldn't change the file. if $copy_on_change && old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && eval "$initialize_posix_glob" && $posix_glob set -f && set X $old && old=:$2:$4:$5:$6 && set X $new && new=:$2:$4:$5:$6 && $posix_glob set +f && test "$old" = "$new" && $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 then rm -f "$dsttmp" else # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || # The rename failed, perhaps because mv can't rename something else # to itself, or perhaps because mv is so ancient that it does not # support -f. { # Now remove or move aside any old file at destination location. # We try this two ways since rm can't unlink itself on some # systems and the destination file might be busy for other # reasons. In this case, the final cleanup might fail but the new # file should still install successfully. { test ! -f "$dst" || $doit $rmcmd -f "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 } } && # Now rename the file to the real destination. $doit $mvcmd "$dsttmp" "$dst" } fi || exit 1 trap '' 0 fi done # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: libnih-1.0.3/INSTALL0000644000175000017500000003633211461165303010741 00000000000000Installation Instructions ************************* Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without warranty of any kind. Basic Installation ================== Briefly, the shell commands `./configure; make; make install' should configure, build, and install this package. The following more-detailed instructions are generic; see the `README' file for instructions specific to this package. Some packages provide this `INSTALL' file but do not implement all of the features documented below. The lack of an optional feature in a given package is not necessarily a bug. More recommendations for GNU packages can be found in *note Makefile Conventions: (standards)Makefile Conventions. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a `Makefile' in each directory of the package. It may also create one or more `.h' files containing system-dependent definitions. Finally, it creates a shell script `config.status' that you can run in the future to recreate the current configuration, and a file `config.log' containing compiler output (useful mainly for debugging `configure'). It can also use an optional file (typically called `config.cache' and enabled with `--cache-file=config.cache' or simply `-C') that saves the results of its tests to speed up reconfiguring. Caching is disabled by default to prevent problems with accidental use of stale cache files. If you need to do unusual things to compile the package, please try to figure out how `configure' could check whether to do them, and mail diffs or instructions to the address given in the `README' so they can be considered for the next release. If you are using the cache, and at some point `config.cache' contains results you don't want to keep, you may remove or edit it. The file `configure.ac' (or `configure.in') is used to create `configure' by a program called `autoconf'. You need `configure.ac' if you want to change it or regenerate `configure' using a newer version of `autoconf'. The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type `./configure' to configure the package for your system. Running `configure' might take a while. While running, it prints some messages telling which features it is checking for. 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with the package, generally using the just-built uninstalled binaries. 4. Type `make install' to install the programs and any data files and documentation. When installing into a prefix owned by root, it is recommended that the package be configured and built as a regular user, and only the `make install' phase executed with root privileges. 5. Optionally, type `make installcheck' to repeat any self-tests, but this time using the binaries in their final installed location. This target does not install anything. Running this target as a regular user, particularly if the prior `make install' required root privileges, verifies that the installation completed correctly. 6. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is also a `make maintainer-clean' target, but that is intended mainly for the package's developers. If you use it, you may have to get all sorts of other programs in order to regenerate files that came with the distribution. 7. Often, you can also type `make uninstall' to remove the installed files again. In practice, not all packages have tested that uninstallation works correctly, even though it is required by the GNU Coding Standards. 8. Some packages, particularly those that use Automake, provide `make distcheck', which can by used by developers to test that all other targets like `make install' and `make uninstall' work correctly. This target is generally not run by end users. Compilers and Options ===================== Some systems require unusual options for compilation or linking that the `configure' script does not know about. Run `./configure --help' for details on some of the pertinent environment variables. You can give `configure' initial values for configuration parameters by setting variables in the command line or in the environment. Here is an example: ./configure CC=c99 CFLAGS=-g LIBS=-lposix *Note Defining Variables::, for more details. Compiling For Multiple Architectures ==================================== You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their own directory. To do this, you can use GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the source code in the directory that `configure' is in and in `..'. This is known as a "VPATH" build. With a non-GNU `make', it is safer to compile the package for one architecture at a time in the source code directory. After you have installed the package for one architecture, use `make distclean' before reconfiguring for another architecture. On MacOS X 10.5 and later systems, you can create libraries and executables that work on multiple system types--known as "fat" or "universal" binaries--by specifying multiple `-arch' options to the compiler but only a single `-arch' option to the preprocessor. Like this: ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CPP="gcc -E" CXXCPP="g++ -E" This is not guaranteed to produce working output in all cases, you may have to build one architecture at a time and combine the results using the `lipo' tool if you have problems. Installation Names ================== By default, `make install' installs the package's commands under `/usr/local/bin', include files under `/usr/local/include', etc. You can specify an installation prefix other than `/usr/local' by giving `configure' the option `--prefix=PREFIX', where PREFIX must be an absolute file name. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you pass the option `--exec-prefix=PREFIX' to `configure', the package uses PREFIX as the prefix for installing programs and libraries. Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories you can set and what kinds of files go in them. In general, the default for these options is expressed in terms of `${prefix}', so that specifying just `--prefix' will affect all of the other directory specifications that were not explicitly provided. The most portable way to affect installation locations is to pass the correct locations to `configure'; however, many packages provide one or both of the following shortcuts of passing variable assignments to the `make install' command line to change installation locations without having to reconfigure or recompile. The first method involves providing an override variable for each affected directory. For example, `make install prefix=/alternate/directory' will choose an alternate location for all directory configuration variables that were expressed in terms of `${prefix}'. Any directories that were specified during `configure', but not in terms of `${prefix}', must each be overridden at install time for the entire installation to be relocated. The approach of makefile variable overrides for each directory variable is required by the GNU Coding Standards, and ideally causes no recompilation. However, some platforms have known limitations with the semantics of shared libraries that end up requiring recompilation when using this method, particularly noticeable in packages that use GNU Libtool. The second method involves providing the `DESTDIR' variable. For example, `make install DESTDIR=/alternate/directory' will prepend `/alternate/directory' before all installation names. The approach of `DESTDIR' overrides is not required by the GNU Coding Standards, and does not work on platforms that have drive letters. On the other hand, it does better at avoiding recompilation issues, and works well even when some directory options were not specified in terms of `${prefix}' at `configure' time. Optional Features ================= If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE is something like `gnu-as' or `x' (for the X Window System). The `README' should mention any `--enable-' and `--with-' options that the package recognizes. For packages that use the X Window System, `configure' can usually find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. Some packages offer the ability to configure how verbose the execution of `make' will be. For these packages, running `./configure --enable-silent-rules' sets the default to minimal output, which can be overridden with `make V=1'; while running `./configure --disable-silent-rules' sets the default to verbose, which can be overridden with `make V=0'. Particular systems ================== On HP-UX, the default C compiler is not ANSI C compatible. If GNU CC is not installed, it is recommended to use the following options in order to use an ANSI C compiler: ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" and if that doesn't work, install pre-built binaries of GCC for HP-UX. On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot parse its `' header file. The option `-nodtk' can be used as a workaround. If GNU CC is not installed, it is therefore recommended to try ./configure CC="cc" and if that doesn't work, try ./configure CC="cc -nodtk" On Solaris, don't put `/usr/ucb' early in your `PATH'. This directory contains several dysfunctional programs; working variants of these programs are available in `/usr/bin'. So, if you need `/usr/ucb' in your `PATH', put it _after_ `/usr/bin'. On Haiku, software installed for all users goes in `/boot/common', not `/usr/local'. It is recommended to use the following options: ./configure --prefix=/boot/common Specifying the System Type ========================== There may be some features `configure' cannot figure out automatically, but needs to determine by the type of machine the package will run on. Usually, assuming the package is built to be run on the _same_ architectures, `configure' can figure that out, but if it prints a message saying it cannot guess the machine type, give it the `--build=TYPE' option. TYPE can either be a short name for the system type, such as `sun4', or a canonical name which has the form: CPU-COMPANY-SYSTEM where SYSTEM can have one of these forms: OS KERNEL-OS See the file `config.sub' for the possible values of each field. If `config.sub' isn't included in this package, then this package doesn't need to know the machine type. If you are _building_ compiler tools for cross-compiling, you should use the option `--target=TYPE' to select the type of system they will produce code for. If you want to _use_ a cross compiler, that generates code for a platform different from the build platform, you should specify the "host" platform (i.e., that on which the generated programs will eventually be run) with `--host=TYPE'. Sharing Defaults ================ If you want to set default values for `configure' scripts to share, you can create a site shell script called `config.site' that gives default values for variables like `CC', `cache_file', and `prefix'. `configure' looks for `PREFIX/share/config.site' if it exists, then `PREFIX/etc/config.site' if it exists. Or, you can set the `CONFIG_SITE' environment variable to the location of the site script. A warning: not all `configure' scripts look for a site script. Defining Variables ================== Variables not defined in a site shell script can be set in the environment passed to `configure'. However, some packages may run configure again during the build, and the customized values of these variables may be lost. In order to avoid this problem, you should set them in the `configure' command line, using `VAR=value'. For example: ./configure CC=/usr/local2/bin/gcc causes the specified `gcc' to be used as the C compiler (unless it is overridden in the site shell script). Unfortunately, this technique does not work for `CONFIG_SHELL' due to an Autoconf bug. Until the bug is fixed you can use this workaround: CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash `configure' Invocation ====================== `configure' recognizes the following options to control how it operates. `--help' `-h' Print a summary of all of the options to `configure', and exit. `--help=short' `--help=recursive' Print a summary of the options unique to this package's `configure', and exit. The `short' variant lists options used only in the top level, while the `recursive' variant lists options also present in any nested packages. `--version' `-V' Print the version of Autoconf used to generate the `configure' script, and exit. `--cache-file=FILE' Enable the cache: use and save the results of the tests in FILE, traditionally `config.cache'. FILE defaults to `/dev/null' to disable caching. `--config-cache' `-C' Alias for `--cache-file=config.cache'. `--quiet' `--silent' `-q' Do not print messages saying which checks are being made. To suppress all normal output, redirect it to `/dev/null' (any error messages will still be shown). `--srcdir=DIR' Look for the package's source code in directory DIR. Usually `configure' can determine that directory automatically. `--prefix=DIR' Use DIR as the installation prefix. *note Installation Names:: for more details, including other options available for fine-tuning the installation locations. `--no-create' `-n' Run the configure checks, but stop before creating any output files. `configure' also accepts some other, not widely useful, options. Run `configure --help' for more details. libnih-1.0.3/ltmain.sh0000755000175000017500000073341511461165277011553 00000000000000# Generated from ltmain.m4sh. # ltmain.sh (GNU libtool) 2.2.6b # Written by Gordon Matzigkeit , 1996 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007 2008 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # GNU Libtool is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # As a special exception to the GNU General Public License, # if you distribute this file as part of a program or library that # is built using GNU Libtool, you may include this file under the # same distribution terms that you use for the rest of that program. # # GNU Libtool is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GNU Libtool; see the file COPYING. If not, a copy # can be downloaded from http://www.gnu.org/licenses/gpl.html, # or obtained by writing to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Usage: $progname [OPTION]... [MODE-ARG]... # # Provide generalized library-building support services. # # --config show all configuration variables # --debug enable verbose shell tracing # -n, --dry-run display commands without modifying any files # --features display basic configuration information and exit # --mode=MODE use operation mode MODE # --preserve-dup-deps don't remove duplicate dependency libraries # --quiet, --silent don't print informational messages # --tag=TAG use configuration variables from tag TAG # -v, --verbose print informational messages (default) # --version print version information # -h, --help print short or long help message # # MODE must be one of the following: # # clean remove files from the build directory # compile compile a source file into a libtool object # execute automatically set library path, then run a program # finish complete the installation of libtool libraries # install install libraries or executables # link create a library or an executable # uninstall remove libraries from an installed directory # # MODE-ARGS vary depending on the MODE. # Try `$progname --help --mode=MODE' for a more detailed description of MODE. # # When reporting a bug, please describe a test case to reproduce it and # include the following information: # # host-triplet: $host # shell: $SHELL # compiler: $LTCC # compiler flags: $LTCFLAGS # linker: $LD (gnu? $with_gnu_ld) # $progname: (GNU libtool) 2.2.6b Debian-2.2.6b-2ubuntu1 # automake: $automake_version # autoconf: $autoconf_version # # Report bugs to . PROGRAM=ltmain.sh PACKAGE=libtool VERSION="2.2.6b Debian-2.2.6b-2ubuntu1" TIMESTAMP="" package_revision=1.3017 # Be Bourne compatible if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then emulate sh NULLCMD=: # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac fi BIN_SH=xpg4; export BIN_SH # for Tru64 DUALCASE=1; export DUALCASE # for MKS sh # NLS nuisances: We save the old values to restore during execute mode. # Only set LANG and LC_ALL to C if already set. # These must not be set unconditionally because not all systems understand # e.g. LANG=C (notably SCO). lt_user_locale= lt_safe_locale= for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${$lt_var+set}\" = set; then save_$lt_var=\$$lt_var $lt_var=C export $lt_var lt_user_locale=\"$lt_var=\\\$save_\$lt_var; \$lt_user_locale\" lt_safe_locale=\"$lt_var=C; \$lt_safe_locale\" fi" done $lt_unset CDPATH : ${CP="cp -f"} : ${ECHO="echo"} : ${EGREP="/bin/grep -E"} : ${FGREP="/bin/grep -F"} : ${GREP="/bin/grep"} : ${LN_S="ln -s"} : ${MAKE="make"} : ${MKDIR="mkdir"} : ${MV="mv -f"} : ${RM="rm -f"} : ${SED="/bin/sed"} : ${SHELL="${CONFIG_SHELL-/bin/sh}"} : ${Xsed="$SED -e 1s/^X//"} # Global variables: EXIT_SUCCESS=0 EXIT_FAILURE=1 EXIT_MISMATCH=63 # $? = 63 is used to indicate version mismatch to missing. EXIT_SKIP=77 # $? = 77 is used to indicate a skipped test to automake. exit_status=$EXIT_SUCCESS # Make sure IFS has a sensible default lt_nl=' ' IFS=" $lt_nl" dirname="s,/[^/]*$,," basename="s,^.*/,," # func_dirname_and_basename file append nondir_replacement # perform func_basename and func_dirname in a single function # call: # dirname: Compute the dirname of FILE. If nonempty, # add APPEND to the result, otherwise set result # to NONDIR_REPLACEMENT. # value returned in "$func_dirname_result" # basename: Compute filename of FILE. # value retuned in "$func_basename_result" # Implementation must be kept synchronized with func_dirname # and func_basename. For efficiency, we do not delegate to # those functions but instead duplicate the functionality here. func_dirname_and_basename () { # Extract subdirectory from the argument. func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"` if test "X$func_dirname_result" = "X${1}"; then func_dirname_result="${3}" else func_dirname_result="$func_dirname_result${2}" fi func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"` } # Generated shell functions inserted here. # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh # is ksh but when the shell is invoked as "sh" and the current value of # the _XPG environment variable is not equal to 1 (one), the special # positional parameter $0, within a function call, is the name of the # function. progpath="$0" # The name of this program: # In the unlikely event $progname began with a '-', it would play havoc with # func_echo (imagine progname=-n), so we prepend ./ in that case: func_dirname_and_basename "$progpath" progname=$func_basename_result case $progname in -*) progname=./$progname ;; esac # Make sure we have an absolute path for reexecution: case $progpath in [\\/]*|[A-Za-z]:\\*) ;; *[\\/]*) progdir=$func_dirname_result progdir=`cd "$progdir" && pwd` progpath="$progdir/$progname" ;; *) save_IFS="$IFS" IFS=: for progdir in $PATH; do IFS="$save_IFS" test -x "$progdir/$progname" && break done IFS="$save_IFS" test -n "$progdir" || progdir=`pwd` progpath="$progdir/$progname" ;; esac # Sed substitution that helps us do robust quoting. It backslashifies # metacharacters that are still active within double-quoted strings. Xsed="${SED}"' -e 1s/^X//' sed_quote_subst='s/\([`"$\\]\)/\\\1/g' # Same as above, but do not quote variable references. double_quote_subst='s/\(["`\\]\)/\\\1/g' # Re-`\' parameter expansions in output of double_quote_subst that were # `\'-ed in input to the same. If an odd number of `\' preceded a '$' # in input to double_quote_subst, that '$' was protected from expansion. # Since each input `\' is now two `\'s, look for any number of runs of # four `\'s followed by two `\'s and then a '$'. `\' that '$'. bs='\\' bs2='\\\\' bs4='\\\\\\\\' dollar='\$' sed_double_backslash="\ s/$bs4/&\\ /g s/^$bs2$dollar/$bs&/ s/\\([^$bs]\\)$bs2$dollar/\\1$bs2$bs$dollar/g s/\n//g" # Standard options: opt_dry_run=false opt_help=false opt_quiet=false opt_verbose=false opt_warning=: # func_echo arg... # Echo program name prefixed message, along with the current mode # name if it has been set yet. func_echo () { $ECHO "$progname${mode+: }$mode: $*" } # func_verbose arg... # Echo program name prefixed message in verbose mode only. func_verbose () { $opt_verbose && func_echo ${1+"$@"} # A bug in bash halts the script if the last line of a function # fails when set -e is in force, so we need another command to # work around that: : } # func_error arg... # Echo program name prefixed message to standard error. func_error () { $ECHO "$progname${mode+: }$mode: "${1+"$@"} 1>&2 } # func_warning arg... # Echo program name prefixed warning message to standard error. func_warning () { $opt_warning && $ECHO "$progname${mode+: }$mode: warning: "${1+"$@"} 1>&2 # bash bug again: : } # func_fatal_error arg... # Echo program name prefixed message to standard error, and exit. func_fatal_error () { func_error ${1+"$@"} exit $EXIT_FAILURE } # func_fatal_help arg... # Echo program name prefixed message to standard error, followed by # a help hint, and exit. func_fatal_help () { func_error ${1+"$@"} func_fatal_error "$help" } help="Try \`$progname --help' for more information." ## default # func_grep expression filename # Check whether EXPRESSION matches any line of FILENAME, without output. func_grep () { $GREP "$1" "$2" >/dev/null 2>&1 } # func_mkdir_p directory-path # Make sure the entire path to DIRECTORY-PATH is available. func_mkdir_p () { my_directory_path="$1" my_dir_list= if test -n "$my_directory_path" && test "$opt_dry_run" != ":"; then # Protect directory names starting with `-' case $my_directory_path in -*) my_directory_path="./$my_directory_path" ;; esac # While some portion of DIR does not yet exist... while test ! -d "$my_directory_path"; do # ...make a list in topmost first order. Use a colon delimited # list incase some portion of path contains whitespace. my_dir_list="$my_directory_path:$my_dir_list" # If the last portion added has no slash in it, the list is done case $my_directory_path in */*) ;; *) break ;; esac # ...otherwise throw away the child directory and loop my_directory_path=`$ECHO "X$my_directory_path" | $Xsed -e "$dirname"` done my_dir_list=`$ECHO "X$my_dir_list" | $Xsed -e 's,:*$,,'` save_mkdir_p_IFS="$IFS"; IFS=':' for my_dir in $my_dir_list; do IFS="$save_mkdir_p_IFS" # mkdir can fail with a `File exist' error if two processes # try to create one of the directories concurrently. Don't # stop in that case! $MKDIR "$my_dir" 2>/dev/null || : done IFS="$save_mkdir_p_IFS" # Bail out if we (or some other process) failed to create a directory. test -d "$my_directory_path" || \ func_fatal_error "Failed to create \`$1'" fi } # func_mktempdir [string] # Make a temporary directory that won't clash with other running # libtool processes, and avoids race conditions if possible. If # given, STRING is the basename for that directory. func_mktempdir () { my_template="${TMPDIR-/tmp}/${1-$progname}" if test "$opt_dry_run" = ":"; then # Return a directory name, but don't create it in dry-run mode my_tmpdir="${my_template}-$$" else # If mktemp works, use that first and foremost my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null` if test ! -d "$my_tmpdir"; then # Failing that, at least try and use $RANDOM to avoid a race my_tmpdir="${my_template}-${RANDOM-0}$$" save_mktempdir_umask=`umask` umask 0077 $MKDIR "$my_tmpdir" umask $save_mktempdir_umask fi # If we're not in dry-run mode, bomb out on failure test -d "$my_tmpdir" || \ func_fatal_error "cannot create temporary directory \`$my_tmpdir'" fi $ECHO "X$my_tmpdir" | $Xsed } # func_quote_for_eval arg # Aesthetically quote ARG to be evaled later. # This function returns two values: FUNC_QUOTE_FOR_EVAL_RESULT # is double-quoted, suitable for a subsequent eval, whereas # FUNC_QUOTE_FOR_EVAL_UNQUOTED_RESULT has merely all characters # which are still active within double quotes backslashified. func_quote_for_eval () { case $1 in *[\\\`\"\$]*) func_quote_for_eval_unquoted_result=`$ECHO "X$1" | $Xsed -e "$sed_quote_subst"` ;; *) func_quote_for_eval_unquoted_result="$1" ;; esac case $func_quote_for_eval_unquoted_result in # Double-quote args containing shell metacharacters to delay # word splitting, command substitution and and variable # expansion for a subsequent eval. # Many Bourne shells cannot handle close brackets correctly # in scan sets, so we specify it separately. *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") func_quote_for_eval_result="\"$func_quote_for_eval_unquoted_result\"" ;; *) func_quote_for_eval_result="$func_quote_for_eval_unquoted_result" esac } # func_quote_for_expand arg # Aesthetically quote ARG to be evaled later; same as above, # but do not quote variable references. func_quote_for_expand () { case $1 in *[\\\`\"]*) my_arg=`$ECHO "X$1" | $Xsed \ -e "$double_quote_subst" -e "$sed_double_backslash"` ;; *) my_arg="$1" ;; esac case $my_arg in # Double-quote args containing shell metacharacters to delay # word splitting and command substitution for a subsequent eval. # Many Bourne shells cannot handle close brackets correctly # in scan sets, so we specify it separately. *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") my_arg="\"$my_arg\"" ;; esac func_quote_for_expand_result="$my_arg" } # func_show_eval cmd [fail_exp] # Unless opt_silent is true, then output CMD. Then, if opt_dryrun is # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP # is given, then evaluate it. func_show_eval () { my_cmd="$1" my_fail_exp="${2-:}" ${opt_silent-false} || { func_quote_for_expand "$my_cmd" eval "func_echo $func_quote_for_expand_result" } if ${opt_dry_run-false}; then :; else eval "$my_cmd" my_status=$? if test "$my_status" -eq 0; then :; else eval "(exit $my_status); $my_fail_exp" fi fi } # func_show_eval_locale cmd [fail_exp] # Unless opt_silent is true, then output CMD. Then, if opt_dryrun is # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP # is given, then evaluate it. Use the saved locale for evaluation. func_show_eval_locale () { my_cmd="$1" my_fail_exp="${2-:}" ${opt_silent-false} || { func_quote_for_expand "$my_cmd" eval "func_echo $func_quote_for_expand_result" } if ${opt_dry_run-false}; then :; else eval "$lt_user_locale $my_cmd" my_status=$? eval "$lt_safe_locale" if test "$my_status" -eq 0; then :; else eval "(exit $my_status); $my_fail_exp" fi fi } # func_version # Echo version message to standard output and exit. func_version () { $SED -n '/^# '$PROGRAM' (GNU /,/# warranty; / { s/^# // s/^# *$// s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/ p }' < "$progpath" exit $? } # func_usage # Echo short help message to standard output and exit. func_usage () { $SED -n '/^# Usage:/,/# -h/ { s/^# // s/^# *$// s/\$progname/'$progname'/ p }' < "$progpath" $ECHO $ECHO "run \`$progname --help | more' for full usage" exit $? } # func_help # Echo long help message to standard output and exit. func_help () { $SED -n '/^# Usage:/,/# Report bugs to/ { s/^# // s/^# *$// s*\$progname*'$progname'* s*\$host*'"$host"'* s*\$SHELL*'"$SHELL"'* s*\$LTCC*'"$LTCC"'* s*\$LTCFLAGS*'"$LTCFLAGS"'* s*\$LD*'"$LD"'* s/\$with_gnu_ld/'"$with_gnu_ld"'/ s/\$automake_version/'"`(automake --version) 2>/dev/null |$SED 1q`"'/ s/\$autoconf_version/'"`(autoconf --version) 2>/dev/null |$SED 1q`"'/ p }' < "$progpath" exit $? } # func_missing_arg argname # Echo program name prefixed message to standard error and set global # exit_cmd. func_missing_arg () { func_error "missing argument for $1" exit_cmd=exit } exit_cmd=: # Check that we have a working $ECHO. if test "X$1" = X--no-reexec; then # Discard the --no-reexec flag, and continue. shift elif test "X$1" = X--fallback-echo; then # Avoid inline document here, it may be left over : elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then # Yippee, $ECHO works! : else # Restart under the correct shell, and then maybe $ECHO will work. exec $SHELL "$progpath" --no-reexec ${1+"$@"} fi if test "X$1" = X--fallback-echo; then # used as fallback echo shift cat </dev/null 2>&1; then taglist="$taglist $tagname" # Evaluate the configuration. Be careful to quote the path # and the sed script, to avoid splitting on whitespace, but # also don't use non-portable quotes within backquotes within # quotes we have to do it in 2 steps: extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"` eval "$extractedcf" else func_error "ignoring unknown tag $tagname" fi ;; esac } # Parse options once, thoroughly. This comes as soon as possible in # the script to make things like `libtool --version' happen quickly. { # Shorthand for --mode=foo, only valid as the first argument case $1 in clean|clea|cle|cl) shift; set dummy --mode clean ${1+"$@"}; shift ;; compile|compil|compi|comp|com|co|c) shift; set dummy --mode compile ${1+"$@"}; shift ;; execute|execut|execu|exec|exe|ex|e) shift; set dummy --mode execute ${1+"$@"}; shift ;; finish|finis|fini|fin|fi|f) shift; set dummy --mode finish ${1+"$@"}; shift ;; install|instal|insta|inst|ins|in|i) shift; set dummy --mode install ${1+"$@"}; shift ;; link|lin|li|l) shift; set dummy --mode link ${1+"$@"}; shift ;; uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u) shift; set dummy --mode uninstall ${1+"$@"}; shift ;; esac # Parse non-mode specific arguments: while test "$#" -gt 0; do opt="$1" shift case $opt in --config) func_config ;; --debug) preserve_args="$preserve_args $opt" func_echo "enabling shell trace mode" opt_debug='set -x' $opt_debug ;; -dlopen) test "$#" -eq 0 && func_missing_arg "$opt" && break execute_dlfiles="$execute_dlfiles $1" shift ;; --dry-run | -n) opt_dry_run=: ;; --features) func_features ;; --finish) mode="finish" ;; --mode) test "$#" -eq 0 && func_missing_arg "$opt" && break case $1 in # Valid mode arguments: clean) ;; compile) ;; execute) ;; finish) ;; install) ;; link) ;; relink) ;; uninstall) ;; # Catch anything else as an error *) func_error "invalid argument for $opt" exit_cmd=exit break ;; esac mode="$1" shift ;; --preserve-dup-deps) opt_duplicate_deps=: ;; --quiet|--silent) preserve_args="$preserve_args $opt" opt_silent=: ;; --verbose| -v) preserve_args="$preserve_args $opt" opt_silent=false ;; --tag) test "$#" -eq 0 && func_missing_arg "$opt" && break preserve_args="$preserve_args $opt $1" func_enable_tag "$1" # tagname is set here shift ;; # Separate optargs to long options: -dlopen=*|--mode=*|--tag=*) func_opt_split "$opt" set dummy "$func_opt_split_opt" "$func_opt_split_arg" ${1+"$@"} shift ;; -\?|-h) func_usage ;; --help) opt_help=: ;; --version) func_version ;; -*) func_fatal_help "unrecognized option \`$opt'" ;; *) nonopt="$opt" break ;; esac done case $host in *cygwin* | *mingw* | *pw32* | *cegcc*) # don't eliminate duplications in $postdeps and $predeps opt_duplicate_compiler_generated_deps=: ;; *) opt_duplicate_compiler_generated_deps=$opt_duplicate_deps ;; esac # Having warned about all mis-specified options, bail out if # anything was wrong. $exit_cmd $EXIT_FAILURE } # func_check_version_match # Ensure that we are using m4 macros, and libtool script from the same # release of libtool. func_check_version_match () { if test "$package_revision" != "$macro_revision"; then if test "$VERSION" != "$macro_version"; then if test -z "$macro_version"; then cat >&2 <<_LT_EOF $progname: Version mismatch error. This is $PACKAGE $VERSION, but the $progname: definition of this LT_INIT comes from an older release. $progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION $progname: and run autoconf again. _LT_EOF else cat >&2 <<_LT_EOF $progname: Version mismatch error. This is $PACKAGE $VERSION, but the $progname: definition of this LT_INIT comes from $PACKAGE $macro_version. $progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION $progname: and run autoconf again. _LT_EOF fi else cat >&2 <<_LT_EOF $progname: Version mismatch error. This is $PACKAGE $VERSION, revision $package_revision, $progname: but the definition of this LT_INIT comes from revision $macro_revision. $progname: You should recreate aclocal.m4 with macros from revision $package_revision $progname: of $PACKAGE $VERSION and run autoconf again. _LT_EOF fi exit $EXIT_MISMATCH fi } ## ----------- ## ## Main. ## ## ----------- ## $opt_help || { # Sanity checks first: func_check_version_match if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then func_fatal_configuration "not configured to build any kind of library" fi test -z "$mode" && func_fatal_error "error: you must specify a MODE." # Darwin sucks eval std_shrext=\"$shrext_cmds\" # Only execute mode is allowed to have -dlopen flags. if test -n "$execute_dlfiles" && test "$mode" != execute; then func_error "unrecognized option \`-dlopen'" $ECHO "$help" 1>&2 exit $EXIT_FAILURE fi # Change the help message to a mode-specific one. generic_help="$help" help="Try \`$progname --help --mode=$mode' for more information." } # func_lalib_p file # True iff FILE is a libtool `.la' library or `.lo' object file. # This function is only a basic sanity check; it will hardly flush out # determined imposters. func_lalib_p () { test -f "$1" && $SED -e 4q "$1" 2>/dev/null \ | $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1 } # func_lalib_unsafe_p file # True iff FILE is a libtool `.la' library or `.lo' object file. # This function implements the same check as func_lalib_p without # resorting to external programs. To this end, it redirects stdin and # closes it afterwards, without saving the original file descriptor. # As a safety measure, use it only where a negative result would be # fatal anyway. Works if `file' does not exist. func_lalib_unsafe_p () { lalib_p=no if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then for lalib_p_l in 1 2 3 4 do read lalib_p_line case "$lalib_p_line" in \#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;; esac done exec 0<&5 5<&- fi test "$lalib_p" = yes } # func_ltwrapper_script_p file # True iff FILE is a libtool wrapper script # This function is only a basic sanity check; it will hardly flush out # determined imposters. func_ltwrapper_script_p () { func_lalib_p "$1" } # func_ltwrapper_executable_p file # True iff FILE is a libtool wrapper executable # This function is only a basic sanity check; it will hardly flush out # determined imposters. func_ltwrapper_executable_p () { func_ltwrapper_exec_suffix= case $1 in *.exe) ;; *) func_ltwrapper_exec_suffix=.exe ;; esac $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1 } # func_ltwrapper_scriptname file # Assumes file is an ltwrapper_executable # uses $file to determine the appropriate filename for a # temporary ltwrapper_script. func_ltwrapper_scriptname () { func_ltwrapper_scriptname_result="" if func_ltwrapper_executable_p "$1"; then func_dirname_and_basename "$1" "" "." func_stripname '' '.exe' "$func_basename_result" func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper" fi } # func_ltwrapper_p file # True iff FILE is a libtool wrapper script or wrapper executable # This function is only a basic sanity check; it will hardly flush out # determined imposters. func_ltwrapper_p () { func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1" } # func_execute_cmds commands fail_cmd # Execute tilde-delimited COMMANDS. # If FAIL_CMD is given, eval that upon failure. # FAIL_CMD may read-access the current command in variable CMD! func_execute_cmds () { $opt_debug save_ifs=$IFS; IFS='~' for cmd in $1; do IFS=$save_ifs eval cmd=\"$cmd\" func_show_eval "$cmd" "${2-:}" done IFS=$save_ifs } # func_source file # Source FILE, adding directory component if necessary. # Note that it is not necessary on cygwin/mingw to append a dot to # FILE even if both FILE and FILE.exe exist: automatic-append-.exe # behavior happens only for exec(3), not for open(2)! Also, sourcing # `FILE.' does not work on cygwin managed mounts. func_source () { $opt_debug case $1 in */* | *\\*) . "$1" ;; *) . "./$1" ;; esac } # func_infer_tag arg # Infer tagged configuration to use if any are available and # if one wasn't chosen via the "--tag" command line option. # Only attempt this if the compiler in the base compile # command doesn't match the default compiler. # arg is usually of the form 'gcc ...' func_infer_tag () { $opt_debug if test -n "$available_tags" && test -z "$tagname"; then CC_quoted= for arg in $CC; do func_quote_for_eval "$arg" CC_quoted="$CC_quoted $func_quote_for_eval_result" done case $@ in # Blanks in the command may have been stripped by the calling shell, # but not from the CC environment variable when configure was run. " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*) ;; # Blanks at the start of $base_compile will cause this to fail # if we don't check for them as well. *) for z in $available_tags; do if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then # Evaluate the configuration. eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`" CC_quoted= for arg in $CC; do # Double-quote args containing other shell metacharacters. func_quote_for_eval "$arg" CC_quoted="$CC_quoted $func_quote_for_eval_result" done case "$@ " in " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*) # The compiler in the base compile command matches # the one in the tagged configuration. # Assume this is the tagged configuration we want. tagname=$z break ;; esac fi done # If $tagname still isn't set, then no tagged configuration # was found and let the user know that the "--tag" command # line option must be used. if test -z "$tagname"; then func_echo "unable to infer tagged configuration" func_fatal_error "specify a tag with \`--tag'" # else # func_verbose "using $tagname tagged configuration" fi ;; esac fi } # func_write_libtool_object output_name pic_name nonpic_name # Create a libtool object file (analogous to a ".la" file), # but don't create it if we're doing a dry run. func_write_libtool_object () { write_libobj=${1} if test "$build_libtool_libs" = yes; then write_lobj=\'${2}\' else write_lobj=none fi if test "$build_old_libs" = yes; then write_oldobj=\'${3}\' else write_oldobj=none fi $opt_dry_run || { cat >${write_libobj}T <?"'"'"' &()|`$[]' \ && func_warning "libobj name \`$libobj' may not contain shell special characters." func_dirname_and_basename "$obj" "/" "" objname="$func_basename_result" xdir="$func_dirname_result" lobj=${xdir}$objdir/$objname test -z "$base_compile" && \ func_fatal_help "you must specify a compilation command" # Delete any leftover library objects. if test "$build_old_libs" = yes; then removelist="$obj $lobj $libobj ${libobj}T" else removelist="$lobj $libobj ${libobj}T" fi # On Cygwin there's no "real" PIC flag so we must build both object types case $host_os in cygwin* | mingw* | pw32* | os2* | cegcc*) pic_mode=default ;; esac if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then # non-PIC code in shared libraries is not supported pic_mode=default fi # Calculate the filename of the output object if compiler does # not support -o with -c if test "$compiler_c_o" = no; then output_obj=`$ECHO "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext} lockfile="$output_obj.lock" else output_obj= need_locks=no lockfile= fi # Lock this critical section if it is needed # We use this script file to make the link, it avoids creating a new file if test "$need_locks" = yes; then until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do func_echo "Waiting for $lockfile to be removed" sleep 2 done elif test "$need_locks" = warn; then if test -f "$lockfile"; then $ECHO "\ *** ERROR, $lockfile exists and contains: `cat $lockfile 2>/dev/null` This indicates that another process is trying to use the same temporary object file, and libtool could not work around it because your compiler does not support \`-c' and \`-o' together. If you repeat this compilation, it may succeed, by chance, but you had better avoid parallel builds (make -j) in this platform, or get a better compiler." $opt_dry_run || $RM $removelist exit $EXIT_FAILURE fi removelist="$removelist $output_obj" $ECHO "$srcfile" > "$lockfile" fi $opt_dry_run || $RM $removelist removelist="$removelist $lockfile" trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15 if test -n "$fix_srcfile_path"; then eval srcfile=\"$fix_srcfile_path\" fi func_quote_for_eval "$srcfile" qsrcfile=$func_quote_for_eval_result # Only build a PIC object if we are building libtool libraries. if test "$build_libtool_libs" = yes; then # Without this assignment, base_compile gets emptied. fbsd_hideous_sh_bug=$base_compile if test "$pic_mode" != no; then command="$base_compile $qsrcfile $pic_flag" else # Don't build PIC code command="$base_compile $qsrcfile" fi func_mkdir_p "$xdir$objdir" if test -z "$output_obj"; then # Place PIC objects in $objdir command="$command -o $lobj" fi func_show_eval_locale "$command" \ 'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE' if test "$need_locks" = warn && test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then $ECHO "\ *** ERROR, $lockfile contains: `cat $lockfile 2>/dev/null` but it should contain: $srcfile This indicates that another process is trying to use the same temporary object file, and libtool could not work around it because your compiler does not support \`-c' and \`-o' together. If you repeat this compilation, it may succeed, by chance, but you had better avoid parallel builds (make -j) in this platform, or get a better compiler." $opt_dry_run || $RM $removelist exit $EXIT_FAILURE fi # Just move the object if needed, then go on to compile the next one if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then func_show_eval '$MV "$output_obj" "$lobj"' \ 'error=$?; $opt_dry_run || $RM $removelist; exit $error' fi # Allow error messages only from the first compilation. if test "$suppress_opt" = yes; then suppress_output=' >/dev/null 2>&1' fi fi # Only build a position-dependent object if we build old libraries. if test "$build_old_libs" = yes; then if test "$pic_mode" != yes; then # Don't build PIC code command="$base_compile $qsrcfile$pie_flag" else command="$base_compile $qsrcfile $pic_flag" fi if test "$compiler_c_o" = yes; then command="$command -o $obj" fi # Suppress compiler output if we already did a PIC compilation. command="$command$suppress_output" func_show_eval_locale "$command" \ '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' if test "$need_locks" = warn && test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then $ECHO "\ *** ERROR, $lockfile contains: `cat $lockfile 2>/dev/null` but it should contain: $srcfile This indicates that another process is trying to use the same temporary object file, and libtool could not work around it because your compiler does not support \`-c' and \`-o' together. If you repeat this compilation, it may succeed, by chance, but you had better avoid parallel builds (make -j) in this platform, or get a better compiler." $opt_dry_run || $RM $removelist exit $EXIT_FAILURE fi # Just move the object if needed if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then func_show_eval '$MV "$output_obj" "$obj"' \ 'error=$?; $opt_dry_run || $RM $removelist; exit $error' fi fi $opt_dry_run || { func_write_libtool_object "$libobj" "$objdir/$objname" "$objname" # Unlock the critical section if it was locked if test "$need_locks" != no; then removelist=$lockfile $RM "$lockfile" fi } exit $EXIT_SUCCESS } $opt_help || { test "$mode" = compile && func_mode_compile ${1+"$@"} } func_mode_help () { # We need to display help for each of the modes. case $mode in "") # Generic help is extracted from the usage comments # at the start of this file. func_help ;; clean) $ECHO \ "Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE... Remove files from the build directory. RM is the name of the program to use to delete files associated with each FILE (typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed to RM. If FILE is a libtool library, object or program, all the files associated with it are deleted. Otherwise, only FILE itself is deleted using RM." ;; compile) $ECHO \ "Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE Compile a source file into a libtool library object. This mode accepts the following additional options: -o OUTPUT-FILE set the output file name to OUTPUT-FILE -no-suppress do not suppress compiler output for multiple passes -prefer-pic try to building PIC objects only -prefer-non-pic try to building non-PIC objects only -shared do not build a \`.o' file suitable for static linking -static only build a \`.o' file suitable for static linking COMPILE-COMMAND is a command to be used in creating a \`standard' object file from the given SOURCEFILE. The output file name is determined by removing the directory component from SOURCEFILE, then substituting the C source code suffix \`.c' with the library object suffix, \`.lo'." ;; execute) $ECHO \ "Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]... Automatically set library path, then run a program. This mode accepts the following additional options: -dlopen FILE add the directory containing FILE to the library path This mode sets the library path environment variable according to \`-dlopen' flags. If any of the ARGS are libtool executable wrappers, then they are translated into their corresponding uninstalled binary, and any of their required library directories are added to the library path. Then, COMMAND is executed, with ARGS as arguments." ;; finish) $ECHO \ "Usage: $progname [OPTION]... --mode=finish [LIBDIR]... Complete the installation of libtool libraries. Each LIBDIR is a directory that contains libtool libraries. The commands that this mode executes may require superuser privileges. Use the \`--dry-run' option if you just want to see what would be executed." ;; install) $ECHO \ "Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND... Install executables or libraries. INSTALL-COMMAND is the installation command. The first component should be either the \`install' or \`cp' program. The following components of INSTALL-COMMAND are treated specially: -inst-prefix PREFIX-DIR Use PREFIX-DIR as a staging area for installation The rest of the components are interpreted as arguments to that command (only BSD-compatible install options are recognized)." ;; link) $ECHO \ "Usage: $progname [OPTION]... --mode=link LINK-COMMAND... Link object files or libraries together to form another library, or to create an executable program. LINK-COMMAND is a command using the C compiler that you would use to create a program from several object files. The following components of LINK-COMMAND are treated specially: -all-static do not do any dynamic linking at all -avoid-version do not add a version suffix if possible -dlopen FILE \`-dlpreopen' FILE if it cannot be dlopened at runtime -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3) -export-symbols SYMFILE try to export only the symbols listed in SYMFILE -export-symbols-regex REGEX try to export only the symbols matching REGEX -LLIBDIR search LIBDIR for required installed libraries -lNAME OUTPUT-FILE requires the installed library libNAME -module build a library that can dlopened -no-fast-install disable the fast-install mode -no-install link a not-installable executable -no-undefined declare that a library does not refer to external symbols -o OUTPUT-FILE create OUTPUT-FILE from the specified objects -objectlist FILE Use a list of object files found in FILE to specify objects -precious-files-regex REGEX don't remove output files matching REGEX -release RELEASE specify package release information -rpath LIBDIR the created library will eventually be installed in LIBDIR -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries -shared only do dynamic linking of libtool libraries -shrext SUFFIX override the standard shared library file extension -static do not do any dynamic linking of uninstalled libtool libraries -static-libtool-libs do not do any dynamic linking of libtool libraries -version-info CURRENT[:REVISION[:AGE]] specify library version info [each variable defaults to 0] -weak LIBNAME declare that the target provides the LIBNAME interface All other options (arguments beginning with \`-') are ignored. Every other argument is treated as a filename. Files ending in \`.la' are treated as uninstalled libtool libraries, other files are standard or library object files. If the OUTPUT-FILE ends in \`.la', then a libtool library is created, only library objects (\`.lo' files) may be specified, and \`-rpath' is required, except when creating a convenience library. If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created using \`ar' and \`ranlib', or on Windows using \`lib'. If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file is created, otherwise an executable program is created." ;; uninstall) $ECHO \ "Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE... Remove libraries from an installation directory. RM is the name of the program to use to delete files associated with each FILE (typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed to RM. If FILE is a libtool library, all the files associated with it are deleted. Otherwise, only FILE itself is deleted using RM." ;; *) func_fatal_help "invalid operation mode \`$mode'" ;; esac $ECHO $ECHO "Try \`$progname --help' for more information about other modes." exit $? } # Now that we've collected a possible --mode arg, show help if necessary $opt_help && func_mode_help # func_mode_execute arg... func_mode_execute () { $opt_debug # The first argument is the command name. cmd="$nonopt" test -z "$cmd" && \ func_fatal_help "you must specify a COMMAND" # Handle -dlopen flags immediately. for file in $execute_dlfiles; do test -f "$file" \ || func_fatal_help "\`$file' is not a file" dir= case $file in *.la) # Check to see that this really is a libtool archive. func_lalib_unsafe_p "$file" \ || func_fatal_help "\`$lib' is not a valid libtool archive" # Read the libtool library. dlname= library_names= func_source "$file" # Skip this library if it cannot be dlopened. if test -z "$dlname"; then # Warn if it was a shared library. test -n "$library_names" && \ func_warning "\`$file' was not linked with \`-export-dynamic'" continue fi func_dirname "$file" "" "." dir="$func_dirname_result" if test -f "$dir/$objdir/$dlname"; then dir="$dir/$objdir" else if test ! -f "$dir/$dlname"; then func_fatal_error "cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" fi fi ;; *.lo) # Just add the directory containing the .lo file. func_dirname "$file" "" "." dir="$func_dirname_result" ;; *) func_warning "\`-dlopen' is ignored for non-libtool libraries and objects" continue ;; esac # Get the absolute pathname. absdir=`cd "$dir" && pwd` test -n "$absdir" && dir="$absdir" # Now add the directory to shlibpath_var. if eval "test -z \"\$$shlibpath_var\""; then eval "$shlibpath_var=\"\$dir\"" else eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\"" fi done # This variable tells wrapper scripts just to set shlibpath_var # rather than running their programs. libtool_execute_magic="$magic" # Check if any of the arguments is a wrapper script. args= for file do case $file in -*) ;; *) # Do a test to see if this is really a libtool program. if func_ltwrapper_script_p "$file"; then func_source "$file" # Transform arg to wrapped name. file="$progdir/$program" elif func_ltwrapper_executable_p "$file"; then func_ltwrapper_scriptname "$file" func_source "$func_ltwrapper_scriptname_result" # Transform arg to wrapped name. file="$progdir/$program" fi ;; esac # Quote arguments (to preserve shell metacharacters). func_quote_for_eval "$file" args="$args $func_quote_for_eval_result" done if test "X$opt_dry_run" = Xfalse; then if test -n "$shlibpath_var"; then # Export the shlibpath_var. eval "export $shlibpath_var" fi # Restore saved environment variables for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${save_$lt_var+set}\" = set; then $lt_var=\$save_$lt_var; export $lt_var else $lt_unset $lt_var fi" done # Now prepare to actually exec the command. exec_cmd="\$cmd$args" else # Display what would be done. if test -n "$shlibpath_var"; then eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\"" $ECHO "export $shlibpath_var" fi $ECHO "$cmd$args" exit $EXIT_SUCCESS fi } test "$mode" = execute && func_mode_execute ${1+"$@"} # func_mode_finish arg... func_mode_finish () { $opt_debug libdirs="$nonopt" admincmds= if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then for dir do libdirs="$libdirs $dir" done for libdir in $libdirs; do if test -n "$finish_cmds"; then # Do each command in the finish commands. func_execute_cmds "$finish_cmds" 'admincmds="$admincmds '"$cmd"'"' fi if test -n "$finish_eval"; then # Do the single finish_eval. eval cmds=\"$finish_eval\" $opt_dry_run || eval "$cmds" || admincmds="$admincmds $cmds" fi done fi # Exit here if they wanted silent mode. $opt_silent && exit $EXIT_SUCCESS $ECHO "X----------------------------------------------------------------------" | $Xsed $ECHO "Libraries have been installed in:" for libdir in $libdirs; do $ECHO " $libdir" done $ECHO $ECHO "If you ever happen to want to link against installed libraries" $ECHO "in a given directory, LIBDIR, you must either use libtool, and" $ECHO "specify the full pathname of the library, or use the \`-LLIBDIR'" $ECHO "flag during linking and do at least one of the following:" if test -n "$shlibpath_var"; then $ECHO " - add LIBDIR to the \`$shlibpath_var' environment variable" $ECHO " during execution" fi if test -n "$runpath_var"; then $ECHO " - add LIBDIR to the \`$runpath_var' environment variable" $ECHO " during linking" fi if test -n "$hardcode_libdir_flag_spec"; then libdir=LIBDIR eval flag=\"$hardcode_libdir_flag_spec\" $ECHO " - use the \`$flag' linker flag" fi if test -n "$admincmds"; then $ECHO " - have your system administrator run these commands:$admincmds" fi if test -f /etc/ld.so.conf; then $ECHO " - have your system administrator add LIBDIR to \`/etc/ld.so.conf'" fi $ECHO $ECHO "See any operating system documentation about shared libraries for" case $host in solaris2.[6789]|solaris2.1[0-9]) $ECHO "more information, such as the ld(1), crle(1) and ld.so(8) manual" $ECHO "pages." ;; *) $ECHO "more information, such as the ld(1) and ld.so(8) manual pages." ;; esac $ECHO "X----------------------------------------------------------------------" | $Xsed exit $EXIT_SUCCESS } test "$mode" = finish && func_mode_finish ${1+"$@"} # func_mode_install arg... func_mode_install () { $opt_debug # There may be an optional sh(1) argument at the beginning of # install_prog (especially on Windows NT). if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh || # Allow the use of GNU shtool's install command. $ECHO "X$nonopt" | $GREP shtool >/dev/null; then # Aesthetically quote it. func_quote_for_eval "$nonopt" install_prog="$func_quote_for_eval_result " arg=$1 shift else install_prog= arg=$nonopt fi # The real first argument should be the name of the installation program. # Aesthetically quote it. func_quote_for_eval "$arg" install_prog="$install_prog$func_quote_for_eval_result" # We need to accept at least all the BSD install flags. dest= files= opts= prev= install_type= isdir=no stripme= for arg do if test -n "$dest"; then files="$files $dest" dest=$arg continue fi case $arg in -d) isdir=yes ;; -f) case " $install_prog " in *[\\\ /]cp\ *) ;; *) prev=$arg ;; esac ;; -g | -m | -o) prev=$arg ;; -s) stripme=" -s" continue ;; -*) ;; *) # If the previous option needed an argument, then skip it. if test -n "$prev"; then prev= else dest=$arg continue fi ;; esac # Aesthetically quote the argument. func_quote_for_eval "$arg" install_prog="$install_prog $func_quote_for_eval_result" done test -z "$install_prog" && \ func_fatal_help "you must specify an install program" test -n "$prev" && \ func_fatal_help "the \`$prev' option requires an argument" if test -z "$files"; then if test -z "$dest"; then func_fatal_help "no file or destination specified" else func_fatal_help "you must specify a destination" fi fi # Strip any trailing slash from the destination. func_stripname '' '/' "$dest" dest=$func_stripname_result # Check to see that the destination is a directory. test -d "$dest" && isdir=yes if test "$isdir" = yes; then destdir="$dest" destname= else func_dirname_and_basename "$dest" "" "." destdir="$func_dirname_result" destname="$func_basename_result" # Not a directory, so check to see that there is only one file specified. set dummy $files; shift test "$#" -gt 1 && \ func_fatal_help "\`$dest' is not a directory" fi case $destdir in [\\/]* | [A-Za-z]:[\\/]*) ;; *) for file in $files; do case $file in *.lo) ;; *) func_fatal_help "\`$destdir' must be an absolute directory name" ;; esac done ;; esac # This variable tells wrapper scripts just to set variables rather # than running their programs. libtool_install_magic="$magic" staticlibs= future_libdirs= current_libdirs= for file in $files; do # Do each installation. case $file in *.$libext) # Do the static libraries later. staticlibs="$staticlibs $file" ;; *.la) # Check to see that this really is a libtool archive. func_lalib_unsafe_p "$file" \ || func_fatal_help "\`$file' is not a valid libtool archive" library_names= old_library= relink_command= func_source "$file" # Add the libdir to current_libdirs if it is the destination. if test "X$destdir" = "X$libdir"; then case "$current_libdirs " in *" $libdir "*) ;; *) current_libdirs="$current_libdirs $libdir" ;; esac else # Note the libdir as a future libdir. case "$future_libdirs " in *" $libdir "*) ;; *) future_libdirs="$future_libdirs $libdir" ;; esac fi func_dirname "$file" "/" "" dir="$func_dirname_result" dir="$dir$objdir" if test -n "$relink_command"; then # Determine the prefix the user has applied to our future dir. inst_prefix_dir=`$ECHO "X$destdir" | $Xsed -e "s%$libdir\$%%"` # Don't allow the user to place us outside of our expected # location b/c this prevents finding dependent libraries that # are installed to the same prefix. # At present, this check doesn't affect windows .dll's that # are installed into $libdir/../bin (currently, that works fine) # but it's something to keep an eye on. test "$inst_prefix_dir" = "$destdir" && \ func_fatal_error "error: cannot install \`$file' to a directory not ending in $libdir" if test -n "$inst_prefix_dir"; then # Stick the inst_prefix_dir data into the link command. relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"` else relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%%"` fi func_warning "relinking \`$file'" func_show_eval "$relink_command" \ 'func_fatal_error "error: relink \`$file'\'' with the above command before installing it"' fi # See the names of the shared library. set dummy $library_names; shift if test -n "$1"; then realname="$1" shift srcname="$realname" test -n "$relink_command" && srcname="$realname"T # Install the shared library and build the symlinks. func_show_eval "$install_prog $dir/$srcname $destdir/$realname" \ 'exit $?' tstripme="$stripme" case $host_os in cygwin* | mingw* | pw32* | cegcc*) case $realname in *.dll.a) tstripme="" ;; esac ;; esac if test -n "$tstripme" && test -n "$striplib"; then func_show_eval "$striplib $destdir/$realname" 'exit $?' fi if test "$#" -gt 0; then # Delete the old symlinks, and create new ones. # Try `ln -sf' first, because the `ln' binary might depend on # the symlink we replace! Solaris /bin/ln does not understand -f, # so we also need to try rm && ln -s. for linkname do test "$linkname" != "$realname" \ && func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })" done fi # Do each command in the postinstall commands. lib="$destdir/$realname" func_execute_cmds "$postinstall_cmds" 'exit $?' fi # Install the pseudo-library for information purposes. func_basename "$file" name="$func_basename_result" instname="$dir/$name"i func_show_eval "$install_prog $instname $destdir/$name" 'exit $?' # Maybe install the static library, too. test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library" ;; *.lo) # Install (i.e. copy) a libtool object. # Figure out destination file name, if it wasn't already specified. if test -n "$destname"; then destfile="$destdir/$destname" else func_basename "$file" destfile="$func_basename_result" destfile="$destdir/$destfile" fi # Deduce the name of the destination old-style object file. case $destfile in *.lo) func_lo2o "$destfile" staticdest=$func_lo2o_result ;; *.$objext) staticdest="$destfile" destfile= ;; *) func_fatal_help "cannot copy a libtool object to \`$destfile'" ;; esac # Install the libtool object if requested. test -n "$destfile" && \ func_show_eval "$install_prog $file $destfile" 'exit $?' # Install the old object if enabled. if test "$build_old_libs" = yes; then # Deduce the name of the old-style object file. func_lo2o "$file" staticobj=$func_lo2o_result func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?' fi exit $EXIT_SUCCESS ;; *) # Figure out destination file name, if it wasn't already specified. if test -n "$destname"; then destfile="$destdir/$destname" else func_basename "$file" destfile="$func_basename_result" destfile="$destdir/$destfile" fi # If the file is missing, and there is a .exe on the end, strip it # because it is most likely a libtool script we actually want to # install stripped_ext="" case $file in *.exe) if test ! -f "$file"; then func_stripname '' '.exe' "$file" file=$func_stripname_result stripped_ext=".exe" fi ;; esac # Do a test to see if this is really a libtool program. case $host in *cygwin* | *mingw*) if func_ltwrapper_executable_p "$file"; then func_ltwrapper_scriptname "$file" wrapper=$func_ltwrapper_scriptname_result else func_stripname '' '.exe' "$file" wrapper=$func_stripname_result fi ;; *) wrapper=$file ;; esac if func_ltwrapper_script_p "$wrapper"; then notinst_deplibs= relink_command= func_source "$wrapper" # Check the variables that should have been set. test -z "$generated_by_libtool_version" && \ func_fatal_error "invalid libtool wrapper script \`$wrapper'" finalize=yes for lib in $notinst_deplibs; do # Check to see that each library is installed. libdir= if test -f "$lib"; then func_source "$lib" fi libfile="$libdir/"`$ECHO "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test if test -n "$libdir" && test ! -f "$libfile"; then func_warning "\`$lib' has not been installed in \`$libdir'" finalize=no fi done relink_command= func_source "$wrapper" outputname= if test "$fast_install" = no && test -n "$relink_command"; then $opt_dry_run || { if test "$finalize" = yes; then tmpdir=`func_mktempdir` func_basename "$file$stripped_ext" file="$func_basename_result" outputname="$tmpdir/$file" # Replace the output file specification. relink_command=`$ECHO "X$relink_command" | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g'` $opt_silent || { func_quote_for_expand "$relink_command" eval "func_echo $func_quote_for_expand_result" } if eval "$relink_command"; then : else func_error "error: relink \`$file' with the above command before installing it" $opt_dry_run || ${RM}r "$tmpdir" continue fi file="$outputname" else func_warning "cannot relink \`$file'" fi } else # Install the binary that we compiled earlier. file=`$ECHO "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"` fi fi # remove .exe since cygwin /usr/bin/install will append another # one anyway case $install_prog,$host in */usr/bin/install*,*cygwin*) case $file:$destfile in *.exe:*.exe) # this is ok ;; *.exe:*) destfile=$destfile.exe ;; *:*.exe) func_stripname '' '.exe' "$destfile" destfile=$func_stripname_result ;; esac ;; esac func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?' $opt_dry_run || if test -n "$outputname"; then ${RM}r "$tmpdir" fi ;; esac done for file in $staticlibs; do func_basename "$file" name="$func_basename_result" # Set up the ranlib parameters. oldlib="$destdir/$name" func_show_eval "$install_prog \$file \$oldlib" 'exit $?' if test -n "$stripme" && test -n "$old_striplib"; then func_show_eval "$old_striplib $oldlib" 'exit $?' fi # Do each command in the postinstall commands. func_execute_cmds "$old_postinstall_cmds" 'exit $?' done test -n "$future_libdirs" && \ func_warning "remember to run \`$progname --finish$future_libdirs'" if test -n "$current_libdirs"; then # Maybe just do a dry run. $opt_dry_run && current_libdirs=" -n$current_libdirs" exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs' else exit $EXIT_SUCCESS fi } test "$mode" = install && func_mode_install ${1+"$@"} # func_generate_dlsyms outputname originator pic_p # Extract symbols from dlprefiles and create ${outputname}S.o with # a dlpreopen symbol table. func_generate_dlsyms () { $opt_debug my_outputname="$1" my_originator="$2" my_pic_p="${3-no}" my_prefix=`$ECHO "$my_originator" | sed 's%[^a-zA-Z0-9]%_%g'` my_dlsyms= if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then if test -n "$NM" && test -n "$global_symbol_pipe"; then my_dlsyms="${my_outputname}S.c" else func_error "not configured to extract global symbols from dlpreopened files" fi fi if test -n "$my_dlsyms"; then case $my_dlsyms in "") ;; *.c) # Discover the nlist of each of the dlfiles. nlist="$output_objdir/${my_outputname}.nm" func_show_eval "$RM $nlist ${nlist}S ${nlist}T" # Parse the name list into a source file. func_verbose "creating $output_objdir/$my_dlsyms" $opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\ /* $my_dlsyms - symbol resolution table for \`$my_outputname' dlsym emulation. */ /* Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION */ #ifdef __cplusplus extern \"C\" { #endif /* External symbol declarations for the compiler. */\ " if test "$dlself" = yes; then func_verbose "generating symbol list for \`$output'" $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist" # Add our own program objects to the symbol list. progfiles=`$ECHO "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` for progfile in $progfiles; do func_verbose "extracting global C symbols from \`$progfile'" $opt_dry_run || eval "$NM $progfile | $global_symbol_pipe >> '$nlist'" done if test -n "$exclude_expsyms"; then $opt_dry_run || { eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T' eval '$MV "$nlist"T "$nlist"' } fi if test -n "$export_symbols_regex"; then $opt_dry_run || { eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T' eval '$MV "$nlist"T "$nlist"' } fi # Prepare the list of exported symbols if test -z "$export_symbols"; then export_symbols="$output_objdir/$outputname.exp" $opt_dry_run || { $RM $export_symbols eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' case $host in *cygwin* | *mingw* | *cegcc* ) eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' ;; esac } else $opt_dry_run || { eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"' eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' eval '$MV "$nlist"T "$nlist"' case $host in *cygwin | *mingw* | *cegcc* ) eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' ;; esac } fi fi for dlprefile in $dlprefiles; do func_verbose "extracting global C symbols from \`$dlprefile'" func_basename "$dlprefile" name="$func_basename_result" $opt_dry_run || { eval '$ECHO ": $name " >> "$nlist"' eval "$NM $dlprefile 2>/dev/null | $global_symbol_pipe >> '$nlist'" } done $opt_dry_run || { # Make sure we have at least an empty file. test -f "$nlist" || : > "$nlist" if test -n "$exclude_expsyms"; then $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T $MV "$nlist"T "$nlist" fi # Try sorting and uniquifying the output. if $GREP -v "^: " < "$nlist" | if sort -k 3 /dev/null 2>&1; then sort -k 3 else sort +2 fi | uniq > "$nlist"S; then : else $GREP -v "^: " < "$nlist" > "$nlist"S fi if test -f "$nlist"S; then eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"' else $ECHO '/* NONE */' >> "$output_objdir/$my_dlsyms" fi $ECHO >> "$output_objdir/$my_dlsyms" "\ /* The mapping between symbol names and symbols. */ typedef struct { const char *name; void *address; } lt_dlsymlist; " case $host in *cygwin* | *mingw* | *cegcc* ) $ECHO >> "$output_objdir/$my_dlsyms" "\ /* DATA imports from DLLs on WIN32 con't be const, because runtime relocations are performed -- see ld's documentation on pseudo-relocs. */" lt_dlsym_const= ;; *osf5*) echo >> "$output_objdir/$my_dlsyms" "\ /* This system does not cope well with relocations in const data */" lt_dlsym_const= ;; *) lt_dlsym_const=const ;; esac $ECHO >> "$output_objdir/$my_dlsyms" "\ extern $lt_dlsym_const lt_dlsymlist lt_${my_prefix}_LTX_preloaded_symbols[]; $lt_dlsym_const lt_dlsymlist lt_${my_prefix}_LTX_preloaded_symbols[] = {\ { \"$my_originator\", (void *) 0 }," case $need_lib_prefix in no) eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms" ;; *) eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms" ;; esac $ECHO >> "$output_objdir/$my_dlsyms" "\ {0, (void *) 0} }; /* This works around a problem in FreeBSD linker */ #ifdef FREEBSD_WORKAROUND static const void *lt_preloaded_setup() { return lt_${my_prefix}_LTX_preloaded_symbols; } #endif #ifdef __cplusplus } #endif\ " } # !$opt_dry_run pic_flag_for_symtable= case "$compile_command " in *" -static "*) ;; *) case $host in # compiling the symbol table file with pic_flag works around # a FreeBSD bug that causes programs to crash when -lm is # linked before any other PIC object. But we must not use # pic_flag when linking with -static. The problem exists in # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;; *-*-hpux*) pic_flag_for_symtable=" $pic_flag" ;; *) if test "X$my_pic_p" != Xno; then pic_flag_for_symtable=" $pic_flag" fi ;; esac ;; esac symtab_cflags= for arg in $LTCFLAGS; do case $arg in -pie | -fpie | -fPIE) ;; *) symtab_cflags="$symtab_cflags $arg" ;; esac done # Now compile the dynamic symbol file. func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?' # Clean up the generated files. func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T"' # Transform the symbol file into the correct name. symfileobj="$output_objdir/${my_outputname}S.$objext" case $host in *cygwin* | *mingw* | *cegcc* ) if test -f "$output_objdir/$my_outputname.def"; then compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` else compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"` finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"` fi ;; *) compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"` finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"` ;; esac ;; *) func_fatal_error "unknown suffix for \`$my_dlsyms'" ;; esac else # We keep going just in case the user didn't refer to # lt_preloaded_symbols. The linker will fail if global_symbol_pipe # really was required. # Nullify the symbol file. compile_command=`$ECHO "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"` finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s% @SYMFILE@%%"` fi } # func_win32_libid arg # return the library type of file 'arg' # # Need a lot of goo to handle *both* DLLs and import libs # Has to be a shell function in order to 'eat' the argument # that is supplied when $file_magic_command is called. func_win32_libid () { $opt_debug win32_libid_type="unknown" win32_fileres=`file -L $1 2>/dev/null` case $win32_fileres in *ar\ archive\ import\ library*) # definitely import win32_libid_type="x86 archive import" ;; *ar\ archive*) # could be an import, or static if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | $EGREP 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then win32_nmres=`eval $NM -f posix -A $1 | $SED -n -e ' 1,100{ / I /{ s,.*,import, p q } }'` case $win32_nmres in import*) win32_libid_type="x86 archive import";; *) win32_libid_type="x86 archive static";; esac fi ;; *DLL*) win32_libid_type="x86 DLL" ;; *executable*) # but shell scripts are "executable" too... case $win32_fileres in *MS\ Windows\ PE\ Intel*) win32_libid_type="x86 DLL" ;; esac ;; esac $ECHO "$win32_libid_type" } # func_extract_an_archive dir oldlib func_extract_an_archive () { $opt_debug f_ex_an_ar_dir="$1"; shift f_ex_an_ar_oldlib="$1" func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" 'exit $?' if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then : else func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" fi } # func_extract_archives gentop oldlib ... func_extract_archives () { $opt_debug my_gentop="$1"; shift my_oldlibs=${1+"$@"} my_oldobjs="" my_xlib="" my_xabs="" my_xdir="" for my_xlib in $my_oldlibs; do # Extract the objects. case $my_xlib in [\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;; *) my_xabs=`pwd`"/$my_xlib" ;; esac func_basename "$my_xlib" my_xlib="$func_basename_result" my_xlib_u=$my_xlib while :; do case " $extracted_archives " in *" $my_xlib_u "*) func_arith $extracted_serial + 1 extracted_serial=$func_arith_result my_xlib_u=lt$extracted_serial-$my_xlib ;; *) break ;; esac done extracted_archives="$extracted_archives $my_xlib_u" my_xdir="$my_gentop/$my_xlib_u" func_mkdir_p "$my_xdir" case $host in *-darwin*) func_verbose "Extracting $my_xabs" # Do not bother doing anything if just a dry run $opt_dry_run || { darwin_orig_dir=`pwd` cd $my_xdir || exit $? darwin_archive=$my_xabs darwin_curdir=`pwd` darwin_base_archive=`basename "$darwin_archive"` darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true` if test -n "$darwin_arches"; then darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'` darwin_arch= func_verbose "$darwin_base_archive has multiple architectures $darwin_arches" for darwin_arch in $darwin_arches ; do func_mkdir_p "unfat-$$/${darwin_base_archive}-${darwin_arch}" $LIPO -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}" cd "unfat-$$/${darwin_base_archive}-${darwin_arch}" func_extract_an_archive "`pwd`" "${darwin_base_archive}" cd "$darwin_curdir" $RM "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" done # $darwin_arches ## Okay now we've a bunch of thin objects, gotta fatten them up :) darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$basename" | sort -u` darwin_file= darwin_files= for darwin_file in $darwin_filelist; do darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP` $LIPO -create -output "$darwin_file" $darwin_files done # $darwin_filelist $RM -rf unfat-$$ cd "$darwin_orig_dir" else cd $darwin_orig_dir func_extract_an_archive "$my_xdir" "$my_xabs" fi # $darwin_arches } # !$opt_dry_run ;; *) func_extract_an_archive "$my_xdir" "$my_xabs" ;; esac my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP` done func_extract_archives_result="$my_oldobjs" } # func_emit_wrapper_part1 [arg=no] # # Emit the first part of a libtool wrapper script on stdout. # For more information, see the description associated with # func_emit_wrapper(), below. func_emit_wrapper_part1 () { func_emit_wrapper_part1_arg1=no if test -n "$1" ; then func_emit_wrapper_part1_arg1=$1 fi $ECHO "\ #! $SHELL # $output - temporary wrapper script for $objdir/$outputname # Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION # # The $output program cannot be directly executed until all the libtool # libraries that it depends on are installed. # # This wrapper script should never be moved out of the build directory. # If it is, it will not operate correctly. # Sed substitution that helps us do robust quoting. It backslashifies # metacharacters that are still active within double-quoted strings. Xsed='${SED} -e 1s/^X//' sed_quote_subst='$sed_quote_subst' # Be Bourne compatible if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then emulate sh NULLCMD=: # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac fi BIN_SH=xpg4; export BIN_SH # for Tru64 DUALCASE=1; export DUALCASE # for MKS sh # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH relink_command=\"$relink_command\" # This environment variable determines our operation mode. if test \"\$libtool_install_magic\" = \"$magic\"; then # install mode needs the following variables: generated_by_libtool_version='$macro_version' notinst_deplibs='$notinst_deplibs' else # When we are sourced in execute mode, \$file and \$ECHO are already set. if test \"\$libtool_execute_magic\" != \"$magic\"; then ECHO=\"$qecho\" file=\"\$0\" # Make sure echo works. if test \"X\$1\" = X--no-reexec; then # Discard the --no-reexec flag, and continue. shift elif test \"X\`{ \$ECHO '\t'; } 2>/dev/null\`\" = 'X\t'; then # Yippee, \$ECHO works! : else # Restart under the correct shell, and then maybe \$ECHO will work. exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"} fi fi\ " $ECHO "\ # Find the directory that this script lives in. thisdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\` test \"x\$thisdir\" = \"x\$file\" && thisdir=. # Follow symbolic links until we get to the real thisdir. file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\` while test -n \"\$file\"; do destdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\` # If there was a directory component, then change thisdir. if test \"x\$destdir\" != \"x\$file\"; then case \"\$destdir\" in [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;; *) thisdir=\"\$thisdir/\$destdir\" ;; esac fi file=\`\$ECHO \"X\$file\" | \$Xsed -e 's%^.*/%%'\` file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\` done " } # end: func_emit_wrapper_part1 # func_emit_wrapper_part2 [arg=no] # # Emit the second part of a libtool wrapper script on stdout. # For more information, see the description associated with # func_emit_wrapper(), below. func_emit_wrapper_part2 () { func_emit_wrapper_part2_arg1=no if test -n "$1" ; then func_emit_wrapper_part2_arg1=$1 fi $ECHO "\ # Usually 'no', except on cygwin/mingw when embedded into # the cwrapper. WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_part2_arg1 if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then # special case for '.' if test \"\$thisdir\" = \".\"; then thisdir=\`pwd\` fi # remove .libs from thisdir case \"\$thisdir\" in *[\\\\/]$objdir ) thisdir=\`\$ECHO \"X\$thisdir\" | \$Xsed -e 's%[\\\\/][^\\\\/]*$%%'\` ;; $objdir ) thisdir=. ;; esac fi # Try to get the absolute directory name. absdir=\`cd \"\$thisdir\" && pwd\` test -n \"\$absdir\" && thisdir=\"\$absdir\" " if test "$fast_install" = yes; then $ECHO "\ program=lt-'$outputname'$exeext progdir=\"\$thisdir/$objdir\" if test ! -f \"\$progdir/\$program\" || { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\ test \"X\$file\" != \"X\$progdir/\$program\"; }; then file=\"\$\$-\$program\" if test ! -d \"\$progdir\"; then $MKDIR \"\$progdir\" else $RM \"\$progdir/\$file\" fi" $ECHO "\ # relink executable if necessary if test -n \"\$relink_command\"; then if relink_command_output=\`eval \$relink_command 2>&1\`; then : else $ECHO \"\$relink_command_output\" >&2 $RM \"\$progdir/\$file\" exit 1 fi fi $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null || { $RM \"\$progdir/\$program\"; $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; } $RM \"\$progdir/\$file\" fi" else $ECHO "\ program='$outputname' progdir=\"\$thisdir/$objdir\" " fi $ECHO "\ if test -f \"\$progdir/\$program\"; then" # Export our shlibpath_var if we have one. if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then $ECHO "\ # Add our own library path to $shlibpath_var $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" # Some systems cannot cope with colon-terminated $shlibpath_var # The second colon is a workaround for a bug in BeOS R4 sed $shlibpath_var=\`\$ECHO \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\` export $shlibpath_var " fi # fixup the dll searchpath if we need to. if test -n "$dllsearchpath"; then $ECHO "\ # Add the dll search path components to the executable PATH PATH=$dllsearchpath:\$PATH " fi $ECHO "\ if test \"\$libtool_execute_magic\" != \"$magic\"; then # Run the actual program with our arguments. " case $host in # Backslashes separate directories on plain windows *-*-mingw | *-*-os2* | *-cegcc*) $ECHO "\ exec \"\$progdir\\\\\$program\" \${1+\"\$@\"} " ;; *) $ECHO "\ exec \"\$progdir/\$program\" \${1+\"\$@\"} " ;; esac $ECHO "\ \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2 exit 1 fi else # The program doesn't exist. \$ECHO \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2 \$ECHO \"This script is just a wrapper for \$program.\" 1>&2 $ECHO \"See the $PACKAGE documentation for more information.\" 1>&2 exit 1 fi fi\ " } # end: func_emit_wrapper_part2 # func_emit_wrapper [arg=no] # # Emit a libtool wrapper script on stdout. # Don't directly open a file because we may want to # incorporate the script contents within a cygwin/mingw # wrapper executable. Must ONLY be called from within # func_mode_link because it depends on a number of variables # set therein. # # ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR # variable will take. If 'yes', then the emitted script # will assume that the directory in which it is stored is # the $objdir directory. This is a cygwin/mingw-specific # behavior. func_emit_wrapper () { func_emit_wrapper_arg1=no if test -n "$1" ; then func_emit_wrapper_arg1=$1 fi # split this up so that func_emit_cwrapperexe_src # can call each part independently. func_emit_wrapper_part1 "${func_emit_wrapper_arg1}" func_emit_wrapper_part2 "${func_emit_wrapper_arg1}" } # func_to_host_path arg # # Convert paths to host format when used with build tools. # Intended for use with "native" mingw (where libtool itself # is running under the msys shell), or in the following cross- # build environments: # $build $host # mingw (msys) mingw [e.g. native] # cygwin mingw # *nix + wine mingw # where wine is equipped with the `winepath' executable. # In the native mingw case, the (msys) shell automatically # converts paths for any non-msys applications it launches, # but that facility isn't available from inside the cwrapper. # Similar accommodations are necessary for $host mingw and # $build cygwin. Calling this function does no harm for other # $host/$build combinations not listed above. # # ARG is the path (on $build) that should be converted to # the proper representation for $host. The result is stored # in $func_to_host_path_result. func_to_host_path () { func_to_host_path_result="$1" if test -n "$1" ; then case $host in *mingw* ) lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g' case $build in *mingw* ) # actually, msys # awkward: cmd appends spaces to result lt_sed_strip_trailing_spaces="s/[ ]*\$//" func_to_host_path_tmp1=`( cmd //c echo "$1" |\ $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""` func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\ $SED -e "$lt_sed_naive_backslashify"` ;; *cygwin* ) func_to_host_path_tmp1=`cygpath -w "$1"` func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\ $SED -e "$lt_sed_naive_backslashify"` ;; * ) # Unfortunately, winepath does not exit with a non-zero # error code, so we are forced to check the contents of # stdout. On the other hand, if the command is not # found, the shell will set an exit code of 127 and print # *an error message* to stdout. So we must check for both # error code of zero AND non-empty stdout, which explains # the odd construction: func_to_host_path_tmp1=`winepath -w "$1" 2>/dev/null` if test "$?" -eq 0 && test -n "${func_to_host_path_tmp1}"; then func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\ $SED -e "$lt_sed_naive_backslashify"` else # Allow warning below. func_to_host_path_result="" fi ;; esac if test -z "$func_to_host_path_result" ; then func_error "Could not determine host path corresponding to" func_error " '$1'" func_error "Continuing, but uninstalled executables may not work." # Fallback: func_to_host_path_result="$1" fi ;; esac fi } # end: func_to_host_path # func_to_host_pathlist arg # # Convert pathlists to host format when used with build tools. # See func_to_host_path(), above. This function supports the # following $build/$host combinations (but does no harm for # combinations not listed here): # $build $host # mingw (msys) mingw [e.g. native] # cygwin mingw # *nix + wine mingw # # Path separators are also converted from $build format to # $host format. If ARG begins or ends with a path separator # character, it is preserved (but converted to $host format) # on output. # # ARG is a pathlist (on $build) that should be converted to # the proper representation on $host. The result is stored # in $func_to_host_pathlist_result. func_to_host_pathlist () { func_to_host_pathlist_result="$1" if test -n "$1" ; then case $host in *mingw* ) lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g' # Remove leading and trailing path separator characters from # ARG. msys behavior is inconsistent here, cygpath turns them # into '.;' and ';.', and winepath ignores them completely. func_to_host_pathlist_tmp2="$1" # Once set for this call, this variable should not be # reassigned. It is used in tha fallback case. func_to_host_pathlist_tmp1=`echo "$func_to_host_pathlist_tmp2" |\ $SED -e 's|^:*||' -e 's|:*$||'` case $build in *mingw* ) # Actually, msys. # Awkward: cmd appends spaces to result. lt_sed_strip_trailing_spaces="s/[ ]*\$//" func_to_host_pathlist_tmp2=`( cmd //c echo "$func_to_host_pathlist_tmp1" |\ $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""` func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\ $SED -e "$lt_sed_naive_backslashify"` ;; *cygwin* ) func_to_host_pathlist_tmp2=`cygpath -w -p "$func_to_host_pathlist_tmp1"` func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\ $SED -e "$lt_sed_naive_backslashify"` ;; * ) # unfortunately, winepath doesn't convert pathlists func_to_host_pathlist_result="" func_to_host_pathlist_oldIFS=$IFS IFS=: for func_to_host_pathlist_f in $func_to_host_pathlist_tmp1 ; do IFS=$func_to_host_pathlist_oldIFS if test -n "$func_to_host_pathlist_f" ; then func_to_host_path "$func_to_host_pathlist_f" if test -n "$func_to_host_path_result" ; then if test -z "$func_to_host_pathlist_result" ; then func_to_host_pathlist_result="$func_to_host_path_result" else func_to_host_pathlist_result="$func_to_host_pathlist_result;$func_to_host_path_result" fi fi fi IFS=: done IFS=$func_to_host_pathlist_oldIFS ;; esac if test -z "$func_to_host_pathlist_result" ; then func_error "Could not determine the host path(s) corresponding to" func_error " '$1'" func_error "Continuing, but uninstalled executables may not work." # Fallback. This may break if $1 contains DOS-style drive # specifications. The fix is not to complicate the expression # below, but for the user to provide a working wine installation # with winepath so that path translation in the cross-to-mingw # case works properly. lt_replace_pathsep_nix_to_dos="s|:|;|g" func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp1" |\ $SED -e "$lt_replace_pathsep_nix_to_dos"` fi # Now, add the leading and trailing path separators back case "$1" in :* ) func_to_host_pathlist_result=";$func_to_host_pathlist_result" ;; esac case "$1" in *: ) func_to_host_pathlist_result="$func_to_host_pathlist_result;" ;; esac ;; esac fi } # end: func_to_host_pathlist # func_emit_cwrapperexe_src # emit the source code for a wrapper executable on stdout # Must ONLY be called from within func_mode_link because # it depends on a number of variable set therein. func_emit_cwrapperexe_src () { cat < #include #ifdef _MSC_VER # include # include # include # define setmode _setmode #else # include # include # ifdef __CYGWIN__ # include # define HAVE_SETENV # ifdef __STRICT_ANSI__ char *realpath (const char *, char *); int putenv (char *); int setenv (const char *, const char *, int); # endif # endif #endif #include #include #include #include #include #include #include #include #if defined(PATH_MAX) # define LT_PATHMAX PATH_MAX #elif defined(MAXPATHLEN) # define LT_PATHMAX MAXPATHLEN #else # define LT_PATHMAX 1024 #endif #ifndef S_IXOTH # define S_IXOTH 0 #endif #ifndef S_IXGRP # define S_IXGRP 0 #endif #ifdef _MSC_VER # define S_IXUSR _S_IEXEC # define stat _stat # ifndef _INTPTR_T_DEFINED # define intptr_t int # endif #endif #ifndef DIR_SEPARATOR # define DIR_SEPARATOR '/' # define PATH_SEPARATOR ':' #endif #if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \ defined (__OS2__) # define HAVE_DOS_BASED_FILE_SYSTEM # define FOPEN_WB "wb" # ifndef DIR_SEPARATOR_2 # define DIR_SEPARATOR_2 '\\' # endif # ifndef PATH_SEPARATOR_2 # define PATH_SEPARATOR_2 ';' # endif #endif #ifndef DIR_SEPARATOR_2 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) #else /* DIR_SEPARATOR_2 */ # define IS_DIR_SEPARATOR(ch) \ (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) #endif /* DIR_SEPARATOR_2 */ #ifndef PATH_SEPARATOR_2 # define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR) #else /* PATH_SEPARATOR_2 */ # define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2) #endif /* PATH_SEPARATOR_2 */ #ifdef __CYGWIN__ # define FOPEN_WB "wb" #endif #ifndef FOPEN_WB # define FOPEN_WB "w" #endif #ifndef _O_BINARY # define _O_BINARY 0 #endif #define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) #define XFREE(stale) do { \ if (stale) { free ((void *) stale); stale = 0; } \ } while (0) #undef LTWRAPPER_DEBUGPRINTF #if defined DEBUGWRAPPER # define LTWRAPPER_DEBUGPRINTF(args) ltwrapper_debugprintf args static void ltwrapper_debugprintf (const char *fmt, ...) { va_list args; va_start (args, fmt); (void) vfprintf (stderr, fmt, args); va_end (args); } #else # define LTWRAPPER_DEBUGPRINTF(args) #endif const char *program_name = NULL; void *xmalloc (size_t num); char *xstrdup (const char *string); const char *base_name (const char *name); char *find_executable (const char *wrapper); char *chase_symlinks (const char *pathspec); int make_executable (const char *path); int check_executable (const char *path); char *strendzap (char *str, const char *pat); void lt_fatal (const char *message, ...); void lt_setenv (const char *name, const char *value); char *lt_extend_str (const char *orig_value, const char *add, int to_end); void lt_opt_process_env_set (const char *arg); void lt_opt_process_env_prepend (const char *arg); void lt_opt_process_env_append (const char *arg); int lt_split_name_value (const char *arg, char** name, char** value); void lt_update_exe_path (const char *name, const char *value); void lt_update_lib_path (const char *name, const char *value); static const char *script_text_part1 = EOF func_emit_wrapper_part1 yes | $SED -e 's/\([\\"]\)/\\\1/g' \ -e 's/^/ "/' -e 's/$/\\n"/' echo ";" cat <"))); for (i = 0; i < newargc; i++) { LTWRAPPER_DEBUGPRINTF (("(main) newargz[%d] : %s\n", i, (newargz[i] ? newargz[i] : ""))); } EOF case $host_os in mingw*) cat <<"EOF" /* execv doesn't actually work on mingw as expected on unix */ rval = _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz); if (rval == -1) { /* failed to start process */ LTWRAPPER_DEBUGPRINTF (("(main) failed to launch target \"%s\": errno = %d\n", lt_argv_zero, errno)); return 127; } return rval; EOF ;; *) cat <<"EOF" execv (lt_argv_zero, newargz); return rval; /* =127, but avoids unused variable warning */ EOF ;; esac cat <<"EOF" } void * xmalloc (size_t num) { void *p = (void *) malloc (num); if (!p) lt_fatal ("Memory exhausted"); return p; } char * xstrdup (const char *string) { return string ? strcpy ((char *) xmalloc (strlen (string) + 1), string) : NULL; } const char * base_name (const char *name) { const char *base; #if defined (HAVE_DOS_BASED_FILE_SYSTEM) /* Skip over the disk name in MSDOS pathnames. */ if (isalpha ((unsigned char) name[0]) && name[1] == ':') name += 2; #endif for (base = name; *name; name++) if (IS_DIR_SEPARATOR (*name)) base = name + 1; return base; } int check_executable (const char *path) { struct stat st; LTWRAPPER_DEBUGPRINTF (("(check_executable) : %s\n", path ? (*path ? path : "EMPTY!") : "NULL!")); if ((!path) || (!*path)) return 0; if ((stat (path, &st) >= 0) && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) return 1; else return 0; } int make_executable (const char *path) { int rval = 0; struct stat st; LTWRAPPER_DEBUGPRINTF (("(make_executable) : %s\n", path ? (*path ? path : "EMPTY!") : "NULL!")); if ((!path) || (!*path)) return 0; if (stat (path, &st) >= 0) { rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR); } return rval; } /* Searches for the full path of the wrapper. Returns newly allocated full path name if found, NULL otherwise Does not chase symlinks, even on platforms that support them. */ char * find_executable (const char *wrapper) { int has_slash = 0; const char *p; const char *p_next; /* static buffer for getcwd */ char tmp[LT_PATHMAX + 1]; int tmp_len; char *concat_name; LTWRAPPER_DEBUGPRINTF (("(find_executable) : %s\n", wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!")); if ((wrapper == NULL) || (*wrapper == '\0')) return NULL; /* Absolute path? */ #if defined (HAVE_DOS_BASED_FILE_SYSTEM) if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':') { concat_name = xstrdup (wrapper); if (check_executable (concat_name)) return concat_name; XFREE (concat_name); } else { #endif if (IS_DIR_SEPARATOR (wrapper[0])) { concat_name = xstrdup (wrapper); if (check_executable (concat_name)) return concat_name; XFREE (concat_name); } #if defined (HAVE_DOS_BASED_FILE_SYSTEM) } #endif for (p = wrapper; *p; p++) if (*p == '/') { has_slash = 1; break; } if (!has_slash) { /* no slashes; search PATH */ const char *path = getenv ("PATH"); if (path != NULL) { for (p = path; *p; p = p_next) { const char *q; size_t p_len; for (q = p; *q; q++) if (IS_PATH_SEPARATOR (*q)) break; p_len = q - p; p_next = (*q == '\0' ? q : q + 1); if (p_len == 0) { /* empty path: current directory */ if (getcwd (tmp, LT_PATHMAX) == NULL) lt_fatal ("getcwd failed"); tmp_len = strlen (tmp); concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); memcpy (concat_name, tmp, tmp_len); concat_name[tmp_len] = '/'; strcpy (concat_name + tmp_len + 1, wrapper); } else { concat_name = XMALLOC (char, p_len + 1 + strlen (wrapper) + 1); memcpy (concat_name, p, p_len); concat_name[p_len] = '/'; strcpy (concat_name + p_len + 1, wrapper); } if (check_executable (concat_name)) return concat_name; XFREE (concat_name); } } /* not found in PATH; assume curdir */ } /* Relative path | not found in path: prepend cwd */ if (getcwd (tmp, LT_PATHMAX) == NULL) lt_fatal ("getcwd failed"); tmp_len = strlen (tmp); concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); memcpy (concat_name, tmp, tmp_len); concat_name[tmp_len] = '/'; strcpy (concat_name + tmp_len + 1, wrapper); if (check_executable (concat_name)) return concat_name; XFREE (concat_name); return NULL; } char * chase_symlinks (const char *pathspec) { #ifndef S_ISLNK return xstrdup (pathspec); #else char buf[LT_PATHMAX]; struct stat s; char *tmp_pathspec = xstrdup (pathspec); char *p; int has_symlinks = 0; while (strlen (tmp_pathspec) && !has_symlinks) { LTWRAPPER_DEBUGPRINTF (("checking path component for symlinks: %s\n", tmp_pathspec)); if (lstat (tmp_pathspec, &s) == 0) { if (S_ISLNK (s.st_mode) != 0) { has_symlinks = 1; break; } /* search backwards for last DIR_SEPARATOR */ p = tmp_pathspec + strlen (tmp_pathspec) - 1; while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) p--; if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) { /* no more DIR_SEPARATORS left */ break; } *p = '\0'; } else { char *errstr = strerror (errno); lt_fatal ("Error accessing file %s (%s)", tmp_pathspec, errstr); } } XFREE (tmp_pathspec); if (!has_symlinks) { return xstrdup (pathspec); } tmp_pathspec = realpath (pathspec, buf); if (tmp_pathspec == 0) { lt_fatal ("Could not follow symlinks for %s", pathspec); } return xstrdup (tmp_pathspec); #endif } char * strendzap (char *str, const char *pat) { size_t len, patlen; assert (str != NULL); assert (pat != NULL); len = strlen (str); patlen = strlen (pat); if (patlen <= len) { str += len - patlen; if (strcmp (str, pat) == 0) *str = '\0'; } return str; } static void lt_error_core (int exit_status, const char *mode, const char *message, va_list ap) { fprintf (stderr, "%s: %s: ", program_name, mode); vfprintf (stderr, message, ap); fprintf (stderr, ".\n"); if (exit_status >= 0) exit (exit_status); } void lt_fatal (const char *message, ...) { va_list ap; va_start (ap, message); lt_error_core (EXIT_FAILURE, "FATAL", message, ap); va_end (ap); } void lt_setenv (const char *name, const char *value) { LTWRAPPER_DEBUGPRINTF (("(lt_setenv) setting '%s' to '%s'\n", (name ? name : ""), (value ? value : ""))); { #ifdef HAVE_SETENV /* always make a copy, for consistency with !HAVE_SETENV */ char *str = xstrdup (value); setenv (name, str, 1); #else int len = strlen (name) + 1 + strlen (value) + 1; char *str = XMALLOC (char, len); sprintf (str, "%s=%s", name, value); if (putenv (str) != EXIT_SUCCESS) { XFREE (str); } #endif } } char * lt_extend_str (const char *orig_value, const char *add, int to_end) { char *new_value; if (orig_value && *orig_value) { int orig_value_len = strlen (orig_value); int add_len = strlen (add); new_value = XMALLOC (char, add_len + orig_value_len + 1); if (to_end) { strcpy (new_value, orig_value); strcpy (new_value + orig_value_len, add); } else { strcpy (new_value, add); strcpy (new_value + add_len, orig_value); } } else { new_value = xstrdup (add); } return new_value; } int lt_split_name_value (const char *arg, char** name, char** value) { const char *p; int len; if (!arg || !*arg) return 1; p = strchr (arg, (int)'='); if (!p) return 1; *value = xstrdup (++p); len = strlen (arg) - strlen (*value); *name = XMALLOC (char, len); strncpy (*name, arg, len-1); (*name)[len - 1] = '\0'; return 0; } void lt_opt_process_env_set (const char *arg) { char *name = NULL; char *value = NULL; if (lt_split_name_value (arg, &name, &value) != 0) { XFREE (name); XFREE (value); lt_fatal ("bad argument for %s: '%s'", env_set_opt, arg); } lt_setenv (name, value); XFREE (name); XFREE (value); } void lt_opt_process_env_prepend (const char *arg) { char *name = NULL; char *value = NULL; char *new_value = NULL; if (lt_split_name_value (arg, &name, &value) != 0) { XFREE (name); XFREE (value); lt_fatal ("bad argument for %s: '%s'", env_prepend_opt, arg); } new_value = lt_extend_str (getenv (name), value, 0); lt_setenv (name, new_value); XFREE (new_value); XFREE (name); XFREE (value); } void lt_opt_process_env_append (const char *arg) { char *name = NULL; char *value = NULL; char *new_value = NULL; if (lt_split_name_value (arg, &name, &value) != 0) { XFREE (name); XFREE (value); lt_fatal ("bad argument for %s: '%s'", env_append_opt, arg); } new_value = lt_extend_str (getenv (name), value, 1); lt_setenv (name, new_value); XFREE (new_value); XFREE (name); XFREE (value); } void lt_update_exe_path (const char *name, const char *value) { LTWRAPPER_DEBUGPRINTF (("(lt_update_exe_path) modifying '%s' by prepending '%s'\n", (name ? name : ""), (value ? value : ""))); if (name && *name && value && *value) { char *new_value = lt_extend_str (getenv (name), value, 0); /* some systems can't cope with a ':'-terminated path #' */ int len = strlen (new_value); while (((len = strlen (new_value)) > 0) && IS_PATH_SEPARATOR (new_value[len-1])) { new_value[len-1] = '\0'; } lt_setenv (name, new_value); XFREE (new_value); } } void lt_update_lib_path (const char *name, const char *value) { LTWRAPPER_DEBUGPRINTF (("(lt_update_lib_path) modifying '%s' by prepending '%s'\n", (name ? name : ""), (value ? value : ""))); if (name && *name && value && *value) { char *new_value = lt_extend_str (getenv (name), value, 0); lt_setenv (name, new_value); XFREE (new_value); } } EOF } # end: func_emit_cwrapperexe_src # func_mode_link arg... func_mode_link () { $opt_debug case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) # It is impossible to link a dll without this setting, and # we shouldn't force the makefile maintainer to figure out # which system we are compiling for in order to pass an extra # flag for every libtool invocation. # allow_undefined=no # FIXME: Unfortunately, there are problems with the above when trying # to make a dll which has undefined symbols, in which case not # even a static library is built. For now, we need to specify # -no-undefined on the libtool link line when we can be certain # that all symbols are satisfied, otherwise we get a static library. allow_undefined=yes ;; *) allow_undefined=yes ;; esac libtool_args=$nonopt base_compile="$nonopt $@" compile_command=$nonopt finalize_command=$nonopt compile_rpath= finalize_rpath= compile_shlibpath= finalize_shlibpath= convenience= old_convenience= deplibs= old_deplibs= compiler_flags= linker_flags= dllsearchpath= lib_search_path=`pwd` inst_prefix_dir= new_inherited_linker_flags= avoid_version=no dlfiles= dlprefiles= dlself=no export_dynamic=no export_symbols= export_symbols_regex= generated= libobjs= ltlibs= module=no no_install=no objs= non_pic_objects= precious_files_regex= prefer_static_libs=no preload=no prev= prevarg= release= rpath= xrpath= perm_rpath= temp_rpath= thread_safe=no vinfo= vinfo_number=no weak_libs= single_module="${wl}-single_module" func_infer_tag $base_compile # We need to know -static, to get the right output filenames. for arg do case $arg in -shared) test "$build_libtool_libs" != yes && \ func_fatal_configuration "can not build a shared library" build_old_libs=no break ;; -all-static | -static | -static-libtool-libs) case $arg in -all-static) if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then func_warning "complete static linking is impossible in this configuration" fi if test -n "$link_static_flag"; then dlopen_self=$dlopen_self_static fi prefer_static_libs=yes ;; -static) if test -z "$pic_flag" && test -n "$link_static_flag"; then dlopen_self=$dlopen_self_static fi prefer_static_libs=built ;; -static-libtool-libs) if test -z "$pic_flag" && test -n "$link_static_flag"; then dlopen_self=$dlopen_self_static fi prefer_static_libs=yes ;; esac build_libtool_libs=no build_old_libs=yes break ;; esac done # See if our shared archives depend on static archives. test -n "$old_archive_from_new_cmds" && build_old_libs=yes # Go through the arguments, transforming them on the way. while test "$#" -gt 0; do arg="$1" shift func_quote_for_eval "$arg" qarg=$func_quote_for_eval_unquoted_result func_append libtool_args " $func_quote_for_eval_result" # If the previous option needs an argument, assign it. if test -n "$prev"; then case $prev in output) func_append compile_command " @OUTPUT@" func_append finalize_command " @OUTPUT@" ;; esac case $prev in dlfiles|dlprefiles) if test "$preload" = no; then # Add the symbol object into the linking commands. func_append compile_command " @SYMFILE@" func_append finalize_command " @SYMFILE@" preload=yes fi case $arg in *.la | *.lo) ;; # We handle these cases below. force) if test "$dlself" = no; then dlself=needless export_dynamic=yes fi prev= continue ;; self) if test "$prev" = dlprefiles; then dlself=yes elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then dlself=yes else dlself=needless export_dynamic=yes fi prev= continue ;; *) if test "$prev" = dlfiles; then dlfiles="$dlfiles $arg" else dlprefiles="$dlprefiles $arg" fi prev= continue ;; esac ;; expsyms) export_symbols="$arg" test -f "$arg" \ || func_fatal_error "symbol file \`$arg' does not exist" prev= continue ;; expsyms_regex) export_symbols_regex="$arg" prev= continue ;; framework) case $host in *-*-darwin*) case "$deplibs " in *" $qarg.ltframework "*) ;; *) deplibs="$deplibs $qarg.ltframework" # this is fixed later ;; esac ;; esac prev= continue ;; inst_prefix) inst_prefix_dir="$arg" prev= continue ;; objectlist) if test -f "$arg"; then save_arg=$arg moreargs= for fil in `cat "$save_arg"` do # moreargs="$moreargs $fil" arg=$fil # A libtool-controlled object. # Check to see that this really is a libtool object. if func_lalib_unsafe_p "$arg"; then pic_object= non_pic_object= # Read the .lo file func_source "$arg" if test -z "$pic_object" || test -z "$non_pic_object" || test "$pic_object" = none && test "$non_pic_object" = none; then func_fatal_error "cannot find name of object for \`$arg'" fi # Extract subdirectory from the argument. func_dirname "$arg" "/" "" xdir="$func_dirname_result" if test "$pic_object" != none; then # Prepend the subdirectory the object is found in. pic_object="$xdir$pic_object" if test "$prev" = dlfiles; then if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then dlfiles="$dlfiles $pic_object" prev= continue else # If libtool objects are unsupported, then we need to preload. prev=dlprefiles fi fi # CHECK ME: I think I busted this. -Ossama if test "$prev" = dlprefiles; then # Preload the old-style object. dlprefiles="$dlprefiles $pic_object" prev= fi # A PIC object. func_append libobjs " $pic_object" arg="$pic_object" fi # Non-PIC object. if test "$non_pic_object" != none; then # Prepend the subdirectory the object is found in. non_pic_object="$xdir$non_pic_object" # A standard non-PIC object func_append non_pic_objects " $non_pic_object" if test -z "$pic_object" || test "$pic_object" = none ; then arg="$non_pic_object" fi else # If the PIC object exists, use it instead. # $xdir was prepended to $pic_object above. non_pic_object="$pic_object" func_append non_pic_objects " $non_pic_object" fi else # Only an error if not doing a dry-run. if $opt_dry_run; then # Extract subdirectory from the argument. func_dirname "$arg" "/" "" xdir="$func_dirname_result" func_lo2o "$arg" pic_object=$xdir$objdir/$func_lo2o_result non_pic_object=$xdir$func_lo2o_result func_append libobjs " $pic_object" func_append non_pic_objects " $non_pic_object" else func_fatal_error "\`$arg' is not a valid libtool object" fi fi done else func_fatal_error "link input file \`$arg' does not exist" fi arg=$save_arg prev= continue ;; precious_regex) precious_files_regex="$arg" prev= continue ;; release) release="-$arg" prev= continue ;; rpath | xrpath) # We need an absolute path. case $arg in [\\/]* | [A-Za-z]:[\\/]*) ;; *) func_fatal_error "only absolute run-paths are allowed" ;; esac if test "$prev" = rpath; then case "$rpath " in *" $arg "*) ;; *) rpath="$rpath $arg" ;; esac else case "$xrpath " in *" $arg "*) ;; *) xrpath="$xrpath $arg" ;; esac fi prev= continue ;; shrext) shrext_cmds="$arg" prev= continue ;; weak) weak_libs="$weak_libs $arg" prev= continue ;; xcclinker) linker_flags="$linker_flags $qarg" compiler_flags="$compiler_flags $qarg" prev= func_append compile_command " $qarg" func_append finalize_command " $qarg" continue ;; xcompiler) compiler_flags="$compiler_flags $qarg" prev= func_append compile_command " $qarg" func_append finalize_command " $qarg" continue ;; xlinker) linker_flags="$linker_flags $qarg" compiler_flags="$compiler_flags $wl$qarg" prev= func_append compile_command " $wl$qarg" func_append finalize_command " $wl$qarg" continue ;; *) eval "$prev=\"\$arg\"" prev= continue ;; esac fi # test -n "$prev" prevarg="$arg" case $arg in -all-static) if test -n "$link_static_flag"; then # See comment for -static flag below, for more details. func_append compile_command " $link_static_flag" func_append finalize_command " $link_static_flag" fi continue ;; -allow-undefined) # FIXME: remove this flag sometime in the future. func_fatal_error "\`-allow-undefined' must not be used because it is the default" ;; -avoid-version) avoid_version=yes continue ;; -dlopen) prev=dlfiles continue ;; -dlpreopen) prev=dlprefiles continue ;; -export-dynamic) export_dynamic=yes continue ;; -export-symbols | -export-symbols-regex) if test -n "$export_symbols" || test -n "$export_symbols_regex"; then func_fatal_error "more than one -exported-symbols argument is not allowed" fi if test "X$arg" = "X-export-symbols"; then prev=expsyms else prev=expsyms_regex fi continue ;; -framework) prev=framework continue ;; -inst-prefix-dir) prev=inst_prefix continue ;; # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* # so, if we see these flags be careful not to treat them like -L -L[A-Z][A-Z]*:*) case $with_gcc/$host in no/*-*-irix* | /*-*-irix*) func_append compile_command " $arg" func_append finalize_command " $arg" ;; esac continue ;; -L*) func_stripname '-L' '' "$arg" dir=$func_stripname_result if test -z "$dir"; then if test "$#" -gt 0; then func_fatal_error "require no space between \`-L' and \`$1'" else func_fatal_error "need path for \`-L' option" fi fi # We need an absolute path. case $dir in [\\/]* | [A-Za-z]:[\\/]*) ;; *) absdir=`cd "$dir" && pwd` test -z "$absdir" && \ func_fatal_error "cannot determine absolute directory name of \`$dir'" dir="$absdir" ;; esac case "$deplibs " in *" -L$dir "*) ;; *) deplibs="$deplibs -L$dir" lib_search_path="$lib_search_path $dir" ;; esac case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) testbindir=`$ECHO "X$dir" | $Xsed -e 's*/lib$*/bin*'` case :$dllsearchpath: in *":$dir:"*) ;; ::) dllsearchpath=$dir;; *) dllsearchpath="$dllsearchpath:$dir";; esac case :$dllsearchpath: in *":$testbindir:"*) ;; ::) dllsearchpath=$testbindir;; *) dllsearchpath="$dllsearchpath:$testbindir";; esac ;; esac continue ;; -l*) if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc*) # These systems don't actually have a C or math library (as such) continue ;; *-*-os2*) # These systems don't actually have a C library (as such) test "X$arg" = "X-lc" && continue ;; *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) # Do not include libc due to us having libc/libc_r. test "X$arg" = "X-lc" && continue ;; *-*-rhapsody* | *-*-darwin1.[012]) # Rhapsody C and math libraries are in the System framework deplibs="$deplibs System.ltframework" continue ;; *-*-sco3.2v5* | *-*-sco5v6*) # Causes problems with __ctype test "X$arg" = "X-lc" && continue ;; *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) # Compiler inserts libc in the correct place for threads to work test "X$arg" = "X-lc" && continue ;; esac elif test "X$arg" = "X-lc_r"; then case $host in *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) # Do not include libc_r directly, use -pthread flag. continue ;; esac fi deplibs="$deplibs $arg" continue ;; -module) module=yes continue ;; # Tru64 UNIX uses -model [arg] to determine the layout of C++ # classes, name mangling, and exception handling. # Darwin uses the -arch flag to determine output architecture. -model|-arch|-isysroot) compiler_flags="$compiler_flags $arg" func_append compile_command " $arg" func_append finalize_command " $arg" prev=xcompiler continue ;; -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) compiler_flags="$compiler_flags $arg" func_append compile_command " $arg" func_append finalize_command " $arg" case "$new_inherited_linker_flags " in *" $arg "*) ;; * ) new_inherited_linker_flags="$new_inherited_linker_flags $arg" ;; esac continue ;; -multi_module) single_module="${wl}-multi_module" continue ;; -no-fast-install) fast_install=no continue ;; -no-install) case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*) # The PATH hackery in wrapper scripts is required on Windows # and Darwin in order for the loader to find any dlls it needs. func_warning "\`-no-install' is ignored for $host" func_warning "assuming \`-no-fast-install' instead" fast_install=no ;; *) no_install=yes ;; esac continue ;; -no-undefined) allow_undefined=no continue ;; -objectlist) prev=objectlist continue ;; -o) prev=output ;; -precious-files-regex) prev=precious_regex continue ;; -release) prev=release continue ;; -rpath) prev=rpath continue ;; -R) prev=xrpath continue ;; -R*) func_stripname '-R' '' "$arg" dir=$func_stripname_result # We need an absolute path. case $dir in [\\/]* | [A-Za-z]:[\\/]*) ;; *) func_fatal_error "only absolute run-paths are allowed" ;; esac case "$xrpath " in *" $dir "*) ;; *) xrpath="$xrpath $dir" ;; esac continue ;; -shared) # The effects of -shared are defined in a previous loop. continue ;; -shrext) prev=shrext continue ;; -static | -static-libtool-libs) # The effects of -static are defined in a previous loop. # We used to do the same as -all-static on platforms that # didn't have a PIC flag, but the assumption that the effects # would be equivalent was wrong. It would break on at least # Digital Unix and AIX. continue ;; -thread-safe) thread_safe=yes continue ;; -version-info) prev=vinfo continue ;; -version-number) prev=vinfo vinfo_number=yes continue ;; -weak) prev=weak continue ;; -Wc,*) func_stripname '-Wc,' '' "$arg" args=$func_stripname_result arg= save_ifs="$IFS"; IFS=',' for flag in $args; do IFS="$save_ifs" func_quote_for_eval "$flag" arg="$arg $wl$func_quote_for_eval_result" compiler_flags="$compiler_flags $func_quote_for_eval_result" done IFS="$save_ifs" func_stripname ' ' '' "$arg" arg=$func_stripname_result ;; -Wl,*) func_stripname '-Wl,' '' "$arg" args=$func_stripname_result arg= save_ifs="$IFS"; IFS=',' for flag in $args; do IFS="$save_ifs" func_quote_for_eval "$flag" arg="$arg $wl$func_quote_for_eval_result" compiler_flags="$compiler_flags $wl$func_quote_for_eval_result" linker_flags="$linker_flags $func_quote_for_eval_result" done IFS="$save_ifs" func_stripname ' ' '' "$arg" arg=$func_stripname_result ;; -Xcompiler) prev=xcompiler continue ;; -Xlinker) prev=xlinker continue ;; -XCClinker) prev=xcclinker continue ;; # -msg_* for osf cc -msg_*) func_quote_for_eval "$arg" arg="$func_quote_for_eval_result" ;; # -64, -mips[0-9] enable 64-bit mode on the SGI compiler # -r[0-9][0-9]* specifies the processor on the SGI compiler # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler # +DA*, +DD* enable 64-bit mode on the HP compiler # -q* pass through compiler args for the IBM compiler # -m*, -t[45]*, -txscale* pass through architecture-specific # compiler args for GCC # -F/path gives path to uninstalled frameworks, gcc on darwin # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC # @file GCC response files -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*) func_quote_for_eval "$arg" arg="$func_quote_for_eval_result" func_append compile_command " $arg" func_append finalize_command " $arg" compiler_flags="$compiler_flags $arg" continue ;; # Some other compiler flag. -* | +*) func_quote_for_eval "$arg" arg="$func_quote_for_eval_result" ;; *.$objext) # A standard object. objs="$objs $arg" ;; *.lo) # A libtool-controlled object. # Check to see that this really is a libtool object. if func_lalib_unsafe_p "$arg"; then pic_object= non_pic_object= # Read the .lo file func_source "$arg" if test -z "$pic_object" || test -z "$non_pic_object" || test "$pic_object" = none && test "$non_pic_object" = none; then func_fatal_error "cannot find name of object for \`$arg'" fi # Extract subdirectory from the argument. func_dirname "$arg" "/" "" xdir="$func_dirname_result" if test "$pic_object" != none; then # Prepend the subdirectory the object is found in. pic_object="$xdir$pic_object" if test "$prev" = dlfiles; then if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then dlfiles="$dlfiles $pic_object" prev= continue else # If libtool objects are unsupported, then we need to preload. prev=dlprefiles fi fi # CHECK ME: I think I busted this. -Ossama if test "$prev" = dlprefiles; then # Preload the old-style object. dlprefiles="$dlprefiles $pic_object" prev= fi # A PIC object. func_append libobjs " $pic_object" arg="$pic_object" fi # Non-PIC object. if test "$non_pic_object" != none; then # Prepend the subdirectory the object is found in. non_pic_object="$xdir$non_pic_object" # A standard non-PIC object func_append non_pic_objects " $non_pic_object" if test -z "$pic_object" || test "$pic_object" = none ; then arg="$non_pic_object" fi else # If the PIC object exists, use it instead. # $xdir was prepended to $pic_object above. non_pic_object="$pic_object" func_append non_pic_objects " $non_pic_object" fi else # Only an error if not doing a dry-run. if $opt_dry_run; then # Extract subdirectory from the argument. func_dirname "$arg" "/" "" xdir="$func_dirname_result" func_lo2o "$arg" pic_object=$xdir$objdir/$func_lo2o_result non_pic_object=$xdir$func_lo2o_result func_append libobjs " $pic_object" func_append non_pic_objects " $non_pic_object" else func_fatal_error "\`$arg' is not a valid libtool object" fi fi ;; *.$libext) # An archive. deplibs="$deplibs $arg" old_deplibs="$old_deplibs $arg" continue ;; *.la) # A libtool-controlled library. if test "$prev" = dlfiles; then # This library was specified with -dlopen. dlfiles="$dlfiles $arg" prev= elif test "$prev" = dlprefiles; then # The library was specified with -dlpreopen. dlprefiles="$dlprefiles $arg" prev= else deplibs="$deplibs $arg" fi continue ;; # Some other compiler argument. *) # Unknown arguments in both finalize_command and compile_command need # to be aesthetically quoted because they are evaled later. func_quote_for_eval "$arg" arg="$func_quote_for_eval_result" ;; esac # arg # Now actually substitute the argument into the commands. if test -n "$arg"; then func_append compile_command " $arg" func_append finalize_command " $arg" fi done # argument parsing loop test -n "$prev" && \ func_fatal_help "the \`$prevarg' option requires an argument" if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then eval arg=\"$export_dynamic_flag_spec\" func_append compile_command " $arg" func_append finalize_command " $arg" fi oldlibs= # calculate the name of the file, without its directory func_basename "$output" outputname="$func_basename_result" libobjs_save="$libobjs" if test -n "$shlibpath_var"; then # get the directories listed in $shlibpath_var eval shlib_search_path=\`\$ECHO \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\` else shlib_search_path= fi eval sys_lib_search_path=\"$sys_lib_search_path_spec\" eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\" func_dirname "$output" "/" "" output_objdir="$func_dirname_result$objdir" # Create the object directory. func_mkdir_p "$output_objdir" # Determine the type of output case $output in "") func_fatal_help "you must specify an output file" ;; *.$libext) linkmode=oldlib ;; *.lo | *.$objext) linkmode=obj ;; *.la) linkmode=lib ;; *) linkmode=prog ;; # Anything else should be a program. esac specialdeplibs= libs= # Find all interdependent deplibs by searching for libraries # that are linked more than once (e.g. -la -lb -la) for deplib in $deplibs; do if $opt_duplicate_deps ; then case "$libs " in *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; esac fi libs="$libs $deplib" done if test "$linkmode" = lib; then libs="$predeps $libs $compiler_lib_search_path $postdeps" # Compute libraries that are listed more than once in $predeps # $postdeps and mark them as special (i.e., whose duplicates are # not to be eliminated). pre_post_deps= if $opt_duplicate_compiler_generated_deps; then for pre_post_dep in $predeps $postdeps; do case "$pre_post_deps " in *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;; esac pre_post_deps="$pre_post_deps $pre_post_dep" done fi pre_post_deps= fi deplibs= newdependency_libs= newlib_search_path= need_relink=no # whether we're linking any uninstalled libtool libraries notinst_deplibs= # not-installed libtool libraries notinst_path= # paths that contain not-installed libtool libraries case $linkmode in lib) passes="conv dlpreopen link" for file in $dlfiles $dlprefiles; do case $file in *.la) ;; *) func_fatal_help "libraries can \`-dlopen' only libtool libraries: $file" ;; esac done ;; prog) compile_deplibs= finalize_deplibs= alldeplibs=no newdlfiles= newdlprefiles= passes="conv scan dlopen dlpreopen link" ;; *) passes="conv" ;; esac for pass in $passes; do # The preopen pass in lib mode reverses $deplibs; put it back here # so that -L comes before libs that need it for instance... if test "$linkmode,$pass" = "lib,link"; then ## FIXME: Find the place where the list is rebuilt in the wrong ## order, and fix it there properly tmp_deplibs= for deplib in $deplibs; do tmp_deplibs="$deplib $tmp_deplibs" done deplibs="$tmp_deplibs" fi if test "$linkmode,$pass" = "lib,link" || test "$linkmode,$pass" = "prog,scan"; then libs="$deplibs" deplibs= fi if test "$linkmode" = prog; then case $pass in dlopen) libs="$dlfiles" ;; dlpreopen) libs="$dlprefiles" ;; link) libs="$deplibs %DEPLIBS%" test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs" ;; esac fi if test "$linkmode,$pass" = "lib,dlpreopen"; then # Collect and forward deplibs of preopened libtool libs for lib in $dlprefiles; do # Ignore non-libtool-libs dependency_libs= case $lib in *.la) func_source "$lib" ;; esac # Collect preopened libtool deplibs, except any this library # has declared as weak libs for deplib in $dependency_libs; do deplib_base=`$ECHO "X$deplib" | $Xsed -e "$basename"` case " $weak_libs " in *" $deplib_base "*) ;; *) deplibs="$deplibs $deplib" ;; esac done done libs="$dlprefiles" fi if test "$pass" = dlopen; then # Collect dlpreopened libraries save_deplibs="$deplibs" deplibs= fi for deplib in $libs; do lib= found=no case $deplib in -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads) if test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" else compiler_flags="$compiler_flags $deplib" if test "$linkmode" = lib ; then case "$new_inherited_linker_flags " in *" $deplib "*) ;; * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;; esac fi fi continue ;; -l*) if test "$linkmode" != lib && test "$linkmode" != prog; then func_warning "\`-l' is ignored for archives/objects" continue fi func_stripname '-l' '' "$deplib" name=$func_stripname_result if test "$linkmode" = lib; then searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path" else searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path" fi for searchdir in $searchdirs; do for search_ext in .la $std_shrext .so .a; do # Search the libtool library lib="$searchdir/lib${name}${search_ext}" if test -f "$lib"; then if test "$search_ext" = ".la"; then found=yes else found=no fi break 2 fi done done if test "$found" != yes; then # deplib doesn't seem to be a libtool library if test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" else deplibs="$deplib $deplibs" test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" fi continue else # deplib is a libtool library # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib, # We need to do some special things here, and not later. if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then case " $predeps $postdeps " in *" $deplib "*) if func_lalib_p "$lib"; then library_names= old_library= func_source "$lib" for l in $old_library $library_names; do ll="$l" done if test "X$ll" = "X$old_library" ; then # only static version available found=no func_dirname "$lib" "" "." ladir="$func_dirname_result" lib=$ladir/$old_library if test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" else deplibs="$deplib $deplibs" test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" fi continue fi fi ;; *) ;; esac fi fi ;; # -l *.ltframework) if test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" else deplibs="$deplib $deplibs" if test "$linkmode" = lib ; then case "$new_inherited_linker_flags " in *" $deplib "*) ;; * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;; esac fi fi continue ;; -L*) case $linkmode in lib) deplibs="$deplib $deplibs" test "$pass" = conv && continue newdependency_libs="$deplib $newdependency_libs" func_stripname '-L' '' "$deplib" newlib_search_path="$newlib_search_path $func_stripname_result" ;; prog) if test "$pass" = conv; then deplibs="$deplib $deplibs" continue fi if test "$pass" = scan; then deplibs="$deplib $deplibs" else compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" fi func_stripname '-L' '' "$deplib" newlib_search_path="$newlib_search_path $func_stripname_result" ;; *) func_warning "\`-L' is ignored for archives/objects" ;; esac # linkmode continue ;; # -L -R*) if test "$pass" = link; then func_stripname '-R' '' "$deplib" dir=$func_stripname_result # Make sure the xrpath contains only unique directories. case "$xrpath " in *" $dir "*) ;; *) xrpath="$xrpath $dir" ;; esac fi deplibs="$deplib $deplibs" continue ;; *.la) lib="$deplib" ;; *.$libext) if test "$pass" = conv; then deplibs="$deplib $deplibs" continue fi case $linkmode in lib) # Linking convenience modules into shared libraries is allowed, # but linking other static libraries is non-portable. case " $dlpreconveniencelibs " in *" $deplib "*) ;; *) valid_a_lib=no case $deplibs_check_method in match_pattern*) set dummy $deplibs_check_method; shift match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"` if eval "\$ECHO \"X$deplib\"" 2>/dev/null | $Xsed -e 10q \ | $EGREP "$match_pattern_regex" > /dev/null; then valid_a_lib=yes fi ;; pass_all) valid_a_lib=yes ;; esac if test "$valid_a_lib" != yes; then $ECHO $ECHO "*** Warning: Trying to link with static lib archive $deplib." $ECHO "*** I have the capability to make that library automatically link in when" $ECHO "*** you link to this library. But I can only do this if you have a" $ECHO "*** shared version of the library, which you do not appear to have" $ECHO "*** because the file extensions .$libext of this argument makes me believe" $ECHO "*** that it is just a static archive that I should not use here." else $ECHO $ECHO "*** Warning: Linking the shared library $output against the" $ECHO "*** static library $deplib is not portable!" deplibs="$deplib $deplibs" fi ;; esac continue ;; prog) if test "$pass" != link; then deplibs="$deplib $deplibs" else compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" fi continue ;; esac # linkmode ;; # *.$libext *.lo | *.$objext) if test "$pass" = conv; then deplibs="$deplib $deplibs" elif test "$linkmode" = prog; then if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then # If there is no dlopen support or we're linking statically, # we need to preload. newdlprefiles="$newdlprefiles $deplib" compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" else newdlfiles="$newdlfiles $deplib" fi fi continue ;; %DEPLIBS%) alldeplibs=yes continue ;; esac # case $deplib if test "$found" = yes || test -f "$lib"; then : else func_fatal_error "cannot find the library \`$lib' or unhandled argument \`$deplib'" fi # Check to see that this really is a libtool archive. func_lalib_unsafe_p "$lib" \ || func_fatal_error "\`$lib' is not a valid libtool archive" func_dirname "$lib" "" "." ladir="$func_dirname_result" dlname= dlopen= dlpreopen= libdir= library_names= old_library= inherited_linker_flags= # If the library was installed with an old release of libtool, # it will not redefine variables installed, or shouldnotlink installed=yes shouldnotlink=no avoidtemprpath= # Read the .la file func_source "$lib" # Convert "-framework foo" to "foo.ltframework" if test -n "$inherited_linker_flags"; then tmp_inherited_linker_flags=`$ECHO "X$inherited_linker_flags" | $Xsed -e 's/-framework \([^ $]*\)/\1.ltframework/g'` for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do case " $new_inherited_linker_flags " in *" $tmp_inherited_linker_flag "*) ;; *) new_inherited_linker_flags="$new_inherited_linker_flags $tmp_inherited_linker_flag";; esac done fi dependency_libs=`$ECHO "X $dependency_libs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` if test "$linkmode,$pass" = "lib,link" || test "$linkmode,$pass" = "prog,scan" || { test "$linkmode" != prog && test "$linkmode" != lib; }; then test -n "$dlopen" && dlfiles="$dlfiles $dlopen" test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen" fi if test "$pass" = conv; then # Only check for convenience libraries deplibs="$lib $deplibs" if test -z "$libdir"; then if test -z "$old_library"; then func_fatal_error "cannot find name of link library for \`$lib'" fi # It is a libtool convenience library, so add in its objects. convenience="$convenience $ladir/$objdir/$old_library" old_convenience="$old_convenience $ladir/$objdir/$old_library" tmp_libs= for deplib in $dependency_libs; do deplibs="$deplib $deplibs" if $opt_duplicate_deps ; then case "$tmp_libs " in *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; esac fi tmp_libs="$tmp_libs $deplib" done elif test "$linkmode" != prog && test "$linkmode" != lib; then func_fatal_error "\`$lib' is not a convenience library" fi continue fi # $pass = conv # Get the name of the library we link against. linklib= for l in $old_library $library_names; do linklib="$l" done if test -z "$linklib"; then func_fatal_error "cannot find name of link library for \`$lib'" fi # This library was specified with -dlopen. if test "$pass" = dlopen; then if test -z "$libdir"; then func_fatal_error "cannot -dlopen a convenience library: \`$lib'" fi if test -z "$dlname" || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then # If there is no dlname, no dlopen support or we're linking # statically, we need to preload. We also need to preload any # dependent libraries so libltdl's deplib preloader doesn't # bomb out in the load deplibs phase. dlprefiles="$dlprefiles $lib $dependency_libs" else newdlfiles="$newdlfiles $lib" fi continue fi # $pass = dlopen # We need an absolute path. case $ladir in [\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;; *) abs_ladir=`cd "$ladir" && pwd` if test -z "$abs_ladir"; then func_warning "cannot determine absolute directory name of \`$ladir'" func_warning "passing it literally to the linker, although it might fail" abs_ladir="$ladir" fi ;; esac func_basename "$lib" laname="$func_basename_result" # Find the relevant object directory and library name. if test "X$installed" = Xyes; then if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then func_warning "library \`$lib' was moved." dir="$ladir" absdir="$abs_ladir" libdir="$abs_ladir" else dir="$libdir" absdir="$libdir" fi test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes else if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then dir="$ladir" absdir="$abs_ladir" # Remove this search path later notinst_path="$notinst_path $abs_ladir" else dir="$ladir/$objdir" absdir="$abs_ladir/$objdir" # Remove this search path later notinst_path="$notinst_path $abs_ladir" fi fi # $installed = yes func_stripname 'lib' '.la' "$laname" name=$func_stripname_result # This library was specified with -dlpreopen. if test "$pass" = dlpreopen; then if test -z "$libdir" && test "$linkmode" = prog; then func_fatal_error "only libraries may -dlpreopen a convenience library: \`$lib'" fi # Prefer using a static library (so that no silly _DYNAMIC symbols # are required to link). if test -n "$old_library"; then newdlprefiles="$newdlprefiles $dir/$old_library" # Keep a list of preopened convenience libraries to check # that they are being used correctly in the link pass. test -z "$libdir" && \ dlpreconveniencelibs="$dlpreconveniencelibs $dir/$old_library" # Otherwise, use the dlname, so that lt_dlopen finds it. elif test -n "$dlname"; then newdlprefiles="$newdlprefiles $dir/$dlname" else newdlprefiles="$newdlprefiles $dir/$linklib" fi fi # $pass = dlpreopen if test -z "$libdir"; then # Link the convenience library if test "$linkmode" = lib; then deplibs="$dir/$old_library $deplibs" elif test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$dir/$old_library $compile_deplibs" finalize_deplibs="$dir/$old_library $finalize_deplibs" else deplibs="$lib $deplibs" # used for prog,scan pass fi continue fi if test "$linkmode" = prog && test "$pass" != link; then newlib_search_path="$newlib_search_path $ladir" deplibs="$lib $deplibs" linkalldeplibs=no if test "$link_all_deplibs" != no || test -z "$library_names" || test "$build_libtool_libs" = no; then linkalldeplibs=yes fi tmp_libs= for deplib in $dependency_libs; do case $deplib in -L*) func_stripname '-L' '' "$deplib" newlib_search_path="$newlib_search_path $func_stripname_result" ;; esac # Need to link against all dependency_libs? if test "$linkalldeplibs" = yes; then deplibs="$deplib $deplibs" else # Need to hardcode shared library paths # or/and link against static libraries newdependency_libs="$deplib $newdependency_libs" fi if $opt_duplicate_deps ; then case "$tmp_libs " in *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; esac fi tmp_libs="$tmp_libs $deplib" done # for deplib continue fi # $linkmode = prog... if test "$linkmode,$pass" = "prog,link"; then if test -n "$library_names" && { { test "$prefer_static_libs" = no || test "$prefer_static_libs,$installed" = "built,yes"; } || test -z "$old_library"; }; then # We need to hardcode the library path if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then # Make sure the rpath contains only unique directories. case "$temp_rpath:" in *"$absdir:"*) ;; *) temp_rpath="$temp_rpath$absdir:" ;; esac fi # Hardcode the library path. # Skip directories that are in the system default run-time # search path. case " $sys_lib_dlsearch_path " in *" $absdir "*) ;; *) case "$compile_rpath " in *" $absdir "*) ;; *) compile_rpath="$compile_rpath $absdir" esac ;; esac case " $sys_lib_dlsearch_path " in *" $libdir "*) ;; *) case "$finalize_rpath " in *" $libdir "*) ;; *) finalize_rpath="$finalize_rpath $libdir" esac ;; esac fi # $linkmode,$pass = prog,link... if test "$alldeplibs" = yes && { test "$deplibs_check_method" = pass_all || { test "$build_libtool_libs" = yes && test -n "$library_names"; }; }; then # We only need to search for static libraries continue fi fi link_static=no # Whether the deplib will be linked statically use_static_libs=$prefer_static_libs if test "$use_static_libs" = built && test "$installed" = yes; then use_static_libs=no fi if test -n "$library_names" && { test "$use_static_libs" = no || test -z "$old_library"; }; then case $host in *cygwin* | *mingw* | *cegcc*) # No point in relinking DLLs because paths are not encoded notinst_deplibs="$notinst_deplibs $lib" need_relink=no ;; *) if test "$installed" = no; then notinst_deplibs="$notinst_deplibs $lib" need_relink=yes fi ;; esac # This is a shared library # Warn about portability, can't link against -module's on some # systems (darwin). Don't bleat about dlopened modules though! dlopenmodule="" for dlpremoduletest in $dlprefiles; do if test "X$dlpremoduletest" = "X$lib"; then dlopenmodule="$dlpremoduletest" break fi done if test -z "$dlopenmodule" && test "$shouldnotlink" = yes && test "$pass" = link; then $ECHO if test "$linkmode" = prog; then $ECHO "*** Warning: Linking the executable $output against the loadable module" else $ECHO "*** Warning: Linking the shared library $output against the loadable module" fi $ECHO "*** $linklib is not portable!" fi if test "$linkmode" = lib && test "$hardcode_into_libs" = yes; then # Hardcode the library path. # Skip directories that are in the system default run-time # search path. case " $sys_lib_dlsearch_path " in *" $absdir "*) ;; *) case "$compile_rpath " in *" $absdir "*) ;; *) compile_rpath="$compile_rpath $absdir" esac ;; esac case " $sys_lib_dlsearch_path " in *" $libdir "*) ;; *) case "$finalize_rpath " in *" $libdir "*) ;; *) finalize_rpath="$finalize_rpath $libdir" esac ;; esac fi if test -n "$old_archive_from_expsyms_cmds"; then # figure out the soname set dummy $library_names shift realname="$1" shift libname=`eval "\\$ECHO \"$libname_spec\""` # use dlname if we got it. it's perfectly good, no? if test -n "$dlname"; then soname="$dlname" elif test -n "$soname_spec"; then # bleh windows case $host in *cygwin* | mingw* | *cegcc*) func_arith $current - $age major=$func_arith_result versuffix="-$major" ;; esac eval soname=\"$soname_spec\" else soname="$realname" fi # Make a new name for the extract_expsyms_cmds to use soroot="$soname" func_basename "$soroot" soname="$func_basename_result" func_stripname 'lib' '.dll' "$soname" newlib=libimp-$func_stripname_result.a # If the library has no export list, then create one now if test -f "$output_objdir/$soname-def"; then : else func_verbose "extracting exported symbol list from \`$soname'" func_execute_cmds "$extract_expsyms_cmds" 'exit $?' fi # Create $newlib if test -f "$output_objdir/$newlib"; then :; else func_verbose "generating import library for \`$soname'" func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?' fi # make sure the library variables are pointing to the new library dir=$output_objdir linklib=$newlib fi # test -n "$old_archive_from_expsyms_cmds" if test "$linkmode" = prog || test "$mode" != relink; then add_shlibpath= add_dir= add= lib_linked=yes case $hardcode_action in immediate | unsupported) if test "$hardcode_direct" = no; then add="$dir/$linklib" case $host in *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;; *-*-sysv4*uw2*) add_dir="-L$dir" ;; *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \ *-*-unixware7*) add_dir="-L$dir" ;; *-*-darwin* ) # if the lib is a (non-dlopened) module then we can not # link against it, someone is ignoring the earlier warnings if /usr/bin/file -L $add 2> /dev/null | $GREP ": [^:]* bundle" >/dev/null ; then if test "X$dlopenmodule" != "X$lib"; then $ECHO "*** Warning: lib $linklib is a module, not a shared library" if test -z "$old_library" ; then $ECHO $ECHO "*** And there doesn't seem to be a static archive available" $ECHO "*** The link will probably fail, sorry" else add="$dir/$old_library" fi elif test -n "$old_library"; then add="$dir/$old_library" fi fi esac elif test "$hardcode_minus_L" = no; then case $host in *-*-sunos*) add_shlibpath="$dir" ;; esac add_dir="-L$dir" add="-l$name" elif test "$hardcode_shlibpath_var" = no; then add_shlibpath="$dir" add="-l$name" else lib_linked=no fi ;; relink) if test "$hardcode_direct" = yes && test "$hardcode_direct_absolute" = no; then add="$dir/$linklib" elif test "$hardcode_minus_L" = yes; then add_dir="-L$dir" # Try looking first in the location we're being installed to. if test -n "$inst_prefix_dir"; then case $libdir in [\\/]*) add_dir="$add_dir -L$inst_prefix_dir$libdir" ;; esac fi add="-l$name" elif test "$hardcode_shlibpath_var" = yes; then add_shlibpath="$dir" add="-l$name" else lib_linked=no fi ;; *) lib_linked=no ;; esac if test "$lib_linked" != yes; then func_fatal_configuration "unsupported hardcode properties" fi if test -n "$add_shlibpath"; then case :$compile_shlibpath: in *":$add_shlibpath:"*) ;; *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;; esac fi if test "$linkmode" = prog; then test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs" test -n "$add" && compile_deplibs="$add $compile_deplibs" else test -n "$add_dir" && deplibs="$add_dir $deplibs" test -n "$add" && deplibs="$add $deplibs" if test "$hardcode_direct" != yes && test "$hardcode_minus_L" != yes && test "$hardcode_shlibpath_var" = yes; then case :$finalize_shlibpath: in *":$libdir:"*) ;; *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; esac fi fi fi if test "$linkmode" = prog || test "$mode" = relink; then add_shlibpath= add_dir= add= # Finalize command for both is simple: just hardcode it. if test "$hardcode_direct" = yes && test "$hardcode_direct_absolute" = no; then add="$libdir/$linklib" elif test "$hardcode_minus_L" = yes; then add_dir="-L$libdir" add="-l$name" elif test "$hardcode_shlibpath_var" = yes; then case :$finalize_shlibpath: in *":$libdir:"*) ;; *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; esac add="-l$name" elif test "$hardcode_automatic" = yes; then if test -n "$inst_prefix_dir" && test -f "$inst_prefix_dir$libdir/$linklib" ; then add="$inst_prefix_dir$libdir/$linklib" else add="$libdir/$linklib" fi else # We cannot seem to hardcode it, guess we'll fake it. add_dir="-L$libdir" # Try looking first in the location we're being installed to. if test -n "$inst_prefix_dir"; then case $libdir in [\\/]*) add_dir="$add_dir -L$inst_prefix_dir$libdir" ;; esac fi add="-l$name" fi if test "$linkmode" = prog; then test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs" test -n "$add" && finalize_deplibs="$add $finalize_deplibs" else test -n "$add_dir" && deplibs="$add_dir $deplibs" test -n "$add" && deplibs="$add $deplibs" fi fi elif test "$linkmode" = prog; then # Here we assume that one of hardcode_direct or hardcode_minus_L # is not unsupported. This is valid on all known static and # shared platforms. if test "$hardcode_direct" != unsupported; then test -n "$old_library" && linklib="$old_library" compile_deplibs="$dir/$linklib $compile_deplibs" finalize_deplibs="$dir/$linklib $finalize_deplibs" else compile_deplibs="-l$name -L$dir $compile_deplibs" finalize_deplibs="-l$name -L$dir $finalize_deplibs" fi elif test "$build_libtool_libs" = yes; then # Not a shared library if test "$deplibs_check_method" != pass_all; then # We're trying link a shared library against a static one # but the system doesn't support it. # Just print a warning and add the library to dependency_libs so # that the program can be linked against the static library. $ECHO $ECHO "*** Warning: This system can not link to static lib archive $lib." $ECHO "*** I have the capability to make that library automatically link in when" $ECHO "*** you link to this library. But I can only do this if you have a" $ECHO "*** shared version of the library, which you do not appear to have." if test "$module" = yes; then $ECHO "*** But as you try to build a module library, libtool will still create " $ECHO "*** a static module, that should work as long as the dlopening application" $ECHO "*** is linked with the -dlopen flag to resolve symbols at runtime." if test -z "$global_symbol_pipe"; then $ECHO $ECHO "*** However, this would only work if libtool was able to extract symbol" $ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could" $ECHO "*** not find such a program. So, this module is probably useless." $ECHO "*** \`nm' from GNU binutils and a full rebuild may help." fi if test "$build_old_libs" = no; then build_libtool_libs=module build_old_libs=yes else build_libtool_libs=no fi fi else deplibs="$dir/$old_library $deplibs" link_static=yes fi fi # link shared/static library? if test "$linkmode" = lib; then if test -n "$dependency_libs" && { test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes || test "$link_static" = yes; }; then # Extract -R from dependency_libs temp_deplibs= for libdir in $dependency_libs; do case $libdir in -R*) func_stripname '-R' '' "$libdir" temp_xrpath=$func_stripname_result case " $xrpath " in *" $temp_xrpath "*) ;; *) xrpath="$xrpath $temp_xrpath";; esac;; *) temp_deplibs="$temp_deplibs $libdir";; esac done dependency_libs="$temp_deplibs" fi newlib_search_path="$newlib_search_path $absdir" # Link against this library test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs" # ... and its dependency_libs tmp_libs= for deplib in $dependency_libs; do newdependency_libs="$deplib $newdependency_libs" if $opt_duplicate_deps ; then case "$tmp_libs " in *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; esac fi tmp_libs="$tmp_libs $deplib" done if test "$link_all_deplibs" != no; then # Add the search paths of all dependency libraries for deplib in $dependency_libs; do path= case $deplib in -L*) path="$deplib" ;; *.la) func_dirname "$deplib" "" "." dir="$func_dirname_result" # We need an absolute path. case $dir in [\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;; *) absdir=`cd "$dir" && pwd` if test -z "$absdir"; then func_warning "cannot determine absolute directory name of \`$dir'" absdir="$dir" fi ;; esac if $GREP "^installed=no" $deplib > /dev/null; then case $host in *-*-darwin*) depdepl= eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` if test -n "$deplibrary_names" ; then for tmp in $deplibrary_names ; do depdepl=$tmp done if test -f "$absdir/$objdir/$depdepl" ; then depdepl="$absdir/$objdir/$depdepl" darwin_install_name=`${OTOOL} -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'` if test -z "$darwin_install_name"; then darwin_install_name=`${OTOOL64} -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'` fi compiler_flags="$compiler_flags ${wl}-dylib_file ${wl}${darwin_install_name}:${depdepl}" linker_flags="$linker_flags -dylib_file ${darwin_install_name}:${depdepl}" path= fi fi ;; *) path="-L$absdir/$objdir" ;; esac else eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` test -z "$libdir" && \ func_fatal_error "\`$deplib' is not a valid libtool archive" test "$absdir" != "$libdir" && \ func_warning "\`$deplib' seems to be moved" path="-L$absdir" fi ;; esac case " $deplibs " in *" $path "*) ;; *) deplibs="$path $deplibs" ;; esac done fi # link_all_deplibs != no fi # linkmode = lib done # for deplib in $libs if test "$pass" = link; then if test "$linkmode" = "prog"; then compile_deplibs="$new_inherited_linker_flags $compile_deplibs" finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs" else compiler_flags="$compiler_flags "`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` fi fi dependency_libs="$newdependency_libs" if test "$pass" = dlpreopen; then # Link the dlpreopened libraries before other libraries for deplib in $save_deplibs; do deplibs="$deplib $deplibs" done fi if test "$pass" != dlopen; then if test "$pass" != conv; then # Make sure lib_search_path contains only unique directories. lib_search_path= for dir in $newlib_search_path; do case "$lib_search_path " in *" $dir "*) ;; *) lib_search_path="$lib_search_path $dir" ;; esac done newlib_search_path= fi if test "$linkmode,$pass" != "prog,link"; then vars="deplibs" else vars="compile_deplibs finalize_deplibs" fi for var in $vars dependency_libs; do # Add libraries to $var in reverse order eval tmp_libs=\"\$$var\" new_libs= for deplib in $tmp_libs; do # FIXME: Pedantically, this is the right thing to do, so # that some nasty dependency loop isn't accidentally # broken: #new_libs="$deplib $new_libs" # Pragmatically, this seems to cause very few problems in # practice: case $deplib in -L*) new_libs="$deplib $new_libs" ;; -R*) ;; *) # And here is the reason: when a library appears more # than once as an explicit dependence of a library, or # is implicitly linked in more than once by the # compiler, it is considered special, and multiple # occurrences thereof are not removed. Compare this # with having the same library being listed as a # dependency of multiple other libraries: in this case, # we know (pedantically, we assume) the library does not # need to be listed more than once, so we keep only the # last copy. This is not always right, but it is rare # enough that we require users that really mean to play # such unportable linking tricks to link the library # using -Wl,-lname, so that libtool does not consider it # for duplicate removal. case " $specialdeplibs " in *" $deplib "*) new_libs="$deplib $new_libs" ;; *) case " $new_libs " in *" $deplib "*) ;; *) new_libs="$deplib $new_libs" ;; esac ;; esac ;; esac done tmp_libs= for deplib in $new_libs; do case $deplib in -L*) case " $tmp_libs " in *" $deplib "*) ;; *) tmp_libs="$tmp_libs $deplib" ;; esac ;; *) tmp_libs="$tmp_libs $deplib" ;; esac done eval $var=\"$tmp_libs\" done # for var fi # Last step: remove runtime libs from dependency_libs # (they stay in deplibs) tmp_libs= for i in $dependency_libs ; do case " $predeps $postdeps $compiler_lib_search_path " in *" $i "*) i="" ;; esac if test -n "$i" ; then tmp_libs="$tmp_libs $i" fi done dependency_libs=$tmp_libs done # for pass if test "$linkmode" = prog; then dlfiles="$newdlfiles" fi if test "$linkmode" = prog || test "$linkmode" = lib; then dlprefiles="$newdlprefiles" fi case $linkmode in oldlib) if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then func_warning "\`-dlopen' is ignored for archives" fi case " $deplibs" in *\ -l* | *\ -L*) func_warning "\`-l' and \`-L' are ignored for archives" ;; esac test -n "$rpath" && \ func_warning "\`-rpath' is ignored for archives" test -n "$xrpath" && \ func_warning "\`-R' is ignored for archives" test -n "$vinfo" && \ func_warning "\`-version-info/-version-number' is ignored for archives" test -n "$release" && \ func_warning "\`-release' is ignored for archives" test -n "$export_symbols$export_symbols_regex" && \ func_warning "\`-export-symbols' is ignored for archives" # Now set the variables for building old libraries. build_libtool_libs=no oldlibs="$output" objs="$objs$old_deplibs" ;; lib) # Make sure we only generate libraries of the form `libNAME.la'. case $outputname in lib*) func_stripname 'lib' '.la' "$outputname" name=$func_stripname_result eval shared_ext=\"$shrext_cmds\" eval libname=\"$libname_spec\" ;; *) test "$module" = no && \ func_fatal_help "libtool library \`$output' must begin with \`lib'" if test "$need_lib_prefix" != no; then # Add the "lib" prefix for modules if required func_stripname '' '.la' "$outputname" name=$func_stripname_result eval shared_ext=\"$shrext_cmds\" eval libname=\"$libname_spec\" else func_stripname '' '.la' "$outputname" libname=$func_stripname_result fi ;; esac if test -n "$objs"; then if test "$deplibs_check_method" != pass_all; then func_fatal_error "cannot build libtool library \`$output' from non-libtool objects on this host:$objs" else $ECHO $ECHO "*** Warning: Linking the shared library $output against the non-libtool" $ECHO "*** objects $objs is not portable!" libobjs="$libobjs $objs" fi fi test "$dlself" != no && \ func_warning "\`-dlopen self' is ignored for libtool libraries" set dummy $rpath shift test "$#" -gt 1 && \ func_warning "ignoring multiple \`-rpath's for a libtool library" install_libdir="$1" oldlibs= if test -z "$rpath"; then if test "$build_libtool_libs" = yes; then # Building a libtool convenience library. # Some compilers have problems with a `.al' extension so # convenience libraries should have the same extension an # archive normally would. oldlibs="$output_objdir/$libname.$libext $oldlibs" build_libtool_libs=convenience build_old_libs=yes fi test -n "$vinfo" && \ func_warning "\`-version-info/-version-number' is ignored for convenience libraries" test -n "$release" && \ func_warning "\`-release' is ignored for convenience libraries" else # Parse the version information argument. save_ifs="$IFS"; IFS=':' set dummy $vinfo 0 0 0 shift IFS="$save_ifs" test -n "$7" && \ func_fatal_help "too many parameters to \`-version-info'" # convert absolute version numbers to libtool ages # this retains compatibility with .la files and attempts # to make the code below a bit more comprehensible case $vinfo_number in yes) number_major="$1" number_minor="$2" number_revision="$3" # # There are really only two kinds -- those that # use the current revision as the major version # and those that subtract age and use age as # a minor version. But, then there is irix # which has an extra 1 added just for fun # case $version_type in darwin|linux|osf|windows|none) func_arith $number_major + $number_minor current=$func_arith_result age="$number_minor" revision="$number_revision" ;; freebsd-aout|freebsd-elf|sunos) current="$number_major" revision="$number_minor" age="0" ;; irix|nonstopux) func_arith $number_major + $number_minor current=$func_arith_result age="$number_minor" revision="$number_minor" lt_irix_increment=no ;; *) func_fatal_configuration "$modename: unknown library version type \`$version_type'" ;; esac ;; no) current="$1" revision="$2" age="$3" ;; esac # Check that each of the things are valid numbers. case $current in 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; *) func_error "CURRENT \`$current' must be a nonnegative integer" func_fatal_error "\`$vinfo' is not valid version information" ;; esac case $revision in 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; *) func_error "REVISION \`$revision' must be a nonnegative integer" func_fatal_error "\`$vinfo' is not valid version information" ;; esac case $age in 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; *) func_error "AGE \`$age' must be a nonnegative integer" func_fatal_error "\`$vinfo' is not valid version information" ;; esac if test "$age" -gt "$current"; then func_error "AGE \`$age' is greater than the current interface number \`$current'" func_fatal_error "\`$vinfo' is not valid version information" fi # Calculate the version variables. major= versuffix= verstring= case $version_type in none) ;; darwin) # Like Linux, but with the current version available in # verstring for coding it into the library header func_arith $current - $age major=.$func_arith_result versuffix="$major.$age.$revision" # Darwin ld doesn't like 0 for these options... func_arith $current + 1 minor_current=$func_arith_result xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" ;; freebsd-aout) major=".$current" versuffix=".$current.$revision"; ;; freebsd-elf) major=".$current" versuffix=".$current" ;; irix | nonstopux) if test "X$lt_irix_increment" = "Xno"; then func_arith $current - $age else func_arith $current - $age + 1 fi major=$func_arith_result case $version_type in nonstopux) verstring_prefix=nonstopux ;; *) verstring_prefix=sgi ;; esac verstring="$verstring_prefix$major.$revision" # Add in all the interfaces that we are compatible with. loop=$revision while test "$loop" -ne 0; do func_arith $revision - $loop iface=$func_arith_result func_arith $loop - 1 loop=$func_arith_result verstring="$verstring_prefix$major.$iface:$verstring" done # Before this point, $major must not contain `.'. major=.$major versuffix="$major.$revision" ;; linux) func_arith $current - $age major=.$func_arith_result versuffix="$major.$age.$revision" ;; osf) func_arith $current - $age major=.$func_arith_result versuffix=".$current.$age.$revision" verstring="$current.$age.$revision" # Add in all the interfaces that we are compatible with. loop=$age while test "$loop" -ne 0; do func_arith $current - $loop iface=$func_arith_result func_arith $loop - 1 loop=$func_arith_result verstring="$verstring:${iface}.0" done # Make executables depend on our current version. verstring="$verstring:${current}.0" ;; qnx) major=".$current" versuffix=".$current" ;; sunos) major=".$current" versuffix=".$current.$revision" ;; windows) # Use '-' rather than '.', since we only want one # extension on DOS 8.3 filesystems. func_arith $current - $age major=$func_arith_result versuffix="-$major" ;; *) func_fatal_configuration "unknown library version type \`$version_type'" ;; esac # Clear the version info if we defaulted, and they specified a release. if test -z "$vinfo" && test -n "$release"; then major= case $version_type in darwin) # we can't check for "0.0" in archive_cmds due to quoting # problems, so we reset it completely verstring= ;; *) verstring="0.0" ;; esac if test "$need_version" = no; then versuffix= else versuffix=".0.0" fi fi # Remove version info from name if versioning should be avoided if test "$avoid_version" = yes && test "$need_version" = no; then major= versuffix= verstring="" fi # Check to see if the archive will have undefined symbols. if test "$allow_undefined" = yes; then if test "$allow_undefined_flag" = unsupported; then func_warning "undefined symbols not allowed in $host shared libraries" build_libtool_libs=no build_old_libs=yes fi else # Don't allow undefined symbols. allow_undefined_flag="$no_undefined_flag" fi fi func_generate_dlsyms "$libname" "$libname" "yes" libobjs="$libobjs $symfileobj" test "X$libobjs" = "X " && libobjs= if test "$mode" != relink; then # Remove our outputs, but don't remove object files since they # may have been created when compiling PIC objects. removelist= tempremovelist=`$ECHO "$output_objdir/*"` for p in $tempremovelist; do case $p in *.$objext | *.gcno) ;; $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*) if test "X$precious_files_regex" != "X"; then if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1 then continue fi fi removelist="$removelist $p" ;; *) ;; esac done test -n "$removelist" && \ func_show_eval "${RM}r \$removelist" fi # Now set the variables for building old libraries. if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then oldlibs="$oldlibs $output_objdir/$libname.$libext" # Transform .lo files to .o files. oldobjs="$objs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP` fi # Eliminate all temporary directories. #for path in $notinst_path; do # lib_search_path=`$ECHO "X$lib_search_path " | $Xsed -e "s% $path % %g"` # deplibs=`$ECHO "X$deplibs " | $Xsed -e "s% -L$path % %g"` # dependency_libs=`$ECHO "X$dependency_libs " | $Xsed -e "s% -L$path % %g"` #done if test -n "$xrpath"; then # If the user specified any rpath flags, then add them. temp_xrpath= for libdir in $xrpath; do temp_xrpath="$temp_xrpath -R$libdir" case "$finalize_rpath " in *" $libdir "*) ;; *) finalize_rpath="$finalize_rpath $libdir" ;; esac done if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then dependency_libs="$temp_xrpath $dependency_libs" fi fi # Make sure dlfiles contains only unique files that won't be dlpreopened old_dlfiles="$dlfiles" dlfiles= for lib in $old_dlfiles; do case " $dlprefiles $dlfiles " in *" $lib "*) ;; *) dlfiles="$dlfiles $lib" ;; esac done # Make sure dlprefiles contains only unique files old_dlprefiles="$dlprefiles" dlprefiles= for lib in $old_dlprefiles; do case "$dlprefiles " in *" $lib "*) ;; *) dlprefiles="$dlprefiles $lib" ;; esac done if test "$build_libtool_libs" = yes; then if test -n "$rpath"; then case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc*) # these systems don't actually have a c library (as such)! ;; *-*-rhapsody* | *-*-darwin1.[012]) # Rhapsody C library is in the System framework deplibs="$deplibs System.ltframework" ;; *-*-netbsd*) # Don't link with libc until the a.out ld.so is fixed. ;; *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) # Do not include libc due to us having libc/libc_r. ;; *-*-sco3.2v5* | *-*-sco5v6*) # Causes problems with __ctype ;; *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) # Compiler inserts libc in the correct place for threads to work ;; *) # Add libc to deplibs on all other systems if necessary. if test "$build_libtool_need_lc" = "yes"; then deplibs="$deplibs -lc" fi ;; esac fi # Transform deplibs into only deplibs that can be linked in shared. name_save=$name libname_save=$libname release_save=$release versuffix_save=$versuffix major_save=$major # I'm not sure if I'm treating the release correctly. I think # release should show up in the -l (ie -lgmp5) so we don't want to # add it in twice. Is that correct? release="" versuffix="" major="" newdeplibs= droppeddeps=no case $deplibs_check_method in pass_all) # Don't check for shared/static. Everything works. # This might be a little naive. We might want to check # whether the library exists or not. But this is on # osf3 & osf4 and I'm not really sure... Just # implementing what was already the behavior. newdeplibs=$deplibs ;; test_compile) # This code stresses the "libraries are programs" paradigm to its # limits. Maybe even breaks it. We compile a program, linking it # against the deplibs as a proxy for the library. Then we can check # whether they linked in statically or dynamically with ldd. $opt_dry_run || $RM conftest.c cat > conftest.c </dev/null` for potent_lib in $potential_libs; do # Follow soft links. if ls -lLd "$potent_lib" 2>/dev/null | $GREP " -> " >/dev/null; then continue fi # The statement above tries to avoid entering an # endless loop below, in case of cyclic links. # We might still enter an endless loop, since a link # loop can be closed while we follow links, # but so what? potlib="$potent_lib" while test -h "$potlib" 2>/dev/null; do potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'` case $potliblink in [\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";; *) potlib=`$ECHO "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";; esac done if eval $file_magic_cmd \"\$potlib\" 2>/dev/null | $SED -e 10q | $EGREP "$file_magic_regex" > /dev/null; then newdeplibs="$newdeplibs $a_deplib" a_deplib="" break 2 fi done done fi if test -n "$a_deplib" ; then droppeddeps=yes $ECHO $ECHO "*** Warning: linker path does not have real file for library $a_deplib." $ECHO "*** I have the capability to make that library automatically link in when" $ECHO "*** you link to this library. But I can only do this if you have a" $ECHO "*** shared version of the library, which you do not appear to have" $ECHO "*** because I did check the linker path looking for a file starting" if test -z "$potlib" ; then $ECHO "*** with $libname but no candidates were found. (...for file magic test)" else $ECHO "*** with $libname and none of the candidates passed a file format test" $ECHO "*** using a file magic. Last file checked: $potlib" fi fi ;; *) # Add a -L argument. newdeplibs="$newdeplibs $a_deplib" ;; esac done # Gone through all deplibs. ;; match_pattern*) set dummy $deplibs_check_method; shift match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"` for a_deplib in $deplibs; do case $a_deplib in -l*) func_stripname -l '' "$a_deplib" name=$func_stripname_result if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then case " $predeps $postdeps " in *" $a_deplib "*) newdeplibs="$newdeplibs $a_deplib" a_deplib="" ;; esac fi if test -n "$a_deplib" ; then libname=`eval "\\$ECHO \"$libname_spec\""` for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do potential_libs=`ls $i/$libname[.-]* 2>/dev/null` for potent_lib in $potential_libs; do potlib="$potent_lib" # see symlink-check above in file_magic test if eval "\$ECHO \"X$potent_lib\"" 2>/dev/null | $Xsed -e 10q | \ $EGREP "$match_pattern_regex" > /dev/null; then newdeplibs="$newdeplibs $a_deplib" a_deplib="" break 2 fi done done fi if test -n "$a_deplib" ; then droppeddeps=yes $ECHO $ECHO "*** Warning: linker path does not have real file for library $a_deplib." $ECHO "*** I have the capability to make that library automatically link in when" $ECHO "*** you link to this library. But I can only do this if you have a" $ECHO "*** shared version of the library, which you do not appear to have" $ECHO "*** because I did check the linker path looking for a file starting" if test -z "$potlib" ; then $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)" else $ECHO "*** with $libname and none of the candidates passed a file format test" $ECHO "*** using a regex pattern. Last file checked: $potlib" fi fi ;; *) # Add a -L argument. newdeplibs="$newdeplibs $a_deplib" ;; esac done # Gone through all deplibs. ;; none | unknown | *) newdeplibs="" tmp_deplibs=`$ECHO "X $deplibs" | $Xsed \ -e 's/ -lc$//' -e 's/ -[LR][^ ]*//g'` if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then for i in $predeps $postdeps ; do # can't use Xsed below, because $i might contain '/' tmp_deplibs=`$ECHO "X $tmp_deplibs" | $Xsed -e "s,$i,,"` done fi if $ECHO "X $tmp_deplibs" | $Xsed -e 's/[ ]//g' | $GREP . >/dev/null; then $ECHO if test "X$deplibs_check_method" = "Xnone"; then $ECHO "*** Warning: inter-library dependencies are not supported in this platform." else $ECHO "*** Warning: inter-library dependencies are not known to be supported." fi $ECHO "*** All declared inter-library dependencies are being dropped." droppeddeps=yes fi ;; esac versuffix=$versuffix_save major=$major_save release=$release_save libname=$libname_save name=$name_save case $host in *-*-rhapsody* | *-*-darwin1.[012]) # On Rhapsody replace the C library with the System framework newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's/ -lc / System.ltframework /'` ;; esac if test "$droppeddeps" = yes; then if test "$module" = yes; then $ECHO $ECHO "*** Warning: libtool could not satisfy all declared inter-library" $ECHO "*** dependencies of module $libname. Therefore, libtool will create" $ECHO "*** a static module, that should work as long as the dlopening" $ECHO "*** application is linked with the -dlopen flag." if test -z "$global_symbol_pipe"; then $ECHO $ECHO "*** However, this would only work if libtool was able to extract symbol" $ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could" $ECHO "*** not find such a program. So, this module is probably useless." $ECHO "*** \`nm' from GNU binutils and a full rebuild may help." fi if test "$build_old_libs" = no; then oldlibs="$output_objdir/$libname.$libext" build_libtool_libs=module build_old_libs=yes else build_libtool_libs=no fi else $ECHO "*** The inter-library dependencies that have been dropped here will be" $ECHO "*** automatically added whenever a program is linked with this library" $ECHO "*** or is declared to -dlopen it." if test "$allow_undefined" = no; then $ECHO $ECHO "*** Since this library must not contain undefined symbols," $ECHO "*** because either the platform does not support them or" $ECHO "*** it was explicitly requested with -no-undefined," $ECHO "*** libtool will only create a static version of it." if test "$build_old_libs" = no; then oldlibs="$output_objdir/$libname.$libext" build_libtool_libs=module build_old_libs=yes else build_libtool_libs=no fi fi fi fi # Done checking deplibs! deplibs=$newdeplibs fi # Time to change all our "foo.ltframework" stuff back to "-framework foo" case $host in *-*-darwin*) newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` new_inherited_linker_flags=`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` deplibs=`$ECHO "X $deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` ;; esac # move library search paths that coincide with paths to not yet # installed libraries to the beginning of the library search list new_libs= for path in $notinst_path; do case " $new_libs " in *" -L$path/$objdir "*) ;; *) case " $deplibs " in *" -L$path/$objdir "*) new_libs="$new_libs -L$path/$objdir" ;; esac ;; esac done for deplib in $deplibs; do case $deplib in -L*) case " $new_libs " in *" $deplib "*) ;; *) new_libs="$new_libs $deplib" ;; esac ;; *) new_libs="$new_libs $deplib" ;; esac done deplibs="$new_libs" # All the library-specific variables (install_libdir is set above). library_names= old_library= dlname= # Test again, we may have decided not to build it any more if test "$build_libtool_libs" = yes; then if test "$hardcode_into_libs" = yes; then # Hardcode the library paths hardcode_libdirs= dep_rpath= rpath="$finalize_rpath" test "$mode" != relink && rpath="$compile_rpath$rpath" for libdir in $rpath; do if test -n "$hardcode_libdir_flag_spec"; then if test -n "$hardcode_libdir_separator"; then if test -z "$hardcode_libdirs"; then hardcode_libdirs="$libdir" else # Just accumulate the unique libdirs. case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) ;; *) hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" ;; esac fi else eval flag=\"$hardcode_libdir_flag_spec\" dep_rpath="$dep_rpath $flag" fi elif test -n "$runpath_var"; then case "$perm_rpath " in *" $libdir "*) ;; *) perm_rpath="$perm_rpath $libdir" ;; esac fi done # Substitute the hardcoded libdirs into the rpath. if test -n "$hardcode_libdir_separator" && test -n "$hardcode_libdirs"; then libdir="$hardcode_libdirs" if test -n "$hardcode_libdir_flag_spec_ld"; then eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" else eval dep_rpath=\"$hardcode_libdir_flag_spec\" fi fi if test -n "$runpath_var" && test -n "$perm_rpath"; then # We should set the runpath_var. rpath= for dir in $perm_rpath; do rpath="$rpath$dir:" done eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var" fi test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs" fi shlibpath="$finalize_shlibpath" test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath" if test -n "$shlibpath"; then eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var" fi # Get the real and link names of the library. eval shared_ext=\"$shrext_cmds\" eval library_names=\"$library_names_spec\" set dummy $library_names shift realname="$1" shift if test -n "$soname_spec"; then eval soname=\"$soname_spec\" else soname="$realname" fi if test -z "$dlname"; then dlname=$soname fi lib="$output_objdir/$realname" linknames= for link do linknames="$linknames $link" done # Use standard objects if they are pic test -z "$pic_flag" && libobjs=`$ECHO "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` test "X$libobjs" = "X " && libobjs= delfiles= if test -n "$export_symbols" && test -n "$include_expsyms"; then $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp" export_symbols="$output_objdir/$libname.uexp" delfiles="$delfiles $export_symbols" fi orig_export_symbols= case $host_os in cygwin* | mingw* | cegcc*) if test -n "$export_symbols" && test -z "$export_symbols_regex"; then # exporting using user supplied symfile if test "x`$SED 1q $export_symbols`" != xEXPORTS; then # and it's NOT already a .def file. Must figure out # which of the given symbols are data symbols and tag # them as such. So, trigger use of export_symbols_cmds. # export_symbols gets reassigned inside the "prepare # the list of exported symbols" if statement, so the # include_expsyms logic still works. orig_export_symbols="$export_symbols" export_symbols= always_export_symbols=yes fi fi ;; esac # Prepare the list of exported symbols if test -z "$export_symbols"; then if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then func_verbose "generating symbol list for \`$libname.la'" export_symbols="$output_objdir/$libname.exp" $opt_dry_run || $RM $export_symbols cmds=$export_symbols_cmds save_ifs="$IFS"; IFS='~' for cmd in $cmds; do IFS="$save_ifs" eval cmd=\"$cmd\" func_len " $cmd" len=$func_len_result if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then func_show_eval "$cmd" 'exit $?' skipped_export=false else # The command line is too long to execute in one step. func_verbose "using reloadable object file for export list..." skipped_export=: # Break out early, otherwise skipped_export may be # set to false by a later but shorter cmd. break fi done IFS="$save_ifs" if test -n "$export_symbols_regex" && test "X$skipped_export" != "X:"; then func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' func_show_eval '$MV "${export_symbols}T" "$export_symbols"' fi fi fi if test -n "$export_symbols" && test -n "$include_expsyms"; then tmp_export_symbols="$export_symbols" test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols" $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"' fi if test "X$skipped_export" != "X:" && test -n "$orig_export_symbols"; then # The given exports_symbols file has to be filtered, so filter it. func_verbose "filter symbol list for \`$libname.la' to tag DATA exports" # FIXME: $output_objdir/$libname.filter potentially contains lots of # 's' commands which not all seds can handle. GNU sed should be fine # though. Also, the filter scales superlinearly with the number of # global variables. join(1) would be nice here, but unfortunately # isn't a blessed tool. $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter delfiles="$delfiles $export_symbols $output_objdir/$libname.filter" export_symbols=$output_objdir/$libname.def $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols fi tmp_deplibs= for test_deplib in $deplibs; do case " $convenience " in *" $test_deplib "*) ;; *) tmp_deplibs="$tmp_deplibs $test_deplib" ;; esac done deplibs="$tmp_deplibs" if test -n "$convenience"; then if test -n "$whole_archive_flag_spec" && test "$compiler_needs_object" = yes && test -z "$libobjs"; then # extract the archives, so we have objects to list. # TODO: could optimize this to just extract one archive. whole_archive_flag_spec= fi if test -n "$whole_archive_flag_spec"; then save_libobjs=$libobjs eval libobjs=\"\$libobjs $whole_archive_flag_spec\" test "X$libobjs" = "X " && libobjs= else gentop="$output_objdir/${outputname}x" generated="$generated $gentop" func_extract_archives $gentop $convenience libobjs="$libobjs $func_extract_archives_result" test "X$libobjs" = "X " && libobjs= fi fi if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then eval flag=\"$thread_safe_flag_spec\" linker_flags="$linker_flags $flag" fi # Make a backup of the uninstalled library when relinking if test "$mode" = relink; then $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $? fi # Do each of the archive commands. if test "$module" = yes && test -n "$module_cmds" ; then if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then eval test_cmds=\"$module_expsym_cmds\" cmds=$module_expsym_cmds else eval test_cmds=\"$module_cmds\" cmds=$module_cmds fi else if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then eval test_cmds=\"$archive_expsym_cmds\" cmds=$archive_expsym_cmds else eval test_cmds=\"$archive_cmds\" cmds=$archive_cmds fi fi if test "X$skipped_export" != "X:" && func_len " $test_cmds" && len=$func_len_result && test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then : else # The command line is too long to link in one step, link piecewise # or, if using GNU ld and skipped_export is not :, use a linker # script. # Save the value of $output and $libobjs because we want to # use them later. If we have whole_archive_flag_spec, we # want to use save_libobjs as it was before # whole_archive_flag_spec was expanded, because we can't # assume the linker understands whole_archive_flag_spec. # This may have to be revisited, in case too many # convenience libraries get linked in and end up exceeding # the spec. if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then save_libobjs=$libobjs fi save_output=$output output_la=`$ECHO "X$output" | $Xsed -e "$basename"` # Clear the reloadable object creation command queue and # initialize k to one. test_cmds= concat_cmds= objlist= last_robj= k=1 if test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "$with_gnu_ld" = yes; then output=${output_objdir}/${output_la}.lnkscript func_verbose "creating GNU ld script: $output" $ECHO 'INPUT (' > $output for obj in $save_libobjs do $ECHO "$obj" >> $output done $ECHO ')' >> $output delfiles="$delfiles $output" elif test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "X$file_list_spec" != X; then output=${output_objdir}/${output_la}.lnk func_verbose "creating linker input file list: $output" : > $output set x $save_libobjs shift firstobj= if test "$compiler_needs_object" = yes; then firstobj="$1 " shift fi for obj do $ECHO "$obj" >> $output done delfiles="$delfiles $output" output=$firstobj\"$file_list_spec$output\" else if test -n "$save_libobjs"; then func_verbose "creating reloadable object files..." output=$output_objdir/$output_la-${k}.$objext eval test_cmds=\"$reload_cmds\" func_len " $test_cmds" len0=$func_len_result len=$len0 # Loop over the list of objects to be linked. for obj in $save_libobjs do func_len " $obj" func_arith $len + $func_len_result len=$func_arith_result if test "X$objlist" = X || test "$len" -lt "$max_cmd_len"; then func_append objlist " $obj" else # The command $test_cmds is almost too long, add a # command to the queue. if test "$k" -eq 1 ; then # The first file doesn't have a previous command to add. eval concat_cmds=\"$reload_cmds $objlist $last_robj\" else # All subsequent reloadable object files will link in # the last one created. eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj~\$RM $last_robj\" fi last_robj=$output_objdir/$output_la-${k}.$objext func_arith $k + 1 k=$func_arith_result output=$output_objdir/$output_la-${k}.$objext objlist=$obj func_len " $last_robj" func_arith $len0 + $func_len_result len=$func_arith_result fi done # Handle the remaining objects by creating one last # reloadable object file. All subsequent reloadable object # files will link in the last one created. test -z "$concat_cmds" || concat_cmds=$concat_cmds~ eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\" if test -n "$last_robj"; then eval concat_cmds=\"\${concat_cmds}~\$RM $last_robj\" fi delfiles="$delfiles $output" else output= fi if ${skipped_export-false}; then func_verbose "generating symbol list for \`$libname.la'" export_symbols="$output_objdir/$libname.exp" $opt_dry_run || $RM $export_symbols libobjs=$output # Append the command to create the export file. test -z "$concat_cmds" || concat_cmds=$concat_cmds~ eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\" if test -n "$last_robj"; then eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\" fi fi test -n "$save_libobjs" && func_verbose "creating a temporary reloadable object file: $output" # Loop through the commands generated above and execute them. save_ifs="$IFS"; IFS='~' for cmd in $concat_cmds; do IFS="$save_ifs" $opt_silent || { func_quote_for_expand "$cmd" eval "func_echo $func_quote_for_expand_result" } $opt_dry_run || eval "$cmd" || { lt_exit=$? # Restore the uninstalled library and exit if test "$mode" = relink; then ( cd "$output_objdir" && \ $RM "${realname}T" && \ $MV "${realname}U" "$realname" ) fi exit $lt_exit } done IFS="$save_ifs" if test -n "$export_symbols_regex" && ${skipped_export-false}; then func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' func_show_eval '$MV "${export_symbols}T" "$export_symbols"' fi fi if ${skipped_export-false}; then if test -n "$export_symbols" && test -n "$include_expsyms"; then tmp_export_symbols="$export_symbols" test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols" $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"' fi if test -n "$orig_export_symbols"; then # The given exports_symbols file has to be filtered, so filter it. func_verbose "filter symbol list for \`$libname.la' to tag DATA exports" # FIXME: $output_objdir/$libname.filter potentially contains lots of # 's' commands which not all seds can handle. GNU sed should be fine # though. Also, the filter scales superlinearly with the number of # global variables. join(1) would be nice here, but unfortunately # isn't a blessed tool. $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter delfiles="$delfiles $export_symbols $output_objdir/$libname.filter" export_symbols=$output_objdir/$libname.def $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols fi fi libobjs=$output # Restore the value of output. output=$save_output if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then eval libobjs=\"\$libobjs $whole_archive_flag_spec\" test "X$libobjs" = "X " && libobjs= fi # Expand the library linking commands again to reset the # value of $libobjs for piecewise linking. # Do each of the archive commands. if test "$module" = yes && test -n "$module_cmds" ; then if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then cmds=$module_expsym_cmds else cmds=$module_cmds fi else if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then cmds=$archive_expsym_cmds else cmds=$archive_cmds fi fi fi if test -n "$delfiles"; then # Append the command to remove temporary files to $cmds. eval cmds=\"\$cmds~\$RM $delfiles\" fi # Add any objects from preloaded convenience libraries if test -n "$dlprefiles"; then gentop="$output_objdir/${outputname}x" generated="$generated $gentop" func_extract_archives $gentop $dlprefiles libobjs="$libobjs $func_extract_archives_result" test "X$libobjs" = "X " && libobjs= fi save_ifs="$IFS"; IFS='~' for cmd in $cmds; do IFS="$save_ifs" eval cmd=\"$cmd\" $opt_silent || { func_quote_for_expand "$cmd" eval "func_echo $func_quote_for_expand_result" } $opt_dry_run || eval "$cmd" || { lt_exit=$? # Restore the uninstalled library and exit if test "$mode" = relink; then ( cd "$output_objdir" && \ $RM "${realname}T" && \ $MV "${realname}U" "$realname" ) fi exit $lt_exit } done IFS="$save_ifs" # Restore the uninstalled library and exit if test "$mode" = relink; then $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $? if test -n "$convenience"; then if test -z "$whole_archive_flag_spec"; then func_show_eval '${RM}r "$gentop"' fi fi exit $EXIT_SUCCESS fi # Create links to the real library. for linkname in $linknames; do if test "$realname" != "$linkname"; then func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?' fi done # If -module or -export-dynamic was specified, set the dlname. if test "$module" = yes || test "$export_dynamic" = yes; then # On all known operating systems, these are identical. dlname="$soname" fi fi ;; obj) if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then func_warning "\`-dlopen' is ignored for objects" fi case " $deplibs" in *\ -l* | *\ -L*) func_warning "\`-l' and \`-L' are ignored for objects" ;; esac test -n "$rpath" && \ func_warning "\`-rpath' is ignored for objects" test -n "$xrpath" && \ func_warning "\`-R' is ignored for objects" test -n "$vinfo" && \ func_warning "\`-version-info' is ignored for objects" test -n "$release" && \ func_warning "\`-release' is ignored for objects" case $output in *.lo) test -n "$objs$old_deplibs" && \ func_fatal_error "cannot build library object \`$output' from non-libtool objects" libobj=$output func_lo2o "$libobj" obj=$func_lo2o_result ;; *) libobj= obj="$output" ;; esac # Delete the old objects. $opt_dry_run || $RM $obj $libobj # Objects from convenience libraries. This assumes # single-version convenience libraries. Whenever we create # different ones for PIC/non-PIC, this we'll have to duplicate # the extraction. reload_conv_objs= gentop= # reload_cmds runs $LD directly, so let us get rid of # -Wl from whole_archive_flag_spec and hope we can get by with # turning comma into space.. wl= if test -n "$convenience"; then if test -n "$whole_archive_flag_spec"; then eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" reload_conv_objs=$reload_objs\ `$ECHO "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'` else gentop="$output_objdir/${obj}x" generated="$generated $gentop" func_extract_archives $gentop $convenience reload_conv_objs="$reload_objs $func_extract_archives_result" fi fi # Create the old-style object. reload_objs="$objs$old_deplibs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test output="$obj" func_execute_cmds "$reload_cmds" 'exit $?' # Exit if we aren't doing a library object file. if test -z "$libobj"; then if test -n "$gentop"; then func_show_eval '${RM}r "$gentop"' fi exit $EXIT_SUCCESS fi if test "$build_libtool_libs" != yes; then if test -n "$gentop"; then func_show_eval '${RM}r "$gentop"' fi # Create an invalid libtool object if no PIC, so that we don't # accidentally link it into a program. # $show "echo timestamp > $libobj" # $opt_dry_run || eval "echo timestamp > $libobj" || exit $? exit $EXIT_SUCCESS fi if test -n "$pic_flag" || test "$pic_mode" != default; then # Only do commands if we really have different PIC objects. reload_objs="$libobjs $reload_conv_objs" output="$libobj" func_execute_cmds "$reload_cmds" 'exit $?' fi if test -n "$gentop"; then func_show_eval '${RM}r "$gentop"' fi exit $EXIT_SUCCESS ;; prog) case $host in *cygwin*) func_stripname '' '.exe' "$output" output=$func_stripname_result.exe;; esac test -n "$vinfo" && \ func_warning "\`-version-info' is ignored for programs" test -n "$release" && \ func_warning "\`-release' is ignored for programs" test "$preload" = yes \ && test "$dlopen_support" = unknown \ && test "$dlopen_self" = unknown \ && test "$dlopen_self_static" = unknown && \ func_warning "\`LT_INIT([dlopen])' not used. Assuming no dlopen support." case $host in *-*-rhapsody* | *-*-darwin1.[012]) # On Rhapsody replace the C library is the System framework compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'` finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'` ;; esac case $host in *-*-darwin*) # Don't allow lazy linking, it breaks C++ global constructors # But is supposedly fixed on 10.4 or later (yay!). if test "$tagname" = CXX ; then case ${MACOSX_DEPLOYMENT_TARGET-10.0} in 10.[0123]) compile_command="$compile_command ${wl}-bind_at_load" finalize_command="$finalize_command ${wl}-bind_at_load" ;; esac fi # Time to change all our "foo.ltframework" stuff back to "-framework foo" compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'` ;; esac # move library search paths that coincide with paths to not yet # installed libraries to the beginning of the library search list new_libs= for path in $notinst_path; do case " $new_libs " in *" -L$path/$objdir "*) ;; *) case " $compile_deplibs " in *" -L$path/$objdir "*) new_libs="$new_libs -L$path/$objdir" ;; esac ;; esac done for deplib in $compile_deplibs; do case $deplib in -L*) case " $new_libs " in *" $deplib "*) ;; *) new_libs="$new_libs $deplib" ;; esac ;; *) new_libs="$new_libs $deplib" ;; esac done compile_deplibs="$new_libs" compile_command="$compile_command $compile_deplibs" finalize_command="$finalize_command $finalize_deplibs" if test -n "$rpath$xrpath"; then # If the user specified any rpath flags, then add them. for libdir in $rpath $xrpath; do # This is the magic to use -rpath. case "$finalize_rpath " in *" $libdir "*) ;; *) finalize_rpath="$finalize_rpath $libdir" ;; esac done fi # Now hardcode the library paths rpath= hardcode_libdirs= for libdir in $compile_rpath $finalize_rpath; do if test -n "$hardcode_libdir_flag_spec"; then if test -n "$hardcode_libdir_separator"; then if test -z "$hardcode_libdirs"; then hardcode_libdirs="$libdir" else # Just accumulate the unique libdirs. case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) ;; *) hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" ;; esac fi else eval flag=\"$hardcode_libdir_flag_spec\" rpath="$rpath $flag" fi elif test -n "$runpath_var"; then case "$perm_rpath " in *" $libdir "*) ;; *) perm_rpath="$perm_rpath $libdir" ;; esac fi case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) testbindir=`${ECHO} "$libdir" | ${SED} -e 's*/lib$*/bin*'` case :$dllsearchpath: in *":$libdir:"*) ;; ::) dllsearchpath=$libdir;; *) dllsearchpath="$dllsearchpath:$libdir";; esac case :$dllsearchpath: in *":$testbindir:"*) ;; ::) dllsearchpath=$testbindir;; *) dllsearchpath="$dllsearchpath:$testbindir";; esac ;; esac done # Substitute the hardcoded libdirs into the rpath. if test -n "$hardcode_libdir_separator" && test -n "$hardcode_libdirs"; then libdir="$hardcode_libdirs" eval rpath=\" $hardcode_libdir_flag_spec\" fi compile_rpath="$rpath" rpath= hardcode_libdirs= for libdir in $finalize_rpath; do if test -n "$hardcode_libdir_flag_spec"; then if test -n "$hardcode_libdir_separator"; then if test -z "$hardcode_libdirs"; then hardcode_libdirs="$libdir" else # Just accumulate the unique libdirs. case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) ;; *) hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" ;; esac fi else eval flag=\"$hardcode_libdir_flag_spec\" rpath="$rpath $flag" fi elif test -n "$runpath_var"; then case "$finalize_perm_rpath " in *" $libdir "*) ;; *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;; esac fi done # Substitute the hardcoded libdirs into the rpath. if test -n "$hardcode_libdir_separator" && test -n "$hardcode_libdirs"; then libdir="$hardcode_libdirs" eval rpath=\" $hardcode_libdir_flag_spec\" fi finalize_rpath="$rpath" if test -n "$libobjs" && test "$build_old_libs" = yes; then # Transform all the library objects into standard objects. compile_command=`$ECHO "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` finalize_command=`$ECHO "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` fi func_generate_dlsyms "$outputname" "@PROGRAM@" "no" # template prelinking step if test -n "$prelink_cmds"; then func_execute_cmds "$prelink_cmds" 'exit $?' fi wrappers_required=yes case $host in *cygwin* | *mingw* ) if test "$build_libtool_libs" != yes; then wrappers_required=no fi ;; *cegcc) # Disable wrappers for cegcc, we are cross compiling anyway. wrappers_required=no ;; *) if test "$need_relink" = no || test "$build_libtool_libs" != yes; then wrappers_required=no fi ;; esac if test "$wrappers_required" = no; then # Replace the output file specification. compile_command=`$ECHO "X$compile_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'` link_command="$compile_command$compile_rpath" # We have no uninstalled library dependencies, so finalize right now. exit_status=0 func_show_eval "$link_command" 'exit_status=$?' # Delete the generated files. if test -f "$output_objdir/${outputname}S.${objext}"; then func_show_eval '$RM "$output_objdir/${outputname}S.${objext}"' fi exit $exit_status fi if test -n "$compile_shlibpath$finalize_shlibpath"; then compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command" fi if test -n "$finalize_shlibpath"; then finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command" fi compile_var= finalize_var= if test -n "$runpath_var"; then if test -n "$perm_rpath"; then # We should set the runpath_var. rpath= for dir in $perm_rpath; do rpath="$rpath$dir:" done compile_var="$runpath_var=\"$rpath\$$runpath_var\" " fi if test -n "$finalize_perm_rpath"; then # We should set the runpath_var. rpath= for dir in $finalize_perm_rpath; do rpath="$rpath$dir:" done finalize_var="$runpath_var=\"$rpath\$$runpath_var\" " fi fi if test "$no_install" = yes; then # We don't need to create a wrapper script. link_command="$compile_var$compile_command$compile_rpath" # Replace the output file specification. link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'` # Delete the old output file. $opt_dry_run || $RM $output # Link the executable and exit func_show_eval "$link_command" 'exit $?' exit $EXIT_SUCCESS fi if test "$hardcode_action" = relink; then # Fast installation is not supported link_command="$compile_var$compile_command$compile_rpath" relink_command="$finalize_var$finalize_command$finalize_rpath" func_warning "this platform does not like uninstalled shared libraries" func_warning "\`$output' will be relinked during installation" else if test "$fast_install" != no; then link_command="$finalize_var$compile_command$finalize_rpath" if test "$fast_install" = yes; then relink_command=`$ECHO "X$compile_var$compile_command$compile_rpath" | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g'` else # fast_install is set to needless relink_command= fi else link_command="$compile_var$compile_command$compile_rpath" relink_command="$finalize_var$finalize_command$finalize_rpath" fi fi # Replace the output file specification. link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'` # Delete the old output files. $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname func_show_eval "$link_command" 'exit $?' # Now create the wrapper script. func_verbose "creating $output" # Quote the relink command for shipping. if test -n "$relink_command"; then # Preserve any variables that may affect compiler behavior for var in $variables_saved_for_relink; do if eval test -z \"\${$var+set}\"; then relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command" elif eval var_value=\$$var; test -z "$var_value"; then relink_command="$var=; export $var; $relink_command" else func_quote_for_eval "$var_value" relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" fi done relink_command="(cd `pwd`; $relink_command)" relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"` fi # Quote $ECHO for shipping. if test "X$ECHO" = "X$SHELL $progpath --fallback-echo"; then case $progpath in [\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";; *) qecho="$SHELL `pwd`/$progpath --fallback-echo";; esac qecho=`$ECHO "X$qecho" | $Xsed -e "$sed_quote_subst"` else qecho=`$ECHO "X$ECHO" | $Xsed -e "$sed_quote_subst"` fi # Only actually do things if not in dry run mode. $opt_dry_run || { # win32 will think the script is a binary if it has # a .exe suffix, so we strip it off here. case $output in *.exe) func_stripname '' '.exe' "$output" output=$func_stripname_result ;; esac # test for cygwin because mv fails w/o .exe extensions case $host in *cygwin*) exeext=.exe func_stripname '' '.exe' "$outputname" outputname=$func_stripname_result ;; *) exeext= ;; esac case $host in *cygwin* | *mingw* ) func_dirname_and_basename "$output" "" "." output_name=$func_basename_result output_path=$func_dirname_result cwrappersource="$output_path/$objdir/lt-$output_name.c" cwrapper="$output_path/$output_name.exe" $RM $cwrappersource $cwrapper trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 func_emit_cwrapperexe_src > $cwrappersource # The wrapper executable is built using the $host compiler, # because it contains $host paths and files. If cross- # compiling, it, like the target executable, must be # executed on the $host or under an emulation environment. $opt_dry_run || { $LTCC $LTCFLAGS -o $cwrapper $cwrappersource $STRIP $cwrapper } # Now, create the wrapper script for func_source use: func_ltwrapper_scriptname $cwrapper $RM $func_ltwrapper_scriptname_result trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15 $opt_dry_run || { # note: this script will not be executed, so do not chmod. if test "x$build" = "x$host" ; then $cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result else func_emit_wrapper no > $func_ltwrapper_scriptname_result fi } ;; * ) $RM $output trap "$RM $output; exit $EXIT_FAILURE" 1 2 15 func_emit_wrapper no > $output chmod +x $output ;; esac } exit $EXIT_SUCCESS ;; esac # See if we need to build an old-fashioned archive. for oldlib in $oldlibs; do if test "$build_libtool_libs" = convenience; then oldobjs="$libobjs_save $symfileobj" addlibs="$convenience" build_libtool_libs=no else if test "$build_libtool_libs" = module; then oldobjs="$libobjs_save" build_libtool_libs=no else oldobjs="$old_deplibs $non_pic_objects" if test "$preload" = yes && test -f "$symfileobj"; then oldobjs="$oldobjs $symfileobj" fi fi addlibs="$old_convenience" fi if test -n "$addlibs"; then gentop="$output_objdir/${outputname}x" generated="$generated $gentop" func_extract_archives $gentop $addlibs oldobjs="$oldobjs $func_extract_archives_result" fi # Do each command in the archive commands. if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then cmds=$old_archive_from_new_cmds else # Add any objects from preloaded convenience libraries if test -n "$dlprefiles"; then gentop="$output_objdir/${outputname}x" generated="$generated $gentop" func_extract_archives $gentop $dlprefiles oldobjs="$oldobjs $func_extract_archives_result" fi # POSIX demands no paths to be encoded in archives. We have # to avoid creating archives with duplicate basenames if we # might have to extract them afterwards, e.g., when creating a # static archive out of a convenience library, or when linking # the entirety of a libtool archive into another (currently # not supported by libtool). if (for obj in $oldobjs do func_basename "$obj" $ECHO "$func_basename_result" done | sort | sort -uc >/dev/null 2>&1); then : else $ECHO "copying selected object files to avoid basename conflicts..." gentop="$output_objdir/${outputname}x" generated="$generated $gentop" func_mkdir_p "$gentop" save_oldobjs=$oldobjs oldobjs= counter=1 for obj in $save_oldobjs do func_basename "$obj" objbase="$func_basename_result" case " $oldobjs " in " ") oldobjs=$obj ;; *[\ /]"$objbase "*) while :; do # Make sure we don't pick an alternate name that also # overlaps. newobj=lt$counter-$objbase func_arith $counter + 1 counter=$func_arith_result case " $oldobjs " in *[\ /]"$newobj "*) ;; *) if test ! -f "$gentop/$newobj"; then break; fi ;; esac done func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj" oldobjs="$oldobjs $gentop/$newobj" ;; *) oldobjs="$oldobjs $obj" ;; esac done fi eval cmds=\"$old_archive_cmds\" func_len " $cmds" len=$func_len_result if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then cmds=$old_archive_cmds else # the command line is too long to link in one step, link in parts func_verbose "using piecewise archive linking..." save_RANLIB=$RANLIB RANLIB=: objlist= concat_cmds= save_oldobjs=$oldobjs oldobjs= # Is there a better way of finding the last object in the list? for obj in $save_oldobjs do last_oldobj=$obj done eval test_cmds=\"$old_archive_cmds\" func_len " $test_cmds" len0=$func_len_result len=$len0 for obj in $save_oldobjs do func_len " $obj" func_arith $len + $func_len_result len=$func_arith_result func_append objlist " $obj" if test "$len" -lt "$max_cmd_len"; then : else # the above command should be used before it gets too long oldobjs=$objlist if test "$obj" = "$last_oldobj" ; then RANLIB=$save_RANLIB fi test -z "$concat_cmds" || concat_cmds=$concat_cmds~ eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\" objlist= len=$len0 fi done RANLIB=$save_RANLIB oldobjs=$objlist if test "X$oldobjs" = "X" ; then eval cmds=\"\$concat_cmds\" else eval cmds=\"\$concat_cmds~\$old_archive_cmds\" fi fi fi func_execute_cmds "$cmds" 'exit $?' done test -n "$generated" && \ func_show_eval "${RM}r$generated" # Now create the libtool archive. case $output in *.la) old_library= test "$build_old_libs" = yes && old_library="$libname.$libext" func_verbose "creating $output" # Preserve any variables that may affect compiler behavior for var in $variables_saved_for_relink; do if eval test -z \"\${$var+set}\"; then relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command" elif eval var_value=\$$var; test -z "$var_value"; then relink_command="$var=; export $var; $relink_command" else func_quote_for_eval "$var_value" relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" fi done # Quote the link command for shipping. relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"` if test "$hardcode_automatic" = yes ; then relink_command= fi # Only create the output if not a dry run. $opt_dry_run || { for installed in no yes; do if test "$installed" = yes; then if test -z "$install_libdir"; then break fi output="$output_objdir/$outputname"i # Replace all uninstalled libtool libraries with the installed ones newdependency_libs= for deplib in $dependency_libs; do case $deplib in *.la) func_basename "$deplib" name="$func_basename_result" eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` test -z "$libdir" && \ func_fatal_error "\`$deplib' is not a valid libtool archive" newdependency_libs="$newdependency_libs $libdir/$name" ;; *) newdependency_libs="$newdependency_libs $deplib" ;; esac done dependency_libs="$newdependency_libs" newdlfiles= for lib in $dlfiles; do case $lib in *.la) func_basename "$lib" name="$func_basename_result" eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` test -z "$libdir" && \ func_fatal_error "\`$lib' is not a valid libtool archive" newdlfiles="$newdlfiles $libdir/$name" ;; *) newdlfiles="$newdlfiles $lib" ;; esac done dlfiles="$newdlfiles" newdlprefiles= for lib in $dlprefiles; do case $lib in *.la) # Only pass preopened files to the pseudo-archive (for # eventual linking with the app. that links it) if we # didn't already link the preopened objects directly into # the library: func_basename "$lib" name="$func_basename_result" eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` test -z "$libdir" && \ func_fatal_error "\`$lib' is not a valid libtool archive" newdlprefiles="$newdlprefiles $libdir/$name" ;; esac done dlprefiles="$newdlprefiles" else newdlfiles= for lib in $dlfiles; do case $lib in [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; *) abs=`pwd`"/$lib" ;; esac newdlfiles="$newdlfiles $abs" done dlfiles="$newdlfiles" newdlprefiles= for lib in $dlprefiles; do case $lib in [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; *) abs=`pwd`"/$lib" ;; esac newdlprefiles="$newdlprefiles $abs" done dlprefiles="$newdlprefiles" fi $RM $output # place dlname in correct position for cygwin tdlname=$dlname case $host,$output,$installed,$module,$dlname in *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;; esac $ECHO > $output "\ # $outputname - a libtool library file # Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION # # Please DO NOT delete this file! # It is necessary for linking the library. # The name that we can dlopen(3). dlname='$tdlname' # Names of this library. library_names='$library_names' # The name of the static archive. old_library='$old_library' # Linker flags that can not go in dependency_libs. inherited_linker_flags='$new_inherited_linker_flags' # Libraries that this one depends upon. dependency_libs='$dependency_libs' # Names of additional weak libraries provided by this library weak_library_names='$weak_libs' # Version information for $libname. current=$current age=$age revision=$revision # Is this an already installed library? installed=$installed # Should we warn about portability when linking against -modules? shouldnotlink=$module # Files to dlopen/dlpreopen dlopen='$dlfiles' dlpreopen='$dlprefiles' # Directory that this library needs to be installed in: libdir='$install_libdir'" if test "$installed" = no && test "$need_relink" = yes; then $ECHO >> $output "\ relink_command=\"$relink_command\"" fi done } # Do a symbolic link so that the libtool archive can be found in # LD_LIBRARY_PATH before the program is installed. func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?' ;; esac exit $EXIT_SUCCESS } { test "$mode" = link || test "$mode" = relink; } && func_mode_link ${1+"$@"} # func_mode_uninstall arg... func_mode_uninstall () { $opt_debug RM="$nonopt" files= rmforce= exit_status=0 # This variable tells wrapper scripts just to set variables rather # than running their programs. libtool_install_magic="$magic" for arg do case $arg in -f) RM="$RM $arg"; rmforce=yes ;; -*) RM="$RM $arg" ;; *) files="$files $arg" ;; esac done test -z "$RM" && \ func_fatal_help "you must specify an RM program" rmdirs= origobjdir="$objdir" for file in $files; do func_dirname "$file" "" "." dir="$func_dirname_result" if test "X$dir" = X.; then objdir="$origobjdir" else objdir="$dir/$origobjdir" fi func_basename "$file" name="$func_basename_result" test "$mode" = uninstall && objdir="$dir" # Remember objdir for removal later, being careful to avoid duplicates if test "$mode" = clean; then case " $rmdirs " in *" $objdir "*) ;; *) rmdirs="$rmdirs $objdir" ;; esac fi # Don't error if the file doesn't exist and rm -f was used. if { test -L "$file"; } >/dev/null 2>&1 || { test -h "$file"; } >/dev/null 2>&1 || test -f "$file"; then : elif test -d "$file"; then exit_status=1 continue elif test "$rmforce" = yes; then continue fi rmfiles="$file" case $name in *.la) # Possibly a libtool archive, so verify it. if func_lalib_p "$file"; then func_source $dir/$name # Delete the libtool libraries and symlinks. for n in $library_names; do rmfiles="$rmfiles $objdir/$n" done test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library" case "$mode" in clean) case " $library_names " in # " " in the beginning catches empty $dlname *" $dlname "*) ;; *) rmfiles="$rmfiles $objdir/$dlname" ;; esac test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i" ;; uninstall) if test -n "$library_names"; then # Do each command in the postuninstall commands. func_execute_cmds "$postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1' fi if test -n "$old_library"; then # Do each command in the old_postuninstall commands. func_execute_cmds "$old_postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1' fi # FIXME: should reinstall the best remaining shared library. ;; esac fi ;; *.lo) # Possibly a libtool object, so verify it. if func_lalib_p "$file"; then # Read the .lo file func_source $dir/$name # Add PIC object to the list of files to remove. if test -n "$pic_object" && test "$pic_object" != none; then rmfiles="$rmfiles $dir/$pic_object" fi # Add non-PIC object to the list of files to remove. if test -n "$non_pic_object" && test "$non_pic_object" != none; then rmfiles="$rmfiles $dir/$non_pic_object" fi fi ;; *) if test "$mode" = clean ; then noexename=$name case $file in *.exe) func_stripname '' '.exe' "$file" file=$func_stripname_result func_stripname '' '.exe' "$name" noexename=$func_stripname_result # $file with .exe has already been added to rmfiles, # add $file without .exe rmfiles="$rmfiles $file" ;; esac # Do a test to see if this is a libtool program. if func_ltwrapper_p "$file"; then if func_ltwrapper_executable_p "$file"; then func_ltwrapper_scriptname "$file" relink_command= func_source $func_ltwrapper_scriptname_result rmfiles="$rmfiles $func_ltwrapper_scriptname_result" else relink_command= func_source $dir/$noexename fi # note $name still contains .exe if it was in $file originally # as does the version of $file that was added into $rmfiles rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}" if test "$fast_install" = yes && test -n "$relink_command"; then rmfiles="$rmfiles $objdir/lt-$name" fi if test "X$noexename" != "X$name" ; then rmfiles="$rmfiles $objdir/lt-${noexename}.c" fi fi fi ;; esac func_show_eval "$RM $rmfiles" 'exit_status=1' done objdir="$origobjdir" # Try to remove the ${objdir}s in the directories where we deleted files for dir in $rmdirs; do if test -d "$dir"; then func_show_eval "rmdir $dir >/dev/null 2>&1" fi done exit $exit_status } { test "$mode" = uninstall || test "$mode" = clean; } && func_mode_uninstall ${1+"$@"} test -z "$mode" && { help="$generic_help" func_fatal_help "you must specify a MODE" } test -z "$exec_cmd" && \ func_fatal_help "invalid operation mode \`$mode'" if test -n "$exec_cmd"; then eval exec "$exec_cmd" exit $EXIT_FAILURE fi exit $exit_status # The TAGs below are defined such that we never get into a situation # in which we disable both kinds of libraries. Given conflicting # choices, we go for a static library, that is the most portable, # since we can't tell whether shared libraries were disabled because # the user asked for that or because the platform doesn't support # them. This is particularly important on AIX, because we don't # support having both static and shared libraries enabled at the same # time on that platform, so we default to a shared-only configuration. # If a disable-shared tag is given, we'll fallback to a static-only # configuration. But we'll never go from static-only to shared-only. # ### BEGIN LIBTOOL TAG CONFIG: disable-shared build_libtool_libs=no build_old_libs=yes # ### END LIBTOOL TAG CONFIG: disable-shared # ### BEGIN LIBTOOL TAG CONFIG: disable-static build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac` # ### END LIBTOOL TAG CONFIG: disable-static # Local Variables: # mode:shell-script # sh-indentation:2 # End: # vi:sw=2